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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
|
#include <iostream>
#include <iomanip>
using namespace std;
const int MAX=14;
const int LENGTH=57;
void line ();
void spaces ();
void board (int beadArray[MAX]);
void solidLine(int LENGTH);
void numbers1();
void numbers2();
void startArray(int beadArray[MAX]);
void printArray(int beadArray[MAX]);
void changingNum1(int beadArray[MAX]);
void changingNum2(int beadArray[MAX]);
int gameOver(int beadArray[MAX]);
int player(int chooseBin);
int chooseBin( int beadArray[MAX],int playerMove, int playerNumber);
int dropBeads(int beadArray[MAX],int playerNumber , int player( int playerNumber),int bin, int turnOver, int chooseBin(int beadArray[MAX], int playerMove, int playerNumber));
int main ()
{
int beadArray[MAX];
int winnerPlayer;
int highBin;
int lowBin;
int playerMove;
int playerNumber;
int bin=0;
int turnOver;
playerNumber=1;
board(beadArray);
winnerPlayer=gameOver(beadArray);
cout<<"here is the winner"<<winnerPlayer;
cout<<"\nPlayer 2 has"<<beadArray[13];
cout<<"\nPlayer 1 has"<<beadArray[6];
playerMove = chooseBin(beadArray, playerNumber);
dropBeads(beadArray, playerNumber,player(playerNumber), bin,turnOver, chooseBin(beadArray,playerMove,playerNumber));
}
void board ( int beadArray[MAX]) // Creates the game board
{
startArray(beadArray);
solidLine(LENGTH); //Produces the top solid line of the game board.
endl(cout);
numbers1(); //*****************************************************************
changingNum1( beadArray); //Produces the top row of numbered tiles as well as bead count per
solidLine(LENGTH); // tile. Produces the top section of the game board as well.
endl(cout); //*****************************************************************
numbers2(); //*****************************************************************
changingNum2( beadArray); //Produces the bottom row of numbered tiles as well as bead count
solidLine(LENGTH); //per tile. Produces the bottom section of the game board as well.
endl(cout); //*****************************************************************
}
/*********************************
Creates a dotted line 9 stars long
with 6 spaces inbetween
paramaters: none
return value: none
********************************/
void line () //Counts spaces inbetween stars
{
int count;
for(int group = 0; group<8; group++)
{
count = 0;
cout<<"*";
while (count<6)
{
cout<< ' ';
count++;
}
}
cout<<'*'<<endl;
}
void solidLine(int LENGTH) // Creates a solid line of stars
{
int count;
for(count=0; count< LENGTH; count++)
{
cout<<'*';
}
}
void numbers1() // creates first level of numbers from 0-6
{
int count;
line();
cout<<"* *";
//Goes from 0-6
for (count = 0; count<6; count++)
{
cout<<setw(4)<<count<<setw(3)<<"*";
}
cout<<" 6 *"<<endl;
for(count=0; count<2; count++)
{
line();
}
}
void numbers2() // Creates second level of numbers from 7-13
{
int count;
line();
cout<<"* 13 *";
//Goes from 0-6
for (count = 12; count>6; count--)
{
cout<<setw(4)<<count<<setw(3)<<"*";
}
cout<<" *"<<endl;
for(count=0; count<3; count++)
{
line();
}
}
void printArray(int beadArray[MAX]) //Function to print the array
{
for (int i=0; i<=13; i++) //Loop to print the beadArray
{
cout<<' '<<beadArray[i];
}
}
void changingNum1(int beadArray[MAX]) // creates first level of changing numbers from 0-6
{
int count;
cout<<"* *";
//Goes from 0-6
for (count = 0; count<7; count++)
{
cout<<setw(3)<<beadArray[count]<<setw(4)<<"*";
}
for(count=0; count<1; count++)
{
endl( cout);
line();
}
}
void changingNum2(int beadArray[MAX]) // creates second level of changing numbers from 7-13
{
int count;
//Goes from 7-13
for (count = 13; count>6; count--)
{
cout<<"*"<<setw(3)<<beadArray[count]<<setw(4);
}
cout<<" * *";
for(count=0; count<1; count++)
{
endl( cout);
line();
}
}
void startArray(int beadArray[MAX]) //Function that gives each bin a starting number of "4" and gives the end bins a value of "0".
{
for (int i=0; i<MAX; i++)
{
beadArray[i]=4;
}
beadArray[6]=0;
beadArray[13]=0;
}
int gameOver(int beadArray[MAX]) //Function determines if the game is over and if so, adds up leftover beads and adds them to the winners end bin.
{
int leftOver=0;
int endGame;
for (int i=0; beadArray[i]==0 && i<7; i++)
{
endGame=1;
cout<<"Congratulations! The winner is Player"<<endGame;
}
for (int i=8; beadArray[i]==0 && i<MAX; i++)
{
endGame=2;
cout<<"Congratulations! The winner is Player"<<endGame;
}
if (endGame==1)
{
for(int i=8; i<MAX; i++)
{
leftOver=beadArray[i]+leftOver;
}
beadArray[6]= beadArray[6]+leftOver;
}
if (endGame==2)
{
for(int i=0; i<6; i++)
{
leftOver=beadArray[i]+leftOver;
}
beadArray[13]= beadArray[13]+leftOver;
}
if(endGame!=1 || endGame!=2)
{
endGame=-1;
}
return endGame;
}
int chooseBin(int playerMove, int beadArray[MAX], int playerNumber) //Function that allows the player to choose the desired bin. Gives limitation to which bins can be chosen per player's turn.
{
int bin=0;
if ( playerNumber==1)
{
cout<<"Player 1, what bin number do you choose?";
cin>>bin;
}
if (bin>0&& bin<<6 && beadArray[bin]!=0)
{
cin>>bin;
beadArray[bin]=0;
}
else if(bin>6 && bin<0 && beadArray[bin]==0 )
{
cout<<"Number must be inbetween 1 - 5 and bin cannot be empty.";
}
if (playerNumber ==2)
{
cout<<"Player 2, what bin number do you choose?";
cin>>bin;
}
if (bin>7 &&bin<<13 && beadArray[bin]!=0)
{
cin>>bin;
beadArray[bin]=0;
}
else if(bin>13 && bin<7 && beadArray[bin]==0)
{
cout<<"Number must be inbetween 7 - 12 and cannot be empty.";
}
return playerNumber;
}
int player(int chooseBin) //function that determines what player's turn it is.
{
int playerNumber=0;
int turnOver=0;
if (changingNum1 ==0 && changingNum2==0)
{
if (turnOver==1 && playerNumber==1)
{
playerNumber=2;
turnOver=0;
}
else if(playerNumber==2 && turnOver==1)
{
playerNumber=1;
turnOver=0;
}
}
}
int dropBeads(int beadArray[MAX],int playerNumber , int player( int playerNumber),int bin, int turnOver, int chooseBin(int beadArray[MAX], int playerMove, int playerNumber)) //drops beads into next bins until it runs out of beads.
{
int hand; //Keeps beads that are picked up.
hand=beadArray[bin];
for(int i=0; i<=hand; i++)
{
while(playerNumber==1 && bin< 7 && bin>=0)
{
bin++;
beadArray[bin]=beadArray[bin]+1;
hand--;
player(chooseBin(beadArray[MAX],playerMove,playerNumber));
}
while (playerNumber==2 && bin>7 && bin<=13)
{
bin++;
beadArray[bin]=beadArray[bin]+1;
hand--;
}
}
}
|