| CODE |
#include <cstdlib> #include <string> #include <iostream> using namespace std; void position(int charX, int charY); //displays users position int move(int charX, int charY, char moveDir, bool XY); //makes player move, cin function, etc. bool checkCoOrd(int charX, int charY); //checks to see if any events are at that Co-Ordinate int encounter(int charX, int charY); //decides what event is at the current co-ordinate, if any. string ENCOUNTER(int encNum); //decides some more what event is at the current co-ordinate, if any. int main() { int charX, charY, encNum; bool XY = false; bool run = true; bool check; char moveDir; string player; string encounterVar; cout << "Hello, welcome to this game.\n\n"; cout << "\tPlease enter your name: "; cin >> player; cout << "\n\n"; charX = 0; charY = 0; while(run != false) { cout << "\n\tPlease enter a direction (W,A,S,D), enter 'Q' to quit: "; cin >> moveDir; cout << "\n\n"; if(moveDir == 'Q') { run = false; return 0; } charX = move(charX, charY, moveDir, XY); XY = true; charY = move(charX, charY, moveDir, XY); XY = false; position(charX, charY); check = checkCoOrd(charX, charY); encNum = encounter(charX, charY); encounterVar = ENCOUNTER(encNum); if(check == true) { cout << "You have encountered " << encounterVar << endl; } } system("PAUSE"); return 0; } void position(int charX, int charY) { cout << "Your position is: " << charX << ", " << charY << ".\n\n"; } int move(int charX, int charY, char moveDir, bool XY) { if(XY == false) { switch(moveDir) { case 'A' : charX = (charX - 1); break; case 'D' : charX = (charX + 1); break; } return charX; } else { switch(moveDir) { case 'W' : charY = (charY + 1); break; case 'S' : charY = (charY - 1); break; } return charY; } } bool checkCoOrd(int charX, int charY) { if((charX == 3 && charY == 4) || (charX == 2 && charY == 8)) { return true; } } int encounter(int charX, int charY) { int num; if((charX == 3 && charY == 4) || (charX == 2 && charY == 8)) { if(charX == 3 && charY == 4) { num = 1; } else if(charX == 2 && charY == 8) { num = 2; } } return num; } string ENCOUNTER(int encNum) { string str; if(encNum == 1 || encNum == 2) { if(encNum == 1) { str = "Goblin"; return str; } else if(encNum ==2) { str = "Dragon"; return str; } } } |
| CODE |
#include <cstdlib> #include <string> #include "RPGfuncts.hpp" #include <iostream> using namespace std; int main() { int charX, charY, encNum, fight; bool XY = false, run = true, check2 = false, alive = true, check; char moveDir, action, talkAct; string player; string encVar; cout << "Hello, welcome to this game.\n\n"; cout << "\tPlease enter your name: "; cin >> player; cout << "\n\n"; charX = 0; charY = 0; while(run != false) { cout << "\n\tPlease enter a direction (W,A,S,D), enter 'Q' to quit: "; cin >> moveDir; cout << "\n\n"; if(moveDir == 'Q') { run = false; return 0; } charX = move(charX, charY, moveDir, XY); XY = true; charY = move(charX, charY, moveDir, XY); XY = false; position(charX, charY); check = checkCoOrd(charX, charY); encNum = encounter(charX, charY); encVar = ENCOUNTER(encNum); if(check == true) { cout << "You have encountered a " << encVar << ".\n\n"; action = event(encNum); switch(action) { case 'A' : Attack(encVar, player); break; case 'T' : fight = Talk(encVar, player, talkAct, charX, charY, check2); break; case 'R' : charX = Run(encVar, charX, charY, check2); check2 = true; charY = Run(encVar, charX, charY, check2); cout << "\nYou have run away!\n\n"; position(charX, charY); check2 = false; break; } } if(fight == 2) { cout << "\n\t\tPrepare to FIGHT!\n\n\n"; alive = Attack(encVar, player); } if(alive == false) { cout << player << " is dead.\n\n"; cout << "\t\t!GAME OVER!\n\n\n"; } } system("PAUSE"); return 0; } |
| CODE |
#include <cstdlib> #include <string> #include <iostream> using namespace std; // ---------------------------------------------------------------------------------------------- /* ********************* DECLARATIONS DECLARATIONS DECLARATIONS DECLARATIONS ***************** */ // ---------------------------------------------------------------------------------------------- void position(int charX, int charY); //displays users position char event(int encNum); //performs actions on encounters, fighting, etc. int move(int charX, int charY, char moveDir, bool XY); //makes player move, cin function, etc. bool checkCoOrd(int charX, int charY); //checks to see if any events are at that Co-Ordinate int encounter(int charX, int charY); //decides what event is at the current co-ordinate, if any. string ENCOUNTER(int encNum); //decides some more what event is at the current co-ordinate, if any. bool Attack(string encVar, string player); //attack function (fight target) int Talk(string encVar, string player, char talkAct, int charX, int charY, bool check2); //talk function (speak to target) int Run(string encVar, int charX, int charY, bool check2); //run function (run away, duh) // --------------------------------------------------------------------------------------- /* **********************FUNCTIONS FUNCTIONS FUNCTIONS FUNCTIONS*********************** */ // --------------------------------------------------------------------------------------- void position(int charX, int charY) { cout << "Your position is: " << charX << ", " << charY << ".\n\n"; } int move(int charX, int charY, char moveDir, bool XY) { if(XY == false) { switch(moveDir) { case 'A' : charX = (charX - 1); break; case 'D' : charX = (charX + 1); break; } return charX; } else { switch(moveDir) { case 'W' : charY = (charY + 1); break; case 'S' : charY = (charY - 1); break; } return charY; } } bool checkCoOrd(int charX, int charY) { if((charX == 3 && charY == 4) || (charX == 2 && charY == 8)) { return true; } } int encounter(int charX, int charY) { int num; if((charX == 3 && charY == 4) || (charX == 2 && charY == 8)) { if(charX == 3 && charY == 4) { num = 1; } else if(charX == 2 && charY == 8) { num = 2; } } return num; } string ENCOUNTER(int encNum) { string str; if(encNum == 1 || encNum == 2) { if(encNum == 1) { str = "Goblin"; return str; } else if(encNum ==2) { str = "Dragon"; return str; } } } char event(int encNum) { char action; string creature; if(encNum == 1) { creature = "Goblin"; } else if(encNum == 2) { creature = "Dragon"; } cout << "\tA - Attack " << creature << ".\n"; cout << "\tT - Talk to " << creature << ".\n"; cout << "\tR - Run away from " << creature << ".\n\n"; cout << "Choose an action: "; cin >> action; switch(action) { case 'A' : cout << "\n\n"; return action; break; case 'T' : cout << "\n\n"; return action; break; case 'R' : cout << "\n\n"; return action; break; default : cout << "\n\nYou did not enter a valid action.\n\n"; break; } } bool Attack(string encVar, string player) { int playLife = 100, playAttack = 30; //set player stats int enemLife, enemAttack; char AtkDef; bool enemLive = true, charLive = true; cout << "\tFight between " << player << " and " << encVar << "!!!!\n\n"; if(encVar == "Goblin") { //set goblin stats enemLife = 100; enemAttack = 20; } else if(encVar == "Dragon") { //set dragon stats enemLife = 150; enemAttack = 25; } while(charLive != false && enemLive != false) { cout << "\tA - Attack\n"; cout << "\tD - Defend\n\n"; cout << "Attack or Defend? "; cin >> AtkDef; if(AtkDef == 'A') { cout << "\n\n" << player << " attacks " << encVar << " and causes " << playAttack << " damage.\n\n"; enemLife = (enemLife - playAttack); if(enemLife > 0) { cout << "\tThe " << encVar << " is now at " << enemLife << " health!\n\n"; } else if(enemLife < 1) { cout << "\tThe " << encVar << " is dead!\n\n"; cout << "\t***YOU WIN!***\n\n\n"; } if(enemLife > 0) { cout << encVar << " counter attacks, causing " << enemAttack << " damage.\n\n"; playLife = (playLife - enemAttack); cout << "\tYour health is now at " << playLife << "!!\n\n"; } } else if(AtkDef == 'D') { cout << player << " enters a defensive stance!\n\n"; cout << encVar << " attacks " << player << "!!\n\n"; cout << encVar << " does half damage because player is in defence -\n\n"; cout << encVar << " does " << (enemAttack / 2) << " damage!\n\n"; playLife = (playLife - (enemAttack / 2)); cout << player << "'s health is increased by 10 health points because of defence mode.\n\n"; playLife = (playLife + 10); } if(playLife < 1) { charLive = false; } if(enemLife < 1) { enemLive = false; } if(charLive == true && enemLive == false) { return true; } else if(charLive == false && enemLive == true) { return false; } } } int Talk(string encVar, string player, char talkAct, int charX, int charY, bool check2) { int act; cout << encVar << ": Hello...\n\n"; cout << "\tH - 'Hello!'\n"; cout << "\tF - 'FIGHT ME!'\n"; cout << "\tK - *Kick " << encVar << " in crotch and run*\n"; cout << "\tR - *RUN!*\n\n"; cout << "Choose an action: "; cin >> talkAct; switch(talkAct) { case 'H' : act = 1; break; case 'F' : act = 2; break; case 'K' : act = 3; break; case 'R' : act = 4; charX = Run(encVar, charX, charY, check2); check2 = true; charY = Run(encVar, charX, charY, check2); cout << "\nYou have run away!\n\n"; position(charX, charY); check2 = false; break; } if(act == 4) { return 0; } switch(act) { case 1 : cout << "\n" << player << ": Hello there.\n\n"; break; case 3 : cout << "\n\t" << player << " kicks the " << encVar << " in the crotch and runs away!\n"; charX = Run(encVar, charX, charY, check2); check2 = true; charY = Run(encVar, charX, charY, check2); cout << "\nYou have run away!\n\n"; position(charX, charY); check2 = false; break; } if(act == 2) { return 2; } } int Run(string encVar, int charX, int charY, bool check2) { switch(check2) { case false : charX = (charX - 2); return charX; break; case true : charY = (charY - 4); return charY; break; } } |
| CODE |
| var = tolower(var); |