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
|
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
class player
{ public:
player (int health);
void gethit ()
{
health=health-10;
cout << "lost ten health"<<" now has "<< health;
}
int health;
};
class baddy
{
public:
baddy (int health);
void gothit()
{
health=health-10;
cout << "lost ten health"<<" now has "<< health;
}
void ambush(player *playpoint)
{
playpoint->gethit();
}
int health;
};
int posx=10;
int posy=10;
char z='*';
char x=' ';
char b='^';
char u='!';
char brdray [20] [20] = { {z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,z},
{z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z}
};
void move ();
void getboard ();
void proximity (baddy &object1,player &object2,char *array ,int s, int j);
bool quit = false;
int loop =0;
int main()
{
player you (100);
baddy them(100);
brdray [5] [5] = u;
while (quit != true)
{
system ("cls");
getboard();
move();
char *array = &brdray[0][0];
proximity( them,you,array,20,20);
loop++;
if (loop==10)
{
cout << "do you want to quit? (y/n)";
char yn;
cin >> yn;
if (yn == 'y')
{
quit = true;
}
else if (yn=='n')
{
loop = 0;
}
}
}
return 0;
}
void getboard ()
{
for (int a=0;a<20;a++)
{
for (int b=0;b<20;b++)
cout<<brdray [a][b];
cout<<endl;
}
}
void move ()
{
int enter;
int a,e,i,o;
brdray [posx] [posy] = x;
a=posx;
i=posx;
e=posy;
o=posy;
a=a+1;
e=e+1;
i=i-1;
o=o-1;
cout << "enter 1,2,3, and 4 to move" <<endl;
cin >> enter;
switch (enter)
{
case 1:
if(brdray [a][posy]!='*')
posx=posx+1;
break;
case 2:
if (brdray [posx][o]!='*')
posy=posy-1;
break;
case 3:
if (brdray[posx][e]!='*')
posy=posy+1;
break;
case 4:
if (brdray [i][posy]!='*')
posx=posx-1;
break;
}
brdray [posx] [posy] = b;
}
void proximity (baddy &object1,player &object2,char *array ,int s, int j)
{
int n,m,k,l;
n=s;
m=j;
n=n+1;
m=m+1;
k=s;
l=j;
l=l-1;
k=k-1;
for (s=0;s<20;s++)
{
for (j=0;j<20;j++)
{
if (brdray [s] [j]=='^'&&brdray [s+1][j]=='!')
{
object2.ambush(&object1);
}
}
}
}
|