C语言写的推箱子小游戏
c吧
全部回复
仅看楼主
level 7
维吾尔☎ 楼主
推箱子:

#include <graphics.h>
#include <stdio.h>
#include <time.h>
/*
1.定义图片变量 IMAGE ---int
2.loadimage加载资源 ---把图片放到变量里面
3.putimage 把图片粘贴窗口上
//切割技术:随机切割---拼图游戏----图片处理之类
*/
IMAGE mm;
int array2D[3][3] = { 0 };
int array1D[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int pos;
int length=9; //值没有初始化
void loadResource()
{
loadimage(&mm, "美女.jpg",900, 900);
//随机初始化
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
//产生一个随机下标
pos = rand() % length;//值没有初始化
array2D[i][j] = array1D[pos];
//调整数组
for (int k = pos; k < length; k++)
{
array1D[k] = array1D[k + 1];
}
length--;
}
}
}
void userUI()
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
if (array2D[i][j] < 4)
{
putimage(j * 300, i * 300, 300, 300, &mm, (array2D[i][j] - 1) * 300, 0);
}
else if (array2D[i][j]>6)
{
putimage(j * 300, i * 300, 300, 300, &mm, (array2D[i][j] - 7) * 300,600);
}
else
{
putimage(j * 300, i * 300, 300, 300, &mm, (array2D[i][j] - 4) * 300,300);
}
}
}
}
int main()
{
//格式和路径
initgraph(900, 900);
srand((unsigned int)time(NULL));
loadResource();
userUI();
getchar();
closegraph();
return 0;
}
推荐下我的C/C+C学习群:626871916,邀请码华灯。不管你是小白还是大牛,小编我都欢迎,不定期分享干货,包括我自己整理的一份C语言学习资料和零基础入门教程,欢迎初学者和在进阶中的小伙伴。
2018年03月10日 04点03分 1
level 7
维吾尔☎ 楼主
2018年03月10日 05点03分 2
level 7
维吾尔☎ 楼主
人腻
2018年03月11日 01点03分 4
level 7
维吾尔☎ 楼主
[呵呵][呵呵]
2018年03月14日 01点03分 10
level 7
维吾尔☎ 楼主
[呵呵][呵呵]
2018年03月16日 00点03分 12
level 8
我只想知道界面怎么做的[乖]
2018年03月16日 01点03分 13
easyx
2018年03月17日 01点03分
level 7
维吾尔☎ 楼主
[呵呵]
2018年03月31日 03点03分 14
level 7
维吾尔☎ 楼主
[呵呵]
2018年04月15日 01点04分 15
level 7
维吾尔☎ 楼主
[呵呵]
2018年04月18日 06点04分 16
1