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
|
#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;
int gameloop();
void gameload();
void descgetter();
void input();
void output();
void locationgetter();
void NPC();
void itemobtained();
int location = 10000;
int north, east, south, west, npc, gender, npctalk, amount;
int coppercoin, silvercoin, goldcoin;
int x = 100;
int y = 100;
string name;
string desc;
string item;
int main(){ // where the code starts
START: // come here if they enter a unacceptable answer
string option; // string for their input
cout << "Would you like to start a new game or load a previous one?" << endl;
cout << "[N]ew Game" << endl;
cout << "[L]oad Game" << endl;
cin >> option; // get our answer
if(option == "N" || "n" ) system("cls"); gameloop(); // if they choose to play a new one we go to the game loop
if(option == "L" || "l" ) system("cls"); gameload(); // if they choose to load we go to the laod menu
goto START; // otherwise we go back to the begging for a new answer
}
int gameloop(){ // here the game loops
int gameon = 0; // int for the loop
while(gameon == 0){ // while the gameon equals 0 we play the game
system("cls"); // here we clear the screen
locationgetter(); // get our location based of our x and y coords
descgetter(); // get our desc based off our location
output(); // here we output the desc to the player
input(); // now we get to see what the player has to say
}
return 0; // end the game when they exit the loop
}
void gameload(){ // here we can load a players previous game
}
void input(){ // here we get our players input
int loop = 0; // the int for the loop
while(loop == 0){ // while loop equals 0 we get input, we exit if they give us an answer
string input; // this is the strign that will hold their input
cin >> input; // now we get their input
if(input == "west" && west == 0) cout << "You can not move that way." << endl; // if they choose west but they cant go west the loop restarts
if(input == "north" && north == 0) cout << "You can not move that way." << endl; // if they choose north but they cant go north the loop restarts
if(input == "east" && east == 0) cout << "You can not move that way." << endl; // if they choose east but they cant go east the loop restarts
if(input == "south" && south == 0) cout << "You can not move that way." << endl; // if they choose south but they cant go south the loop restarts
if(input == "west" && west == 1){--x; loop = 1;} // if they succesfully go west we take away from x
if(input == "north" && north == 1){++y; loop = 1;} // if they succesfully go north we add to y
if(input == "east" && east == 1) {++x; loop = 1;} // if they succesfully go east we add to x
if(input == "south" && south == 1){--y; loop =1;} // if they succesfully go south we take away from y
if(input == "talk" && npc == 0)cout << "There is no one to talk to." << endl; // if they choose to talk and no one is there this happens
if(input == "talk" && npc == 1 && gender == 1)cout << "You move over to the man." << endl; NPC(); // if they choose to talk and it is a male this happens
if(input == "talk" && npc == 1 && gender == 0)cout << "You move over to the woman." << endl; // if they choose to talk and it is a female this happens
}
}
void output(){ // here we output to the screen
cout << desc << endl; // here we output the description
}
void itemobtained(){
system("cls");
system("color FE");
system("color EF");
system("color FE");
system("color EF");
system("color FE");
system("color EF");
system("color FE");
system("color EF");
system("color F6");
cout << "You have obtained " << amount << " " << item << "(s)!!!" << endl;
if(item == "gold coins"){goldcoin = goldcoin + amount;}
}
void NPC(){
int answer1;
if(npctalk == 1){
cout << "Hey der, meh names John. If ya be lookin' for Wenheinster Town just go up north." << endl;
cout << "\t[1] I don't have any money..." << endl;
cout << "\t[2] Thanks for the help, i'll be on my way now." << endl;
cin >> answer1;
if(answer1 == 1){
cout << "Well.. Here, take this, it a be 'nough for a weapon to defend youself." << endl;
system("pause");
item = "gold coins";
amount = 10;
itemobtained();
}
}
}
void locationgetter(){
if(x == 100 && y == 100) location = 1;
if(x == 99 && y == 101) location = 2;
if(x == 100 && y == 101)location = 3;
}
void descgetter(){
switch(location){
case 1: desc = "You are in a large orange room. You can move north, east, south, and west. A man can be seen in the corner."; west = 0; south = 0; east = 0; north = 1; npc = 1; gender = 1; npctalk = 1; break;
case 2: desc = "You are in a large blue room. You can move east."; west = 0; south = 0; east = 1; north = 0; npc = 0; gender = 2; npctalk = 0; break;
case 3: desc = "You are in a large grey room. You can move west and south."; west = 1; south = 1; east = 0; north = 0; npc = 0; gender = 2; npctalk = 0; break;
}
}
|