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
|
#include <iostream>
using namespace std;
void shuffleCards (int[], int& position);
void drawCards (int ocean[], int& oceanPos, int hand[], int& handSize, int &drawn );
void stealCards(int, int& [], int&, int& [], int&);
int main()
{
char yesNo = 'y';
while (yesNo == 'y') {
int ocean [32];
for (int i = 0; i < 32; i++) // initialize the deck
{
ocean [i] = 2 + rand() % 9;
}
// Declare variables
int oceanPos;
int playerHand [32];
int computerHand[32];
int playerSize = 0;
int computerSize = 0;
int drawn;
shuffleCards (ocean, oceanPos); //shuffles the card
for (int i = 0; i < 5; i++)
{
drawCards(ocean, oceanPos, playerHand, playerSize, drawn);
}
for (int i = 0; i < 5; i++)
{
drawCards(ocean, oceanPos, computerHand, computerSize, drawn);
}
cout << "Would you like to play again?";
cin >> yesNo;
}
return 0;
}
void shuffleCards (int ocean[], int& position)
{
int i;
int j;
int temp; // temporary storage
for (i = 0; i < 32; i++) {
j = 1 + rand() % 32;
temp = ocean[i]; // store in temp
ocean [i] = ocean[j]; // j fills the empty i
ocean [j] = temp; // temp(or i) goes to empty j.
}
position = 0;
}
void drawCards ( int ocean[], int& oceanPos, int hand[], int& handSize, int &drawn )
{
drawn = ocean[oceanPos];
handSize++; // increase the player's cards count
hand[handSize] = drawn; // make a room for the new card
oceanPos++;
}
int countRank ( int rank, int hand[], int handSize )
{
int i;
int count = 0;
for ( i = 0; i < handSize; i++ )
{
if ( hand[i] == rank )
{
count++;
}
}
return count;
}
void stealCards (int rank, int& from[], int& fromSize, int& to[], int& toSize )
{
for (int i = 0; i < fromSize; i++ )
{
if (from[i] == rank)
{
toSize++;
to[toSize] = rank;
fromSize--;
// how do you remove an array from fromSize?
}
}
}
|