Author Topic: Just starting out, help appreciated.  (Read 5784 times)

jamms87

  • Newcomer
  • Posts: 2
  • Karma: +0/-0
    • View Profile
    • Email
Just starting out, help appreciated.
« on: February 11, 2012, 01:48:40 PM »
Hello, I just started out using a tutorial that described how to create the basics of a roguelike using c++ and running the code through the command prompt. I finished the tutorial and started fiddling about on my own and have hit a bug I can't seem to work out.

I have set up a function which allows the player to open doors if they have a key, it works fine. I then tried to set up a way of opening doors using magic, rather than put the code in again I thought I could just do as I have below (ignore everything other than the OpenDoorCommand bit). It works in the sense that the door opens however when the user selects option 3 the map, UI and player disappear until they select which direction the door is in.

Any tips or suggestions would be much appreciated.

Code: [Select]
void ManaCommand( void )
{
   
// Draw some notification to the user
console.SetPosition( 60, 2 );
console << "1. Damage Enemy.";
console.SetPosition( 60, 4 );
console << "2. Heal yourself.";
console.SetPosition( 60, 6 );
console << "3. Open Door.";
console.SetPosition( 60, 8 );
console << "4. Chop Tree";

// Let the user decide where to look
char nKey = getch();
int nDeltaX = 0;
int nDeltaY = 0;

// Clear the screen to get rid of the notification text
console.Clear();

// Compute which tile the user specified
switch( nKey )
{
// Damage Enemy
case '1':
nDeltaX = 0;
nDeltaY = 1;
break;

// Heal yourself
case '2':
nDeltaX = -1;
nDeltaY = 0;
break;

// Open Door
case '3':
    OpenDoorCommand();
    break;
// Chop Tree
case '4':
ChopTreeCommand();
                break;

// Not a valid direction
default:
// No direction specified, so abort
console.Clear();
return;


}

guest509

  • Guest
Re: Just starting out, help appreciated.
« Reply #1 on: February 11, 2012, 02:11:07 PM »
  One of the console.clear commands is probably to blame. Likely the first one.

jamms87

  • Newcomer
  • Posts: 2
  • Karma: +0/-0
    • View Profile
    • Email
Re: Just starting out, help appreciated.
« Reply #2 on: February 11, 2012, 02:17:54 PM »
That solved it, thanks very much.

guest509

  • Guest
Re: Just starting out, help appreciated.
« Reply #3 on: February 11, 2012, 04:11:16 PM »
  Sweet man. Glad I could help. I'm actually one of the worst coders here. I'm delighted I was able to assist. Sometimes it just takes another set of eyes.