-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgames.cpp
69 lines (62 loc) · 1.66 KB
/
games.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
58
59
60
61
62
63
64
65
66
67
68
69
#include "games.h"
#include <QTime>
#include <QIcon>
#include "pile.h"
#include <QList>
games::games(QWidget* parent)
{
setParent(parent);
}
games::~games(){
for(int i = 0; i<104; i++){
deck[i] = NULL;
}
}
void games::shuffle(card *deck[], int n){
QTime time = QTime::currentTime();
qsrand((uint)time.msec());
for(int i = 0; i<52*n;i++ ){
int r = qrand()%52;
card *temp = deck[i];
deck[i] = deck[r];
deck[r] = temp;
}
}
void games::generateDeck(){
//char* suit[] = {'c','d', 'h', 's'};
pips pip[] = {ACE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING};
for(int i = 0; i<13;i++ ){
deck[i] = new card(pip[i], CLUBS, i,i,parentWidget());
deck[i]->piles = &piles;
deck[i]->setHistory(&history);
deck[i]->setImage();
deck[i]->show();
}
for(int i = 13; i<26;i++ ){
deck[i] = new card(pip[i-13], DIAMONDS, i,i,parentWidget());
deck[i]->piles = &piles;
deck[i]->setHistory(&history);
deck[i]->setImage();
deck[i]->show();
}
for(int i = 26; i<39;i++ ){
deck[i] = new card( pip[i-26], HEARTS, i,i,parentWidget());
deck[i]->piles = &piles;
deck[i]->setHistory(&history);
deck[i]->setImage();
deck[i]->show();
}
for(int i = 39; i<52 ;i++ ){
deck[i] = new card(pip[i-39], SPADES, i,i,parentWidget());
deck[i]->piles = &piles;
deck[i]->setHistory(&history);
deck[i]->setImage();
deck[i]->show();
}
}
void games::pushMove(Move m){
history.push(m);
}
QStack<Move>* games::getMoves(){
return &history;
}