#include

#include

#include //图形界面

#include

#include

using namespace std;

#define VK_SHIFT  0x10

#pragma warning(disable:4996)//使用sprintf时需要的头文件

int a, b, X, Y;

int g = 0;

int t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0;

int map2D[9][10] = {

9, 9, 1, 1, 1, 1, 1, 1, 1, 1 ,

9, 9, 1, 0, 0, 0, 1, 2, 0, 1 ,

9, 1, 1, 0, 0, 3, 2, 2, 2, 1 ,

9, 1, 0, 0, 3, 0, 1, 5, 2, 1 ,

1, 1, 0, 1, 1, 3, 1, 0, 1, 1 ,

1, 0, 0, 0, 3, 0, 0, 3, 0, 1 ,

1, 0, 0, 0, 1, 0, 0, 0, 0, 1 ,

1, 1, 1, 1, 1, 1, 1, 4, 0, 1 ,

9, 9, 9, 9, 9, 9, 1, 1, 1, 1

}; //0空地,1墙,2目的地,4和6人物(玩家),3箱子,9背景

int mapSecond[9][10] = {

9, 9, 1, 1, 1, 1, 1, 1, 1, 1,

9, 9, 1, 0, 0, 0, 1, 2, 0, 1,

9, 1, 1, 0, 0, 3, 2, 2, 2, 1,

9, 1, 0, 0, 3, 0, 1, 5, 2, 1,

1, 1, 0, 1, 1, 3, 1, 0, 1, 1,

1, 0, 0, 0, 3, 0, 0, 3, 0, 1,

1, 0, 0, 0, 1, 0, 0, 0, 0, 1,

1, 1, 1, 1, 1, 1, 1, 4, 0, 1,

9, 9, 9, 9, 9, 9, 1, 1, 1, 1

};

int mapSecond1[9][10] = {

1, 1, 1, 1, 1, 1, 1, 1, 9, 9,

1, 0, 0, 1, 0, 0, 0, 1, 9, 9,

1, 0, 3, 2, 2, 3, 0, 1, 9, 9,

1, 4, 3, 2, 5, 0, 1, 1, 9, 9,

1, 0, 3, 2, 2, 3, 0, 1, 9, 9,

1, 0, 0, 1, 0, 0, 0, 1, 9, 9,

1, 1, 1, 1, 1, 1, 1, 1, 9, 9,

9, 9, 9, 9, 9, 9, 9, 9, 9, 9,

9, 9, 9, 9, 9, 9, 9, 9, 9, 9

};

int mapSecond2[9][10] = {

9, 9, 9, 9, 9, 9, 9, 9, 9, 9,

9, 9, 9, 1, 1, 1, 1, 9, 9, 9,

9, 9, 1, 1, 0, 0, 1, 9, 9, 9,

9, 9, 1, 4, 3, 0, 1, 9, 9, 9,

9, 9, 1, 1, 3, 0, 1, 1, 9, 9,

9, 9, 1, 1, 0, 3, 0, 1, 9, 9,

9, 9, 1, 2, 3, 0, 0, 1, 9, 9,

9, 9, 1, 2, 2, 5, 2, 1, 9, 9,

9, 9, 9, 9, 9, 9, 9, 9, 9, 9

};

int mapSecond3[9][10] = {

9, 9, 1, 1, 1, 1, 1, 1, 9, 9,

9, 9, 1, 2, 0, 2, 2, 1, 9, 9,

9, 9, 1, 2, 0, 3, 2, 1, 9, 9,

9, 1, 1, 1, 0, 0, 3, 1, 1, 9,

9, 1, 0, 3, 0, 0, 3, 0, 1, 9,

9, 1, 0, 1, 3, 1, 1, 0, 1, 9,

9, 1, 0, 0, 0, 4, 0, 0, 1, 9,

9, 1, 1, 1, 1, 1, 1, 1, 1, 9,

9, 9, 9, 9, 9, 9, 9, 9, 9, 9

};

int mapSecond4[9][10] = {

1, 1, 1, 1, 1, 9, 9, 9, 9, 9,

1, 0, 0, 0, 1, 1, 1, 1, 1, 9,

1, 0, 1, 0, 1, 0, 0, 0, 1, 9,

1, 0, 3, 0, 0, 0, 3, 0, 1, 9,

1, 2, 2, 1, 3, 1, 3, 1, 1, 9,

1, 2, 4, 3, 0, 0, 0, 1, 9, 9,

1, 2, 2, 0, 0, 1, 1, 1, 9, 9,

1, 1, 1, 1, 1, 1, 9, 9, 9, 9,

9, 9, 9, 9, 9, 9, 9, 9, 9, 9

};

void repeat(){

if (t1 == 1){

for (int i = 0; i < 9; i++){

for (int j = 0; j < 10; j++){

map2D[i][j] = mapSecond[i][j];

}

}

}

}

void repeat1(){

if (t2 == 1){

for (int i = 0; i < 9; i++){

for (int j = 0; j < 10; j++){

map2D[i][j] = mapSecond1[i][j];

}

}

}

}

void repeat2(){

if (t3 == 1){

for (int i = 0; i < 9; i++){

for (int j = 0; j < 10; j++){

map2D[i][j] = mapSecond2[i][j];

}

}

}

}

void repeat3(){

if (t4 == 1){

for (int i = 0; i < 9; i++){

for (int j = 0; j < 10; j++){

map2D[i][j] = mapSecond3[i][j];

}

}

}

}

void repeat4(){

if (t5 == 1){

for (int i = 0; i < 9; i++){

for (int j = 0; j < 10; j++){

map2D[i][j] = mapSecond4[i][j];

}

}

}

}

void initmap()

{

IMAGE map[7];

char filename[20] = "";

for (int i = 0; i < 7; i++)

{

sprintf_s(filename, "素材/%d.jpg", i);

loadimage(&map[i], filename, 20, 20);

}

int x, y;

for (int rowNum = 0; rowNum < 9; rowNum++)

{

for (int colNum = 0; colNum < 10; colNum++)

{

x = colNum * 20+100;

y = rowNum * 20+60;

putimage(x, y, &map[map2D[rowNum][colNum]]);

}

}

}

void playGame()

{

//a为行,b列

for (int i = 0; i < 9; i++){

for (int j = 0; j < 10; j++){

if (map2D[i][j] == 4 || map2D[i][j] == 6){

a = i;

b = j;

X = a;

Y = b;

}

}

}

char ch;

ch = getch();

switch (ch)

{

case 'T':

case 't':

g = 1;

break;

//0空地,1墙,2目的地,4人物(玩家),3箱子

case 'W':

case 'w':

case 72:

if (map2D[a - 1][b] == 0)

{

map2D[a - 1][b] += 4;

map2D[a][b] -= 4;

}

else if (map2D[a - 1][b] == 2)

{

map2D[a - 1][b] += 4;

map2D[a][b] -= 4;

}

else if (map2D[a - 1][b] == 3 || map2D[a - 1][b] == 5)//人前面是箱子或者箱子+目的地

{

if (map2D[a - 1][b] == 3)

{

if (map2D[a - 2][b] == 0)

{

map2D[a - 2][b] += 3;

map2D[a - 1][b] += 1;

map2D[a][b] -= 4;

}

else if (map2D[a - 2][b] == 2)

{

map2D[a - 2][b] += 3;

map2D[a - 1][b] += 1;

map2D[a][b] -= 4;

}

}

else//前面是5

{

if (map2D[a - 2][b] == 0)

{

map2D[a - 2][b] += 3;

map2D[a - 1][b] += 1;

map2D[a][b] -= 4;

}

else if (map2D[a - 2][b] == 2)

{

map2D[a - 2][b] += 3;

map2D[a - 1][b] += 1;

map2D[a][b] -= 4;

}

}

}

for (int i = 0; i < 9; i++){

for (int j = 0; j < 10; j++){

if (map2D[i][j] == 4 || map2D[i][j] == 6){

a = i;

b = j;

}

}

}

break;

case 'S':

case 's':

case 80:

if (map2D[a + 1][b] == 0)

{

map2D[a + 1][b] += 4;

map2D[a][b] -= 4;

}

else if (map2D[a + 1][b] == 2)

{

map2D[a + 1][b] += 4;

map2D[a][b] -= 4;

}

else if (map2D[a + 1][b] == 3 || map2D[a + 1][b] == 5)//人前面是箱子或者箱子+目的地

{

if (map2D[a + 1][b] == 3)

{

if (map2D[a + 2][b] == 0)

{

map2D[a + 2][b] += 3;

map2D[a + 1][b] += 1;

map2D[a][b] -= 4;

}

else if (map2D[a + 2][b] == 2)

{

map2D[a + 2][b] += 3;

map2D[a + 1][b] += 1;

map2D[a][b] -= 4;

}

}

else

{

if (map2D[a + 2][b] == 0)

{

map2D[a + 2][b] += 3;

map2D[a + 1][b] += 1;

map2D[a][b] -= 4;

}

else if (map2D[a + 2][b] == 2)

{

map2D[a + 2][b] += 3;

map2D[a + 1][b] += 1;

map2D[a][b] -= 4;

}

}

}

for (int i = 0; i < 9; i++){

for (int j = 0; j < 10; j++){

if (map2D[i][j] == 4 || map2D[i][j] == 6){

a = i;

b = j;

}

}

}

break;

case 'A':

case 'a':

case 75:

if (map2D[a][b - 1] == 0)

{

map2D[a][b - 1] += 4;

map2D[a][b] -= 4;

}

else if (map2D[a][b - 1] == 2)

{

map2D[a][b - 1] += 4;

map2D[a][b] -= 4;

}

else if (map2D[a][b - 1] == 3 || map2D[a][b - 1] == 5)//人前面是箱子或者箱子+目的地

{

if (map2D[a][b - 1] == 3)

{

if (map2D[a][b - 2] == 0)

{

map2D[a][b - 2] += 3;

map2D[a][b - 1] += 1;

map2D[a][b] -= 4;

}

else if (map2D[a][b - 2] == 2)

{

map2D[a][b - 2] += 3;

map2D[a][b - 1] += 1;

map2D[a][b] -= 4;

}

}

else

{

if (map2D[a][b - 2] == 0)

{

map2D[a][b - 2] += 3;

map2D[a][b - 1] += 1;

map2D[a][b] -= 4;

}

else if (map2D[a][b - 2] == 2)

{

map2D[a][b - 2] += 3;

map2D[a][b - 1] += 1;

map2D[a][b] -= 4;

}

}

}

for (int i = 0; i < 9; i++){

for (int j = 0; j < 10; j++){

if (map2D[i][j] == 4 || map2D[i][j] == 6){

a = i;

b = j;

}

}

}

break;

case 'D':

case 'd':

case 77:

if (map2D[a][b + 1] == 0)

{

map2D[a][b + 1] += 4;

map2D[a][b] -= 4;

}

else if (map2D[a][b + 1] == 2)

{

map2D[a][b + 1] += 4;

map2D[a][b] -= 4;

}

else if (map2D[a][b + 1] == 3 || map2D[a][b + 1] == 5)//人前面是箱子或者箱子+目的地

{

if (map2D[a][b + 1] == 3)

{

if (map2D[a][b + 2] == 0)

{

map2D[a][b + 2] += 3;

map2D[a][b + 1] += 1;

map2D[a][b] -= 4;

}

else if (map2D[a][b + 2] == 2)

{

map2D[a][b + 2] += 3;

map2D[a][b + 1] += 1;

map2D[a][b] -= 4;

}

}

else

{

if (map2D[a][b + 2] == 0)

{

map2D[a][b + 2] += 3;

map2D[a][b + 1] += 1;

map2D[a][b] -= 4;

}

else if (map2D[a][b + 2] == 2)

{

map2D[a][b + 2] += 3;

map2D[a][b + 1] += 1;

map2D[a][b] -= 4;

}

}

}

for (int i = 0; i < 9; i++){

for (int j = 0; j < 10; j++){

if (map2D[i][j] == 4 || map2D[i][j] == 6){

a = i;

b = j;

}

}

}

break;

}

}

int main()

{

int dat, I;

int P = 6;//过关条件

t1 = 1;

char q[20] = "";

int w[5] = { 0 };//存放最高纪录

char m[20] = "";

int d, h;

xin:

dat = 0, I = 0, a = 0, b = 0;

if (t1 == 1 || t2 == 1) {

P = 6;

}

else if (t3 == 1 || t4 == 1 || t5 == 1){

P = 5;

}

d = 0, h = 0;//d为当前步数,h为最高步数

initgraph(400, 550);

repeat();

repeat1();

repeat2();

repeat3();

repeat4();

for (int i = 0; i < 2000; i++){

cleardevice();//清屏

int R = 0;

outtextxy(28, 0, "注:1.开始游戏前需要点击shift键后才能使用;");

outtextxy(60, 20, "2.不可以悔棋,按T键可以重新开始本关卡。");

sprintf(m, "当前已经走了%d步", I);

outtextxy(130, 300, m);

for (int k = 0; k < 9; k++)

{

for (int j = 0; j < 10; j++)

{

if (map2D[k][j] == 5){

R = R + 1;

}

}

}

initmap();

d = i;

if (R == P)

break;

playGame();

if (a != X||b != Y){  //X,Y为玩家当前位置的上一个位置的坐标

I++;

}

if (g == 1){

g = 0;

goto xin;

}

}

outtextxy(130, 320, "恭喜过关!");

if (t1 == 1){

dat = 0;

ifstream infile("file/xin.dat", ios::in);

if (!infile){

}

else{

infile >> w[dat];

h = w[dat];

}

infile.close();

if (h == 0 || d < h) {

ofstream outfile("file/xin.dat", ios::out);

h = d;

w[dat] = h;

outfile << w[dat];

outfile.close();

}

}

else if (t2 == 1){

dat = 1;

ifstream infile("file/xin1.dat", ios::in);

if (!infile){

}

else{

infile >> w[dat];

h = w[dat];

}

infile.close();

if (h == 0 || d < h) {

ofstream outfile("file/xin1.dat", ios::out);

h = d;

w[dat] = h;

outfile << w[dat];

outfile.close();

}

}

else if (t3 == 1){

dat = 2;

ifstream infile("file/xin2.dat", ios::in);

if (!infile){

}

else{

infile >> w[dat];

h = w[dat];

}

infile.close();

if (h == 0 || d < h) {

ofstream outfile("file/xin2.dat", ios::out);

h = d;

w[dat] = h;

outfile << w[dat];

outfile.close();

}

}

else if (t4 == 1){

dat = 3;

ifstream infile("file/xin3.dat", ios::in);

if (!infile){

}

else{

infile >> w[dat];

h = w[dat];

}

infile.close();

if (h == 0 || d < h) {

ofstream outfile("file/xin3.dat", ios::out);

h = d;

w[dat] = h;

outfile << w[dat];

outfile.close();

}

}

else if (t5 == 1){

dat = 4;

ifstream infile("file/xin4.dat", ios::in);

if (!infile){

}

else{

infile >> w[dat];

h = w[dat];

}

infile.close();

if (h == 0 || d < h) {

ofstream outfile("file/xin4.dat", ios::out);

h = d;

w[dat] = h;

outfile << w[dat];

outfile.close();

}

}

//ifstream infile("file/xin.dat", ios::in);

//if (!infile){

//}

//else{

//        infile >> w[dat];

//        h = w[dat];

//}

//infile.close();

//if (h == 0 || d < h) {

//        ofstream outfile("file/xin.dat", ios::out);

//        h = d;

//        w[dat] = h;

//        outfile << w[dat];

//        outfile.close();

//}

sprintf(q, "当前关卡最高纪录为%d步", w[dat]);

outtextxy(130, 350, q);

outtextxy(130, 400, "是否重新挑战?(Y/N)");

char ch, cha;

ch = getch();

switch (ch){

case 'Y':

case 'y':

outtextxy(130, 420, "加载中......");

Sleep(1500);

goto xin;

break;

default:

break;

}

outtextxy(80, 420, "请选择关卡(1,2,3,4,5,0[退出])");

faulse:

cha = getch();

switch (cha){

case '1':

t1 = 0; t2 = 0, t3 = 0, t4 = 0, t5 = 0;

t1 = 1;

goto xin;

break;

case '2':

t1 = 0; t2 = 0, t3 = 0, t4 = 0, t5 = 0;

t2 = 1;

goto xin;

break;

case '3':

t1 = 0; t2 = 0, t3 = 0, t4 = 0, t5 = 0;

t3 = 1;

goto xin;

break;

case '4':

t1 = 0; t2 = 0, t3 = 0, t4 = 0, t5 = 0;

t4 = 1;

goto xin;

break;

case '5':

t1 = 0; t2 = 0, t3 = 0, t4 = 0, t5 = 0;

t5 = 1;

goto xin;

break;

case '0':

outtextxy(150, 450, "按enter键继续退出!");

break;

……………………

…………限于本文篇幅 余下代码请从51黑下载附件…………

c语言 游戏程序,C语言做的推箱子游戏源程序相关推荐

  1. Unity游戏源码分享-3d机器人推箱子游戏

    Unity游戏源码分享-3d机器人推箱子游戏 一个非常意思的3D游戏 工程地址:https://download.csdn.net/download/Highning0007/88098014

  2. 黑马程序员——C基础之推箱子游戏

    ------- iOS培训.android培训.java培训.期待与您交流! ---------- #include <stdio.h> #define kRows 10 #define ...

  3. 使用Rust编写推箱子游戏基础篇

    使用Rust编写推箱子游戏教程已翻译完成 项目地址 在线阅读 推箱子是个啥样的游戏嘞? 没玩过推箱子游戏?想当年用诺基亚黑白屏手机的时候就有这款游戏了.你可以下载一个玩一下或者点这里看下维基百科的介绍 ...

  4. greenfoot推箱子游戏_推箱子小游戏V2.0更新

    小游戏实践 推箱子V2.0 大家好,我是努力学习争取成为优秀的Game Producer的路人猿,我们上期一起学习制作推箱子的简易V1.0版本,学习了如何响应用户的输入以及面对箱子的各种情况,今天我们 ...

  5. Android开发入门——推箱子游戏开发实战(十二)

    绘制游戏局面 本文是推箱子游戏程序开发的第七步.系列文章前五篇描述准备工作,故本文编号是(十二).本文讲解如何绘制游戏局面. 本文目标 本文讲解如何绘制游戏局面.游戏局面的示例如图1,图2所示.这两幅 ...

  6. C++入门——实现推箱子游戏

    参考 <C和C++游戏趣味编程> 童晶 推箱子游戏 玩家通过键盘控制游戏角色将所有黄色箱子推到白色方块处 用字符数组存储关卡数据 游戏一共有6种元素: (1)空白区域:玩家可以穿过,箱子可 ...

  7. 程序员带你回味童年,一起用C语言做一个“推箱子”玩!【文末源码】

    这篇文章是用C语言做了一个推箱子小游戏,实现起来比较简单,和大家一起回味一下童年捧着按键机玩推箱子的日子!文末附带万字源码! 目录 一.写在前面 二.设计思路 1.主界面函数介绍 2.选择界面函数 3 ...

  8. c语言多关卡推箱子程序,多关卡地图推箱子游戏

    多关卡地图推箱子游戏 # include # include # include //调出地图 void file(int map[14][16],int n,int flag) //n表示关卡数 , ...

  9. c语言推箱子游戏实习报告,用C语言编写推箱子游戏

    本文实例为大家分享了C语言推箱子游戏的具体实现代码,供大家参考,具体内容如下 #include #include #include #include //行和列 #define ROW 10 #def ...

最新文章

  1. 【Ubuntu】Ubuntu下的录频软件SimpleScreenRecorder
  2. 资源下载 | 历年 AAAI 最佳论文(since 1996)
  3. ASP.NET Web 页面生命中的一天
  4. 波司登在“寒潮”下再创新高,羽绒服行业真的靠天吃饭?
  5. 01.ShardingSphere笔记
  6. 前端学习(598):查看localstorage和sessionstorage
  7. 剧情反转:今年AI要凉!薪资碾压全行,但人才缺500万!
  8. vue项目使用electron打包成桌面应用
  9. Python中Text函数常用增删改查阅用法实例汇总
  10. 自编码器(Auto-encoder) (下)它的应用
  11. Unity 移动端的复制这么写
  12. 大数据概述(尚硅谷)
  13. 【C / EasyX】十字消除游戏的实现方法
  14. mysql sniffer下载_Gitee 极速下载
  15. 雷达的工作原理示意图_雷达基本理论与基本原理
  16. 当前linux的ks文件,高手请进!请教linux自动安装文件ks.cfg
  17. JAVA图片加水印(电子奖状填充名字)
  18. LearnGL - 03 - DrawQuad - VBO/EBO - 理解 CW, CCW 的正背面
  19. 2011斯坦福大学iOS应用开发教程学习笔记(第六课)故事版
  20. python有哪些细节描写_关于描写细节描写的句子

热门文章

  1. Docker swarm mode
  2. c# async/await编程
  3. ORC文件存储格式的深入探究
  4. 启动Kafka失败Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c0000000, 107
  5. 大剑无锋----SpringMVC原理详细解析
  6. leetcode 777. Swap Adjacent in LR String | 777. 在LR字符串中交换相邻字符(双指针)
  7. Libra教程之:move语言的特点和例子
  8. 程序员如何用糖果实现盈利 - [别人家的程序员01]
  9. java虚拟机性能监控调优及原则
  10. 测试点2和测试点4错的来:1044 火星数字 (20分)