1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <iostream>
#include <windows.h>
#include <graphics.h>
#include <conio.h>
using namespace std;
bool gameOver;
enum eDirection {STOP = 0, LEFT, UP, RIGHT, DOWN, END, PAUSE};
eDirection dir;
int windowW = 1200, windowH = 1000;
int bodyL = (windowW / 2) - 30, bodyT = (windowH / 2) -30, bodyR = (windowW / 2) + 30, bodyB = (windowH / 2) + 30;
int roomL = 200, roomT = 200, roomR = 1500, roomB = 1500; //board
void setup(){
gameOver = false;
rectangle(bodyL, bodyT, bodyR, bodyB);
rectangle(roomL, roomT, roomR, roomB); //board
}
void imput(){
if(_kbhit()){
switch(_getch()){
case 'a':
dir = LEFT
break;
case 'w':
dir = UP;
break;
case 'd':
dir = RIGHT;
break;
case 's':
dir = DOWN;
break;
case 'p':
dir = PAUSE;
break;
case 'x':
dir = END;
break;
}
}
}
void logic(){
switch(dir){
case LEFT:
roomL += 20;
roomR += 20;
break;
case UP:
roomT += 20;
roomB += 20;
break;
case RIGHT:
roomL -= 20;
roomR -= 20;
break;
case DOWN:
roomT -= 20;
roomB -= 20;
break;
case PAUSE:
system("pause");
break;
case END:
exit(0);
break;
}
}
void draw(){
rectangle(bodyL, bodyT, bodyR, bodyB);
rectangle(roomL, roomT, roomR, roomB); //board
dir = STOP;
}
int main()
{
initwindow(windowW, windowH, "");
setup();
int page = 0;
system("pause");
while(!gameOver){
setactivepage(page);
setvisualpage(1 - page);
cleardevice();
imput();
logic();
draw();
page = 1 - page;
Sleep(20);
}
return 0;
}
| |