资源简介
用win32在控制台通过简单字符实现的推箱子游戏,比较简单,主要可以看下小游戏开发思路。vs2013编译可运行。

代码片段和文件信息
/**********************
************************/
enum GAME_ELEMENT_
{
GAME_GROUND = 0
GAME_WALL
GAME_BOXDESTINATION
GAME_DESTINATION
GAME_BOX
GAME_MAN
GAME_MANDESINATION
};
#define MAP_ROW 7
#define MAP_COLUMN 10
#include
#include
#include
using namespace std;
//空地为0 墙为1 箱子为4 人为5 目的为3
int map[MAP_ROW][MAP_COLUMN] = {
{0111111100}
{0100000100}
{0104441100}
{0100033111}
{0110033401}
{0010500001}
{0011111111}
};
int manrowstate = 0;
int mancolumstate = 0;
int LastState = GAME_GROUND;
void GetManState()
{
for (int i = 0; i < MAP_ROW; i++)
{
for (int j = 0; j < MAP_COLUMN; j++)
{
if ((map[i][j]== GAME_MAN)|| (map[i][j] == GAME_MANDESINATION))
{
manrowstate = i;
mancolumstate = j;
}
}
}
}
void DrowMap()
{
system(“cls“);
int i = 0 j = 0;
for (i = 0; i < MAP_ROW; i++)
{
for (int j = 0; j < MAP_COLUMN; j++)
{
switch (map[i][j])
{
case GAME_GROUND:
{
printf(“ “);
break;
}
case GAME_WALL:
{
printf(“■“);
break;
}
case GAME_BOXDESTINATION:
{
printf(“★“);
break;
}
case GAME_BOX:
{
printf(“□“);
break;
}
case GAME_DESTINATION:
{
printf(“☆“);
break;
}
case GAME_MAN:
case GAME_MANDESINATION:
{
printf(“♀“);
break;
}
default:
break;
}
}
printf(“\n“);
}
}
void PlayGame()
{
char keyinput;
keyinput = _getch();
bool gostate = false;
switch (keyinput)
{
case ‘w‘:
//空地
if (map[manrowstate - 1][mancolumstate]==GAME_GROUND)
{
gostate = true;
}
// 前面是箱子
if (map[manrowstate - 1][mancolumstate] == GAME_BOX)
{
if (map[manrowstate - 2][mancolumstate]== GAME_GROUND) //箱子前面是空地
{
gostate = true;
map[manrowstate - 2][mancolumstate] = GAME_BOX;
}
else if (map[manrowstate - 2][mancolumstate] == GAME_DESTINATION)//箱子前面是目的地
{
gostate = true;
map[manrowstate - 2][mancolumstate] = GAME_BOXDESTINATION;
}
}
if (map[manrowstate - 1][mancolumstate] == GAME_BOXDESTINATION)
{
if (map[manrowstate - 2][mancolumstate] == GAME_GROUND) //箱子前面是空地
{
gostate = true;
map[manrowstate - 1][mancolumstate] = GAME_DESTINATION;
map[manrowstate - 2][mancolumstate] = GAME_BOX;
}
else if (map[manrowstate - 2][mancolumstate] == GAME_DESTINATION)//箱子前面是目的地
{
gostate = true;
map[manrowstate - 1][mancolumstate] = GAME_DESTINATION;
map[manrowstate - 2][mancolumstate] = GAME_BOXDESTINATION;
}
}
if (map[manrowstate - 1][mancolumstate] == GAME_DESTINATION)
{
gostate = true;
map[manrowstate - 1][mancolumstate] = GAME_DESTINATION;
}
if (gostate == true)
{
map[manrowstate][mancolumstate] = LastState;
if (map[manrowstate - 1][mancolumstate] == GAME_DESTINATION)
{
LastSta
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-02-03 10:14 GamePlay\
目录 0 2018-02-03 10:14 GamePlay\Debug\
文件 35840 2018-02-03 10:14 GamePlay\Debug\win32box.exe
文件 232912 2018-02-03 10:14 GamePlay\Debug\win32box.ilk
文件 388096 2018-02-03 10:14 GamePlay\Debug\win32box.pdb
文件 970 2018-02-03 10:14 GamePlay\GamePlay.sln
文件 18944 2018-02-03 10:14 GamePlay\GamePlay.v12.suo
目录 0 2018-02-03 10:09 GamePlay\win32box\
目录 0 2018-02-03 10:14 GamePlay\win32box\Debug\
文件 17435 2018-02-03 10:14 GamePlay\win32box\Debug\main.obj
文件 52224 2018-02-03 10:14 GamePlay\win32box\Debug\vc120.idb
文件 61440 2018-02-03 10:14 GamePlay\win32box\Debug\vc120.pdb
文件 625 2018-02-03 10:14 GamePlay\win32box\Debug\win32box.Build.CppClean.log
文件 1294 2018-02-03 10:14 GamePlay\win32box\Debug\win32box.log
目录 0 2018-02-03 10:14 GamePlay\win32box\Debug\win32box.tlog\
文件 2512 2018-02-03 10:14 GamePlay\win32box\Debug\win32box.tlog\CL.read.1.tlog
文件 332 2018-02-03 10:14 GamePlay\win32box\Debug\win32box.tlog\CL.write.1.tlog
文件 576 2018-02-03 10:14 GamePlay\win32box\Debug\win32box.tlog\cl.command.1.tlog
文件 1002 2018-02-03 10:14 GamePlay\win32box\Debug\win32box.tlog\li
文件 2810 2018-02-03 10:14 GamePlay\win32box\Debug\win32box.tlog\li
文件 310 2018-02-03 10:14 GamePlay\win32box\Debug\win32box.tlog\li
文件 150 2018-02-03 10:14 GamePlay\win32box\Debug\win32box.tlog\win32box.lastbuildstate
文件 8124 2018-02-03 10:09 GamePlay\win32box\main.cpp
文件 4085 2018-02-03 10:09 GamePlay\win32box\win32box.vcxproj
文件 945 2018-02-03 10:09 GamePlay\win32box\win32box.vcxproj.filters
相关资源
- flash3.0小游戏
- Scrach 欢乐狙击手.sb2
- linux应用层的华容道游戏源代码
- 小鸡快跑游戏.
- 推箱子及人工智能寻路C 源代码
- [易语言]游戏多开例程
- 贪吃蛇游戏设计(汇编语言)
- VC 游戏编程—附源代码
- C 纸牌游戏——21点
- 分享 mud 文字游戏 源码
- c 制作的RPG小游戏
- 五子棋游戏实现悔棋功能
- zlib 最新 1.2.8 win32 win64 编译好的dll
- 找不同FLASH游戏源码
- planeGame飞机游戏
- 拼图游戏源代码 powerbuilder 9.0实例
- 解决WPE进不了游戏的最佳方法(闭屏
- linux扫雷游戏代码
- 多线程实例:桌面智能弹球小游戏
- “猜数字”游戏 算法破解
- OpenGL-3D坦克模拟
- 联机版井字棋源码
- 拼图游戏(可自由选择难度)
- 扫雷(MVC架构)
- 解封SHOW 51VV 9158 封机器码类游戏机
- scratch穿越迷宫.sb2
- 小鱼捉迷藏Scratch小游戏
- GlowtoolsA-wdf网易游戏wdf查看及解包
- 游戏音频图像提取工具GARbro
- OPENGL实现世界上最小的3D游戏
评论
共有 条评论