-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartmenu.cpp
More file actions
129 lines (114 loc) · 3.76 KB
/
startmenu.cpp
File metadata and controls
129 lines (114 loc) · 3.76 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
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
124
125
126
127
128
129
#include "startmenu.h"
#include "gameview.h"
#include "finalgraph.h"
#include <QString>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QDebug>
/*
Function: StartMenu Constructor
Params: parent
Desc: Instantiates the start menu with necessary parts
Returns: none
*/
StartMenu::StartMenu(QWidget *parent)
{
GameView& game = GameView::GetInstance();
connect( &game, &GameView::onAIComplete, this, &StartMenu::UpdateGraph);
QLabel *title = new QLabel("DUNEALERT",this);
title->setAlignment(Qt::AlignHCenter);
QLabel *title2 = new QLabel("Use WASD to move around. During fights, press F to fight and B to bribe. To use an item, during fights press the corresponding numeric button.",this);
title2->setAlignment(Qt::AlignHCenter);
QPushButton *play_btn = new QPushButton("One Player", this);
QPushButton *two_play_btn = new QPushButton("Two Player", this);
QPushButton *ai = new QPushButton("Simulation", this);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(title);
layout->addWidget(title2);
layout->addWidget(play_btn);
layout->addWidget(two_play_btn);
layout->addWidget(ai);
QGraphicsScene *scene = new QGraphicsScene;
QGraphicsView *view = new QGraphicsView();
view->setScene(scene);
layout->addWidget(view);
wins_ = new FinalGraph(-50, 5, 5, Qt::GlobalColor::blue);
loses_ = new FinalGraph(-50, 50, 5, Qt::GlobalColor::red);
l = new QLabel("Games Played: 0");
layout->addWidget(l);
scene->addText("Wins Loses");
scene->addItem(wins_);
scene->addItem(loses_);
view->show();
connect(two_play_btn, SIGNAL(clicked()), this, SLOT(PlayTwoPlayer()));
connect(play_btn,SIGNAL(clicked()),this,SLOT(PlaySinglePlayer()));
connect(ai,SIGNAL(clicked()),this,SLOT(PlaySimulation()));
setLayout(layout);
}
/*
Function: play_single_player
Params: none
Desc: Calls the game view to create a new game in single player mode.
Returns: none
*/
void StartMenu::PlaySinglePlayer() {
close();
GameView& game = GameView::GetInstance();
game.SetMode(Mode::SinglePlayer);
game.CreateSinglePlayerOverWorld();
game.show();
}
/*
Function: play_two_player
Params: none
Desc: Calls the game view to create a new game in two player mode.
Returns: none
*/
void StartMenu::PlayTwoPlayer() {
close();
GameView& game = GameView::GetInstance();
game.SetMode(Mode::TwoPlayer);
game.CreateTwoPlayerOverWorld();
game.show();
}
/*
Function: play_simulation
Params: none
Desc: Plays one round of the simulation
Returns: none
*/
void StartMenu::PlaySimulation() {
//Each ai encounter lasts 30 seconds
int ai_duration = 30000;
GameView& game = GameView::GetInstance();
//After the ai_duration is over, the game ends and the score is tallied.
QTimer::singleShot(ai_duration, [=](){
GameView& game = GameView::GetInstance();
game.EndGame();
});
game.SetMode(Mode::Simulation);
game.CreateAIOverworld();
game.show();
}
/*
Function: UpdateGraph
Params: gold, final gold value in a game
Desc: Given the final gold value of a simulated game, calculates whether or not the ai could be considered winning, then updates the graph.
Returns: none
*/
void StartMenu::UpdateGraph(int gold) {
//If the simulated player ends with more than 0 gold count it as a win!
if (gold >= 0) {
win_count_ ++;
} else {
loss_count_ ++;
}
float base_height = 100;
int total_games = win_count_ + loss_count_;
wins_->setHeight(-(win_count_ / (loss_count_ + win_count_)) * base_height);
loses_->setHeight(-(loss_count_ / (loss_count_ + win_count_)) * base_height);
QString s = QString::fromStdString("Games Played: " + std::to_string(total_games));
l->setText(s);
// scene_->update();
}