c语言游戏编程掌机太空大战 - 爱问答

(爱问答)

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')//避免误输入,两个变量同时判断,左移

下面的多是


相关标签:c语言

下一篇:c语言编程软件哪个好,win7系统

上一篇:我的佳能mp236一体打印机能扫描能复印为什么不能打印文件

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?