• 大小: 6.81MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-24
  • 语言: C/C++
  • 标签: 推箱子  语言编程  

资源简介

C语言基础项目,C语言多关卡设计,C语言可视化编程,C语言可视化推箱子

资源截图

代码片段和文件信息

/*
1.基本绘图窗口
2.基本贴图
3.二维数组制作小游戏地图
4.按键处理:用户交互方式
5.多关卡设计:三维数组的使用
*/
#define _CRT_SECURE_NO_WARNINGS
#include 
#include 
#include 
//1.二位数组把地图绘制出来
int  map[3][7][8] =
{
1 1 1 1 1 1 1 1
1 3 4 0 0 4 3 1
1 0 1 0 1 1 0 1
1 0 0 5 4 3 0 1
1 0 1 0 1 1 0 1
1 3 4 0 0 4 3 1
1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1
1 3 4 0 0 4 3 1
1 0 1 0 1 1 0 1
1 3 4 5 4 3 0 1
1 0 1 0 1 1 0 1
1 3 4 0 0 4 3 1
1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1
1 3 4 0 0 4 3 1
1 0 1 0 4 3 0 1
1 3 4 5 4 3 0 1
1 0 1 0 1 1 0 1
1 3 4 0 0 4 3 1
1 1 1 1 1 1 1 1
};
IMAGE img[6];
int cos = 0; //控制关卡
//0.bmp  1.bmp 3.bmp
int imgURLIndex[6] = { 0 1 3 4 5 7 };
void loadResource()
{
//批处理
for (int i = 0; i < 6; i++)
{
char fileName[20] = ““;
//printf:打印到屏幕
//0.bmp  1.bmp
sprintf(fileName “%d.bmp“ imgURLIndex[i]); 
loadimage(img + i fileName);
}
}
void drawMap()
{
int x y;
for (int i = 0; i < 7; i++)
{
for (int j = 0; j < 8; j++)
{
x = 64 * j;
y = 64 * i;
switch (map[cos][i][j])
{
case 0:
putimage(x y img + 0);
break;
case 1:
putimage(x y img + 1);
break;
case 3:
putimage(x y img + 2);
break;
case 4:
putimage(x y img + 3);
break;
case 5:
case 8:
putimage(x y img + 4);
break;
case 7:
putimage(x y img + 5);
break;
}
}
}
}
void  keyDown()
{
//定位人在哪里?
int i j; //数组中值是5和8 时候是人
for (i = 0; i < 7; i++)
{
for (j = 0; j < 8; j++)
{
if (map[cos][i][j] == 5 || map[cos][i][j] == 8)
{
break;  //break跳出一层循环
}
}
if (map[cos][i][j] == 5 || map[cos][i][j] == 8)
{
break;
}
}
char userKey = _getch();
//小键盘:72 80 75 77
switch (userKey)
{
case ‘w‘:
case ‘W‘:
case 72:
//什么时候能动?上面是空地0或者目的地3
if (map[cos][i - 1][j] == 0 || map[cos][i - 1][j] == 3)
{
//能走是怎么走的
map[cos][i][j] -= 5;
map[cos][i - 1][j] += 5;
}
//是箱子 :4  箱子+目的:7
else if (map[cos][i - 1][j] == 4 || map[cos][i - 1][j] == 7)
{
if (map[cos][i - 2][j] == 0 || map[cos][i - 2][j] == 3)
{
//能走是怎么走的
map[cos][i][j] -= 5;
map[cos][i - 1][j] += 1;
map[cos][i - 2][j] += 4;
}
}
break;
case ‘s‘:
case ‘S‘:
case 80:
if (map[cos][i + 1][j] == 0 || map[cos][i + 1][j] == 3)
{
//能走是怎么走的
map[cos][i][j] -= 5;
map[cos][i + 1][j] += 5;
}
//是箱子 :4  箱子+目的:7
else if (map[cos][i + 1][j] == 4 || map[cos][i + 1][j] == 7)
{
if (map[cos][i + 2][j] == 0 || map[cos][i + 2][j] == 3)
{
//能走是怎么走的
map[cos][i][j] -= 5;
map[cos][i + 1][j] += 1;
map[cos][i + 2][j] += 4;
}
}
break;
case ‘A‘:
case ‘a‘:
case 75:
if (map[cos][i][j - 1] == 0 || map[cos][i][j - 1] == 3)
{

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     109056  2019-04-03 21:36  myBoxGame\Debug\myBoxGame.exe

     文件     683544  2019-04-03 21:36  myBoxGame\Debug\myBoxGame.ilk

     文件     789504  2019-04-03 21:36  myBoxGame\Debug\myBoxGame.pdb

     文件      31744  2019-04-03 20:41  myBoxGame\Debug\二维数组.exe

     文件     227020  2019-04-03 20:41  myBoxGame\Debug\二维数组.ilk

     文件     445440  2019-04-03 20:41  myBoxGame\Debug\二维数组.pdb

     文件     103424  2019-04-03 20:30  myBoxGame\Debug\绘图窗口.exe

     文件     678772  2019-04-03 20:30  myBoxGame\Debug\绘图窗口.ilk

     文件     781312  2019-04-03 20:30  myBoxGame\Debug\绘图窗口.pdb

     文件      12344  2018-10-15 16:17  myBoxGame\myBoxGame\0.bmp

     文件      12344  2018-10-15 16:17  myBoxGame\myBoxGame\1.bmp

     文件      12344  2018-10-15 16:17  myBoxGame\myBoxGame\3.bmp

     文件      12344  2018-10-15 16:17  myBoxGame\myBoxGame\4.bmp

     文件      12344  2018-10-15 16:17  myBoxGame\myBoxGame\5.bmp

     文件      12344  2018-10-15 16:17  myBoxGame\myBoxGame\7.bmp

     文件       1780  2019-04-03 21:36  myBoxGame\myBoxGame\Debug\myBoxGame.log

     文件      41815  2019-04-03 21:36  myBoxGame\myBoxGame\Debug\myBoxGame.obj

     文件        714  2019-04-03 21:36  myBoxGame\myBoxGame\Debug\myBoxGame.tlog\cl.command.1.tlog

     文件      18300  2019-04-03 21:36  myBoxGame\myBoxGame\Debug\myBoxGame.tlog\CL.read.1.tlog

     文件        800  2019-04-03 21:36  myBoxGame\myBoxGame\Debug\myBoxGame.tlog\CL.write.1.tlog

     文件       1432  2019-04-03 21:36  myBoxGame\myBoxGame\Debug\myBoxGame.tlog\link.command.1.tlog

     文件       2724  2019-04-03 21:36  myBoxGame\myBoxGame\Debug\myBoxGame.tlog\link.read.1.tlog

     文件        768  2019-04-03 21:36  myBoxGame\myBoxGame\Debug\myBoxGame.tlog\link.write.1.tlog

     文件        253  2019-04-03 21:36  myBoxGame\myBoxGame\Debug\myBoxGame.tlog\myBoxGame.lastbuildstate

     文件     519168  2019-04-03 21:36  myBoxGame\myBoxGame\Debug\vc120.idb

     文件     167936  2019-04-03 21:36  myBoxGame\myBoxGame\Debug\vc120.pdb

     文件       4482  2019-04-03 21:36  myBoxGame\myBoxGame\myBoxGame.cpp

     文件       3385  2019-04-03 20:17  myBoxGame\myBoxGame\myBoxGame.vcxproj

     文件        950  2019-04-03 20:17  myBoxGame\myBoxGame\myBoxGame.vcxproj.filters

     文件   32899072  2019-04-03 21:42  myBoxGame\myBoxGame.sdf

............此处省略46个文件信息

评论

共有 条评论