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
|
#include<iostream>
using namespace std;
int top(int deck[], int stackTop);
bool isEmptyStack(int stackTop);
bool isFullStack(int stackTop);
void push (int deck[], int& stackTop, int card);
void pop (int deck[], int& stackTop);
int main()
{
int card;
int stackTop = 0;
int maxStackSize = 100;
int deck[maxStackSize];
cout <<"Start Game"<<endl;
int count1 = 0;
int count2 = 0;
cout <<"Player 1 -"<< count1 << endl;
cout <<"Player 2 -"<< count2 << endl;
push(deck, stackTop, card);
while(!isEmptyStack(stackTop))
{
for(int i=0; i>= maxStackSize; i++)
{
cout <<"Player 1 turn" << endl;
top(deck, stackTop);
cout <<"Player 1 draws -" << top(deck, stackTop) << endl;
if(top(deck,stackTop)==0)
{
count1 = count1 - 10;
cout <<"Turn over" << endl;
pop(deck, stackTop);
}
else if(top(deck,stackTop)==1
{
count1= count1 +1;
pop(deck,stackTop);
cout <<"Draw again"<< endl;
top(deck,stackTop);
}
else if(top(deck,stackTop)==2)
{
count1 = count1 +2;
pop(deck,stackTop);
push(deck,StackTop);
cout<<"Turn over" << endl;
}
else if(top(deck,stackTop)== 3)
{
count1 = count1 +3;
cout<<"Turn over" << endl;
pop(deck,stackTop);
}
else if(top(deck,stackTop)== 4)
{
count1 = count1 +4;
cout<<"Turn over" << endl;
pop(deck,stackTop);
}
else if(top(deck,stackTop)== 35)
{
count1 = count1 +5;
cout<<"Turn over" << endl;
pop(deck,stackTop);
}
else if(top(deck,stackTop)== 6)
{
count1 = count1 +6;
cout<<"Turn over" << endl;
pop(deck,stackTop);
}
else if(top(deck,stackTop)== 7)
{
count1 = count1 +7
cout<<"Turn over" << endl;
pop(deck,stackTop);
}
else if(top(deck,stackTop)== 8)
{
count1 = count1 +8;
cout<<"Turn over" << endl;
pop(deck,stackTop);
}
else if(top(deck,stackTop)== 9)
{
count1 = count1 +9;
cout<<"Turn over" << endl;
pop(deck,stackTop);
}
else if(top(deck,stackTop)== 10)
{
count1 = count1 +10;
cout<<"Turn over" << endl;
pop(deck,stackTop);
}
else
cout << "Invalid "<< endl;
}
return 0;
}
int top(int deck[], int stackTop)
{
if(stackTop != 0)
return deck[stackTop-1];
else
{
cout << "******** EMPTY STACK, nothing to return *********" << endl;
return -9999;
}
}
bool isEmptyStack(int stackTop)
{
return(stackTop==0);
}
bool isFullStack(int stackTop)
{
return(stackTop == maxStackSize);
}
void push(int deck[], int& stackTop, int card)
{
if(!isFullStack(stackTop))
{
card = rand() % 10 + 1
deck[stackTop] = card;
stackTop++;
}
else
cout <<"Cannot add to a full stack" << endl;
}
void pop(int stack[], int& stackTop)
{
if(!isEmptyStack(stackTop))
stackTop--;
else
cout <<"Cannot remove from an empty stack" << endl;
}
|