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 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
|
Write your question here.
[code]
#include <iostream>
#include "windows.h"
#include <time.h>
using namespace std;
//variables
const char HEIGHT = 16, WIDTH = 16;
const char enemy = 'X'; //fire enemy
const char enemy_2 = 'Y'; // water enemyy
const char enemy_3 = 'Z'; //earth wnemy
const char hero = 'P'; // player
const char treasure = 'T'; //treasures
char keys; //player input
char ans; // player answers
int score;
char exiting = 'x';
void Format()
{
cout<<"WELCOME TO THE DONGEON, TRAVELLER!"<<endl;
cout<<"_________________________________"<<endl<<endl;
cout<<"Please note that your score increases ad you walk more."<<endl;
cout<<"Your goal is to find the hidden trasures."<<endl;
cout<<"Try to move around in every spot. Dont be afraid."<<endl<<endl;
cout<<"Your SCORE :_"<<score<<endl;
//format for beginning of the game
}
struct enemyTypes
{
int x;
int y;
// enemy position
};
enemyTypes fireEnemy;
enemyTypes earthEnemy;
enemyTypes waterEnemy;
enemyTypes treasureEnemy;
//declare the enemy types. treasure included because need the positiomn to work the same way as enemies
void MazeArray (unsigned char maze[HEIGHT][WIDTH], int HEIGHT, int WIDTH){
for(int y=0 ; y< HEIGHT ; y++){
cout<<endl;
for(int x=0; x< WIDTH ; x++){
cout<< maze[y][x];
}
}
//shows the array
}
unsigned char maze[WIDTH][HEIGHT] = {
//1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#', //1
'#',' ',' ','#',' ','#',' ','#','#',' ',' ',' ',' ',' ',' ','#', //2
'#',' ','#','#','#',' ',' ',' ',' ',' ','#',' ',' ',' ','#','#', //3
'#',' ',' ',' ',' ',' ',' ','#',' ','#',' ','#',' ','#',' ','#', //4
'#',' ',' ',' ',' ','#','#','#',' ','#',' ',' ','#','#',' ','#', //5
'#',' ','#','#','#','#','#','#',' ','#',' ',' ','#','#',' ','#', //6
'#',' ',' ',' ',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ','#', //7
'#',' ','#','#',' ','#',' ','#',' ',' ','#','#','#',' ',' ','#', //8
'#',' ',' ','#',' ',' ',' ','#',' ',' ','#',' ','#','#',' ','#', //9
'#',' ','#','#','#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#', //10
'#',' ','#',' ',' ',' ','#','#','#','#','#',' ','#','#','#','#', //11
'#',' ',' ',' ',' ','#',' ',' ',' ',' ','#',' ',' ',' ',' ','#', //12
'#','#','#',' ','#','#',' ','#','#',' ','#','#','#',' ',' ','#', //13
'#',' ',' ',' ',' ',' ',' ',' ','#',' ',' ',' ',' ',' ','#','#', //14
'#',' ',' ','#','#','#',' ',' ','#',' ','#','#',' ',' ',' ','#', //15
'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#', //16
//maze coordinates
};
struct movingHero{
int x;
int y;
};
movingHero player;
//declare structre of player
void playerProperties(){
player,x=1;
player,y=1;
maze[player,x][player,y]= hero;
//properties of player and position x and y and adds character to it
}
void clearScreen(){
system("CLS");
Format();
maze[player,x][player,y]= hero;
MazeArray (maze,HEIGHT,WIDTH);
//clears screen when hit enter then call the format function and adds in player in the maze
}
void addEnemies(){
srand(time(NULL));
fireEnemy,x=rand()%14;
fireEnemy,y=rand()%12;
earthEnemy,x=rand()%14;
earthEnemy,y=rand()%13;
waterEnemy,x=rand()%14;
waterEnemy,y=rand()%10+1;
maze[fireEnemy,x][fireEnemy,y]= enemy;
maze[earthEnemy,x][earthEnemy,y]= enemy_2;
maze[waterEnemy,x][waterEnemy,y]= enemy_3;
//adds enemies and rand postiomn
}
void replaceEnemies(){
srand(time(NULL));
maze[fireEnemy,x][fireEnemy,y]= ' ';
maze[earthEnemy,x][earthEnemy,y]= ' ';
maze[waterEnemy,x][waterEnemy,y]= ' ';
//places an enpty space in the spot of enemy when interacts with player
addEnemies();
clearScreen();
//function to replace all enemies once enemy is encountered
//triggered when enemy is attacked
}
void winFunction(){
treasure,x=rand()%14+1;
treasure,y=rand()%14+1;
//maze[treasure,x][treasure,y]=treasure
//treasure is invisible; hence player must LOOK FOR THE TREASURE
}
void elseIf(){
cout<<"You've attacked the monster! It teleports to another place. You gained 2 ponts!"<<endl;
system("PAUSE");
maze[player,x][player,y]= ' ';
player,x=rand()%14;
player,y=rand()%14;
clearScreen();
//pauses game>replaces player positon>calls clearscreen
}
void fireEnemy(){
cout<<"you've encountered a dragon monster and it is breathing fire!! What's your move?"<<endl;
cout<<"Shoot it ( * ) or Scare it away ( ~ )?"<<endl;
cin>>ans;
if(ans == '*')
{
cout<<"The creature is dead"<<endl;
score += 5;
cout<<"You earned 5 points. Now move along."<<endl;
system("PAUSE");
}
else if (ans == '~')
{
score -= 5;
cout<<"You were burned by the monster!"<<endl;
cout<<"You are injured. However, you managed to escape. You lost 5 points."<<endl;
system("PAUSE");
//fireEnemy function>ask player>add or minus points
}
}
void waterEnemy(){
cout<<"you've encountered a bee monster! It is trying to sting you! What's your move?"<<endl;
cout<<" Punch it! ( * ) or SCREAMMMM!! ( ~ )?"<<endl;
cin>>ans;
if(ans == '*')
{
cout<<"The creature got angrier! It stings you in the face!"<<endl;
score -= 2;
cout<<"You lost 2 points. Lesson learnt, NEVER PUNCH A BEE."<<endl;
system("PAUSE");
}
else if (ans == '~')
{
score += 5;
cout<<"The bee monster was shocked!"<<endl;
cout<<"To Bee or not to Bee? It carried you away to somewhere else. You earned 5 points."<<endl;
elseIf();
//beeEnemy function>ask player>add or minus points>if ans= ~ then player teleports
}
}
void answer(){
cout<<"The dungeon swallows you into the ground and brought you back to the start!";
score -= 10;
cout<<"Oops! 10points deducted."<<endl;
maze[player,x][player,y]= ' ';
system("PAUSE");
playerProperties();
clearScreen();
}
void earthEnemy(){
cout<<"The earthworm monster appears! What are you going to do?!"<<endl;
cout<<"Slash it with a katana ( * ) or Throw salt ( ~ )"
cin>>ans;
if(ans=='*')
{answer();
}
else if(ans == '~'){
score += 5;
cout<<"The monster's skin dries out into a pulp of its dehydrated flesh! Eww!"<<endl;
cout<<"You puked at the disgusting sight of it and left. You gained 5 points"<<endl;
}
//ask player>if * then player sent back to start point
}
void enemyAttack(movingHero a) {
// function to detect if player hits an enemy or treasure
if(maze[fireEnemy,x][fireEnemy,y]== maze[a,x][a,y]) {
FireEnemy();
replaceEnemies();
//so if enemy hits fire enemy, the FireEnemyy fucntion is called and player is asked a question>something happens depending on player's answer
//after this part, enemy is replaced/repositioned
}
if(maze[waterEnemy,x][waterEnemy,y]== maze[a,x][a,y]) {
WaterEnemy();
replaceEnemies();
}
if(maze[earthEnemy,x][earthEnemy,y]== maze[a,x][a,y]) {
EarthEnemy();
replaceEnemies();
}
if(maze[treasure,x][treasure,y]== maze[a,x][a,y]) {
cout<<"Something caught your attention..."<<endl;
cout<<"A metallic shine in the dark and you stepped closer..."<<endl;
cout<<"The thing that was shining is the treasure. YOU DID IT!"<<endl<<endl;
cout<<"The treasure is worth "<< score << "in gold"<<endl;
//treasure is worth player's score
system("PAUSE");
exit(1);
}
}
int main(){
Format();
addEnemies();
winFunction();
playerProperties();
MazeArray(maze, HEIGHT, WIDTH);
// calls back all functions
do{
enemyAttack(player);
//calls attack function detecting if player hhits enemy
cin>>keys;
switch(keys){
case 'd';
{
if(maze[player,x][player,y+1] != '#' )
{
maze[player,x][player,y]= ' ';
player,y++;
clearScreen();
score++;
}
break;
}
case 'a';
{
if(maze[player,x][player,y-1] != '#' )
{
maze[player,x][player,y]= ' ';
player,y--;
clearScreen();
score++;
}
break;
}
case 's';
{
if(maze[player,x+1][player,y] != '#' )
{
maze[player,x][player,y]= ' ';
player,x++;
clearScreen();
score++;
}
break;
}
case 'w';
{
if(maze[player,x-1][player,y] != '#' )
{
maze[player,x][player,y]= ' ';
player,x--;
clearScreen();
score++;
}
break;
}
}
}
while(exiting == 'x');
return 0;
}
|