- //
- // main.c
- // 推箱子游戏C
- //
- // Created by 晟昊的MACPro on 14-8-15.
- // Copyright (c) 2014年 晟昊的MACPro. All rights reserved.
- //
- /*
- 推箱子游戏:
- 游戏说明:玩家通过键盘录入 w,s,a,d控制小人向不同方向移动,
- 其中w代表向上移动,s代表向下移动,a代表向左移动,d 代表向右移动,
- 当小人在箱子后面的时候可以推着箱子向前移动,当箱子移动到出口的位置,玩家胜利
- 地图如下:
- ##########
- #O #### #
- # X#### #
- # #
- ###### #
- # #### #
- # #
- # ######
- #
- ##########
- 说明: # 代表墙, O代表小人 ,' ' 代表路, X代表箱子
- */
- #include <stdio.h>
- #define LINES 10
- #define COLUS 11
- #define boolean int
- #define true 1
- #define false 0
- void DrawMap(char Map[][COLUS]){
- for (int i=0; i<LINES; i++) printf("%s\\n",Map[i]);
- }
- void playerChoice(int *nextpersonX,int *nextpersonY,int
- *nextboxX,int* nextboxY){
- printf("请输入一个方向 [w,a,s,d]分别代表[上下左右]\\n\\n");
- char direction = ' ';
- scanf(" %c",&direction);
- switch (direction) {
- case 'w':
- case 'W':
- (*nextpersonX)--;
- (*nextboxX)--;
- break;
- case 'a':
- case 'A':
- (*nextpersonY)--;
- (*nextboxY)--;
- break;
- case 's':
- case 'S':
- (*nextpersonX)++;
- (*nextboxX)++;
- break;
- case 'D':
- case 'd':
- (*nextpersonY)++;
- (*nextboxY)++;
- break;
- default:
- printf("\\n!!!!输入错误 请重新输入:!!!!\\n");
- break;
- }
- }
- void swap(char Map[][COLUS],int *x1,int *y1,int *x2,int *y2){
- char temp;
- temp = Map[*x1][*y1];
- Map[*x1][*y1] = Map[*x2][*y2];
- Map[*x2][*y2] = temp;
- //x1 = x2 , y1 = y2
- *x1 = *x2;
- *y1 = *y2;
- }
- boolean isLose(char map[][COLUS],int boxX,int boxY,char deadquater){
- printf("(%d,%d)",boxX,boxY);
- if( (map[boxX+1][boxY] == deadquater&&map[boxX][boxY+1]==deadquater)
- ||(map[boxX-1][boxY] == deadquater&&map[boxX][boxY+1]==deadquater)
- ||(map[boxX-1][boxY] == deadquater&&map[boxX][boxY-1]==deadquater)
- ||(map[boxX+1][boxY] == deadquater&& map[boxX][boxY-1]==deadquater)
- ) return true;
- return false;
- }
- int main(int dad,const char * sdsadp[])
- {
- //2.定义变量来创建必要的坐标系统 记录当前位置
- int persionX,persionY,boxX,boxY;
- persionX = persionY = 1;
- boxX = boxY = 2;
- char fuckyou[] = "\\n扛把子B哥:\\t\\t妹子你知道么? 我的大
- //该片段来自于http://www.codesnippet.cn/detail/1812201411319.html
来源: http://www.codesnippet.cn/detail/1812201411319.html