Jump to content

  • Log In with Google      Sign In   
  • Create Account


markrodgers11

Member Since 05 Oct 2012
Offline Last Active Jun 02 2013 09:45 PM
-----

#4988157 string vs string literals.

Posted by markrodgers11 on 08 October 2012 - 05:57 PM

hmm. alright that was explained perfectly! Thanks! :D


#4987822 First "game" in C++

Posted by markrodgers11 on 07 October 2012 - 07:25 PM

I've been reading a book on C++ and I decided it'd be good practice to code something from scratch instead of outside of the book. I decided it wouldn't be too hard to code a knock off of ZORK...I was wrong Posted Image

It's not that I find it HARD to code a knock off of ZORK but one thing after another keeps adding up and my main.cpp is getting so huge im started to get lost! ...I know, i know, its not THAT big, but for someone like me who is used to coding little things like calculators and other basic things, its pretty long ;p

I know I've probably coded this in a stupid way so If anyone has some suggestions as to how I can split it into other files or reuse parts of code so I don't have to manually re-write things, etc. Maybe some new methods I could check into because idk if this is normal but I feel like I used if, if else, and else statements for practically everything! xD

any advice / critic is appreciated. Thanks!


#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
//strings
string name;
string input;
string output;
string confirm;
string currentArea;
string area;
bool confused;
bool dark;
//commands
string about;
string help;
string n;
string e;
string s;
string w;
string look;
string open;
string close;
//objects
string door1 = "closed";
bool checkArea(string area)
{
if (area == "area1")
{
  if (input == "n")
  {
   look = "There is a mountain range to the North.";
   cout << look;
   confused = false;
  }
  else if (input == "e")
  {
   look = "The door seems to be unlocked.";
   cout << look;
   confused = false;
  }
  else if (input == "s")
  {
   look = "*I watch the waves run up the shore.*";
   cout << look;
   confused = false;
  }
  else if (input == "w")
  {
   look = "There seems to be what appears as a chain-link fence running from the coast to the mountain line. The fence has a gate but it looks as if it is locked.";
   cout << look;
   confused = false;
  }
  else
  {
   confused = true;
  }
}
if (area == "area2")
{
  if (input == "n")
  {
   look = "There is a painting of a whealthy looking man with a mustache on this wall.";
   cout << look;
   confused = false;
  }
  else if (input == "e")
  {
   look = "It is dark inside but I see a desk...";
   cout << look;
   confused = false;
  }
  else if (input == "s")
  {
   look = "Nothing here.";
   cout << look;
   confused = false;
  }
  else if (input == "w")
  {
  
  }
  else
  {
   confused = true;
  }
}
return false;
}
void checkInput()
{
cout << endl << "> ";
cin >> input;

if (input == "about")
{
  output = "You are playing a text based RPG coded by Mark Rodgers.";
  cout << output << endl;
  checkInput();
}
else if (input == "help")
{
  output = "COMMAND LIST:\n help - welcome!\n about - info about the game\n look - describe surroundings\n name - reminds you of your name\n open_OBJECTNAME - opens specified object\n close_OBJECTNAME - closes specified object\n exit - close game (alternative: quit)\n\nMOVEMENT:\n n - Move North\n e - Move East\n s - Move South\n w - Move West";
  cout << output << endl;
  checkInput();
}
else if (input == "look")
{
  cout << look << endl;
  checkInput();
}
else if (input == "name")
{
  output = name;
  cout << "My name is " << name << "." << endl;
  checkInput();
}
else if (input == "open_door")
{
  if (look == "The door seems to be unlocked.")
  {
   if (door1 == "closed")
   {
	output = "*I open the door*";
	cout << output << endl;
	door1 = "opened";
  
	checkInput();
   }
   else if (door1 == "opened")
   {
	output = "The door is already open.";
	cout << output << endl;
	checkInput();
   }
  }
  else
  {
   output = "There is nothing here to open.";
   cout << output << endl;
   checkInput();
  }
}
else if (input == "close_door")
{
  if (look == "The door seems to be unlocked.")
  {
   if (door1 == "opened")
   {
	output = "*I close the door*";
	cout << output << endl;
	door1 = "closed";
	checkInput();
   }
   else if (door1 == "closed")
   {
	output = "The door is already closed.";
	cout << output << endl;
	checkInput();
   }
  }
  else
  {
   output = "There is nothing here to open.";
   cout << output << endl;
   checkInput();
  }
}
else if (input == "exit" || input == "quit")
{
  cout << "Are you sure?(y/n)" << endl << endl << "> ";
  cin >> confirm;
  if (confirm == "yes" || confirm == "YES" || confirm == "Yes" || confirm == "y" || confirm == "Y")
  {
   return;
  }
  else if (confirm == "no" || confirm == "NO" || confirm == "No" || confirm == "n" || confirm == "N")
  {
   checkInput();
  }
  else
  {
   output = "Invalid response.";
   cout << output << endl;
   checkInput();
  }
}
else
{
  checkArea(currentArea);
  if (confused = true)
  {
   output = "Huh?";
   cout << output << endl;
  }
  checkInput();
}
}
void area2()
{
currentArea = "area2";
dark = true;
look = "It is dark inside but I see a desk...";
cout << look << endl;
checkInput();
}
void area1()
{
currentArea = "area1";
look = "I am standing on the beach.\nThere is a small shack to the east.";
cout << look << endl;
checkInput();
}
void main()
{
SetConsoleTitle( "ZORK" );
cout << "What is my name?" << endl << endl << "> ";
cin >> name;
area1();
}



#4987593 string vs string literals.

Posted by markrodgers11 on 06 October 2012 - 11:47 PM

I am currently reading a book called "Accelerated C++ Practical Programming by Example" by Andrew Koenig and Barbara E. Moo and am confused on the difference between a string and a string literal.

Here is the excerpt from what I read:

The second new idea is that we can use + to concatenate a string and a string literal--or, for that matter, two strings (but not two string literals).




#4987314 winapi and directx

Posted by markrodgers11 on 05 October 2012 - 08:20 PM

both really useful replies! thanks :)
@riverreal thanks, i thought id need to know like all of winapi to go on to directx :P okay so ill go with directx11 cause its more up to date and stuff, although wont i need to check to make sure my card is compatible with directx11?
@clb yeah, tbh, thats how I've done alot of my previous programming ;p


PARTNERS