資源簡介
C語言推箱子游戲(有注釋文檔),強化學習數組以及對函數定義調用,我在每行代碼都給出的詳細的解釋,非常適合初學者
代碼片段和文件信息
//?newPushBox.cpp?:?定義控制臺應用程序的入口點。
//
#include?“stdafx.h“
#include?
#include?
const?int?nBoxCount?=?20;
const?int?nMaxLevel?=?2;
const?int?nTotleLevelCount?=?nMaxLevel?+?1;
const?int?nRoleInitPos[nTotleLevelCount]?=?{44?56?67};//每一關人物的初始化位置
const?int?nBoxCountPerLevel[nTotleLevelCount]?=?{4?3?1};//每一關箱子的數量
const?int?nBoxArrayPerLevel[nTotleLevelCount][nBoxCount]?=?{{33?35?43?54}?{65?66?67}?{76}};//每一關箱子的初始化位置
//字符數組,三張表,100行,每行有三個表單(三列)每行存儲一個字符串(不是字符),一共有100個字符串(一個字符串占一行)
char?szMap[nTotleLevelCount][100][3]?=?{
{
“??““??““¤““¤““¤““??““??““??““??““??“?
“??““??““¤““⊙““¤““??““??““??““??““??“
“??““??““¤““□““¤““¤““¤““¤““??““??“
“¤““¤““¤““□““□““□““⊙““¤““??““??“
“¤““⊙““□““□““□““¤““¤““¤““??““??“
“¤““¤““¤““¤““□““¤““??““??““??““??“
“??““??““??““¤““⊙““¤““??““??““??““??“
“??““??““??““¤““¤““¤““??““??““??““??“
“??““??““??““??““??““??““??““??““??““??“
“??““??““??““??““??““??““??““??““??““??“?
}?
{
“¤““¤““¤““¤““¤““¤““¤““¤““¤““¤“?
“¤““□““□““□““□““¤““□““□““□““¤“
“¤““□““□““□““□““¤““□““□““□““¤“
“¤““□““□““□““□““¤““□““□““□““¤“
“¤““□““□““□““□““□““□““□““□““¤“
“¤““□““□““□““□““□““□““□““□““¤“
“¤““□““□““¤““□““□““□““□““□““¤“
“¤““□““□““¤““□““⊙““⊙““⊙““□““¤“
“¤““□““□““¤““□““□““□““□““□““¤“
“¤““¤““¤““¤““¤““¤““¤““¤““¤““¤“?
}?
{
“¤““¤““¤““¤““¤““¤““¤““¤““¤““¤“?
“¤““□““□““□““□““□““□““□““□““¤“
“¤““□““□““□““□““□““□““□““□““¤“
“¤““□““□““□““□““□““□““□““□““¤“
“¤““□““□““□““□““□““□““□““□““¤“
“¤““□““□““□““□““□““□““□““□““¤“
“¤““□““□““□““□““□““□““□““□““¤“
“¤““□““□““□““□““⊙““□““□““□““¤“
“¤““□““□““□““□““□““□““□““□““¤“
“¤““¤““¤““¤““¤““¤““¤““¤““¤““¤“?
}
};
int?nRoleIndex;//人物的位置
int?nBoxArray[nBoxCount];//用來保持箱子的位置
bool?isFinish;
int?nLevel?=?0;
bool?isWall(int?nMapIndex)
{
bool?bReturn?=?false;
//strcmpj字符串比較函數參數為需要比較的字符串
//返回值是0說明兩個字符串相等不為0兩個字符串不想等
if?(0?==?strcmp(szMap[nLevel][nMapIndex]?“¤“))//撞墻為真
{
bReturn?=?true;
}
return?bReturn;
}
bool?isEnd(int?nMapIndex)//判斷箱子是否移到目的地
{
bool?bReturn?=?false;
//strcmpj字符串比較函數參數為需要比較的字符串
//返回值是0說明兩個字符串相等不為0兩個字符串不想等
if?(0?==?strcmp(szMap[nLevel][nMapIndex]?“⊙“))
{
bReturn?=?true;
}
return?bReturn;
}
int?getBoxIndexInArray(int?nMapIndex)
{
int?nIndex?=?-1;
for?(int?i?=?0;?i? {
if?(nBoxArray[i]?==?nMapIndex)//箱子的位置是否與遍歷到的位置相等,從而畫出箱子
{
nIndex?=?i;//那個箱子
break;
}
}
return?nIndex;//箱子下標
}
void?init()//初始化
{
nRoleIndex?=?nRoleInitPos[nLevel];//每一關的人物的初始化位置
for?(int?i?=?0;?i? {
nBoxArray[i]?=?nBoxArrayPerLevel[nLevel][i];/
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-12-20?13:40??newPushBox\
?????目錄???????????0??2014-11-27?14:03??newPushBox\Debug\
?????文件???????33280??2014-12-01?16:59??newPushBox\Debug\newPushBox.exe
?????文件?????????406??2013-11-24?11:02??newPushBox\Debug\newPushBox.exe.manifest
?????文件??????358928??2014-12-01?16:59??newPushBox\Debug\newPushBox.ilk
?????文件??????510976??2014-12-01?16:59??newPushBox\Debug\newPushBox.pdb
?????文件???????38400??2014-11-27?14:03??newPushBox\Debug\push.exe
?????文件??????316636??2014-11-27?14:03??newPushBox\Debug\push.ilk
?????文件??????420864??2014-11-27?14:03??newPushBox\Debug\push.pdb
?????文件???????28672??2014-11-27?15:52??newPushBox\Debug\sdf.exe
?????文件??????329580??2014-11-27?15:52??newPushBox\Debug\sdf.ilk
?????文件??????420864??2014-11-27?15:52??newPushBox\Debug\sdf.pdb
?????目錄???????????0??2014-12-20?13:39??newPushBox\ipch\
?????目錄???????????0??2014-12-20?13:39??newPushBox\ipch\newpushbox-2c882587\
?????文件????33357824??2014-12-20?13:39??newPushBox\ipch\newpushbox-2c882587\newpushbox-e922c93f.ipch
?????目錄???????????0??2013-11-24?10:42??newPushBox\newPushBox\
?????目錄???????????0??2014-12-01?16:59??newPushBox\newPushBox\Debug\
?????文件???????30236??2014-12-01?16:59??newPushBox\newPushBox\Debug\CL.read.1.tlog
?????文件????????2224??2014-12-01?16:59??newPushBox\newPushBox\Debug\CL.write.1.tlog
?????文件????????2786??2014-12-01?16:59??newPushBox\newPushBox\Debug\cl.command.1.tlog
?????文件???????????2??2014-12-01?16:59??newPushBox\newPushBox\Debug\li
?????文件???????????2??2014-12-01?16:59??newPushBox\newPushBox\Debug\li
?????文件????????3006??2014-12-01?16:59??newPushBox\newPushBox\Debug\li
?????文件????????5590??2014-12-01?16:59??newPushBox\newPushBox\Debug\li
?????文件????????1646??2014-12-01?16:59??newPushBox\newPushBox\Debug\li
?????文件?????????962??2014-12-01?16:59??newPushBox\newPushBox\Debug\mt.command.1.tlog
?????文件?????????654??2014-12-01?16:59??newPushBox\newPushBox\Debug\mt.read.1.tlog
?????文件?????????360??2014-12-01?16:59??newPushBox\newPushBox\Debug\mt.write.1.tlog
?????文件?????????552??2013-11-24?11:02??newPushBox\newPushBox\Debug\newPushBox.Build.CppClean.log
?????文件?????????381??2014-12-01?16:59??newPushBox\newPushBox\Debug\newPushBox.exe.intermediate.manifest
?????文件??????????69??2014-12-01?16:59??newPushBox\newPushBox\Debug\newPushBox.lastbuildstate
............此處省略54個文件信息
評論
共有 條評論