Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Text based game challenge: write the code and run it The idea is fairly simple;

ID: 3630022 • Letter: T

Question

Text based game challenge: write the code and run it
The idea is fairly simple; you make a game which has a text based interface. People often use “the guessing game” as an example of a basic game. Given that the interface is text (as it often is), even something as simple as that is a text based game. I would hope you would make something a bit more complex than that however

The games will be scored on scales of 1-10 based on the following criteria:
Creativity – The uniqueness of the game. What amount/quality of thought went into the game?.
Game Play – How fun is it to play? How smooth is the interface? Isn’t that what games are about anyways?
Quality of code – How well structured the code is. How easy is it to maintain and add on to. How well "good" practice was followed
Game play and Quality of code will each be worth 40% of your score while Creativity will be 20%. I am allowing a few Third party libraries (listed below) to be used and you can ask me if you would like to use something else. Full source code is required and should be in C or C++(along with any necessary files)

he following libraries are allowed:
Boost 1.47.0 – all of it, anything in it is fair game
Ncurses 4.0 and PDcurses 3.4 – I’m allowing both so that almost all platforms can have a curses library
Lua 5.1.4 or Lua 5.2(beta) – You can use either but it has to be embedded, this is a C/C++ programming challenge so you can’t just use pure Lua; it should be used as an extension.

Explanation / Answer

Here is my text-based RPG game. I wrote it in two header files and one .cpp file.
Here is main.cpp . . .
#include "Libraries.h"

int gameOver()
{
cout << "You were killed!" << endl << endl;
cout << "GAME OVER" << endl << endl;
cout << "Press enter to exit . . ." << endl;
ofstream outFile;
outFile.open("C:\Documents and Settings\myUserHere\My Documents\TG Save Loc.txt");
outFile << "10" << endl << "-1" << endl;
outFile.close();
cin.sync();
cin.get();
exit(0); // No major memory losses will be occurred with this exit()
}

int flee()
{
cout << endl << "Fleeing . . ." << endl << endl;
Sleep((((time(0)%2)+1)*1000-400));
int iEscapeChance = time(0)%3;
if(iEscapeChance == 0)
{
cout << "You successfully escape!" << endl << endl;
system("PAUSE");
system("CLS");
cout << "You continue roaming the forest . . ." << endl;
return 0;
}
else
{
cout << endl << endl << "The creature catches you from behind while you are fleeing . . ." << endl;
gameOver();
exit(0);
}
}

int attack(int *iHealth)
{
system("CLS");
int iHitDamage = time(0)%11;
*iHealth -= iHitDamage;
if(*iHealth <= 0)gameOver();
return 0;
}void save(int health, int survivals)
{
ofstream outFile;
outFile.open("C:\Documents and Settings\myUserHereMy Documents\TG Save Loc.txt");
outFile << health << endl << survivals << endl;
outFile.close();
}

void incorrectPass()
{
cout << "Your entry is invalid." << endl;
cout << "Press enter to exit." << endl;
cin.sync();
cin.get();
}

int main()
{
bool saveAlert = false;
bool correctPass = auth("myPassHere");
if(!correctPass)
{
incorrectPass();
return 0;
}
int iHealth = 583558; // iFish = 3;
static int iCreaturesSurvived = -3;
ifstream inFile;
inFile.open("C:\Documents and Settings\myUserHere\My Documents\TG Save Loc.txt");
if(inFile.fail()) cout << "There was an error in accessing data from the save file . . ." << endl;
inFile >> iHealth >> iCreaturesSurvived;
if(iHealth == 583558) cout << "There was an error in retrieving the player-health from the save file . . ." << endl;
if(iCreaturesSurvived == -3) cout << "There was an error in retrieving the player-survivals from the save file . . ." << endl;
inFile.close();
short int iChoice = +3;
system("CLS");
cout << "Press enter to start your adventure . . ." << endl;
cin.sync();
cin.get();
system("CLS");
cout << "You roam some random forest, seeking riches and jewels . . ." << endl;
do
{
iCreaturesSurvived++;
if(!saveAlert)
{
int iTime = time(0)%10;
{//Operations being done on iTime . . .
if(iTime == 1) iTime = 5;
else if(iTime == 2) iTime = 5;
else if(iTime == 3) iTime = 4;
else if(iTime == 4) iTime = 3;
else if(iTime == 5) iTime = 2;
else if(iTime == 6) iTime = 2;
else if(iTime == 7) iTime = 3;
else if(iTime == 8) iTime = 2;
else if(iTime == 9) iTime = 4;
else iTime = 2;
}
iTime = iTime%10+1;
iTime = iTime*1000-1000;
Sleep(iTime);
}
cin.clear();
cin.sync();
system("CLS");
static int iAnotherCreature = 0; // This variable checks if you have encountered your first creature or not
if(iAnotherCreature == 0 && iCreaturesSurvived == 0)
{
cout << "You encounter a strange creature!";
iAnotherCreature++;
}
else cout << "You encounter another one of those strange creatures!";
if(iCreaturesSurvived != 0) cout << endl << "You have encountered and survived " << iCreaturesSurvived << " creatures so far.";
if(iHealth != 1) cout << endl << "You're health: " << iHealth << " points." << endl;
else cout << endl << "You're health: 1 point." << endl;
cout << endl << "Enter the number for the action you would like to perform." << endl << endl << "1 - Attack it" << endl << "2 - Flee" << endl << "3 - Save game" << endl << "4 - Exit game" << endl << endl << "> ";
string sSafetyNetConversion;
invalidChoice:
cin.sync();
getline(cin, sSafetyNetConversion);
if (sSafetyNetConversion == "1") iChoice = 1;
else if(sSafetyNetConversion == "2") iChoice = 2;
else if(sSafetyNetConversion == "3") iChoice = 3;
else if(sSafetyNetConversion == "4") iChoice = 4;
else /* If the entry is unknown */ iChoice = 5;
switch(iChoice)
{
case 1:
{
int iCopyOfHealth = iHealth;
attack(&iHealth);
if(iCopyOfHealth != iHealth && iHealth != 1) cout << "You kill the creature with " << iHealth << " health points remaining." << endl << endl;
else if(iHealth == 1) cout << "You kill the creature with 1 health point remaining." << endl << endl;
else cout << "You kill the creature, unscathed." << endl << endl;
system("PAUSE");
system("CLS");
cout << "You continue roaming the forest . . ." << endl;
break;
}
case 2:
{
flee();
break;
}
case 3:
{
system("CLS");
save(iHealth, iCreaturesSurvived);
iCreaturesSurvived--;
iAnotherCreature--;
saveAlert = true;
cout << "The game has been saved." << endl;
cout << "Press enter to continue." << endl;
cin.sync();
cin.get();
break;
}
case 4:
{
system("CLS");
save(iHealth, iCreaturesSurvived-1);
cout << "The game has been saved." << endl;
cout << "Press enter to exit." << endl;
cin.sync();
cin.get();
return 0;
}
default:
{
system("CLS");
cout << "Unrecognzed command." << endl;
goto invalidChoice;
}
}
}
while(true);
}


















Here is Libraries.h . . .
#ifdef __STRICT_ANSI__
#undef __STRICT_ANSI__ // I don't want strict ANSI now . . .
#endif
#ifndef LIBRARIES_H_INCLUDED
#define LIBRARIES_H_INCLUDED
#include
#include
#include
#include
#include
#include
#include "authentication.h"
#include
#include
using namespace std;
#endif // LIBRARIES_H_INCLUDED



Here is authentication.h . . .
#ifndef AUTHENTICATION_H_INCLUDED
#define AUTHENTICATION_H_INCLUDED
#include
#include
bool auth(std::string desiredPass)
{
std::string password;
std::cout << "Enter the password." << std::endl;
std::cin >> password;
std::cin.sync();

if(password == desiredPass)
return true;

else return false;
}
#endif // AUTHENTICATION_H_INCLUDED

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote