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
|
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctime>
using namespace std;
struct pos
{
int x;
int y;
};
struct Player1
{
bool UP;
bool RIGHT;
bool DOWN;
bool LEFT;
char symbol;
int LIVES;
int weapon;
int kills;
int deaths;
pos position;
void initPlayer1 ()
{
symbol = '@';
LIVES = 5;
weapon = 1;
kills = 0;
deaths = 0;
position.x = 1;
position.y = 1;
}
};
struct poss
{
int x;
int y;
};
struct EnemyNPC
{
int symboll;
int livesh;
int weaponn;
pos enemypos;
void initEnemyNPC ()
{
symboll = 'K';
livesh = 5;
weaponn = 2;
}
};
const int CLMN = 15;
int Gamespeed = 100;
void movePlayer1(Player1&, char[][CLMN], char, int, int, int&, int);
void menu (int);
void initBoard(char[][CLMN], int, int);
void showBoard(char[][CLMN], int, int);
void instructions();
void userOption (int);
void EnemyNPCPos (char[][CLMN], EnemyNPC, Player1, int, int);
void scoreBoard(Player1, int, int);
int main()
{
int opt;
const int MAX_LIVES = 5;
const int MIN_LIVES = 0;
const int HUNGER = 10;
const int RW = 15;
const int MAX_ACTIONS = 10;
int counterr = 0;
char board[RW][CLMN];
char movement;
cout << "\t\tWelcome \n"
<< "Will you choose play?\n\n"
<< endl;
cout << "1. play\n"
<< "2. quit\n"
<< "Enter your option (1 or 2): ";
cin >> opt;
userOption (opt);
switch (opt)
{
case 1:
cout << "EASY MODE\n" << endl;
EnemyNPC dead;
dead.initEnemyNPC();
Player1 zombiePlayer1;
zombiePlayer1.initPlayer1();
initBoard(board, RW, CLMN);
EnemyNPCPos (board, dead, zombiePlayer1, RW, CLMN);
board[zombiePlayer1.position.x][zombiePlayer1.position.y] = zombiePlayer1.symbol;
while(movement != 'q')
{
instructions();
showBoard(board, RW, CLMN);
scoreBoard(zombiePlayer1, counterr, MAX_ACTIONS);
cout << "Move your Player1" << endl;
cin >> movement;
movePlayer1(zombiePlayer1, board, movement, RW, CLMN, counterr, MAX_ACTIONS);
}
break;
case 2:
cout << "R.I.P.";
}
return 0;
}
void initBoard(char array[][CLMN], int rwSize, int clmnSize)
{
for(int rw = 0; rw < rwSize; rw++)
{
for(int clmn = 0; clmn < clmnSize; clmn++)
{
array[rw][clmn] = 250;
}
}
for(int clmn = 0; clmn < clmnSize; clmn++)
{
array[0][clmn] = 205;
array[rwSize-1][clmn] = 205;
}
for(int rw =0; rw < rwSize; rw++)
{
array[rw][0] = 186;
array[rw][clmnSize-1] = 186;
}
array[0][0] = 201;
array[0][clmnSize-1] = 187;
array[rwSize-1][0] = 200;
array[rwSize-1][clmnSize-1] = 188;
}
void showBoard(char array[][CLMN], int rwSize, int clmnSize)
{
cout << endl;
for(int rw = 0; rw < rwSize; rw++)
{
for(int clmn = 0; clmn < clmnSize; clmn++)
{
cout << array[rw][clmn];
}
cout << endl;
}
}
void movePlayer1(Player1& userposition, char arrays[][CLMN], char actions, int rw, int clmn, int& counter, int maxActions)
{
if(counter < maxActions)
{
if(actions == 's' && userposition.position.x < rw-2)
{
arrays[userposition.position.x][userposition.position.y] = 250;
userposition.position.x += 1;
arrays[userposition.position.x][userposition.position.y] = userposition.symbol;
counter++;
system("cls");
}
else if(actions == 'a' && userposition.position.y > 1)
{
arrays[userposition.position.x][userposition.position.y] = 250;
userposition.position.y -= 1;
arrays[userposition.position.x][userposition.position.y] = userposition.symbol;
counter++;
system("cls");
}
else if(actions == 'd' && userposition.position.y < clmn-2)
{
arrays[userposition.position.x][userposition.position.y] = 250;
userposition.position.y += 1;
arrays[userposition.position.x][userposition.position.y] = userposition.symbol;
counter++;
system("cls");
}
else if(actions == 'w' && userposition.position.x > 1)
{
arrays[userposition.position.x][userposition.position.y] = 250;
userposition.position.x -= 1;
arrays[userposition.position.x][userposition.position.y] = userposition.symbol;
counter++;
system("cls");
}
}
else if(actions == 'q')
{
cout << "\n\t\tTOO BAD!" << endl;
system("cls");
}
else
{
cout << "You've entered the wrong input" << endl;
system("cls");
}
if(counter == maxActions)
cout << "You have used up all your actions!\n";
}
void instructions()
{
cout << "Player1 Movement:\n"
<< "\t\tw = UP\n"
<< "\t\ta = LEFT\n"
<< "\t\ts = DOWN\n"
<< "\t\td = RIGHT\n"
<< "\t\tq = QUIT\n"<< endl;
}
void userOption (int option)
{
if(option != 1 || option != 2)
cout << "\nYou much choose to fight or face your doom\n";
}
void scoreBoard(Player1 userposition, int counter, int maxActions)
{
cout << "Kills: " << userposition.kills << endl;
cout << "Deaths: " << userposition.deaths << endl;
cout << "Ammo: " << userposition.ammo << endl;
cout << "Tuna of Lives cans: " << userposition.LIVES << endl;
cout << "Your move: " << counter << "/" << maxActions << endl;
}
void EnemyNPCPos (char arrays[][CLMN], EnemyNPC z, Player1 w, int rw, int clmn)
{
srand(time(0));
z.enemypos.x = rand() % 13 + 1;
z.enemypos.y = rand() % 13 + 1;
while(z.enemypos.x == w.position.x && z.enemypos.y == w.position.y && z.enemypos.x > rw-2 && z.enemypos.y < 1 && z.enemypos.y > clmn-2 && z.enemypos.x < 1)
{
z.enemypos.x = rand() % 13 + 1;
z.enemypos.y = rand() % 13 + 1;
}
arrays[z.enemypos.x][z.enemypos.y] = z.symboll;
}
|