-
Notifications
You must be signed in to change notification settings - Fork 3
/
mainGame.cpp
152 lines (140 loc) · 4.76 KB
/
mainGame.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* mainGame.cpp
*
* Created on: Nov 26, 2017
* Author: lowji
*/
//created this source file to make the compiler work properly
#include <sstream>
#include <iostream>
#include <string>
#include "Player.h"
#include "ConsoleUI.h"
#include "Card.h"
#include "Deck.h"
#include "Board.h"
#include "helper.h"
int main(){
//set up user interface
ConsoleUI* ui = new ConsoleUI();
ui->welcome();
string inputTemp;
inputTemp = ui->input("Input your name: ");
Player* human = new Player(inputTemp);
Player* AI = new Player("AI");
helper* help=new helper();
inputTemp=ui->input("How much do you want to buy-in?");
while(!help->isInt(inputTemp)||stoi(inputTemp)<20){
ui->output("Invalid input. Input must be an integer equal or larger than 20");
inputTemp=ui->input("How much do you want to buy-in?");
}
human->setTotalChips(stoi(inputTemp));
AI->setTotalChips(stoi(inputTemp));
inputTemp=ui->input("How much do you want the small blind to be?");
while(!help->isInt(inputTemp)||stoi(inputTemp)<=0||stoi(inputTemp)>(human->getTotalChips()/20)){
ui->output("Invalid input.\nBlind must be a positive integer that is less than or equal to 5% of your chips.");
inputTemp=ui->input("How much do you want the small blind to be?");
}
ui->output("");
ui->output("Your name is "+human->getName());
ui->output("Your opponent name is "+AI->getName());
ui->output("");
//print table: your stack, small blind, big blind, pot(needs to make)
ui->output("================GAME BEGINS================\n");
Board* bd = new Board(human,AI,0);
bd->setBlind(stoi(inputTemp));
bool foldFlag;
int countRound=0;
while(human->getTotalChips() > 0 && AI->getTotalChips() > 0)
{
countRound++;
ui->output("---------------ROUND "+to_string(countRound)+" BEGIN------------\n");
foldFlag=false;
//bd->clearBoard();
ui->output("------------Begin Pre-flop---------------\n");
foldFlag=bd->preflop(); //returns true if folded
if (foldFlag){
//there's probably an easier way to do this
bd->clearBoard();
bd->printBoard();
inputTemp=ui->input("Do you want to continue?(Y/N) ");
while(inputTemp != "Y" && inputTemp != "N" && inputTemp != "y" && inputTemp != "n"){
ui->output("Please select Y or N");
inputTemp=ui->input("Do you want to continue?(Y/N) ");
}
if(inputTemp == "N" || inputTemp == "n")
{
break;
}
continue;
}
ui->output("------------Begin Flop---------------\n");
foldFlag=bd->flop();
if (foldFlag){
bd->clearBoard();
bd->printBoard();
inputTemp=ui->input("Do you want to continue?(Y/N) ");
while(inputTemp != "Y" && inputTemp != "N" && inputTemp != "y" && inputTemp != "n"){
ui->output("Please select Y or N");
inputTemp=ui->input("Do you want to continue?(Y/N) ");
}
if(inputTemp == "N" || inputTemp == "n")
{
break;
}
continue;
}
ui->output("--------------Begin Turn---------------\n");
foldFlag=bd->turn();
if (foldFlag){
bd->clearBoard();
bd->printBoard();
inputTemp=ui->input("Do you want to continue?(Y/N) ");
while(inputTemp != "Y" && inputTemp != "N" && inputTemp != "y" && inputTemp != "n"){
ui->output("Please select Y or N");
inputTemp=ui->input("Do you want to continue?(Y/N) ");
}
if(inputTemp == "N" || inputTemp == "n")
{
break;
}
continue;
}
ui->output("--------------Begin River---------------\n");
foldFlag=bd->river();
if (foldFlag){
bd->clearBoard();
bd->printBoard();
inputTemp=ui->input("Do you want to continue?(Y/N) ");
while(inputTemp != "Y" && inputTemp != "N" && inputTemp != "y" && inputTemp != "n"){
ui->output("Please select Y or N");
inputTemp=ui->input("Do you want to continue?(Y/N) ");
}
if(inputTemp == "N" || inputTemp == "n")
{
break;
}
continue;
}
bd->clearBoard();
bd->printBoard();
inputTemp=ui->input("Do you want to continue?(Y/N) ");
while(inputTemp != "Y" && inputTemp != "N" && inputTemp != "y" && inputTemp != "n"){
ui->output("Please select Y or N");
inputTemp=ui->input("Do you want to continue?(Y/N) ");
}
if(inputTemp == "N" || inputTemp == "n")
{
break;
}
ui->output("-----------------END OF ROUND "+to_string(countRound)+"---------------\n");
}
ui->output("You have played "+to_string(countRound)+" round(s).");
if(human->getTotalChips() > AI->getTotalChips()){
ui->output("Congratulations you have won $"+ to_string((human->getTotalChips() - AI->getTotalChips()) / 2)+" from our AI.");
}
else if(human->getTotalChips() <= 0)
ui->output("Unfortunately, you have lost all of your chips. Better luck next time!");
else
ui->output("You left the game with $"+to_string(human->getTotalChips())+ ".");
}