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
|
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
class baddy
{
public:
int givehit ()
{
bealth=bealth-10;
if (bealth<10)
{
cout << "you got the wanker"<<endl;
return 2;
}
}
int bealth;
string bame;
int battackpower;
int bosx;
int bosy;
char bad;
int bice;
};
class player
{
public:
void attack (baddy *e)
{
e->givehit();
}
int gethit ()
{
health=health-10;
if (health<10)
{
cout << "your dead innit"<<endl;
return 1;
}
}
int health;
string name;
int attackpower;
int dice;
char you;
};
int getrandom ();
void fight ();
char z = '*';
char x = ' ';
char brdray [10] [10] = { {z,z,z,z,z,z,z,z,z,z},
{z,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,z}, {z,z,z,z,z,z,z,z,z,z} };
int bosx=2;
int bosy=2;
char them = '!';
char you = 'O';
void start ();
void getbrd ();
void bdymove ();
void move ();
int posx = 5;
int posy = 5;
string enter;
int main ()
{
cout << "enter your name contender 1" <<endl;
cin >> enter;
system ("cls");
baddy estateagent;
estateagent.bame="barry";
estateagent.bealth=20;
player playa;
playa.name=enter;
playa.health=100;
start();
while (1)
{
getbrd();
move();
bdymove();
fight();
system ("CLS");
}
return 0;
}
void getbrd ()
{
for (int a = 0;a<10;a++)
{
for (int b =0;b<10;b++)
cout << brdray [a][b];
cout<<endl;
}
}
void move ()
{
int mv;
cout << "1 is up, 2 is down, 3 is left and 4 is right"<< endl;
cin >> mv;
char w;
char a,x,d,n;
brdray [posx] [posy] = x;
int chekposx = posx;
int chekposy = posy;
int chukposx=posx;
int chukposy=posy;
chekposx=chekposx-1;
chekposy=chekposy-1;
chukposx=chukposx+1;
chukposy=chukposy+1;
switch (mv)
{
case 1:
if (brdray[chekposx] [chekposy]!=z)
{posx=posx-1;}
break;
case 2:
if (brdray[chukposx] [chukposy]!=z)
{posx=posx+1;}
break;
case 3:
if (brdray[chekposx] [chekposy]!=z)
{posy=posy-1;}
break;
case 4:
if (brdray[chukposx] [chukposy]!=z)
{posy=posy+1;}
break;
}
brdray [posx] [posy] =you;
}
void start()
{
brdray [posx] [posy]=you;
brdray [bosx] [bosy]=them;
}
void bdymove ()
{
brdray [bosx] [bosy] = x;
if (posx>bosx)
{
bosx++;
}
if (posx<bosx)
{
bosx--;
}
if (posy>bosy)
{
bosy++;
}
if (posy<bosy)
{
bosy--;
}
brdray [bosx] [bosy]=them;
}
void fight ()
{
int hilo;
int randomnum;
randomnum=getrandom();
player *playpointer;
baddy *badpointer;
if (brdray [posx] [posy]==brdray [bosx] [bosy])
{
cout << "you must FIGHT!! 1 to block 2 to attack"<<endl;
cin >> hilo;
switch (hilo)
{
case 1:
cout << "you block his attack...";
if (hilo < randomnum)
cout <<"and hit him";
player.attack(&baddy);// i know each of these are different just i wanted to show my trains of thought
if (hilo > randomnum)
cout << "only to get hit when open";
baddy->givehit(player);//though i dont know what i was thinking here
break;
case 2:
cout << "you swing...";
if (hilo > randomnum)
cout << "and get the bastard";
playa.attack(&baddy); //i dont see why this doesnt work
if (hilo < randomnum)
cout << "you misss and he kicks you up the arse";
baddy->givehit(); //and here proves i have still not grasped the ->
break;
}
}
}
int getrandom ()
{
int number;
srand(time_t(0));
number=1+(rand()%6);
return number;
}
|