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
|
#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&);
void removeCards(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 ) // transfers a card to another player
{
for (int i = 0; i < fromSize-1; )
{
if (from[i] == rank)
{
toSize++; // increase the size of an array
to[toSize] = rank; // the new card is being added to the hand
}
}
removeCards (int& from[], int&fromSize, int rank);
}
void removeCards (int& from[], int& fromSize, int rank ) // removes a card from a deck after it is given to the player.
{
for (int i =0; i < fromSize; i++)
{
if (from[i] == rank )
// shift each value one by one
for (int j = 0; j < fromSize - 1; j++)
{
from[i+j] = from [i+j+1];
}
fromSize--;
}
}
void checkSets (int rank, int hand[], int& handSize, int& score, char pronoun[])
{
int count = countRank (rank, hand, handSize);
if (count == 4)
{
// remove these values from an array
}
score++;
}
|