1 Attachment(s)
Directional Keys - Useing in Console
Ok, i am trying to use the directional arrows to decide where the user moves too. I used to use letters off the keyboard, but with the use of barons keys.h i hoped to use the directionals.
Unfortunatly none of the K_NAME 's are working, these are what is defined in the .h file. I have attahced the .h file and pasted the code to the program, i want to know what i am doing wrong, this is my first time trying this.
Code:
/* Steven Billington
[email protected]
Caverns.cpp
September 27, 2002
This is my first game ever. Its a relativley simple program
as it should be cause its newbie made. Its a console based text RPG.
Welcome to Caverns, enjoy!
*/
/****************************
*****************************
Updated September 28, 2002
*****************************
****************************/
/* These are our Preprocessor directives*/
#include <iomanip.h>
#include "keys.h"
#include <iostream.h> /* For input/output*/
#include <stdlib.h> /* For clear screen*/
#include <conio.h> /* For getch() - makes program pause till user
user presses a key*/
/* Declare variables for game-play.
The names should explain it, email me
if you don't understand something.*/
int User_Location_X = 0;
int User_Location_Y = 0;
int Amulet = 0;
int Quarter_Staff = 0;
int Chainmail_Armor = 0;
int Heal_Potion = 0;
int Spell_Book = 0;
int magic = 100;
int points = 0;
int health = 100;
int protection = 0;
int end_game = 50;
/* Our variable for users choices throught
game play.*/
char input;
/* Declare main as variable type integer.*/
void openmessage ()
{
cout <<setw(50) <<"***************************"<<"\n";
cout <<setw(50) <<"**** Caverns ***"<<"\n";
cout <<setw(50) <<"**** Steven Billington ***"<<"\n";
cout <<setw(50) <<"***************************"<<"\n";
/*Take user input and display opening messages
The user name can be up to 20 characters long*/
char name[20];
cout <<"Please enter your first name and press enter twice: ";
cin >>name; /* Store users name*/
cout <<"You may see controls at any time by pressing (HOME)\n\n";
}
void directions ()
{
cout <<"North = Up Arrow\nSouth = Down Arrow\nWest = Left Arrow\nEast = Right Arrow\n";
cout <<"\n";
cout <<"Home = Information\n";
cout <<"\n";
cout <<"Insert = Health\nP = Points\n";
cout <<"\n";
cout <<"End = Exit\n";
cout <<"\n";
}
int main ()
{
openmessage(); /* Call opening message*/
getch();
do/* Start loop*/
{
/* Checks to see if the points are at 100
if they are, user wins and game ends.*/
if (points == 100)
{
cout <<"You have reached 100 points, you win!!\n\n";
getch();
return 0;
}
/* Checks to see if health is at a value of 0
if it is the user has lost and game ends.*/
if (health == 0)
{
cout <<"Game Over!\n\n";
getch();
return 0;
}
/* Check user position.*/
if (User_Location_Y == 25)
{
cout <<"You cannot continue in this direction\n";
User_Location_Y--;
getch();
}
else if (User_Location_Y == -25)
{
cout <<"You cannot continue in this direction\n";
User_Location_Y++;
getch();
}
else if (User_Location_X == 25)
{
cout <<"You cannot continue in this direction\n";
User_Location_X--;
getch();
}
else if (User_Location_X == -25)
{
cout <<"You cannot continue in this direction\n";
User_Location_X++;
}
/* This decrements by 1 every loop, when it hits 0 game ends.*/
end_game--;
if (end_game == 0)
{
system("cls");
cout <<"You have used all your energy, GAME OVER!\n";
return 0;
}
/* This displays every loop.*/
system("cls");
directions();
cout <<"Select a Direction: ";
cin >>input;
cout <<"\n";
/* Key for user initiated exit.*/
if (input == K_END)
{
system("cls");
return 0;
}
/* Key for information menu.*/
if (input == K_HOME)
{
cout <<"North (1)\nSouth (2)\nEast(3)\nWest (4)\nQuit (Q)\nUse Heal (H)\n";
cout <<"Spell (S)\nWeapon (W)\nRun (R)\nHelp (I)\nLife (L)\nPoints (P)\n\n";
}
/* Key for checking health status.*/
if (input == K_INSERT)
{
cout <<"Health is "<<health<<"\n\n";
}
/* Key for checking point status.*/
if (input == K_P || input == K_p)
{
cout <<"Points are "<<points<<"\n\n";
}
/* Update user position and update accordingly.*/
if (input == K_UP)
{
User_Location_Y = User_Location_Y++;
}
if (input == K_DOWN)
{
User_Location_Y = User_Location_Y--;
}
if (input == K_RIGHT)
{
User_Location_X = User_Location_X++;
}
if (input == K_LEFT)
{
User_Location_X = User_Location_X--;
}
/***************************************************************
****************************************************************
Code for Amulet
****************************************************************
***************************************************************/
if (User_Location_X == 0 && User_Location_Y == 5)
{
if (Amulet == 1)
{
cout <<"You have returned to where you found Soris's Amulet.\n\n";
}
else if (Amulet == 0)
{
cout <<"You found Soris's Amulet!\n\n";
cout <<"You feel protected and are awarded ten points.\n\n";
Amulet = 1;
}
}
/***************************************************************
****************************************************************
Code for Quarter_Staff
****************************************************************
***************************************************************/
if (User_Location_X == 7 && User_Location_Y == 0)
{
if (Quarter_Staff == 1)
{
cout <<"You find the marble pillar on which your quarter staff had been.\n\n";
}
else if (Quarter_Staff == 0)
{
cout <<"You have aquired a Quarter Staff! You feel secure with your weapon.\n\n";
Quarter_Staff = 1;
points = points + 10;
}
}
/***************************************************************
****************************************************************
Code for Chainmail_Armor
****************************************************************
***************************************************************/
if (User_Location_X == 0 && User_Location_Y == 17)
{
if (Chainmail_Armor == 1)
{
cout <<"You see an old crate where a chainmail armor once rested.\n\n";
}
else if (Chainmail_Armor == 0)
{
cout <<"You have found an old set of Chainmail Armor! It appears in good shape.\n\n";
int user_choice;
cout <<"Equip Y/N? ";
cin >>user_choice;
if (user_choice == 'Y' || user_choice == 'y')
{
cout <<"You equip the chainmail.\n\n";
Chainmail_Armor = 1;
protection++;
}
if (user_choice == 'N' || user_choice == 'n')
{
cout <<"You drop the chainmail.\n\n";
Chainmail_Armor = 0;
}
}
}
/***************************************************************
****************************************************************
Code for Heal_Potion
****************************************************************
***************************************************************/
if (User_Location_X == -7 && User_Location_Y == 0)
{
if (Heal_Potion == 1 || Heal_Potion == 2)
{
cout <<"You have stumbled upon an empty bag, once containing a heal potion.\n\n";
}
else if (Heal_Potion == 0)
{
cout <<"You have uncoverd a bag, in it contains a heal potion, which you pick up.\n\n";
cout <<"You may use this at anytime by pressing (H).\n\n";
Heal_Potion = 1;
points = points + 10;
}
}
/***************************************************************
****************************************************************
Code for Heal_Potion Use.
****************************************************************
***************************************************************/
if (input == 'H' || input == 'h')
{
if (Heal_Potion == 1)
{
cout <<"You drink the potion.\n\n";
Heal_Potion = 2;
health = health + 5;
}
else if (Heal_Potion == 0)
{
cout <<"You don't have a health potion.\n\n";
}
else if (Heal_Potion == 2)
{
cout <<"You already used your potion.\n\n";
}
}
/***************************************************************
****************************************************************
Code for Spell_Book
****************************************************************
***************************************************************/
if (User_Location_X == 0 && User_Location_Y == -9)
{
if (Spell_Book == 1)
{
cout <<"You feel enchanted as you find where a spell book once sat.\n\n";
}
else if (Spell_Book == 0)
{
cout <<"You find an enchanted spell book!\n\n";
points = points + 10;
Spell_Book = 1;
}
}
/***************************************************************
****************************************************************
Code for Monster one
****************************************************************
***************************************************************/
if (User_Location_X == 2)
{
cout <<"You encounter a troll!\n\n";
cout <<"Spell (S)\nWeapon (W)\nRun (R)\n\n";
cin >>input;
if (input == 'S' || input == 's')
{
if (magic <= 1)
{
cout <<"You have no magic ability left!\n\n";
cout <<"The troll strikes you! You lose 10 health points!\n\n";
health = health - 10;
cout <<"Points are "<<points<<"\n\n";
cout <<"Health is "<<health<<"\n\n";
}
else if (magic >= 5)
{
cout <<"You cast a spell, but the troll is immune!\n\n";
cout <<"The troll strikes you! You lose 10 health points!\n\n";
health = health - 10;
magic = magic - 50;
cout <<"Points are "<<points<<"\n\n";
cout <<"Health is "<<health<<"\n\n";
}
}
else if (input == 'W' || input == 'w')
{
cout <<"You strike and kill the troll!\n\n";
cout <<"You gain 20 points!\n\n";
points = points + 20;
cout <<"Points are "<<points<<"\n\n";
cout <<"Health is "<<health<<"\n\n";
}
else if (input == 'R' || input == 'r')
{
cout <<"You try to escape....you escape but the troll hits you.\n\n";
cout <<"You lose 20 health points\n\n";
health = health - 20;
cout <<"Points are "<<points<<"\n\n";
cout <<"Health is "<<health<<"\n\n";
}
}
/***************************************************************
****************************************************************
Code for Monster two
****************************************************************
***************************************************************/
if (User_Location_Y == -4)
{
cout <<"You encounter a wombat!\n\n";
cout <<"Spell (S)\nWeapon (W)\nRun (R)\n\n";
cin >>input;
if (input == 'S' || input == 's')
{
if (magic <= 1)
{
cout <<"You have no magic ability left!\n\n";
cout <<"The troll strikes you! You lose 10 health points!\n\n";
health = health - 10;
cout <<"Points are "<<points<<"\n\n";
cout <<"Health is "<<health<<"\n\n";
}
else if (magic >= 5)
{
cout <<"You cast a spell, but the wombat is immune!\n\n";
cout <<"The wombat strikes you! You lose 20 health points!\n\n";
health = health - 20;
magic = magic - 50;
cout <<"Points are "<<points<<"\n\n";
cout <<"Health is "<<health<<"\n\n";
}
}
else if (input == 'W' || input == 'w')
{
cout <<"You strike and kill the wombat!\n\n";
cout <<"You gain 50 points!\n\n";
points = points + 50;
cout <<"Points are "<<points<<"\n\n";
cout <<"Health is "<<health<<"\n\n";
}
else if (input == 'R' || input == 'r')
{
cout <<"You try to escape....you escape but the wombat hits you.\n\n";
cout <<"You lose 20 health points\n\n";
health = health - 20;
cout <<"Points are "<<points<<"\n\n";
cout <<"Health is "<<health<<"\n\n";
}
}
/***************************************************************
****************************************************************
Code for Monster three - impossible to beat
****************************************************************
***************************************************************/
if (User_Location_X == -11)
{
cout <<"You encounter a powerful Ghost!\n\n";
cout <<"Spell (S)\nWeapon (W)\nRun (R)\n\n";
cin >>input;
if (input == 'S' || input == 's')
{
cout <<"You cast a spell, but the ghost resists!!\n\n";
cout <<"The ghost strikes you! You lose 100 health points!\n\n";
health = 0;
cout <<"Points are "<<points<<"\n\n";
cout <<"Health is "<<health<<"\n\n";
}
else if (input == 'W' || input == 'w')
{
cout <<"You try to hit the ghost, but miss!\n\n";
points = points - 20;
cout <<"Points are "<<points<<"\n\n";
cout <<"Health is "<<health<<"\n\n";
}
else if (input == 'R' || input == 'r')
{
cout <<"You try to escape....you escape but the ghost hits you.\n\n";
cout <<"You lose 100 health points\n\n";
health = 0;
cout <<"Points are "<<points<<"\n\n";
cout <<"Health is "<<health<<"\n\n";
}
}
}
/* Loop does these actions while end_game
does NOT qual true.*/
while(end_game!=1);
/* Return value for main.*/
return 0;
}