69,382
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#define My 24
#define Nx 30
void Ini(int (*map)[Nx])
{
int i, j;
for (i = 0; i < My; i++)
{
for (j = 0; j < Nx - 1; j++)
map[i][j] = 0;
map[i][Nx - 1] = -1;
}
for (i = 0; i < Nx - 2; i++)
{
map[0][i] = 21;
map[My - 1][i] = 21;
}
for (i = 0; i < My - 1; i++)
{
map[i][0] = 23;
map[i][Nx - 2] = 23;
}
map[0][0] = 20;
map[0][Nx - 2] = 22;
map[My - 1][0] = 24;
map[My - 1][Nx - 2] = 25;
}
void Print(int map[My][Nx])
{
int i, j;
for(i = 0; i < My; i++)
{
for(j = 0; j < Nx; j++)
{
switch(map[i][j])
{
case 0:
printf(" "); //数字0
break;
case 1:
printf("█"); //数字1
break;
case 2:
printf("◎");//数字2 = 子弹
break;
case 20:
printf("╔"); //数字20
break;
case 21:
printf("═"); //数字21
break;
case 22:
printf("╗"); //数字22
break;
case 23:
printf("║"); //数字23
break;
case 24:
printf("╚"); //数字24
break;
case 25:
printf("╝"); //数字25
break;
case -1:
printf("\n"); //数字-1
break;
}
}
}
}
void Wmove(int (*map)[Nx], int xiaot[2][3], int x, int y)
{
int i, j;
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
map[y + i - 1][x + j - 1] = xiaot[i][j];
}
void Dmove(int (*map)[Nx], int xiaot[3][2], int x, int y)
{
int i, j;
for (i = 0; i < 3; i++)
for (j = 0; j < 2; j++)
map[y + i - 1][x + j] = xiaot[i][j];
}
void Amove(int (*map)[Nx], int xiaot[3][2], int x, int y)
{
int i, j;
for (i = 0; i < 3; i++)
for (j = 0; j < 2; j++)
map[y - 1 + i][x - 1 + j] = xiaot[i][1 - j];
}
void Smove(int (*map)[Nx], int xiaot[2][3], int x, int y)
{
int i, j;
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
map[y + i - 1][x + j - 1] = xiaot[1 - i][j];
}
/*
void Zidan(int (*map)[Nx], int *x, int *y,int flag)
{
int zidan = 2;
switch (flag)
{
case 1:
*y++;
break;
}
map[*y][*x] = zidan;
}*/
void Move(int (*map)[Nx],int *x,int *y,int *flag,int key)
{
int lxiaot[3][2] = {1,0,1,1,1,0}, xiaot[2][3] = {0,1,0,1,1,1};
switch (key)
{
case 72:
{
if (*flag == 1)
{
if (*y > 2)
(*y)--;
Wmove(map, xiaot, *x, *y);
}
else
{Wmove(map, xiaot, *x, *y);*flag = 1;}
break;
}
case 77:
{
if (*flag == 2)
{
if (*x < Nx - 4)
(*x)++;
Dmove(map, lxiaot, *x, *y);
}
else
{Dmove(map, lxiaot, *x, *y);*flag = 2;}
break;
}
case 75:
{
if (*flag == 3)
{
if (*x > 2)
(*x)--;
Amove(map, lxiaot, *x, *y);
}
else
{Amove(map, lxiaot, *x, *y);*flag = 3;}
break;
}
case 80:
{
if (*flag == 4)
{
if (*y < My - 3)
(*y)++;
Smove(map, xiaot, *x, *y);
}
else
{Smove(map, xiaot, *x, *y);*flag = 4;}
break;
}
}
}
void begin()
{
int map[My][Nx], x = 2, y = My - 3;
int key = 0, flag = 1;
Ini(map);
Print(map);
while(key != 27)
{
key = getch();
system("CLS");
Ini(map);
Move(map,&x,&y,&flag,key);
Print(map);
}
}
int main()
{
begin();
return 0;
}