• 大小: 16.42MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-14
  • 语言: C/C++
  • 标签: 推箱子  

资源简介

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 < nBoxCountPerLevel[nLevel]; i++)//每一关箱子的数量
{
if (nBoxArray[i] == nMapIndex)//箱子的位置是否与遍历到的位置相等,从而画出箱子
{
nIndex = i;//那个箱子
break;
}
}

return nIndex;//箱子下标
}

void init()//初始化
{
nRoleIndex = nRoleInitPos[nLevel];//每一关的人物的初始化位置
for (int i = 0; i < nBoxCountPerLevel[nLevel]; 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\link.5152.read.1.tlog
     文件           2  2014-12-01 16:59  newPushBox\newPushBox\Debug\link.5152.write.1.tlog
     文件        3006  2014-12-01 16:59  newPushBox\newPushBox\Debug\link.command.1.tlog
     文件        5590  2014-12-01 16:59  newPushBox\newPushBox\Debug\link.read.1.tlog
     文件        1646  2014-12-01 16:59  newPushBox\newPushBox\Debug\link.write.1.tlog
     文件         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个文件信息

评论

共有 条评论