rendered paste body#include <iostream>#include <conio.h>#include <windows.h>#include <time.h>using namespace std;int running=0;int initvar=0;int dir=2;int xpos = 39, ypos = 13;int oldxpos, oldypos;int draw=1;int lives=3;void sleep(unsigned int mseconds){ clock_t goal = mseconds + clock(); while (goal > clock());}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 init(){ for (int i=0; i < 80; i++) { for (int j=0; j < 25; j++) { gotoxy(i,j); cout<<" "; } }}void draw_status(){ for (int i=0; i < 80; i++) { gotoxy(i,1); cout<<"-"; }}int main(){ if (initvar==0) { init(); initvar=1; draw_status(); } while(running != 1) { if (_kbhit()) { int ch = getch(); oldxpos = xpos; oldypos = ypos; switch(ch) { case 27 : { running = 1; break; } case 72 : { if (ypos > 3) ypos--; dir=8; draw = 1; break; } case 75 : { if (xpos > 1) xpos--; dir=4; draw = 1; break; } case 77 : { if (xpos < 78) xpos++; dir=6; draw = 1; break; } case 80 : { if (ypos < 23) ypos++; dir=2; draw = 1; break; } case 224 : { break; //do nothing } default : { //cout<<ch; break; } } } if (draw == 1) { gotoxy(oldxpos-1,oldypos-1); cout<<" "; gotoxy(oldxpos-1,oldypos); cout<<" "; gotoxy(oldxpos-1,oldypos+1); cout<<" "; gotoxy(0,0); cout<<" "; gotoxy(0,0); cout<<xpos <<"," <<ypos; switch(dir) { case 8 : { gotoxy(xpos-1,ypos-1); cout<<"\"|\""; gotoxy(xpos-1,ypos); cout<<"\"O\""; gotoxy(xpos-1,ypos+1); cout<<"\" \""; break; } case 4 : { gotoxy(xpos-1,ypos-1); cout<<"==="; gotoxy(xpos-1,ypos); cout<<"-O "; gotoxy(xpos-1,ypos+1); cout<<"==="; break; } case 6 : { gotoxy(xpos-1,ypos-1); cout<<"==="; gotoxy(xpos-1,ypos); cout<<" O-"; gotoxy(xpos-1,ypos+1); cout<<"==="; break; } case 2 : { gotoxy(xpos-1,ypos-1); cout<<"\" \""; gotoxy(xpos-1,ypos); cout<<"\"O\""; gotoxy(xpos-1,ypos+1); cout<<"\"|\""; break; } } gotoxy(0,0); draw = 0; } sleep(5); } init(); return 0;}