• 大小: 157KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-18
  • 语言: 其他
  • 标签: win32  推箱子  游戏  

资源简介

用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\link.command.1.tlog
     文件        2810  2018-02-03 10:14  GamePlay\win32box\Debug\win32box.tlog\link.read.1.tlog
     文件         310  2018-02-03 10:14  GamePlay\win32box\Debug\win32box.tlog\link.write.1.tlog
     文件         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

评论

共有 条评论