资源简介
用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
相关资源
- FLASH套环游戏flash
- 体感游戏切水果.sb3
- 迷宫游戏课程设计论文有程序
- 单片机游戏-推箱子游戏
- 排序系统设计类似于出圈游戏
- 剑侠情缘3网络版全套源代码
- 数据结构课程设计报告 迷宫游戏
- 简洁完整的flash拼图游戏AS3.0
- 51单片机贪吃蛇游戏程序
- 编写推箱子游戏程序第三步——选择
- 一个flashas3.0的拼图游戏代码
- 嵌入式赛车小游戏 源代码
- 3D游戏与计算机图形学中的数学方法
- 8086汇编语言实现双人贪食蛇游戏
- STM32开发板设计贪吃蛇游戏
- checker 国际跳棋游戏
- Unity 消灭病毒游戏源码含详细的教程
- flash as3制作的连连看小游戏
- DirectX游戏
- VHDL写的拔河游戏机
- 斗地主游戏逻辑流程图
- 基于VGA和FPGA实现的打砖块反弹球游戏
- Flash拼图游戏源代码
- 基于51单片机LCDLM041L显示贪吃蛇小游戏
- 分享几个汇编语言写的游戏
- 非常优秀的棋牌类游戏源码,包含A
- Labview实现的11款小游戏.zip
- 象棋游戏人人,人机
- 弹球游戏(课程设计)
- 暗黑源代码
评论
共有 条评论