Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <stdlib.h>
- #include <string>
- #include <fstream>
- #include "../Character/char_creation.h"
- #include "../Character/char_sheet.h"
- #include "../GameStory/intro.h"
- using namespace std;
- void in_game_actions();
- void game_help();
- void game_save();
- void game_load();
- void invalid_input();
- string menu_action;
- int story_progress;
- void main()
- {
- system("CLS");
- string main_menu_comm;
- cout << "Welcome to the development of the text based game!" << endl;
- cout << "------------------New game (N)-----------------" << endl;
- cout << "------------------Load game (L)----------------" << endl;
- retry:
- cin >> main_menu_comm;
- if (main_menu_comm == "N" || main_menu_comm == "n" || main_menu_comm == "New" || main_menu_comm == "new") {char_creation();}
- else if (main_menu_comm == "L" || main_menu_comm == "l" || main_menu_comm == "Load" || main_menu_comm == "load") {game_load();}
- else {goto retry;}
- }
- void in_game_actions()
- {
- start:
- char confirmation;
- char action[50];
- cin >> action;
- switch (action[0])
- {
- case 'C': case 'c': player.player_info_full(); goto start;
- case 'M' : case 'm':
- cout << "Do you wish to return to the main menu?" << endl;
- cin >> confirmation;
- if (confirmation == 'Y' || confirmation == 'y') {main();}
- else {goto start;}
- case 'S': case 's':
- cout << "Do you wish to save the game?" << endl;
- cin >> confirmation;
- if (confirmation == 'Y' || confirmation == 'y') {game_save(); goto start;}
- else {goto start;}
- case 'H': case 'h': game_help(); goto start;
- case 'E': case 'e': switch (action[1])
- {
- case 'X': case 'x': menu_action = "exit"; break;
- case 'N': case 'n': if (action[5] != '-') {invalid_input();}
- switch (action[6])
- {
- case 'C': case 'c': menu_action = "castle"; break;
- }
- } break;
- case 'L': case 'l': menu_action = "look"; break;
- case 'R': case 'r': menu_action = "rest"; break;
- case 'P': case 'p': if (action[4] != '-') {invalid_input();}
- switch (action[5])
- {
- case 'P': case 'p': menu_action = "pitchfork"; break;
- case 'A': case 'a': menu_action = "axe"; break;
- } break;
- }
- }
- void invalid_input()
- {
- cout << "Invalid input. Type 'help' for support." << endl;
- in_game_actions();
- }
- void game_help()
- {
- cout << "___________________HELP___________________" << endl;
- cout << "These commands can be lower or upper case:" << endl;
- cout << " " << endl;
- cout << "Main Menu (Main)" << endl;
- cout << "Save Game (Save)" << endl;
- cout << "Character Pane (Char)" << endl;
- cout << "Inventory (Inv)" << endl;
- cout << " " << endl;
- cout << "The following commands have to be ALL lowercase with the exception of the initial letter:" << endl;
- cout << " " << endl;
- cout << "== Every character action has to be typed with at least the first two letters. Example: 'exit' can be typed as 'ex', 'exi' or 'exit' but NOT 'e'." << endl;
- cout << endl;
- cout << "== If action involves two stages, such as enter ___ or pick up ___ then you have to type the character action followed " << endl << "by '-' and then the item/location. Example: pick-axe, enter-town." << endl;
- cout << "_________________END HELP_________________" << endl;
- }
- void game_save()
- {
- ofstream savefile;
- savefile.open("save_game.txt");
- if (savefile.is_open()
- {
- savefile << player.playername << endl;
- savefile << player.playergender << endl;
- savefile << player.playerage << endl;
- savefile << player.playerstatus << endl;
- savefile << player.playerclass << endl;
- savefile << HP << endl;
- savefile << Strength << endl;
- savefile << Dexterity << endl;
- savefile << Charisma << endl;
- savefile << Speech << endl;
- savefile << story_progress << endl;
- savefile.close();
- cout << "Game saved." << endl;
- }
- else {cout << "Error saving game. Please try again." << endl;}
- }
- void game_load()
- {
- ifstream loadfile;
- loadfile.open("save_game.txt");
- if (loadfile.is_open())
- {
- cout << "Game loaded. Returning to your last checkpoint." << endl;
- loadfile >> player.playername;
- loadfile >> player.playergender;
- loadfile >> player.playerage;
- loadfile >> player.playerstatus;
- loadfile >> player.playerclass;
- loadfile >> HP;
- loadfile >> Strength;
- loadfile >> Dexterity;
- loadfile >> Charisma;
- loadfile >> Speech;
- loadfile >> story_progress;
- loadfile.close();
- system("pause");
- system("CLS");
- intro(story_progress);
- }
- else { cout << "Error opening file. Please try again." << endl; system("pause"); main(); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement