-
Notifications
You must be signed in to change notification settings - Fork 2
/
player.c
84 lines (76 loc) · 1.53 KB
/
player.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <stdlib.h>
#include "player.h"
void init_player(struct player *p)
{
p->health = 100; // could change, not sure about the value
mana_init(&p->manapool);
p->hand = (card_t*)malloc(NUM_OF_CARDS_IN_HAND * sizeof(card_t));
int i;
for(i = 0; i < 5; ++i) // the player draws five cards from the deck
{
p->hand[i] = draw_card(&p->deck);
}
}
void change_health(struct player *p, int hp, int modifier)
{
if(modifier == INCREASE)
{
p->health += hp;
}
else if(modifier == DECREASE)
{
p->health -= hp;
}
}
void print_health(struct player p)
{
printf("Player health: %d\n", p.health);
}
void print_hand(struct player p)
{
int i;
for(i = 0; i < NUM_OF_CARDS_IN_HAND; ++i)
{
if(p.hand[i].name != NULL && p.hand[i].name != "") // if the card is not "deleted" (played or whatever)
{
print_card(p.hand[i]);
}
}
}
// why should this return struct card_t ?
void play_card_from_hand(struct player *p, char *card_name)
{
// put the card with the name "card_name" on the field
int i;
for(i = 0; i < NUM_OF_CARDS_IN_HAND; ++i)
{
if(p->hand[i].name == card_name)
{
p->hand[i].name = "";
p->hand[i].life = 0;
p->hand[i].force = 0;
p->hand[i].cost = 0;
break;
}
}
}
void turn_begin(struct player *p)
{
int i;
for(i = 0; i < NUM_OF_CARDS_IN_HAND; ++i)
{
if(p->hand[i].name == NULL || p->hand[i].name == "") // finds an empty spot
{
if(p->deck.top <= 0)
{
printf("There are no more cards in the deck.\n");
}
else
{
p->hand[i] = draw_card(&p->deck);
}
break;
}
}
}