資源簡介
用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? {
for?(int?j?=?0;?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? {
for?(int?j?=?0;?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
評論
共有 條評論