c语言基于easyX樱花特效,C++基于easyx图形库实现推箱子游戏
本文实例为大家分享了C++实现推箱子游戏的具体代码,供大家参考,具体内容如下
头文件:
#include
#include
//#include
#include
#include
#include
//播放音乐需要的头文件
#include
#pragma comment(lib,"winmm.lib")
//格子边长
#define SPACE 60
//6.3.1 定义变量
IMAGE png[12];//5张图,定义5个变量,定义一个数组
#define MapMany 6
//枚举方向
enum CH {
right = 1,
left = 2,
up = 3,
down = 4
}ch;
//定义一个全局三维数组
//0表示空地“ ” 1表示墙“■” 2代表目的地“⊙” 3代表人站在空地上“♀” 4代表箱子“□”
//5箱子与目的地重合“◆” 6,人站在目的地上“♀”
//下面定义地图
int map[MapMany][10][10] = {
//图一
{
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 2, 0, 1, 1, 0, 0, 0, 2, 1 },
{ 1, 0, 0, 1, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 1, 1, 1, 0, 4, 1 },
{ 1, 0, 0, 1, 1, 1, 1, 0, 0, 1 },
{ 1, 0, 0, 1, 1, 1, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 1, 1, 0, 0, 0, 1 },
{ 1, 4, 0, 0, 0, 0, 0, 3, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
},
//图二
{
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 0, 1, 2, 0, 0, 0, 4, 0, 1 },
{ 1, 0, 1, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 1, 0, 0, 1, 1, 0, 0, 1 },
{ 1, 0, 1, 0, 0, 1, 1, 0, 0, 1 },
{ 1, 0, 1, 1, 1, 1, 1, 0, 3, 1 },
{ 1, 0, 1, 1, 1, 1, 1, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 2, 0, 0, 4, 0, 0, 0, 0, 1 },
{ 1,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, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
},
//图六
{
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
}
};
//定义当前关卡
int WhatMap = 0;//初始化位第0张地图
void DrawMap(int n);
void initscreen();
void ManUp();
int KbHit();
void ManUp();
void ManRight();
void ManLeft();
void ManDown();
int GameOver();
void drawGame();
CPP文件:
#include"SokoBan.h"
int main()
{
initscreen();
//播放音乐
mciSendString(TEXT("open sun.mp3 alias mysong"), NULL, 0, NULL);
mciSendString(TEXT("play mySong"), NULL, 0, NULL);
while (1)
{
switch (KbHit())
{
case 4:ManUp(); break;
case 2:ManLeft(); break;
case 1:ManRight(); break;
case 3:ManDown(); break;
//case 0:continue;
}
drawGame();
if (GameOver())
{
WhatMap++;
Sleep(1000);
}
if (WhatMap == 3)break;
}
loadimage(&png[7], _T("6.jpg"), 10*SPACE, 10*SPACE, true);
putimage(0, 0, &png[7]);
Sleep(10000);
return 0;
//printf("作者:小豆芽\n时间:2018/12/18\n版权:2862841130@qq.com");
//system("pause");
}
//设置窗口大小
void initscreen()
{
initgraph(10 * SPACE, 10 * SPACE );
//6.3.2 加载图片
//0表示空地“ ” 1表示墙“■” 2代表目的地“⊙” 3代表人站在空地上“♀” 4代表箱子“□”
//5箱子与目的地重合“◆” 6,人站在目的地上“♀”
loadimage(&png[0], _T("0.jpg"), SPACE, SPACE, true);
loadimage(&png[1], _T("1.jpg"), SPACE, SPACE, true);
loadimage(&png[2], _T("2.jpg"), SPACE, SPACE, true);
loadimage(&png[3], _T("3.jpg"), SPACE, SPACE, true);
loadimage(&png[4], _T("4.jpg"), SPACE, SPACE, true);
loadimage(&png[5], _T("5.jpg"), SPACE, SPACE, true);
loadimage(&png[6], _T("3.jpg"), SPACE, SPACE, true);
//以下是windows窗口
//system("mode con cols=20 lines=10"); //cols 代表列 //lines 代表行
// //设置标题
//SetConsoleTitleA("推箱子"); //设置标题
}
//贴图
void drawGame() {
for (int i = 0; i < 10; i++) {//显示一行
for (int j = 0; j < 10; j++) {//显示一个格子
putimage(j*SPACE, i*SPACE, &png[map[WhatMap][i][j]]);
}
}
}
//画出地图
//0表示空地“ ” 1表示墙“■” 2代表目的地“⊙” 3代表人“♀” 4代表箱子“□”
//5箱子与目的地重合“◆” 6,人站在目的地
void DrawMap(int n)
{
system("cls");
for (int j = 0; j < 10; j++)
{
int i;
for (i = 0; i < 10; i++)
{
if (map[WhatMap][i][j] == 0)printf(" ");
if (map[WhatMap][i][j] == 1)printf("■");
if (map[WhatMap][i][j] == 2)printf("⊙");
if (map[WhatMap][i][j] == 3)printf("♀");
if (map[WhatMap][i][j] == 4)printf("□");
if (map[WhatMap][i][j] == 5)printf("◆");
if (map[WhatMap][i][j] == 6)printf("♀");
}
if(i<9)printf("\n");
}
}
//判断按键操作
int KbHit()
{
if (GetAsyncKeyState(VK_UP)&1)return up;
else if (GetAsyncKeyState(VK_DOWN)&1)return down;
else if (GetAsyncKeyState(VK_RIGHT)&1)return right;
else if (GetAsyncKeyState(VK_LEFT)&1)return left;
else return 0;
}
//********************************************人向上移动
void ManUp()
{
//先找到人的位置
int i, j;
for (i = 0; i < 10; i++)
{
int flag = 0;
for (j = 0; j < 10; j++)
if (map[WhatMap][i][j] == 3 || map[WhatMap][i][j] == 6)
{
flag = 1;
break;
}
if (flag)break;
}
//人的位置是map[WhatMap][i][j];
//改变人的方向
//人的位置是空地
if (map[WhatMap][i][j] == 3)
{
//***********人的上面是空地
if (map[WhatMap][i + 1][j] == 0)
{
map[WhatMap][i][j] = 0;
map[WhatMap][i + 1][j] = 3;
}
//************人的上面是目的地
else if (map[WhatMap][i + 1][j] == 2)
{
map[WhatMap][i][j] = 0;
map[WhatMap][i + 1][j] = 6;
}
//*************人的上面是箱子
else if (map[WhatMap][i + 1][j] == 4)
{
//1,***********箱子上面是目的地
if (map[WhatMap][i + 2][j] == 2)
{
map[WhatMap][i][j] = 0;
map[WhatMap][i + 1][j] = 3;
map[WhatMap][i + 2][j] = 5;
}
//2,************箱子上面是空地
else if (map[WhatMap][i + 2][j] == 0)
{
map[WhatMap][i][j] = 0;
map[WhatMap][i + 1][j] = 3;
map[WhatMap][i + 2][j] = 4;
}
//3,*************箱子上面是。。。。。
}
}
//人的位置是目的地
else if (map[WhatMap][i][j] == 6)
{
//***********人的上面是空地
if (map[WhatMap][i + 1][j] == 0)
{
map[WhatMap][i][j] = 2;
map[WhatMap][i + 1][j] = 3;
}
//************人的上面是目的地
else if (map[WhatMap][i + 1][j] == 2)
{
map[WhatMap][i][j] = 2;
map[WhatMap][i + 1][j] = 6;
}
//*************人的上面是箱子
else if (map[WhatMap][i + 1][j] == 4)
{
//1,***********箱子上面是目的地
if (map[WhatMap][i + 2][j] == 2)
{
map[WhatMap][i][j] = 2;
map[WhatMap][i + 1][j] = 3;
map[WhatMap][i + 2][j] = 5;
}
//2,************箱子上面是空地
else if (map[WhatMap][i + 2][j] == 0)
{
map[WhatMap][i][j] = 2;
map[WhatMap][i + 1][j] = 3;
map[WhatMap][i + 2][j] = 4;
}
//3,*************箱子上面是。。。。。
}
}
}
//********************************************人向右移动
void ManRight()
{
//先找到人的位置
int i, j;
for (i = 0; i < 10; i++)
{
int flag = 0;
for (j = 0; j < 10; j++)
if (map[WhatMap][i][j] == 3 || map[WhatMap][i][j] == 6)
{
flag = 1;
break;
}
if (flag)break;
}
//人的位置是map[WhatMap][i][j];
//改变人的方向
//人的位置是空地
if (map[WhatMap][i][j] == 3)
{
//***********人的右面是空地
if (map[WhatMap][i][j+1] == 0)
{
map[WhatMap][i][j] = 0;
map[WhatMap][i][j+1] = 3;
}
//************人的右面是目的地
else if (map[WhatMap][i][j+1] == 2)
{
map[WhatMap][i][j] = 0;
map[WhatMap][i][j+1] = 6;
}
//*************人的右面是箱子
else if (map[WhatMap][i][j+1] == 4)
{
//1,***********箱子右面是目的地
if (map[WhatMap][i][j+2] == 2)
{
map[WhatMap][i][j] = 0;
map[WhatMap][i][j+1] = 3;
map[WhatMap][i][j+2] = 5;
}
//2,************箱子右面是空地
else if (map[WhatMap][i][j+2] == 0)
{
map[WhatMap][i][j] = 0;
map[WhatMap][i][j+1] = 3;
map[WhatMap][i][j+2] = 4;
}
//3,*************箱子右面是。。。。。
}
}
//人的位置是目的地
else if (map[WhatMap][i][j] == 6)
{
//***********人的右面是空地
if (map[WhatMap][i][j+1] == 0)
{
map[WhatMap][i][j] = 2;
map[WhatMap][i][j+1] = 3;
}
//************人的右面是目的地
else if (map[WhatMap][i][j+1] == 2)
{
map[WhatMap][i][j] = 2;
map[WhatMap][i][j+1] = 6;
}
//*************人的右面是箱子
else if (map[WhatMap][i][j+1] == 4)
{
//1,***********箱子右面是目的地
if (map[WhatMap][i][j+2] == 2)
{
map[WhatMap][i][j] = 2;
map[WhatMap][i][j+1] = 3;
map[WhatMap][i][j+2] = 5;
}
//2,************箱子右面是空地
else if (map[WhatMap][i][j+2] == 0)
{
map[WhatMap][i][j] = 2;
map[WhatMap][i][j+1] = 3;
map[WhatMap][i][j+2] = 4;
}
//3,*************箱子右面是。。。。。
}
}
}
//********************************************人向左移动
void ManLeft()
{
//先找到人的位置
int i, j;
for (i = 0; i < 10; i++)
{
int flag = 0;
for (j = 0; j < 10; j++)
if (map[WhatMap][i][j] == 3 || map[WhatMap][i][j] == 6)
{
flag = 1;
break;
}
if (flag)break;
}
//人的位置是map[WhatMap][i][j];
//改变人的方向
//人的位置是空地
if (map[WhatMap][i][j] == 3)
{
//***********人的左面是空地
if (map[WhatMap][i][j-1] == 0)
{
map[WhatMap][i][j] = 0;
map[WhatMap][i][j-1] = 3;
}
//************人的左面是目的地
else if (map[WhatMap][i][j-1] == 2)
{
map[WhatMap][i][j] = 0;
map[WhatMap][i][j-1] = 6;
}
//*************人的左面是箱子
else if (map[WhatMap][i][j-1] == 4)
{
//1,***********箱子左面是目的地
if (map[WhatMap][i][j-2] == 2)
{
map[WhatMap][i][j] = 0;
map[WhatMap][i][j-1] = 3;
map[WhatMap][i][j-2] = 5;
}
//2,************箱子左面是空地
else if (map[WhatMap][i][j-2] == 0)
{
map[WhatMap][i][j] = 0;
map[WhatMap][i][j-1] = 3;
map[WhatMap][i][j-2] = 4;
}
//3,*************箱子左面是。。。。。
}
}
//人的位置是目的地
else if (map[WhatMap][i][j] == 6)
{
//***********人的上面是空地
if (map[WhatMap][i][j-1] == 0)
{
map[WhatMap][i][j] = 2;
map[WhatMap][i][j-1] = 3;
}
//************人的上面是目的地
else if (map[WhatMap][i][j-1] == 2)
{
map[WhatMap][i][j] = 2;
map[WhatMap][i][j-1] = 6;
}
//*************人的上面是箱子
else if (map[WhatMap][i][j-1] == 4)
{
//1,***********箱子上面是目的地
if (map[WhatMap][i][j-2] == 2)
{
map[WhatMap][i][j] = 2;
map[WhatMap][i][j-1] = 3;
map[WhatMap][i][j-2] = 5;
}
//2,************箱子上面是空地
else if (map[WhatMap][i][j-2] == 0)
{
map[WhatMap][i][j] = 2;
map[WhatMap][i][j-1] = 3;
map[WhatMap][i][j-2] = 4;
}
//3,*************箱子上面是。。。。。
}
}
}
//********************************************人向下移动
void ManDown()
{
//先找到人的位置
int i, j;
for (i = 0; i < 10; i++)
{
int flag = 0;
for (j = 0; j < 10; j++)
if (map[WhatMap][i][j] == 3 || map[WhatMap][i][j] == 6)
{
flag = 1;
break;
}
if (flag)break;
}
//人的位置是map[WhatMap][i][j];
//改变人的方向
//人的位置是空地
if (map[WhatMap][i][j] == 3)
{
//***********人的下面是空地
if (map[WhatMap][i - 1][j] == 0)
{
map[WhatMap][i][j] = 0;
map[WhatMap][i - 1][j] = 3;
}
//************人的上面是目的地
else if (map[WhatMap][i - 1][j] == 2)
{
map[WhatMap][i][j] = 0;
map[WhatMap][i - 1][j] = 6;
}
//*************人的上面是箱子
else if (map[WhatMap][i - 1][j] == 4)
{
//1,***********箱子上面是目的地
if (map[WhatMap][i - 2][j] == 2)
{
map[WhatMap][i][j] = 0;
map[WhatMap][i - 1][j] = 3;
map[WhatMap][i - 2][j] = 5;
}
//2,************箱子上面是空地
else if (map[WhatMap][i - 2][j] == 0)
{
map[WhatMap][i][j] = 0;
map[WhatMap][i - 1][j] = 3;
map[WhatMap][i - 2][j] = 4;
}
//3,*************箱子上面是。。。。。
}
}
//人的位置是目的地
else if (map[WhatMap][i][j] == 6)
{
//***********人的上面是空地
if (map[WhatMap][i - 1][j] == 0)
{
map[WhatMap][i][j] = 2;
map[WhatMap][i - 1][j] = 3;
}
//************人的上面是目的地
else if (map[WhatMap][i - 1][j] == 2)
{
map[WhatMap][i][j] = 2;
map[WhatMap][i - 1][j] = 6;
}
//*************人的上面是箱子
else if (map[WhatMap][i - 1][j] == 4)
{
//1,***********箱子上面是目的地
if (map[WhatMap][i - 2][j] == 2)
{
map[WhatMap][i][j] = 2;
map[WhatMap][i - 1][j] = 3;
map[WhatMap][i - 2][j] = 5;
}
//2,************箱子上面是空地
else if (map[WhatMap][i - 2][j] == 0)
{
map[WhatMap][i][j] = 2;
map[WhatMap][i - 1][j] = 3;
map[WhatMap][i - 2][j] = 4;
}
//3,*************箱子上面是。。。。。
}
}
}
//判断游戏是否结束
int GameOver()
{
//统计目的地的个数
int flag = 0;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
if (map[WhatMap][i][j] == 2)flag++;
}
}
//箱子到达目的地的个数
int count = 0;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
if (map[WhatMap][i][j] == 4)count++;
}
}
if (count == 0&&flag == 0 )return 1;
else return 0;
}
运行效果:
游戏资源:
1.
2.
3.
4.
5.
6.
结束展示:
更多有趣的经典小游戏实现专题,分享给大家:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
c语言基于easyX樱花特效,C++基于easyx图形库实现推箱子游戏相关推荐
- c语言语音控制游戏文献,C语言课程设计-基于C语言推箱子游戏设计-毕业论文文献.doc...
gd工程职业技术学院毕业论文 基于C语言的推箱子游戏设计 Design of the push box Based on Combined Language 作者姓名: 学科专业: 应用电子技术 学院 ...
- c 语言推箱子vs,基于C语言实现推箱子游戏
本文实例为大家分享了C语言实现推箱子游戏的具体代码,供大家参考,具体内容如下 代码在vs2013上测试运行. 思想: 1):地图用二维数组实现,箱子.墙壁.人等事物用不同的数字表示,遍历二维数组,遇到 ...
- 【java毕业设计】基于java+swing+Eclipse的推箱子游戏设计与实现(毕业论文+程序源码)——推箱子游戏
基于java+swing+Eclipse的推箱子游戏设计与实现(毕业论文+程序源码) 大家好,今天给大家介绍基于java+swing+Eclipse的推箱子游戏设计与实现,文章末尾附有本毕业设计的论文 ...
- 推箱子游戏java毕业答辩ppt_基于Java推箱子游戏的设计与实现
基于Java推箱子游戏的设计与实现(任务书,外文翻译,毕业论文20000字,程序代码,答辩PPT) 摘 要 社会在进步,人们生活质量也在日益提高.高强度的压力也接踵而来.社会中急需出现新的有效方 ...
- 基于HTML(canvas)的推箱子游戏
基于HTML(canvas)的推箱子游戏.zip 有积分的自己自行下载吧,没有积分的兄弟可以评论留邮箱,看到后会给你们发过去. 游戏截图 设计过程 1. 设计目标:推箱子游戏2. 设计思路 ...
- 基于java的推箱子游戏系统设计与实现(项目报告+答辩PPT+源代码+部署视频)
项目报告 基于Java的推箱子游戏设计与实现 社会在进步,人们生活质量也在日益提高.高强度的压力也接踵而来.社会中急需出现新的有效方式来缓解人们的压力.此次设计符合了社会需求,Java推箱子游戏可以让 ...
- 基于Java+Swing实现推箱子游戏
基于Java+Swing实现推箱子游戏 一.系统介绍 二.功能展示 三.其他系统 四.获取源码 一.系统介绍 基于JAVA的推箱子游戏系统主要用于实现游戏推箱子功能,提供多种不同难度的关卡.本系统结构 ...
- C语言+easyx图形库 推箱子游戏1.0
本人编程小白,在学完C语言后尝试学习制作了推箱子小游戏,途中收获颇多,在此对于整个过程做一回顾梳理,若有写的不对的地方,还望各位大佬指正. 本篇文章为1.0版本,没有关卡,但拥有推箱子游戏较核心的功能 ...
- 基于单片机的推箱子游戏设_推箱子游戏51单片机课设计(最全).doc
<51单片机> 课程设计 题 目:基于51单片机的推箱子游戏设计 目 录 1.课程设计目的1 2.课程设计题目和实现目标1 3.设计方案1 4.Proteus仿真原理图7 5.程序设计9 ...
最新文章
- 基于Kubernetes构建现代大数据管道
- codeforces524E
- python【力扣LeetCode算法题库】5- 最长回文子串
- ATT开源项目反客为主
- 比亚迪汉鸿蒙系统测评_华为正式进军汽车领域!鸿蒙OS车机系统加持:帮助更多车企quot;造好车quot;...
- Problem G. Pandaria(线段树合并 + Kruskal 重构树)
- 《Python爬虫开发与项目实战》——1.6 小结
- 有关Activity的Launch mode 以及Intent的setFlags(转载)
- MongoDB 插入、更新、删除
- ABB主计算机作用是什么,一文读懂ABB机器人通信功能
- 使用Gradle构建Spring源码
- linux用openssl制作自签名数字证书
- 轴承后缀ce和ca_轴承cc和ca与cde4有什么区别
- Google adsense帐户被封到解封全过程
- W3af详细安装与基本使用
- Xcode No certificate for team ‘xxx‘ matching ‘iPhone Developer: xxx (xxx)‘
- 像素三国志在线html5小游戏,像素三国志
- 计算机毕业设计Java传统文化知识竞赛系统(源码+系统+mysql数据库+lw文档
- Memcached replace 命令
- 优麒麟系统Ubuntu Kylin的网络配置