i added the VK code as indicated above, and got these errors:
Compiling...
Caverns.cpp
D:\MyProjects\Game related 1\Caverns\Caverns.cpp(92) : error C2065: 'STD_IN' : undeclared identifier
D:\MyProjects\Game related 1\Caverns\Caverns.cpp(92) : error C2146: syntax error : missing ')' before identifier 'PUT_HANDLE'
D:\MyProjects\Game related 1\Caverns\Caverns.cpp(92) : error C2059: syntax error : ')'
D:\MyProjects\Game related 1\Caverns\Caverns.cpp(105) : warning C4244: '=' : conversion from 'unsigned short' to 'char', possible loss of data
D:\MyProjects\Game related 1\Caverns\Caverns.cpp(107) : error C2065: 'STD_INPUT_' : undeclared identifier
D:\MyProjects\Game related 1\Caverns\Caverns.cpp(107) : error C2146: syntax error : missing ')' before identifier 'HANDLE'
D:\MyProjects\Game related 1\Caverns\Caverns.cpp(107) : error C2059: syntax error : ')'
D:\MyProjects\Game related 1\Caverns\Caverns.cpp(224) : error C2065: 'VK_P' : undeclared identifier
D:\MyProjects\Game related 1\Caverns\Caverns.cpp(224) : error C2065: 'VK_p' : undeclared identifier
Error executing cl.exe.
Caverns.obj - 8 error(s), 1 warning(s)
heres the code from beginning to end of section thats in trouble:
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 <windows.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";
}
bool Keypress(char &Key)
{
INPUT_RECORD Event;
DWORD NumberOfEvents, EventsRead, EventCounter;
GetNumberOfConsoleInputEvents(GetStdHandle(STD_IN
PUT_HANDLE), &NumberOfEvents);
if (NumberOfEvents == 0)
return false;
for (EventCounter = 0; EventCounter < NumberOfEvents; EventCounter++)
{
PeekConsoleInput(GetStdHandle(STD_INPUT_HANDLE),
&Event, 1, &EventsRead);
if ((Event.EventType == KEY_EVENT) && ((Event.Event.KeyEvent.bKeyDown)))
{
ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE)
, &Event, 1, &EventsRead);
Key = Event.Event.KeyEvent.wVirtualKeyCode;
if (!(FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_
HANDLE))))
exit(0);
return true;
}
else
ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE)
, &Event, 1, &EventsRead);
}
return false;
}
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";
char key = 0;
for (;;)
{
/* Key for user initiated exit.*/
if (Keypress(key))
{
if (key == VK_LEFT)
User_Location_X = User_Location_X--;
if (key == VK_RIGHT)
User_Location_X = User_Location_X++;
if (key == VK_DOWN)
User_Location_Y = User_Location_Y--;
if (key == VK_UP)
User_Location_Y = User_Location_Y++;
if (key == VK_ESCAPE)
return 0;
if (key == VK_HOME)
directions();
if (key == VK_INSERT)
cout <<"Health is: "<<health<<"\n";
if (key == VK_P || key == VK_p)
cout <<"Points are: "<<points<<"\n";
}
}