-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
212 lines (186 loc) · 6.7 KB
/
main.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include <iostream>
#include <vector>
#include "Player.h"
#include "Card.h"
#include "Deck.h"
#include "AI.h"
using namespace std;
constexpr auto WINNING_SCORE = 500;
//// Intro which includes rules for the game
//void outputIntro();
//
//// Outputs winner and ending
//void outputEnding(Player &player, AI &comp);
//
//// Deals the deck
//// Inserts a card into players hand, pops card off of the deck
//// then inserts a card into computer's hand and pops a card off
//// the deck. Continues till each player has a full hand
//void dealDeck(Player& player, AI& comp, Deck& deck, int count);
bool checkPlayerScores(vector<Player>& Players);
void main()
{
// Outputs the rules for the game
//outputIntro();
string name;
// Retrieve user's name and initialize the Player
cout << "\nEnter numebr of players: ";
getline(cin, name);
size_t numberOfPlayers = atoi(name.c_str());
if (numberOfPlayers < 2)
{
numberOfPlayers = 2;
}
else if (numberOfPlayers > 6)
{
numberOfPlayers = 6;
}
vector<Player> Players;
for (size_t i = 0; i < numberOfPlayers - 1; i++)
{
// Retrieve user's name and initialize the Player
cout << "\nEnter " << i + 1 << "'th players name: ";
getline(cin, name);
Players.push_back(Player(name, 0));
}
// Retrieve a name for the computer and initialize the computer
cout << "\nEnter a name for the computer: ";
getline(cin, name);
Players.push_back(AI(name, 0));
// initialize and shuffle up the deck
Deck* deck = new Deck(true, 2);
deck->ShuffleDeck();
size_t roundCount = 0;
//// Game continues as long as neither player has over WINNING_SCORE points
while (!checkPlayerScores(Players))
{
deck.
// deck.dealCards(Player a, AI b;)
// // Deal the deck
// dealDeck(user, comp, deck, roundCount);
// // Reset count back to roundCount --> alternate who goes first
// unsigned int count = roundCount;
// // Commence the game, game continues as long as both players have cards
// while ((user.GetHandSize() > 0) && (comp.GetHandSize() > 0) && (deck.GetDeckSize() > 0))
// {
// // Must call gameplay every play through the hand
// if (count % 2 == 0) // Player is up
// user.GamePlay(deck, comp.ReturnVectorOfMyMeldedCards(), comp.GetName());
// else // Computer is up
// comp.GamePlay(deck);
// count++;
// }
// // Round is over, must increment the round count
// roundCount++;
//}
//// Someone has won by now
//outputEnding(user, comp);
//return;
// }
//void outputIntro()
//{
// cout << "Welcome to Rummy 500!\n";
// cout << "Written by Austin Heimark\n\n";
//
// // List the rules
// cout << "RULES OF THE GAME:\n" <<
// "It is you versus the computer.\n" <<
// "First player to " << WINNING_SCORE << " points wins.\n" <<
// "Each player is dealt " << CARDS_DEALT << " cards of a standard \n" <<
// DECK_SIZE << " card deck each hand.\n" <<
// "User (you) goes first; this alternates each hand.\n" <<
// "Players earn points by melding \ncards from their hand into the meld area.\n" <<
// "Players may meld a set of \ncards once they have at least 3 of a kind\n" <<
// "(ex: 3 " << Rank(5) << "s) or 3 in a row \nof the same suit (ex: 4,5,6 of spades).\n" <<
// "Each turns starts with picking \nup a card, and ends by discarding a card.\n" <<
// "The hand continues until \none player has used all of their cards.\n" <<
// "Points are tallied at the end of each hand.\n" <<
// "Point per card are as follows:\n" <<
// Rank(0) + RANK_OFFSET << " ... " << Rank(8) + RANK_OFFSET << " --> " << TWO_THROUGH_NINE_POINTS << " points\n" <<
// Rank(9) + RANK_OFFSET << " ... " << Rank(11) + RANK_OFFSET << " --> " << TEN_THROUGH_KING_POINTS << " points\n" <<
// Rank(12) + RANK_OFFSET << " --> " << ACE_POINTS << " points. " <<
// "New hands keep being dealt \nuntil a player has over " << WINNING_SCORE << " points.\n" <<
// "If both players end with over " << WINNING_SCORE << "\npoints, player with more points wins.\n" <<
// "When you are prompted for card \n" <<
// "locations, it is zero based. That is\n" <<
// "if you want the first card from your hand\n" <<
// "you would enter '" << EMPTY << "'. If choosing multiple cards\n" <<
// "use one space between numbers.\n" <<
// "The first letter or number is the rank\n" <<
// "and after the dash is the suit of the card\n" <<
// "H = Hearts, S = Spades, D = Diamonds, C = Clubs.\n" <<
// "Please not that the face cards will not be sorted in your hand,\n" <<
// "However, the non face cards will be sorted!\n" <<
// "You must meld at least one card when you pick\nit up from the pick up pile\n" <<
// YES << " means 'Yes' when asked yes/no questions.\nAnything else will be interpreted as a no.\n" <<
// "When melding cards, always tell which cards you \nwant to meld from your hand in decreasing location order.\n" <<
// "And when telling the computer these meld spots, \nterminate your entries with a " << TERMINATE_NUMBER << ".\n";
//}
//
//void outputEnding(Player& player, Computer& comp)
//{
// cout << "Final Score:\n" << player.GetName() << ": " << player.GetScore() << "\n" << comp.GetName() << ": " << comp.GetScore() << "\n\n";
//
// // Whichever player has the higher score wins
// if (player.GetScore() >= comp.GetScore())
// cout << "Congratulations, " << player.GetName() << "! You beat the computer in Rummy 500!";
// else
// cout << "Sorry, " << comp.GetName() << " defeated you!";
//
// // Thanks to the players
// cout << "\n\nI hope you enjoyed my game!" <<
// "\nFeedback please to: [email protected]\n\n";
//}
//
//void dealDeck(Player& user, Computer& comp, Cards& deck, int count)
//{
// if (count % EVEN_ODD == EMPTY) // Deal to user first
// {
// unsigned int i = EMPTY;
// while (i < EVEN_ODD * CARDS_DEALT)
// {
// user.InsertIntoHand(deck.TopDeckCard());
// deck.PopOffCard();
// i++;
// comp.InsertIntoHand(deck.TopDeckCard());
// deck.PopOffCard();
// i++;
// }
// deck.AdjustPickPile();
// }
// else // Deal to computer first
// {
// unsigned int j = EMPTY;
// while (j < EVEN_ODD * CARDS_DEALT)
// {
// comp.InsertIntoHand(deck.TopDeckCard());
// deck.PopOffCard();
// j++;
// user.InsertIntoHand(deck.TopDeckCard());
// deck.PopOffCard();
// j++;
// }
// deck.AdjustPickPile();
// }
//}
//
//void ScoreOutput(Player& user, Computer& comp, int roundCount)
//{
// cout << "After " << roundCount << " rounds:\n" <<
// "Your current score: " << user.GetScore() << "\n" <<
// comp.GetName() << "'s current score: " << comp.GetScore() << "\n" <<
// "And the game continues...\n\n";
//}
}
}
bool checkPlayerScores(vector<Player>& Players)
{
for (size_t i = 0; i < Players.size(); i++)
{
if (Players[i].GetScore() > WINNING_SCORE)
{
return true;
}
}
return false;
}