-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chance.cpp
57 lines (48 loc) · 1.69 KB
/
Chance.cpp
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
#include "Chance.h"
Chance::Chance(Card **cards, ALLEGRO_BITMAP *image, ALLEGRO_BITMAP *button) : cards(cards), picked_cards(0){
ok_button = new Button*[1];
ok_button[0] = new Button(Question_pos_x_standard + (al_get_bitmap_width(image) / 2) - 40, Question_pos_y_standard + al_get_bitmap_height(image) - (al_get_bitmap_height(image) /6), Question_pos_x_standard + (al_get_bitmap_width(image) / 2) + 40, Question_pos_y_standard + al_get_bitmap_height(image) - (al_get_bitmap_height(image) /6) + 25, 1, "OK", button);
window = new Question(Question_pos_x_standard, Question_pos_y_standard, ok_button, 1, "", "", image);
suffle_cards();
}
int Chance::pick_card(){ //Returns id of card
char c[] = {"Chance"};
char a[] = {"Community Chest"};
if(picked_cards >= (ant_cards / 2)){
suffle_cards();
picked_cards = 0;
}
Card* temp = cards[picked_cards++];
if(temp == 0)
return 0;
while(temp->get_disabled())
temp = cards[++picked_cards];
if(temp->get_action() == 9 || temp->get_action() == 10)
temp->set_disabled(true);
//Chaning text in window
if(temp->get_type())
window->set_text(c, (temp->get_text()));
else
window->set_text(a, (temp->get_text()));
window->set_active(true);
return(temp->get_id());
}
void Chance::suffle_cards(){
srand(time(NULL));
Card *temp1;
for(int i = 0; i < (ant_cards / 2); i++){
int random_number = i + rand() % ((ant_cards / 2) - i);
temp1 = cards[i];
if(temp1->get_action() == 0)
temp1 = cards[0];
cards[i] = cards[random_number];
cards[random_number] = temp1;
}
}
void Chance::return_chance_card(){
for(int i = 0; i < (ant_cards / 2); i++){
if(cards[i]->get_action() == 9 || cards[i]->get_action() == 10){
cards[i]->set_disabled(false);
}
}
}