-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
136 lines (115 loc) · 3.32 KB
/
Copy pathmain.cpp
File metadata and controls
136 lines (115 loc) · 3.32 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
130
131
132
133
134
135
136
#include <iostream>
#include <string>
#include <fstream>
#include <ctime>
#include <chrono>
#include "Deck.h"
#include "Card.h"
#include "Player.h"
#include "Dealer.h"
#include "Game.h"
string playerName;
int main(void){
srand(time(0));
Game game;
Deck *deck = new Deck();
int cardCounter = 0;
int choice;
int ctr=2;
int deal = 0;
int won=0,lost=0;
ofstream file;
auto game_begin = chrono::system_clock::to_time_t(chrono::system_clock::now());
cout << "What is your name?: ";
cin >> playerName;
Player player(playerName);
Dealer dealer;
deck->shuffle();
game.newDeal(deck, player, dealer, cardCounter);
bool ans=true;
while(ans){
cout << endl << "Twist (1)" << endl << "Stick (2)" << endl << "Exit (3)"<< endl;
do{
cin >> choice;
} while (!(choice > 0 && choice < 4));
switch (choice) {
case 1:{
player.addCard(deck->selectCard(cardCounter));
cardCounter++;
game.gameInfo(player, dealer);
if (game.whoWin(player, dealer) == (-2)) {
game.gameSummary(player, dealer);
cout << endl << "Dealer won" << endl << "You lost " << endl;
lost++;
cout << endl << "#NEW GAME#" << endl;
game.newDeal(deck, player, dealer, cardCounter);
deal++;
}
else if (game.whoWin(player, dealer) == 2) {
game.gameSummary(player, dealer);
cout << endl << "Dealer lost" << endl << "You win " << endl;
won++;
cout << endl <<"#NEW GAME#" << endl;
game.newDeal(deck, player, dealer, cardCounter);
deal++;
}
}break;
case 2:{
game.gameSummary(player, dealer);
if (game.whoWin(player, dealer) == 1){
cout << endl << "Winner!" << endl << "You win "<< endl;
won++;
cout << endl << "#NEW GAME#" << endl;
game.newDeal(deck, player, dealer, cardCounter);
deal++;
}
else if (game.whoWin(player, dealer) == 0){
cout << endl << "Tie!" << endl;
cout << endl << "#NEW GAME#" << endl;
game.newDeal(deck, player, dealer, cardCounter);
deal++;
}
else if (game.whoWin(player, dealer) == (-1)){
cout << endl << "Dealer won" << endl << "You lost " << endl;
lost++;
cout << endl << "#NEW GAME#" << endl;
game.newDeal(deck, player, dealer, cardCounter);
deal++;
}
else if (game.whoWin(player, dealer) == 3) {
game.gameSummary(player, dealer);
cout << endl << "Pontoon!" << endl << "You win " << endl;
won++;
cout << endl << "#NEW GAME#" << endl;
game.newDeal(deck, player, dealer, cardCounter);
deal++;
}
}break;
case 3:{
ans = false;
break;
}break;
}
}
auto game_end = chrono::system_clock::to_time_t(chrono::system_clock::now());
system("clear");
cout << "\n\nGame Started at"<<ctime(&game_begin)<<endl;
cout << "Game Ended at"<<ctime(&game_end)<<endl;
cout << "Rounds = "<<deal<<endl;
cout << "Won = "<<won<<endl;
cout << "Lost = "<<lost<<endl;
cout << "";
int random_number = rand()%10000000;
string filePath = "pontoon_";
filePath += std::to_string(random_number);
file.open (filePath+".txt");
file << "\n\nGame Started at"<<ctime(&game_begin)<<endl;
file << "Game Ended at"<<ctime(&game_end)<<endl;
file << "Rounds = "<<deal<<endl;
file << "Won = "<<won<<endl;
file << "Lost = "<<lost<<endl;
file << "";
file.close();
cout<<"Logs generated"<<endl;
system("clear");
}