-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcardgame.cpp
123 lines (110 loc) · 2.78 KB
/
cardgame.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "cardgame.h"
#include "ui_cardgame.h"
#include "pile.h"
#include "card.h"
#include "freecell.h"
#include "spider.h"
#include "klondike.h"
#include "helpdialog.h"
#include "aboutdialog.h"
#include <QMessageBox>
#include <QIcon>
CardGame::CardGame(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::CardGame)
{
ui->setupUi(this);
QPixmap icon = QPixmap::fromImage(QImage(":/icon.png"));
this->setWindowIcon(QIcon(icon));
this->setWindowTitle("Solitaire");
card::Initialize();
}
CardGame::~CardGame()
{
piles.clear();
delete ui;
}
void CardGame::on_action_Redeal_triggered()
{
if(game){
game->redeal();
}
}
void CardGame::on_action_Freecell_triggered()
{
if(game){
game->clear();
// game->~games();
}
game = new freecell(ui->centralWidget);
game->generateDeck();
game->setUp();
}
void CardGame::on_action_Spider_triggered()
{
if(game){
game->clear();
//game->~games();
}
game = new spider(ui->centralWidget);
game->generateDeck();
game->setUp();
}
void CardGame::on_action_Klondike_triggered()
{
if(game){
game->clear();
// game->~games();
}
game = new klondike(ui->centralWidget);
game->generateDeck();
game->setUp();
}
void CardGame::on_action_About_triggered()
{
AboutDialog *aDialog = new AboutDialog(this);
aDialog->setWindowIcon(QIcon(QPixmap::fromImage(QImage(":/info.png"))));
aDialog->setWindowTitle("About");
aDialog->show();
}
card* CardGame:: getCard(int id, Pile* on){
for(int i = 0; i< on->getSize(); i++){
if(on->getCards()[i]->getId() == id){
return on->getCards()[i];
}
}
return NULL;
}
void CardGame::on_action_Undo_triggered()
{
if(game){
if(game->getMoves()){
if(!game->getMoves()->empty()){
Move m = game->getMoves()->pop();
for(int i=0;i<m.getCards()->size();i++){
int id = m.getCards()->value(i);
card* c = getCard(id,m.getTo());
if(m.getCardFaceDown()!=200){
if(m.getCardFaceDown()!= m.getCards()->value(0)){
card* cFaceDown = getCard(m.getCardFaceDown(),m.getFrom());
cFaceDown->setFaceDown();
cFaceDown->setImage();
}else{
card* cFaceDown = getCard(m.getCardFaceDown(),m.getTo());
cFaceDown->setFaceDown();
cFaceDown->setImage();
}
}
m.getTo()->take(c);
m.getFrom()->put(c);
}
}
}
}
}
void CardGame::on_action_Help_triggered()
{
HelpDialog *hd = new HelpDialog(this);
hd->setWindowTitle("Help");
hd->show();
}