-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeck.cpp
More file actions
59 lines (51 loc) ยท 1.52 KB
/
deck.cpp
File metadata and controls
59 lines (51 loc) ยท 1.52 KB
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
#include "deck.h"
Deck::Deck(Hwatoo* card) { // Constructor
for (int i = 0; i < number_of_card_; i++) {
card_list_.push_back(card[i]);
}
}
void Deck::distributeCard() {
// 2๋ฒ ๋ฐ๋ณตํ์ฌ ๋ฐ๋ฅ์๋ 6์ฅ(3์ฅ์ฉ ๋๋ฒ), ํ๋ ์ด์ด๋ 7์ฅ์ฉ(4์ฅ,3์ฅ)
// ๋์๊ฐ๋๋ก ํ๋ค.
int count = 4;
// std::cout << "distribute" << std::endl;
for (int i = 0; i < 2; i++) { // ๋๋ฒ์ ๊ฑธ์ณ ๋๋ ์ค๋ค.
for (int i = 0; i < 3; i++) { // ๋ฐ๋ฅ์ 6์ฅ : 3์ฅ์ฉ ๋๋ฒ
Hwatoo card = deck_list_.front();
deck_list_.pop();
floor.addCard(card);
}
for (int i = 0; i < count; i++) {
Hwatoo card = deck_list_.front(); // player1 ์๊ฒ 4์ฅ, 3์ฅ
deck_list_.pop();
player1.addCard(card);
card = deck_list_.front(); // player2 ์๊ฒ 4์ฅ, 3์ฅ
deck_list_.pop();
player2.addCard(card);
card = deck_list_.front(); // player3 ์๊ฒ 4์ฅ, 3์ฅ
deck_list_.pop();
player3.addCard(card);
}
count--;
}
}
void Deck::gameStart() { // ๊ฒ์ ์์ ์ ์นด๋ ์๊ธฐ + deck(queue)์ ๋ฃ๊ธฐ +
// ์นด๋ ๋ถ๋ฐฐ( ๋ฐ๋ฅ, ํ๋ ์ด์ด)
cardShuffle();
inputDeck();
distributeCard();
}
void Deck::cardShuffle() { // ์นด๋ ์๊ธฐ
srand((unsigned)time(NULL));
for (int i = 0; i < number_of_card_; i++) {
int random = rand() % (number_of_card_);
Hwatoo temp = card_list_.at(i);
card_list_.at(i) = card_list_.at(random);
card_list_.at(random) = temp;
}
}
void Deck::inputDeck() { // ์นด๋ ๋ฆฌ์คํธ๋ฅผ ๋ฑ์ ๋ฃ๊ธฐ
for (Hwatoo value : card_list_) {
deck_list_.push(value);
}
}