用用C语言编写推箱子游戏语言编写推箱子游戏
主要为大家详细介绍了用C语言编写推箱子游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣
的小伙伴们可以参考一下
本文实例为大家分享了C语言推箱子游戏的具体实现代码,供大家参考,具体内容如下
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include <conio.h>
//行和列
#define ROW 10
#define COL 11
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
/**
*
*
*/
//地图
char map[ROW][COL] = {
"##########",//0
"### ##",//1
"### ##",//2
"##AX # ##",//3
"### ## ",//4
"##### #",//5
"## #",//6
"# ####",//7
"### ",//8
"##########" //9
//A:人 , X:箱子
} ;
//打印地图
void showMap();
//接收小人的方向
char enterDirection();
//小人向上移动的方法
void moveToUp();
//小人向下移动的方法
void moveToDown();
//小人向右移动的方法
void moveToRight();
//小人向左移动的方法
void moveToLeft();
//当前小人的坐标
int currentPersonRow = 3;
int currentPersonCol = 2;
//当前箱子的坐标
int currentBoxRow = 3;
int currentBoxCol = 3;
int main(int argc, char *argv[]) {
//system("clear");
printf("点击回车键开始游戏 ^_^");
//1代表运行 0停止
int flag = 1;
while(flag==1){
//显示地图
showMap();
//接收小人的方向
char dir = enterDirection();
switch(dir){
//小人向上移动
case 'w':
case 'W':
moveToUp();
break;
//小人向下移动
case 's':
case 'S':
moveToDown();
break;
//小人向右移动