From cb033f1736cca83409d62577c72e321e8dc15d53 Mon Sep 17 00:00:00 2001 From: "Gloria Addo Mills (addomilg)" Date: Fri, 20 Mar 2020 17:44:07 +0000 Subject: [PATCH] Add files via upload --- ConsoleApplication1.cpp | 155 +++++++++++++++++++++++ Handhouse.cpp | 263 ++++++++++++++++++++++++++++++++++++++++ Looping.cpp | 59 +++++++++ Looping.h | 18 +++ Player.h | 28 +++++ PlayerOptions.h | 6 + 6 files changed, 529 insertions(+) create mode 100644 ConsoleApplication1.cpp create mode 100644 Handhouse.cpp create mode 100644 Looping.cpp create mode 100644 Looping.h create mode 100644 Player.h create mode 100644 PlayerOptions.h diff --git a/ConsoleApplication1.cpp b/ConsoleApplication1.cpp new file mode 100644 index 0000000..7e3b843 --- /dev/null +++ b/ConsoleApplication1.cpp @@ -0,0 +1,155 @@ +// ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + + +// Run program: Ctrl + F5 or Debug > Start Without Debugging menu +// Debug program: F5 or Debug > Start Debugging menu + +// Tips for Getting Started: +// 1. Use the Solution Explorer window to add/manage files +// 2. Use the Team Explorer window to connect to source control +// 3. Use the Output window to see build output and other messages +// 4. Use the Error List window to view errors +// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project +// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file +#include +#include +#include +#include +#include + +#include +using namespace std; + +int main() { + + string First; + string Last; + string Gender; + string Title; + string YN; + string Bank; + string Number; + + cout << "Welcome to my program! This is a choose your own adventure story designed by Nicholas Rising as his first more complicated C++ program. To use this, read what people say. When prompted to act, just type it in below. Use \"Y\" for yes and \"N\" for no. Also, capitalization matters. Without further ado, lets get into it!" << endl << endl; + + + cout << "-------------------------------------------------------------------------------------------" << endl << endl; + + cout << "Please enter your first name:"; + cin >> First; + cout << "Please enter your last name:"; + cin >> Last; + cout << "Please enter your gender: (M/F)"; + cin >> Gender; + cout << "Please enter your 9-diget social security number:"; + cin >> Bank; + + cout << endl; + cout << "Just kidding. Testing to see if you were paying attention. :)" << endl; + cout << endl; + + + cout << "-------------------------------------------------------------------------------------------" << endl << endl; + + if (Gender == "M") { + Title = "Mr."; + } + if (Gender == "F") { + Title = "Ms."; + } + cout << "You are walking down an old country road. You have no memories. All you remember is your name and that you woke up this morning, and felt an urge to walk in this particular direction." << endl << endl; + + cout << "In the distance you see a man tending some flowers at the entrance of what apears to be a dojo. As you get closer, you see that he is quite elderly." << endl << endl; + + cout << "He looks up towards you. He stares at you for a second and then exclaims \"Oh! I apologise that I did not recognize you sooner, " << Title << " " << Last << "! Come, let us see the sensei.\"" << endl << endl; + + cout << "You ask him who he is. He looks into your eyes. \"So it is true, you did lose your memories. My name is Master Motoyuki. Follow me.\"" << endl << endl; + + cout << "Master Motoyuki seems to know who you are, so he may be able to treat your amnesia, but you also must stay wary of strangers. Do you follow him? (Y/N):"; + cin >> YN; + cout << endl; + + cout << "-------------------------------------------------------------------------------------------" << endl << endl; + + if (YN == "Y") { + cout << "You follow Master Motoyuki as he walks past an arched gateway into what appeares to be a courtyard." << endl << endl; + + cout << "Master Motoyuki beckons you into a building in front of you. Inside is a simple room with no furnature and a wood floor. In front of you, sitting on a cushion, is a man with a long beard wearing traditional Japanese robes. You feel like you recognize him." << endl << endl; + + cout << "The man looks up. \"Ah! You have returned, " << First << ".\" How are you? I have been told you lost your memory. Is this true?\" You nod your head. \"I see. I have some explaining to do.\"" << endl << endl; + + cout << "\"Myself, the other Masters including yourself, and the students here, are part of a group known as the Emperors Guard. Our duty is to protect the emperor from harm. However, we remain anonomous to all including the Emperor, and only appear in times of dire need. You, Master " << Last << ", disapeared a couple of days ago, and we feared that you were captured by our enemies. However, our town prophet told us that you would return, short of your memory.\"" << endl << endl; + + cout << "\"Oh, and excuse me for not mentioning it earlier, my name is Sensei Yushiro. I am the teacher here, and you are a Master. The Masters are students who came here and passed all of our trials. The students are new recruits and train here with the goal to one day become a Master. All of us here are sworn to secrecy to prevent our enemies from finding us.\"" << endl << endl; + + cout << "\"Of course, some bounty hunters hired by our opposition find us, but we try to cover up the mess as best as we can. Anyways, to get your memory back you must...\"" << endl << endl; + + cout << "Sudenly, you hear an explosion. The floor rocks. You see flames outside. Sensei Yushiro grabs you by the wrist. \"We must hide, " << First << ", it seems they have found us!\" Sensei Yushiro seems concerned for your safety and is woried by \"they\", but it also looks like the base of the Emperors Guard is in trouble. Do you go with Sensei Yushiro? (Y/N):"; + cin >> YN; + cout << endl << endl; + + cout << "-------------------------------------------------------------------------------------------" << endl << endl; + + if (YN == "Y") { + cout << "You decide to do what Sensei Yushiro says, and you follow him." << endl << endl; + + cout << "Sensei Yushiro leads you to a stone wall. He taps a small stone protruding fro1m it and the wall rotates open. \"Thats amazing!\" you exclaim. Sensei Yushiro shushes you and drags you into the darkness behind the wall. He grabs a torch on the wall and lights it." << endl << endl; + + cout << "In front of you is a staircase. Sensei Yushiro beckons you down it. You make the decent. At the bottom is a door. Sensei Yushiro pulls out a key and opens the door." << endl << endl; + cout << "Inside are stacks of hay bails, food, and other esentials. Sensei Yushiro explains how this room is a storehouse for the dojo. You sudenly hear a noise comming from upstairs" << endl << endl; + } + if (YN == "N") { + cout << "You decide you must help and can't just hide, and you break free of Sensei Yushiro grasp." << endl << endl; + + } + } + if (YN == "N") { + cout << "You do not trust him and run in the opposite direction." << endl << endl; + + cout << "Master Motoyuki turns around to beckon you in, when he sees you running away. \"Get him!\" he exclaims." << endl << endl; + + cout << "You continue to run. You see a grove of trees you can hide in, but just as you begin heading towards it, black hooded figures emurge from the trees. You turn around and see you are compleatly surrounded." << endl << endl; + + cout << "The people are compleatly covered in a skin-tight black cloth, except for their eyes. You feel like you have seen them before. Master Motoyuki walks towards the circle of ninjas surounding you. He enters the ring. \"So, you thought you could escape your greatest enemy. I guess you do still have your memory and were lying. He walks up to you and stares you staight in the eyes." << endl << endl; + cout << "\"Where are you hiding it.\"" << endl << endl; + + cout << "\"What is this man talking about?\", you think. Do you:" << endl << endl; + + cout << "1) Attack him" << endl << endl; + + cout << "2) Tell him you have no idea what he is talking about and that you truly have no memory" << endl << endl; + + cout << "3) Try to run through the people surounding you" << endl << endl; + + cout << "Do you (Answer with a number):"; + cin >> Number; + cout << endl; + + cout << "-------------------------------------------------------------------------------------------" << endl << endl; + + if (Number == "1") { + cout << "You punch Master Motoyuki in the face." << endl << endl; + + cout << "Master Motoyuki takes a step back, suprised by your sudden assault. However, he is tougher then what his age says, and he seems fine." << endl << endl; + + cout << "The black-clothed ninjas begin circling towards you, but with a wave, Master Motoyuki stops them. He then takes a swing at you. You barley see it coming, when you feel his fist punch you in the check. You collapse to the ground and everything goes dark." << endl << endl; + + goto Blackout; + } + if (Number == "2") { + cout << "\"I have no idea what you are talking about!\" you exclaim." << endl << endl; + + cout << "Master Moyoyuki punches you in the face. As you fall, he growles \"You liar.\"" << endl << endl; + + cout << "You hit the ground with a thud. Everything starts to spin and then goes dark." << endl << endl; + + Blackout: + cout << "You wake up in a dark room." << endl << endl; + } + if (Number == "3") { + cout << "You decide to break through the circle around you. You run, but they lock arms, making your escape imposible." << endl << endl; + } + } + return 0; +} \ No newline at end of file diff --git a/Handhouse.cpp b/Handhouse.cpp new file mode 100644 index 0000000..ab590e1 --- /dev/null +++ b/Handhouse.cpp @@ -0,0 +1,263 @@ +// Handhouse.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include +#include +#include + +#include "Player.h" +//#include "Looping.h" + + +using namespace std; + +#include +#include +#include // For the command handling function. +#include // Will be used to eliminate case sensitivity problems. + +using namespace std; + +enum allDirections { north, south, west, east }; +enum allRooms { kitchen, bedroom, bathroom, hall }; +enum allVerbs { take, drop, use, examine, inventory, look }; + +const int wrong = -1; +const int directions = 4; +const int ROOMS = 4; +const int VERBS = 8; + +struct word +{ + string word; + int code; +}; + +struct room +{ + string description; + int doors[directions]; +}; + + +void set_rooms(room* rms) +{ + rms[bathroom].description.assign("bathroom"); + rms[bathroom].doors[north] = wrong; + rms[bathroom].doors[east] = wrong; + rms[bathroom].doors[south] = kitchen; + rms[bathroom].doors[west] = wrong; + + rms[bedroom].description.assign("bedroom"); + rms[bedroom].doors[north] = wrong; + rms[bedroom].doors[east] = wrong; + rms[bedroom].doors[south] = hall; + rms[bedroom].doors[west] = wrong; + + rms[kitchen].description.assign("kitchen"); + rms[kitchen].doors[north] = bathroom; + rms[kitchen].doors[east] = hall; + rms[kitchen].doors[south] = wrong; + rms[kitchen].doors[west] = wrong; + + rms[hall].description.assign("hall"); + rms[hall].doors[north] = bedroom; + rms[hall].doors[east] = wrong; + rms[hall].doors[south] = wrong; + rms[hall].doors[west] = kitchen; + + +} + + +void set_directions(word* dir) +{ + dir[north].code = north; + dir[north].word = "north"; + dir[east].code = east; + dir[east].word = "east"; + dir[south].code = south; + dir[south].word = "south"; + dir[west].code = west; + dir[west].word = "west"; +} + + +void set_verbs(word* vbs) +{ + // enum allVerbs {take, drop, use, OPEN, CLOSE, examine, inventory, look}; + vbs[take].code = take; + vbs[take].word = "take"; + vbs[drop].code = drop; + vbs[drop].word = "drop"; + vbs[use].code = use; + vbs[use].word = "use"; + vbs[examine].code = examine; + vbs[examine].word = "examine"; + vbs[inventory].code = inventory; + vbs[inventory].word = "inventory"; + vbs[look].code = look; + vbs[look].word = "look"; +} + + + +void section_command(string Cmd, string& wd1, string& wd2) +{ + string sub_str; + vector words; + char search = ' '; + size_t i, j; + + + for (i = 0; i < Cmd.size(); i++) + { + if (Cmd.at(i) != search) + { + sub_str.insert(sub_str.end(), Cmd.at(i)); + } + if (i == Cmd.size() - 1) + { + words.push_back(sub_str); + sub_str.clear(); + } + if (Cmd.at(i) == search) + { + words.push_back(sub_str); + sub_str.clear(); + } + } + + // Very simple. For the moment I only want the first to words at most (verb / noun). + if (words.size() == 0) + { + cout << "No command given" << endl; + } + if (words.size() == 1) + { + wd1 = words.at(0); + } + if (words.size() == 2) + { + wd1 = words.at(0); + wd2 = words.at(1); + } + if (words.size() > 2) + { + cout << "Command too long. Only type one or two words (direction or verb and noun)" << endl; + } +} + +//all available doors +void look_around(int loc, room* rms, word* dir) +{ + int i; + cout << "You are in a " << rms[loc].description << "." << endl; + + + for (i = 0; i < directions; i++) + { + if (rms[loc].doors[i] != wrong) + { + cout << "There is an exit " << dir[i].word << " to a " << rms[rms[loc].doors[i]].description << "." << endl; + } + } +} + +bool parser(int& loc, string wd1, string wd2, word* dir, word* vbs, room* rms) +{ + int i; + for (i = 0; i < directions; i++) + { + if (wd1 == dir[i].word) + { + if (rms[loc].doors[dir[i].code] != wrong) + { + loc = rms[loc].doors[dir[i].code]; + cout << "I am now in a " << rms[loc].description << "." << endl; + return true; + } + else + { + cout << "No exit that way." << endl; + return true; + } + } + } + + // verb section + int VERB_ACTION = wrong; + + for (i = 0; i < VERBS; i++) + { + if (wd1 == vbs[i].word) + { + VERB_ACTION = vbs[i].code; + break; + } + } + + if (VERB_ACTION == look) + { + + look_around(loc, rms, dir); + return true; + } + + if (VERB_ACTION == wrong) + { + cout << "No valid command entered." << endl; + return true; + } + return false; +} + + +//This is the main function from where the other functions are called. +int main() +{ + Game game; + //game.RunFunctions(); + + string command; + string word_1; + string word_2; + + room rooms[ROOMS]; + set_rooms(rooms); + + word directions[directions]; + set_directions(directions); + + word verbs[VERBS]; + set_verbs(verbs); + + int location = kitchen; // enumrator 0. + + while (word_1 != "quit") + { + string command; + cout << "What is your next move? "; + cin >> command; + cout << command << endl; + + word_1.clear(); + word_2.clear(); + + // Call the function that handles the command line format. + section_command(command, word_1, word_2); + + // Call the parser. + if (word_1 != "quit") + { + parser(location, word_1, word_2, directions, verbs, rooms); + } + } + + return 0; + + +} + + + diff --git a/Looping.cpp b/Looping.cpp new file mode 100644 index 0000000..9890418 --- /dev/null +++ b/Looping.cpp @@ -0,0 +1,59 @@ +#include "Looping.h" + +#include + +using namespace std; + + void Game::Greetings() { + cout << "Welcome to the Haunted House!" << endl; + cout << "Please enter your name..." << endl; + string name; + cin >> name; + userPlayer.ChosenName(name); + cout << "Hello " << userPlayer.GetName() << endl; + } + + //This is where the player will be able to see the options to choose from + void Game::optionsAvailable() const { + cout << "Here are your current options...(Enter your choice)" << endl; + cout << "1: Quit" << endl; + } + + //This is the function where the player will input their decision + void Game::receiveInput(string& playerInput) const { + cin >> playerInput; + } + + //comparing the input of the player until correct + playerChoices Game::CompareInput(string& playerInput) const { + playerChoices chosenChoice = playerChoices::None; + if (playerInput.compare("1") == 0) + { + cout << "The game is closing..." << endl; + chosenChoice = playerChoices::Quit; + } + + else + { + cout << "You might have made a mistake, try again!" << endl; + + } + //if wrong choice it gets you back to the chosing point + + return chosenChoice; + } + + //calling all the previous functions related to the choices + void Game::RunFunctions() + { + //Greetings(); + bool expectation = false; + while (expectation == false) { + optionsAvailable(); + string playerInput; + receiveInput(playerInput); + expectation = CompareInput(playerInput) == playerChoices::Quit; + } + + + } diff --git a/Looping.h b/Looping.h new file mode 100644 index 0000000..c026592 --- /dev/null +++ b/Looping.h @@ -0,0 +1,18 @@ +#pragma once + +#include "Player.h" +#include "PlayerOptions.h" + +using namespace std; + +class Game +{ +private: + Player userPlayer; + void Greetings(); + void optionsAvailable() const; + void receiveInput(string& playerInput) const; + playerChoices CompareInput(string& playerInput) const; +public: + void RunFunctions(); +}; \ No newline at end of file diff --git a/Player.h b/Player.h new file mode 100644 index 0000000..fcbf2bd --- /dev/null +++ b/Player.h @@ -0,0 +1,28 @@ +#pragma once + +#include + + +using namespace std; + +class Player +{ +private: + string player_Name; + +public: + Player() + { + + } + + void ChosenName(const string& name) + { + player_Name = name; + } + + const string& GetName() const + { + return player_Name; + } +}; \ No newline at end of file diff --git a/PlayerOptions.h b/PlayerOptions.h new file mode 100644 index 0000000..0c688ee --- /dev/null +++ b/PlayerOptions.h @@ -0,0 +1,6 @@ +#pragma once + +//this is a list of choices the player has +enum class playerChoices { + Quit, None +}; \ No newline at end of file