Code:
#define WIN32_LEAN_AND_MEAN
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include <string.h>
#include <fstream.h>
typedef enum UPARAM {ZIP,UP,DOWN,LEFT,RIGHT,Q,A,Z,W,S,X};
int Frames = 0;
int COL_MAX = 80;
int ROW_MAX = 24;
int PLAYERX = 22;
int PLAYERY = 39;
int WINPLAYERX = PLAYERY;
int WINPLAYERY = PLAYERX;
char ITEM = '$';
char PLAYER = (char)1;
char ItemMessage[50] = "You picked up an item!";
int ItemMessageLength = strlen(ItemMessage);
char GamePath[50];
char* message = new char[50];//6
char MAP[24][80] = {
" _____________________________________________________________________________ ",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| $ |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
" ----------------------------------------------------------------------------- "};
void display();
int ReadFiles();
void clrscr();
int QueryGame();
int Log(const char* output);
void gotoxy(int x,int y);
void PlaceChar();
UPARAM PassParam(UPARAM Uparam);
int main()
{
//QueryGame();
//ReadFiles();
message = " ";
char input;
char arrow;
UPARAM Uparam = ZIP;
display();
PlaceChar();
gotoxy(ROW_MAX,COL_MAX);
/////////////GAME PUMP/////////////GAME PUMP////////////////////
/////////////GAME PUMP/////////////GAME PUMP////////////////////
/////////////GAME PUMP/////////////GAME PUMP////////////////////
while(1)
{
//Clear game command
Uparam = ZIP;
//OUTPUT MESSAGE (BLANK IF THERE IS NOTHING TO SAY)
if(!strcmpi(message," "))
{
}
else
{
gotoxy(ROW_MAX,COL_MAX);
printf(message);
printf(" ");
gotoxy(ROW_MAX,COL_MAX);
//Log();
while(!kbhit());
}
message = " ";
while(!kbhit())
{
Frames++;
}
input = getch();
//IF ARROW KEY...
if((int)input == -32)
{
arrow = getch();
switch(arrow)
{
case 'H':
{
Uparam = UP;
}break;
case 'P':
{
Uparam = DOWN;
}break;
case 'K':
{
Uparam = LEFT;
}break;
case 'M':
{
Uparam = RIGHT;
}break;
}
}
//IF OTHER THAN ARROW KEY...
else
{
switch(input)
{
case 'x':
{
clrscr();
printf("%d",Frames);
getch();
return 0;
}break;
case 'a':
{
MessageBox(NULL,"FIRE!","You attacked",MB_ICONEXCLAMATION);
}break;
}
}
//SEND MESSAGE
PassParam(Uparam);
}
/////////////END GAME PUMP/////////////END GAME PUMP////////////////////
/////////////END GAME PUMP/////////////END GAME PUMP////////////////////
/////////////END GAME PUMP/////////////END GAME PUMP////////////////////
return 0;
}
void display()
{
char displayer;
for(int loop2 = 0; loop2 < ROW_MAX; loop2++)
{
for(int loop1 = 0; loop1 < COL_MAX; loop1++)
{
displayer = MAP[loop2][loop1];
printf("%c",displayer);
if(loop1 == (COL_MAX))
printf("\n");
}
}
}
UPARAM PassParam(UPARAM Uparam)
{
switch(Uparam)
{
case UP:
{
if(MAP[PLAYERX - 1][PLAYERY] != ' ')
{
if(MAP[PLAYERX - 1][PLAYERY] == ITEM)
{
message = ItemMessage;
gotoxy(WINPLAYERX,WINPLAYERY);
printf(" ");
gotoxy(WINPLAYERX,WINPLAYERY - 1);
printf("%c",PLAYER);
gotoxy(0,ROW_MAX);
PLAYERX = PLAYERX - 1;
WINPLAYERY = PLAYERX;
}
else
{
}
}
else
{
gotoxy(WINPLAYERX,WINPLAYERY);
printf(" ");
gotoxy(WINPLAYERX,WINPLAYERY - 1);
printf("%c",PLAYER);
gotoxy(0,ROW_MAX);
PLAYERX = PLAYERX - 1;
WINPLAYERY = PLAYERX;
}
}break;
case DOWN:
{
if(MAP[PLAYERX + 1][PLAYERY] != ' ')
{
if(MAP[PLAYERX + 1][PLAYERY] == ITEM)
{
message = ItemMessage;
gotoxy(WINPLAYERX,WINPLAYERY);
printf(" ");
gotoxy(WINPLAYERX,WINPLAYERY + 1);
printf("%c",PLAYER);
gotoxy(0,ROW_MAX);
PLAYERX = PLAYERX + 1;
WINPLAYERY = PLAYERX;
}
else
{
}
}
else
{
gotoxy(WINPLAYERX,WINPLAYERY);
printf(" ");
gotoxy(WINPLAYERX,WINPLAYERY + 1);
printf("%c",PLAYER);
gotoxy(0,ROW_MAX);
PLAYERX = PLAYERX + 1;
WINPLAYERY = PLAYERX;
}
}break;
case LEFT:
{
if(MAP[PLAYERX][PLAYERY - 1] != ' ' || MAP[PLAYERX][PLAYERY - 2] != ' ')
{
if(MAP[PLAYERX][PLAYERY - 2] == ITEM)
{
message = ItemMessage;
gotoxy(WINPLAYERX,WINPLAYERY);
printf(" ");
gotoxy(WINPLAYERX - 2,WINPLAYERY);
printf("%c",PLAYER);
gotoxy(0,ROW_MAX);
PLAYERY = PLAYERY - 2;
WINPLAYERX = PLAYERY;
}
else
{
}
}
else
{
gotoxy(WINPLAYERX,WINPLAYERY);
printf(" ");
gotoxy(WINPLAYERX - 2,WINPLAYERY);
printf("%c",PLAYER);
gotoxy(0,ROW_MAX);
PLAYERY = PLAYERY - 2;
WINPLAYERX = PLAYERY;
}
}break;
case RIGHT:
{
if(MAP[PLAYERX][PLAYERY + 1] != ' ' || MAP[PLAYERX][PLAYERY + 2] != ' ')
{
if(MAP[PLAYERX][PLAYERY + 2] == ITEM)
{
message = ItemMessage;
gotoxy(WINPLAYERX,WINPLAYERY);
printf(" ");
gotoxy(WINPLAYERX +2,WINPLAYERY);
printf("%c",PLAYER);
gotoxy(0,ROW_MAX);
PLAYERY = PLAYERY + 2;
WINPLAYERX = PLAYERY;
}
else
{
}
}
else
{
gotoxy(WINPLAYERX,WINPLAYERY);
printf(" ");
gotoxy(WINPLAYERX + 2,WINPLAYERY);
printf("%c",PLAYER);
gotoxy(0,ROW_MAX);
PLAYERY = PLAYERY + 2;
WINPLAYERX = PLAYERY;
}
}break;
default:
{
}break;
}
return ZIP;
}
int ReadFiles()
{
char* COLMAX = new char[2];
char* ROWMAX = new char[2];
ifstream FileReader(GamePath/*\\boarddimensions.txt*/);
FileReader>>ROWMAX;
FileReader>>COLMAX;
FileReader.close();
COL_MAX = atoi(COLMAX);
return 0;
}
int QueryGame()
{
printf("Input game path\n");
cin.getline(GamePath,50,'\n');
ReadFiles();
//clrscr();
return 0;
}
int Log(const char* output)
{
ofstream writer(GamePath/*\\Log.txt*/);
writer<<message<<endl;
return 0;
}
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void PlaceChar()
{
gotoxy(PLAYERY,PLAYERX);
printf("%c",PLAYER);
gotoxy(COL_MAX,ROW_MAX);
}
void clrscr()
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
}