c语言游戏编程掌机太空大战
我编程编着编着脑子糊涂了,玩过这款掌机游戏的童鞋帮忙完善一下啊:
#include<Windows.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include< conio.h >
int HelpMain()//帮助界面
{
char help[20][100] = { " Welcome & Help ",//文字
"=======================================",
"This is a game.You just to fight." ,
"You can enter 'a' , 's' , 'd' and 'w'.",
"They can help you move.",
"Of course.If you bullets that hit the enemy.You will K.O.",
"=========================================================",
"Enter 'enter' to begining"
};
system("cls");
int i; //输出文字
for (i = 0; i <= 8; i++)
puts(help[i]);
system("pause");//暂停
return 0;
}
int StartGameMain()//开始游戏
{
printf("If you affirm the can Game Start,enter 'enter'to start: ");
system("pause");//暂停
return 0;
}
int FightSystemMain()//战斗系统——游戏主体
{
int OSx, OSy, Ex, Ey;//己方坐标,敌方坐标
OSx = 3, OSy = 6;
int OSshotX[5] = { 0 }, OSshotY[5] = { 0 }, OSshotS = 5;
char map[9][14] = { "#############",//游戏区域
"# #",
"# #",
"# #",
"# #",
"# #",
"# #",
"#############"
};
char moveO, OSShot, moveE[10];//决定是否发出子弹,移动方向
int i = 0;//第i个子弹
while (1)//死循环,重复循环节直至结束
{
system("cls");//游戏以一秒一次刷新率运行
printf("You Can Shot: %d ", OSshotS);
for (int i = 0; i <= 7; i++)
puts(map[i]);
Sleep(500);
int levels = 1,enemies;//游戏等级决定敌人数量
enemies = levels;
moveO = getch();
OSShot = getch();
if (moveO || OSShot == 'a')//避免误输入,两个变量同时判断,左移
{
if (map[OSx][OSy - 1] != '#')
{
map[OSx][OSy] = ' ';
OSy--;
map[OSx][OSy] = 'O';
}
}
if (moveO || OSShot == 'd')//右移
{
if (map[OSx][OSy + 1] != '#')
{
map[OSx][OSy] = ' ';
OSy++;
map[OSx][OSy] = 'O';
}
}
if (moveO || OSShot == 's')//后退
{
if (map[OSx + 1][OSy] != '#')
{
map[OSx][OSy] = ' ';
OSx++;
map[OSx][OSy] = 'O';
}
}
if (moveO || OSShot == 'w')//前进
{
if (map[OSx - 1][OSy] != '#')
{
map[OSx][OSy] = ' ';
OSx--;
map[OSx][OSy] = 'O';
}
}
if (moveO || OSShot == 'j')//攻击
{
if (map[OSx - 1][OSy] != '#')
{
if (OSshotS < 5)//子弹限制五发
{
i++;
OSshotX[i] = OSx;
OSshotY[i] = OSy;
map[OSshotX[i]][OSshotY[i]] = '*';
OSshotS++;
}
}
}
for (int ii = 0; ii <= i; ii++)//批次处理每个子弹
{
switch (map[OSshotX[i] - 1][OSshotY[i]])//switch比较每一个子弹的去向
{
case 'V':
{
map[OSshotX[i]][OSshotY[i]] = ' ';
map[OSshotX[i]-1][OSshotY[i]] = ' ';
i--;
}
case ' ':
{
map[OSshotX[i]][OSshotY[i]] = '*';
i--;
}
default:
{
map[OSshotX[i]][OSshotY[i]] = ' ';
OSshotX[i]--;
map[OSshotX[i]][OSshotY[i]] = '*';
}
}
}
}
return 0;
}
int main()
{
HelpMain();
StartGameMain();
system("cls");
FightSystemMain();
printf("Enter 'enter' to end of the Game.");
char a;
a = getchar();
return 0;
}
程序至少移动部分全有问题,
if (moveO || OSShot == 'a')//避免误输入,两个变量同时判断,左移
你的moveO 肯定是非0,那么条件永远成立
所以正确的应该是
if (moveO && OSShot == 'a')//避免误输入,两个变量同时判断,左移
下面的多是