C++加EasyX实现多关卡推箱子,包括撤回,存档功能。
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <graphics.h>
#include <conio.h>
#include <fstream>
using namespace std;
const int Length = 5, width = 12, height = 16;
/*-------------------------按钮---------------------------*/
class Button
{
int Buttonwidth = 80;
int Buttonheight = 40;
const char* str;
int x, y;
public:
Button(int x, int y, const char* str, int Buttonwidth = 80, int Buttonheight = 40)
{
this->x = x;
this->y = y;
this->str = str;
this->Buttonwidth = Buttonwidth;
this->Buttonheight = Buttonheight;
}
//位置(x,y)处画按钮
void drawButton()
{
setfillcolor(WHITE);
fillrectangle(x, y, x + Buttonwidth, y + Buttonheight);
setbkmode(TRANSPARENT);
RECT r1 = {
x,y,x + Buttonwidth,y + Buttonheight };
settextstyle(20, 0, _T("华文楷体"),0,0,100,false, false, false);
settextcolor(BLACK);
drawtext(str, &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
};
//判断点(x,y)是不是在按钮(bx,by)范围内
bool judgeButton(int x, int y, int bx, int by, int Buttonwidth = 80, int Buttonheight = 40) {
if (x >= bx && x <= bx + Buttonwidth && y >= by && y <= by + Buttonheight)
return true;
return false;
}
/*---------------------------图片输出的类----------------------------*/
class PRINT
{
int X, Y;
int XX, YY;
int t;
int x, y;
int n, m;
const int fangcun = 40;
char CH;
IMAGE xiaozhi, wasi, jinglingqiuK, jinglingqiuP, qiang, pikaqiu, jinglingqiu, bai;
public:
void sdfs(int t, int const& width, int const& height,
char const CH, int const WIDTH, int const HEIGHT)
{
this->x = 0;
this->y = 0;
this->m = width;
this->n = height;
this->t = t;
this->CH = CH;
this->X = WIDTH;
this->Y = HEIGHT;
loadimage(&qiang, "qiang.jpg", fangcun, fangcun);
loadimage(&jinglingqiuK, "jinglingqiuk.jpg", fangcun, fangcun);
loadimage(&bai, "bai.jpg", fangcun, fangcun);
loadimage(&xiaozhi, "xiaozhi1.jpg", fangcun, fangcun);
loadimage(&jinglingqiuP, "jinglingqiuP.jpg", fangcun, fangcun);
loadimage(&pikaqiu, "pikaqiu.jpg", fangcun, fangcun);
}
void Tihuan(char(*A)[width][height])
{
for (x = 0; x < n; x++)
for (y = 0; y < m; y++)
{
switch (A[t][y][x])
{
case '#':
putimage(x * fangcun, y * fangcun, &qiang);
break;
case 'S':
putimage(x * fangcun, y * fangcun, &xiaozhi);
break;
case 'O':
putimage(x * fangcun, y * fangcun, &pikaqiu);
break;
case '*':
putimage(x * fangcun, y * fangcun, &jinglingqiuK);
break;
case '@':
putimage(x * fangcun, y * fangcun, &jinglingqiuP);
break;
case '1':
putimage(x * fangcun, y * fangcun, &bai);
break;
}
}
}
};
/*-----------------------------------------------------------------------------------------------------*/
class observers
{
public:
void Step(int& X, int& Y, char ch)
{
switch (ch)
{
case