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
|
#include <iostream>
#include <string>
#include <conio.h>
#include <windows.h>
#include <cstdlib>
#include <time.h>
using namespace std;
bool inval=false;
class AllTheMoves
{
public:
//.......................
//.......................
void move(char fakechoice,string &fakeboard,int &fakecounter,int &fakemoves);
//.......................
//.......................
void outside(char fakechoice1,string fakeboard1,int &fakecounter1);
};
int main()
{
system("color 3a");
system("title Hepic Game");
cout<<"Put <q> when want to stop the game.\nTry to take them:<*>."<<endl;
Sleep(4000);
system("cls");
//Rules
//.......................
//.......................
string board="|@ |\n"
"| |\n"
"| |\n"
"| |\n"
"| |\n"
"| |\n"
"| |\n";
int counter=1;
int moves=0;
char choice;
bool play=true;
int score=0;
int food;
AllTheMoves m;
//.......................
//.......................
srand(time(NULL));
food=rand()%158+1;
while(food==0 || food==23 || food==46 || food==69 || food==92 ||food==115 || food==138 || food==21 || food==44 || food==67 || food==90 || food==113 || food==136 ||food==159
|| food==22 || food==45 || food==68 || food==91 || food==114 || food==139 ||food==162)
{
srand(time(NULL));
food=rand()%30+1;
}
board[food]='*';
while(play==true)
{
cout<<"\nWelcome in my game\n\n";
cout<<board;
cout<<"\nMoves:"<<moves<<endl;
cout<<"\nPosition:"<<counter<<endl;
cout<<"\nScore:"<<score<<endl;
if(board[food]=='@')
{
score++;
srand(time(NULL));
food=rand()%30+1;
//////////////////////
/////////////////////////
while(food==0 || food==23 || food==46 || food==69 || food==92 ||food==115 || food==138 || food==21 || food==44 || food==67 || food==90 || food==113 || food==136 ||food==159
|| food==22 || food==45 || food==68 || food==91 || food==114 || food==139 ||food==162)
{
srand(time(NULL));
food=rand()%30+1;
}
/////////////////////////
board[food]='*';
}
if(play==true)
{
cout<<"\nChooce:";
choice=getch();
cout<<endl;
}
////////////////////////////////
///////////////////////////////
m.outside(choice,board,counter);
inval=false;
m.move(choice,board,counter,moves);
/////////////////////////
counter++;
/////////////////////
Sleep(50);
system("cls");
////////////////////
if(choice==113)
{
play=false;
}
///////////////////
}
cout<<"\nYour score is:"<<score<<endl;
}
void AllTheMoves::move(char fakechoice,string &fakeboard,int &fakecounter,int &fakemoves)
{
if(fakechoice==100)
{
fakeboard[fakecounter]=' ';
fakeboard[fakecounter+1]='@';
fakemoves++;
}
//.......................
//.......................
else if(fakechoice==97)
{
fakeboard[fakecounter]=' ';
fakeboard[fakecounter-1]='@';
fakecounter-=2;
fakemoves++;
}
else if(fakechoice==119)
{
fakeboard[fakecounter]=' ';
fakeboard[fakecounter-23]='@';
fakecounter-=24;
fakemoves++;
}
else if(fakechoice==113)
{
cout<<"\nYou asked to stop the game.\n\n";
Sleep(2000);
}
else if(fakechoice==115)
{
fakeboard[fakecounter]=' ';
fakeboard[fakecounter+23]='@';
fakecounter+=22;
fakemoves++;
}
//.......................
//.......................
else
{
cout<<"\nInvalid Move\n";
fakecounter--;
inval=true;
Sleep(500);
}
}
void AllTheMoves::outside(char fakechoice1,string fakeboard1,int &fakecounter1)
{
if( (fakeboard1[1]=='@' && fakechoice1==97) || (fakeboard1[24]=='@' && fakechoice1==97)
|| (fakeboard1[47]=='@' && fakechoice1==97) || (fakeboard1[70]=='@' && fakechoice1==97)
|| (fakeboard1[93]=='@' && fakechoice1==97) || (fakeboard1[116]=='@' && fakechoice1==97)
|| (fakeboard1[139]=='@' && fakechoice1==97) )
{
cout<<"You can't go more left";
Sleep(500);
fakecounter1+=1;
}
else if( (fakeboard1[20]=='@' && fakechoice1==100) || (fakeboard1[43]=='@' && fakechoice1==100)
|| (fakeboard1[66]=='@' && fakechoice1==100) || (fakeboard1[89]=='@' && fakechoice1==100)
|| (fakeboard1[112]=='@' && fakechoice1==100) || (fakeboard1[135]=='@' && fakechoice1==100)
|| (fakeboard1[158]=='@' && fakechoice1==100) )
{
cout<<"You can't go more right";
Sleep(500);
fakecounter1-=1;
}
else if( (fakeboard1[1]=='@' && fakechoice1==119) || (fakeboard1[2]=='@' && fakechoice1==119)
|| (fakeboard1[3]=='@' && fakechoice1==119) || (fakeboard1[4]=='@' && fakechoice1==119)
|| (fakeboard1[5]=='@' && fakechoice1==119) || (fakeboard1[6]=='@' && fakechoice1==119)
|| (fakeboard1[7]=='@' && fakechoice1==119) || (fakeboard1[8]=='@' && fakechoice1==119)
|| (fakeboard1[9]=='@' && fakechoice1==119) || (fakeboard1[10]=='@' && fakechoice1==119)
|| (fakeboard1[11]=='@' && fakechoice1==119) || (fakeboard1[12]=='@' && fakechoice1==119)
|| (fakeboard1[13]=='@' && fakechoice1==119) || (fakeboard1[14]=='@' && fakechoice1==119)
|| (fakeboard1[15]=='@' && fakechoice1==119) || (fakeboard1[16]=='@' && fakechoice1==119)
|| (fakeboard1[17]=='@' && fakechoice1==119) || (fakeboard1[18]=='@' && fakechoice1==119)
|| (fakeboard1[19]=='@' && fakechoice1==119) || (fakeboard1[20]=='@' && fakechoice1==119) )
{
cout<<"You can't go more up";
Sleep(500);
fakecounter1+=23;
}
else if( (fakeboard1[139]=='@' && fakechoice1==115) || (fakeboard1[140]=='@' && fakechoice1==115)
|| (fakeboard1[141]=='@' && fakechoice1==115) || (fakeboard1[142]=='@' && fakechoice1==115)
|| (fakeboard1[143]=='@' && fakechoice1==115) || (fakeboard1[144]=='@' && fakechoice1==115)
|| (fakeboard1[145]=='@' && fakechoice1==115) || (fakeboard1[146]=='@' && fakechoice1==115)
|| (fakeboard1[147]=='@' && fakechoice1==115) || (fakeboard1[148]=='@' && fakechoice1==115)
|| (fakeboard1[149]=='@' && fakechoice1==115) || (fakeboard1[150]=='@' && fakechoice1==115)
|| (fakeboard1[151]=='@' && fakechoice1==115) || (fakeboard1[152]=='@' && fakechoice1==115)
|| (fakeboard1[153]=='@' && fakechoice1==115) || (fakeboard1[154]=='@' && fakechoice1==115)
|| (fakeboard1[155]=='@' && fakechoice1==115) || (fakeboard1[156]=='@' && fakechoice1==115)
|| (fakeboard1[157]=='@' && fakechoice1==115) || (fakeboard1[158]=='@' && fakechoice1==115) )
{
cout<<"You can't go more down";
Sleep(500);
fakecounter1-=23;
}
}
|