<> The realization of pushing box game

<> Construction of development environment

* Because what I use here is vs2019 So use 2019 To demonstrate
* First, baidu homepage search easyx
* Find the official website

* After downloading, just open the installation
* You can install it directly according to your own version
*
In this way, the development environment is set up
<> Game implementation

* reminder
Need to add header file graphics.h #include <graphics.h> #include <iostream> #include
<stdlib.h> #include <string.h> #include <conio.h> using namespace std; #define
RATIO 61 #define SCREEN_WIDTH 960 #define SCREEN_HEIGHT 768 // Key upper , lower , Left , right Control direction
,‘q’ sign out #define KEY_UP 'w' //char'a' #define KEY_LEFT 'a' #define KEY_RIGHT 'd' #
define KEY_DOWN 's' #define KEY_QUIT 'q' #define LINE 9 #define COLUMN 12 #
define START_X 100 // Image display offset #define START_Y 150 enum _PROPS { WALL, // wall FLOOR,
// floor BOX_DES, // Box destination MAN, // Villain BOX, // case HIT, // Box hit target ALL }; // Game control direction enum
_DIRECTION{ UP, DOWN, LEFT, RIGHT }; struct _POS { int x; // Row of 2-D array of Villains int y;
// The columns of the two-dimensional array of Villains }; IMAGE images[ALL]; struct _POS man; // The position of the villain in the two-dimensional array /* Game map */ int
map[LINE][COLUMN] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 1, 0, 1, 1, 1
, 1, 1, 1, 1, 0, 0 }, { 0, 1, 4, 1, 0, 2, 1, 0, 2, 1, 1, 0 }, { 0, 1, 0, 1, 0, 1
, 0, 0, 1, 1, 1, 0 }, { 0, 1, 0, 2, 0, 1, 1, 4, 1, 1, 1, 0 }, { 0, 1, 1, 1, 1, 3
, 1, 1, 1, 4, 1, 0 }, { 0, 1, 2, 1, 1, 4, 1, 1, 1, 1, 1, 0 }, { 0, 1, 0, 0, 1, 0
, 1, 1, 0, 0, 1, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, };
/*************************************************** * Change the corresponding props in the game view and display them again * input : *
line - Item in row subscript of map array * column- - Item subscript in the column of map array * prop - Types of props * Return value : nothing
***************************************************/ void changeMap(int line,
int column, enum _PROPS prop) { map[line][column] = prop; putimage(START_X +
column* RATIO, START_Y + line * RATIO, &images[prop]); }
/************************************************** * Four directions of the game ( upper , lower , Left , right ) Control of * input :
* direct - People's direction * output : nothing ***************************************************/
void gameControl(enum _DIRECTION direct) { int x = man.x; int y = man.y; if (
direct= UP) {// First, deal with the situation that the forward direction is the floor if ((x - 1) >= 0 && map[x - 1][y] == FLOOR) {
changeMap(x - 1, y, MAN);// The advance of villain man.x = x - 1; changeMap(x, y, FLOOR); } }
else if (direct == DOWN) { if ((x + 1) < LINE && map[x + 1][y] == FLOOR) {
changeMap(x + 1, y, MAN);// The advance of villain man.x = x + 1; changeMap(x, y, FLOOR); } }
else if (direct == LEFT) { if ((y - 1) >= 0 && map[x][y - 1] == FLOOR) {
changeMap(x, y - 1, MAN);// The advance of villain man.y = y - 1; changeMap(x, y, FLOOR); } }
else if (direct == RIGHT) { if ((y + 1) < COLUMN && map[x][y + 1] == FLOOR) {
changeMap(x, y + 1, MAN);// The advance of villain man.y = y + 1; changeMap(x, y, FLOOR); } } }
int main(void) { IMAGE bg_img; // The initialization of the game background is like , It's the same with the stage initgraph(SCREEN_WIDTH,
SCREEN_HEIGHT); loadimage(&bg_img, _T("blackground.bmp"), SCREEN_WIDTH,
SCREEN_HEIGHT, true); putimage(0, 0, &bg_img); // Load item icon loadimage(&images[WALL],
_T("wall.bmp"), RATIO, RATIO, true); loadimage(&images[FLOOR], _T("floor.bmp"),
RATIO, RATIO, true); loadimage(&images[BOX_DES], _T("des.bmp"), RATIO, RATIO,
true); loadimage(&images[MAN], _T("man.bmp"), RATIO, RATIO, true); loadimage(&
images[BOX], _T("box.bmp"), RATIO, RATIO, true); loadimage(&images[HIT], _T(
"box.bmp"), RATIO, RATIO, true); for (int i = 0; i < LINE; i++) { for (int j = 0
; j < COLUMN; j++) { if (map[i][j] == MAN) { man.x = i; man.y = j; }
// Display props puimage( The position coordinates of the upper left corner of the picture are displayed in the position of the window , Address of array putimage(START_X + j * RATIO, START_Y + i
* RATIO, &images[map[i][j]]); } } // Game link bool quit = false; do { if (_kbhit()) {
// Player buttons char ch = _getch(); if (ch == KEY_UP) { gameControl(UP); } else if (ch ==
KEY_DOWN) { gameControl(DOWN); } else if (ch == KEY_LEFT) { gameControl(LEFT);
} else if (ch == KEY_RIGHT) { gameControl(RIGHT); } else if (ch == KEY_QUIT) {
quit= true; } } Sleep(100); // dormancy 100ms ,100 millisecond 0.1 second } while (quit = false); //!quit
system("pause"); return 0; // Qiniu College - Residual core }

Technology
©2019-2020 Toolsou All rights reserved,
latex Custom commands in ———\newcommand( Essence )2020 year 8 month 9 day C# Basic knowledge reflex Maximum security risk of cloud computing : Unclear safety responsibility Map---Java judge Map Contains a keyvs2017, establish C++Win32 Windows Forms Application Go language Array initialization and basic operations Vue Transfer parameters and receiving of page Jump java Several common runtime exceptions and simple examples css Basics 2:flex Multi row layout with gaps element ui Drop down box search function