Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualmarkrodgers11

Posted 08 October 2012 - 11:25 AM

Wow thanks guys. Some really great responses. Looks like I've got lots of new things to look into Posted Image
I don't know anything about classes atm or loading rooms via text files, etc.

Thanks for all the great responses!

EDIT: Today i scraped the old one and did it again from scratch (changed the dialogue alittle ;p) but it still seems as I am hard-coding it, which is what i was trying to avoid doing again xD I haven't yet looked into classes/vecters/arrays/etc, so I will take a look at those tonight and hopefully that will make my games less "hard-coded" ;p

#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
string charName, charRace, charClass;
string input;
string look;
string activeRoom;
string pos, north, east, south, west;
string open_door, close_door;
bool doorOpened;
bool doorInRange;
void checkInput()
{
cout << "> ";
cin >> input;
if (input == "help")
{
  cout << endl << "COMMAND LIST:\n\n help - Welcome to ZORK ;]\n look - describe your surroundings\n exit - closes ZORK (alternative: quit)\n\nMOVEMENT:\n\n n - moves North\n e - moves East\n s - moves South\n w - moves West\n\nACTIONS:\n\n open_OBJECTNAME - opens object\n close_OBJECTNAME - closes object\n\n";
}
else if (input == "exit" || input == "quit")
{
  return;
}
else if (input == "look")
{
  cout << endl << look;
}
else if (input == "n")
{
  pos = north;
  look = pos;
  cout << endl << look;
}
else if (input == "e")
{
  pos = east;
  look = pos;
  cout << endl << look;
}
else if (input == "s")
{
  pos = south;
  look = pos;
  cout << endl << look;
}
else if (input == "w")
{
  pos = west;
  look = pos;
  cout << endl << look;
}
else if (input == "open_door")
{
  if (activeRoom == "room1")
  {
   if (look == north)
   {
    doorInRange = true;
    if (doorOpened = false)
    {
	 cout << "Door opened.\n\n";
	 doorOpened = true;
    }
    else if (doorOpened = true)
    {
	 cout << "Door is already open.\n\n";
    }
   }
   else
   {
    doorInRange = false;
    cout << "No door is in range.\n\n";
   }
  }
}
else if (input == "close_door")
{
  if (doorOpened = true)
  {
   cout << "Door closed.\n\n";
   doorOpened = false;
  }
  else if (doorOpened = false)
  {
   cout << "Door is already closed.\n\n";
  }
}
else
{
  cout << "huh?\n\n";
}
checkInput();
}

void room1()
{
activeRoom = "room1";
doorOpened = false;
pos = north;
north = "There is a small shack here. It appears as if it is unlocked.\n\n";
east = "A chain-linked fence blocks moving this direction.\n\n";
south = "There is an ocean here.\n\n";
west = "A mountain range blocks me from going here.\n\n";
cout << endl << north;
look = north;
checkInput();
}
string pickName()
{
//name selection
cout << "What is your name?\n\n" << "> ";
cin >> charName;
return charName;
}
string pickRace()
{
//race selection
cout << endl << "What race do you want to be?\n Human\n Orc\n Elf\n\n" << "> ";
cin >> charRace;
if (charRace == "human" || charRace == "HUMAN" || charRace == "Human")
{
  charRace = "human";
}
else if (charRace == "orc" || charRace == "ORC" || charRace == "Orc")
{
  charRace = "orc";
}
else if (charRace == "elf" || charRace == "ELF" || charRace == "Elf")
{
  charRace = "elf";
}
else
{
  cout << "Invalid Entry.\n Valid inputs are 'human', 'orc', or 'elf'\n\n";
  pickRace();
}
return charRace;
}
string pickClass()
{
//class selection
cout << endl << "What race do you want to be?\n Assassin\n Hunter\n Wizard\n\n" << "> ";
cin >> charClass;
if (charClass == "assassin" || charClass == "ASSASSIN" || charClass == "Assassin")
{
  charClass = "assassin";
}
else if (charClass == "hunter" || charClass == "HUNTER" || charClass == "Hunter")
{
  charClass = "hunter";
}
else if (charClass == "wizard" || charClass == "WIZARD" || charClass == "Wizard")
{
  charClass = "wizard";
}
else
{
  cout << "Invalid Entry.\n Valid inputs are 'assassin', 'hunter', or 'wizard'\n\n";
  pickClass();
}
return charClass;
}
void charVerify()
{
cout << "Welcome to ZORK " << charName << "! You are a " << charRace << " playing as a\\an " << charClass << ".\nAny last changes you want to make?\n\n1) Change Name\n2) Change Race\n3) Change Class\n4) Continue\n\n" << endl << "> ";
cin >> input;
if (input == "1")
{
  pickName();
  charVerify();
}
else if (input == "2")
{
  pickRace();
  charVerify();
}
else if (input == "3")
{
  pickClass();
  charVerify();
}
else if (input == "4")
{
  room1();
}
else
{
  cout << "Invalid Entry.\n Valid inputs are '1', '2', '3', or '4'\n\n";
  charVerify();
}
}
void main()
{
SetConsoleTitle("Text-Based RPG");
pickName();
pickRace();
pickClass();
charVerify();
system("pause");
return;
}

#1markrodgers11

Posted 08 October 2012 - 10:00 AM

Wow thanks guys. Some really great responses. Looks like I've got lots of new things to look into :D
I don't know anything about classes atm or loading rooms via text files, etc.

Thanks for all the great responses!

PARTNERS