Code:
#include <iostream.h>
#include <windows.h>
#include <conio.h>
#include <fstream.h>
#include <stdlib.h>
#include <string>
#include <stdio.h>
int keypress=0;
char message[50];
char tempmessage[50];
int space1gone=0;
int space2gone=0;
void frame (int xmin,int ymin,int xmax,int ymax);
void gotoxy(int,int);
void printmove(char message[], char tempmessage[], int& space1gone, int& space2gone);
void determinemessage(char message[], char tempmessage[], int keypress);
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
int main()
{
frame(0,0,55,20); //Biggest box
frame(56,0,79,24); //Right-side box
frame(0,21,55,24); //Message Box
for(;;)
{
if(kbhit())
{
keypress=_getch();
determinemessage(message, tempmessage, keypress); //Determine what to print
printmove(message, tempmessage, space1gone, space2gone); //print in correct spot
}
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
void frame (int xmin, int ymin, int xmax, int ymax)
{
int count;
gotoxy(xmin,ymin);
putchar(218);
gotoxy(xmax,ymin);
putchar(191);
gotoxy(xmin,ymax);
putchar(192);
gotoxy(xmax,ymax);
putchar(217);
gotoxy(xmin+1,ymin);
for(count=xmin; count<xmax-1; count++)
putchar(196);
gotoxy(xmin+1,ymax);
for(count=xmin; count<xmax-1; count++)
putchar(196);
for(count=ymin+1; count<=ymax-1; count++)
{
gotoxy(xmin,count);
putchar(179);
}
for(count=ymin+1; count<=ymax-1; count++)
{
gotoxy(xmax,count);
putchar(179);
}
}
void gotoxy(int x, int y)
{
HANDLE hConsoleOutput;
COORD dwCursorPosition;
dwCursorPosition.X = x;
dwCursorPosition.Y = y;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
}
void printmove(char message[], char tempmessage[], int& space1gone, int& space2gone)
{
if(space2gone==0) //checks if first spot is open
{
if(space1gone==0) //checks if second spot is open
{
gotoxy(1,22);
cout<<message;
}
else if(space1gone==1) //first spot is used, second is open
{
gotoxy(1,23);
cout<<message;
}
space1gone=1;
}
else if(space2gone==1) //second spot is used
{
gotoxy(1,22);
cout<<tempmessage;
gotoxy(1,23);
cout<<message;
}
space2gone=1;
}
void determinemessage(char message[], char tempmessage[], int keypress)
{
strcpy(tempmessage,message);
if(keypress==72)
strcpy(message, "You moved up");
if(keypress==75)
strcpy(message, "You moved left");
if(keypress==80)
strcpy(message, "You moved down");
if(keypress==77)
strcpy(message, "You moved right");
}
i would really appreciate some help