C语⾔设计推箱⼦⼩游戏(课程设计)C语⾔设计推箱⼦⼩游戏(课程设计)
代码如下:
#include<stdio.h>
#include"get_keyboard.h"
int boards[7][8]=
{
{0,1,1,1,1,1,1,0},
{0,1,0,0,0,0,1,1},
{1,3,0,1,1,2,0,1},
{1,0,3,3,2,0,0,1},
{1,0,0,1,2,0,0,1},
{1,0,0,4,0,1,1,1},
{1,1,1,1,1,0,0,0}
};
//记录⼩⽼⿏的位置控制移动改变⼩⽼⿏在地图中的位置
int row =0;
int col =0;
int cnt =0;
int pos =0;
void print_boards(){
int i,j;
for(i =0;i<7;i++){
for(j =0;j<8;j++){
switch(boards[i][j]){
case0:printf(" ");break;
case1:printf("#");break;
case2:printf("@");break;
case3:printf("0");break;
case4:printf("&");break;
}
}
printf("\n");
}
}
void left(){
switch(boards[row][col-1]){
case0:boards[row][col-1]=4;
posi();
col -=1;
pos =0;
break;
case1:break;
case2:if(boards[row][col-2]==0){
boards[row][col-1]=4;
boards[row][col-2]=2;
posi();
pos =0;
col -=1;
}else if(boards[row][col-2]==3){
boards[row][col-1]=4;
boards[row][col-2]=0;
posi();
pos =0;
col -=1;
cnt++;
}
break;
break;
case3:boards[row][col-1]=4;
posi();
pos =3;
col -=1;
break;
}
}
void right(){
switch(boards[row][col+1]){
case0:boards[row][col+1]=4;
posi();
col +=1;
pos =0;
break;
case1:break;
case2:if(boards[row][col+2]==0){                              boards[row][col+1]=4;
boards[row][col+2]=2;
posi();
col +=1;
pos =0;
}else if(boards[row][col+2]==3){                              boards[row][col+1]=4;
boards[row][col+2]=0;
posi();
col  +=1;
pos =0;
cnt++;
}
break;
case3:boards[row][col+1]=4;
posi();
col +=1;
pos =3;
break;
}
}
void up(){
switch(boards[row-1][col]){
case0:boards[row-1][col]=4;
posi();
row -=1;
pos =0;
break;
case1:break;
case2:if(boards[row-2][col]==0){
boards[row-1][col]=4;
boards[row-2][col]=2;
posi();
row -=1;
pos =0;
}else if(boards[row-2][col]==3){                              boards[row-1][col]=4;
boards[row-2][col]=0;
posi();
posi();
row -=1;
cnt++;
pos =0;
}
break;
case3:boards[row-1][col]=4;
c语言编程小游戏posi();
row -=1;
pos =3;
break;
}
}
void down(){
switch(boards[row+1][col]){
case0:boards[row+1][col]=4;
posi();
row +=1;
pos =0;
break;
case1:break;
case2:if(boards[row+2][col]==0){                              boards[row+1][col]=4;
boards[row+2][col]=2;
posi();
row +=1;
pos =0;
}else if(boards[row+2][col]==3){                              boards[row+1][col]=4;
boards[row+2][col]=0;
posi();
row +=1;
pos =0;
cnt++;
}
break;
case3:boards[row+1][col]=4;
posi();
row +=1;
pos =3;
break;
}
}
void posi(){
switch(pos){
case0:boards[row][col]=0;break;
case1:boards[row][col]=1;break;
case2:boards[row][col]=2;break;
case3:boards[row][col]=3;break;
}
return;
}
int main(){
int i,j;
for(i =0;i<7;i++){
for(j =0;j<8;j++){
if(boards[i][j]==4){
if(boards[i][j]==4){
row = i;
col = j;
break;
}
}
}
print_boards();
while(cnt!=3){
int move =get_keyboard();
system("clear");
switch(move){
case KEY_UP:up();print_boards();break;
case KEY_DOWN:down();print_boards();break;
case KEY_RIGHT:right();print_boards();break;
case KEY_LEFT:left();print_boards();break;
case KEY_ENTER:;print_boards();break;
}
}
return0;
}
我的资源中有免费资源哦

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。