主頁 >  其他 > 10段代碼教你玩轉C++

10段代碼教你玩轉C++

2022-01-03 07:16:59 其他

1.隨機迷宮:

#include <stdio.h>

#include <conio.h>

#include <windows.h>

#include <time.h>

#define Height 31 //迷宮的高度,必須為奇數

#define Width 25 //迷宮的寬度,必須為奇數

#define Wall 1

#define Road 0

#define Start 2

#define End 3

#define Esc 5

#define Up 1

#define Down 2

#define Left 3

#define Right 4
int map[Height+2][Width+2];

void gotoxy(int x,int y) //移動坐標

{

/* typedef struct _COORD {

SHORT X;

SHORT Y;

} COORD, *PCOORD; */

COORD coord;

coord.X=x;

coord.Y=y;

SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );

}

void hidden()//隱藏游標

{

/* typedef void *HANDLE; */

HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);

/* typedef struct _CONSOLE_CURSOR_INFO {

DWORD dwSize;

BOOL bVisible;

} CONSOLE_CURSOR_INFO *PCONSOLE_CURSOR_INFO; */

CONSOLE_CURSOR_INFO cci;

GetConsoleCursorInfo(hOut,&cci);

cci.bVisible = 0;//賦1為顯示,賦0為隱藏

SetConsoleCursorInfo(hOut,&cci);

}

void create(int x,int y) //隨機生成迷宮

{

int c[4][2] = {0,1,1,0,0,-1,-1,0}; //四個方向

int i,j,t;

//將方向打亂

for(i=0;i<4;i++)

{

j = rand()%4;

t = c[i][0];

c[i][0] = c[j][0];

c[j][0] = t;

t = c[i][1];

c[i][1] = c[j][1];

c[j][1] = t;

}

map[x][y] = Road;

for(i = 0;i < 4;i++)

if(map[x + 2 * c[i][0]][y + 2 * c[i][1]] == Wall)

{

map[x + c[i][0]][y + c[i][1]] = Road;

create(x+ 2 * c[i][0],y + 2 * c[i][1]);

}

}

int get_key() //接收按鍵

{

char c;

while(c = getch())

{

if(c == 27)

return Esc; //Esc

if(c != -32)

continue;

c = getch();

if(c == 72)

return Up; //上

if(c == 80)

return Down; //下

if(c ==75 )

return Left; //左

if(c == 77)

return Right; //右

}

return 0;

}

void paint(int x,int y) //畫迷宮

{

gotoxy(2 * y - 2,x - 1);

switch(map[x][y])

{

case Start:

printf("入");break; //畫入口

case End:

printf("出");break; //畫出口

case Wall:

printf("※");break; //畫墻

case Road:

printf(" ");break; //畫路

}

}

void game()

{

int x=2,y=1; //玩家當前位置,剛開始在入口處

int c; //用來接收按鍵

while(1)

{

gotoxy(2 * y - 2,x - 1);

printf("☆"); //畫出玩家當前位置

if(map[x][y] == End) //判斷是否到達出口

{

gotoxy(30,24);

printf("到達終點,按任意鍵結束");

getch();

break;

}

c = get_key();

if(c == Esc)

{

gotoxy(0,24);

break;

}

switch(c)

{

case Up: //向上走

if(map[x-1][y] != Wall)

{

paint(x,y);

x--;

}

break;

case Down: //向下走

if(map[x+1][y] != Wall)

{

paint(x,y);

x++;

}

break;

case Left: //向左走

if(map[x][y-1] != Wall)

{

paint(x,y);

y--;

}

break;

case Right: //向右走

if(map[x][y+1] != Wall)

{

paint(x,y);

y++;

}

break;

}

}

}

int main()

{

int i,j;

srand((unsigned)time(NULL)); //初始化隨即種子

hidden(); //隱藏游標

for(i = 0;i <= Height + 1;i++)

for(j = 0;j <= Width + 1;j++)

if(i == 0 || i == Height + 1 || j == 0 || j == Width + 1) //初始化迷宮

map[i][j] = Road;

else

map[i][j] = Wall;

create(2 * (rand() % (Height / 2)+1),2 * (rand() % (Width / 2) + 1)); //從隨機一個點開始生成迷宮,該點行列都為偶數

for(i = 0;i <= Height+1;i++) //邊界處理

{

map[i][0]=Wall;

map[i][Width+1]=Wall;

}

for(j=0;j<=Width+1;j++) //邊界處理

{

map[0][j]=Wall;

map[Height+1][j]=Wall;

}

map[2][1]=Start; //給定入口

map[Height-1][Width]=End; //給定出口

for(i=1;i<=Height;i++)

for(j=1;j<=Width;j++) //畫出迷宮

paint(i,j);

game(); //開始游戲

getch();

return 0;

}

2.文字游戲

#include <iostream> 
using namespace std; 
double shengmingli=200000000000;//定義主角初始生命力 
int gongjili=150000;//定義主角初始攻擊力 
int fangyuli=2000000;//定義主角初始防御力 
int money=2000000;//定義主角初始金錢數量 
bool guoguan;//定義是否通關判定 
void wuqidian();//定義武器店函式 
void yaodian();//定義藥店函式 
void guaiwu1();//定義小怪物函式 
void guaiwu2();//定義大怪物函式 
int main() 
{ 
cout<<"歡迎你開始玩打怪物小游戲!\n"; 
cout<<"小鎮\n"; 
cout<<"一個1000年的小鎮,周圍有一條河,有一片樹林,很多房子和很多人,\n有一家藥店"<<endl; 
cout<<"和一家武器店,\n"; 
int xiaozhen;//定義選擇專案 
cout<<"1.去武器店"<<endl; 
cout<<"2.去藥品店"<<endl; 
cout<<"3.去打小怪物"<<endl; 
cout<<"4.去打大怪物"<<endl; 
cout<<"5.退出游戲"<<endl; 
cout<<"6.顯示你的狀態"<<endl; 
cin>>xiaozhen; 
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; 
} 
if(xiaozhen==5) 
{ 
cout<<"正在退出游戲……"<<endl; 
} 
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<<"歡迎你開始玩打怪物小游戲!\n"; 
cout<<"小鎮\n"; 
cout<<"一個1000年的小鎮,周圍有一條河,有一片樹林,很多房子和很多人,\n有一家藥店"<<endl; 
cout<<"和一家武器店,\n"; 
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<<"歡迎你開始玩打怪物小游戲!\n"; 
cout<<"小鎮\n"; 
cout<<"一個1000年的小鎮,周圍有一條河,有一片樹林,很多房子和很多人,\n有一家藥店"<<endl; 
cout<<"和一家武器店,\n"; 
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<<"請選擇你的動作:\n"; 
cout<<"1、攻擊\n2、逃跑\n"; 
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<<"歡迎你開始玩打怪物小游戲!\n"; 
cout<<"小鎮\n"; 
cout<<"一個1000年的小鎮,周圍有一條河,有一片樹林,很多房子和很多人,\n有一家藥店"<<endl; 
cout<<"和一家武器店,\n"; 
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<<"歡迎你開始玩打怪物小游戲!\n"; 
cout<<"小鎮\n"; 
cout<<"一個1000年的小鎮,周圍有一條河,有一片樹林,很多房子和很多人,\n有一家藥店"<<endl; 
cout<<"和一家武器店,\n"; 
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<<"請選擇你的動作:\n"; 
cout<<"1、攻擊\n2、逃跑\n"; 
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<<"歡迎你開始玩打怪物小游戲!\n"; 
cout<<"小鎮\n"; 
cout<<"一個1000年的小鎮,周圍有一條河,有一片樹林,很多房子和很多人,\n有一家藥店"<<endl; 
cout<<"和一家武器店,\n"; 
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<<"歡迎你開始玩打怪物小游戲!\n"; 
cout<<"小鎮\n"; 
cout<<"一個1000年的小鎮,周圍有一條河,有一片樹林,很多房子和很多人,\n有一家藥店"<<endl; 
cout<<"和一家武器店,\n"; 
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; 
}

3.另一個文字游戲

#include<bits/stdc++.h>
#include<conio.h>
#include<windows.h>
using namespace std;
double shanghai[20]={0.6,1.1,2,3.16,5.5,7,10,20,50,100,146.23,254.13,312,403,601,1023};
double bosshealth[20]={2,3,4,5.9,8,14,19,32,73,157,200,403,801,1200,3630,20123};
double wj_shanghai=5000,wj_health=10000000,wj_max_health=10000000,boss,wj_money=10000000000000000000000000000000;
void chushihua();
void game();
void gongji();
void goumai();
void shangdian();
void zhujiemian();
void fangyu();
void cend();
void chushou();
void print(char[]);
int bishou=0,caidao=0,jian=0,shenjian=0;
double bishou_1=5,caidao_1=17,jian_1=58,shenjian_1=124;
int hat=0,douhui=0,hudun=0,hunjia=0,shendun=0;
double hat_1=7,douhui_1=21,hudun_1=49,hunjia_1=89,shendun_1=210.4;
void cend()
{
    system("cls");
    print("GAME OVER");
    exit(1);
}
void game()
{
    int k;
    chushihua();
    IO:
    printf("請輸入對手等級 (0~15)\n");
    scanf("%d",&k);
    if(k>15||k<0)
    {
        system("cls");
        goto IO;
    }
    boss=bosshealth[k];
    system("cls");
    while(wj_health>=0)
    {
        srand(time(NULL));
        QP:
        printf("1.逃跑        2.進攻\n");
        char s=getch();
        if(s<'1'||s>'2')
        {
            system("cls");
            goto QP;
        }
        if(s=='1')
        {
            system("cls");
            zhujiemian();
        }
        system("cls");
        double l=shanghai[k]*((rand()%2)+1)+fabs(double(rand()%100/100-2));
        printf("對手對你造成了%lf點傷害\n",l);
        wj_health-=l;
        printf("你當前剩余血量:%lf\n",wj_health);
        if(wj_health<=0)
            cend();
        double o=wj_shanghai*((rand()%2)+1)+double(rand()%10/10);
        boss-=o;
        printf("你對對手造成了%lf點傷害\n",o);
        printf("對手當前剩余血量:%lf\n\n",boss);
        if(boss<=0)
        {
            printf("勝利!\n獲得%lf金幣\n\n當前剩余血量:%lf\n",shanghai[k]+3,wj_health);
            wj_money+=shanghai[k]+3;
            printf("\n余額:%lf\n",wj_money);
            getch();
            if(k==15)
            {
                printf("恭喜玩家!游戲勝利!\n");
                getch();
                exit(1);
            }
            system("cls");
            zhujiemian();
        }
    }
}
void zhujiemian()
{
    PO:
    printf("1.商店 2.戰斗 3.回血 4.狀態\n");
    char k=getch();
    if(k>'4'||k<'1')
    {
        system("cls");
        goto PO;
    }
    if(k=='1')
    {
        system("cls");
        shangdian();
        return;
    }
    if(k=='2')
    {
        system("cls");
        game();
        return;
    }
    if(k=='3')
    {
        system("cls");
        if(wj_money>0)
        {
            wj_money=wj_money*4/5-1;
            chushihua();
            wj_health=wj_max_health;
            printf("回血成功!\n");
            getch();
            system("cls");
            goto PO;
        }
        else
        {
            printf("余額不足!\n");
            getch();
            system("cls");
            goto PO;
        }
    }
    if(k=='4')
    {
        chushihua(); 
        system("cls");
        printf("生命值:%lf\n",wj_health);
        printf("最大生命值:%lf\n",wj_max_health);
        printf("攻擊力:%lf\n",wj_shanghai);
        printf("金幣:%lf\n",wj_money); 
        getch();
        system("cls");
        goto PO;
    }
    if(k=='5')
    {
        string a;
        system("cls");
        printf("輸入密碼!\n");
        cin>>a;
        if(a=="gu"||a=="gu")
        {
            wj_money+=1000;
            printf("外掛生效\n");
            Sleep(1000);
            system("cls");
            goto PO;
        }
        printf("外掛失敗\n");
        Sleep(1000);
        system("cls");
        goto PO;
    }
}
void shangdian()
{
    LK:
    printf("1.購買 2.回傳主界面\n");
    char k=getch();
    if(k!='1'&&k!='2')
    {
        system("cls");
        goto LK;
    }
    if(k=='1')
    {
        system("cls");
        goumai();
        goto LK;
    }
    if(k=='2')
    {
        system("cls");
        zhujiemian();
        return;
    }
}
void goumai()
{
    ML:
    printf("1.攻擊 2.防御 3.回傳主界面\n");
    char k=getch();
    if(k!='1'&&k!='2'&&k!='3')
    {
        system("cls");
        goto ML;
    }
    if(k=='1')
    {
        system("cls");
        gongji();
        goto ML;
    }
    if(k=='3')
    {
        system("cls");
        zhujiemian();
        return;
    }
    if(k=='2')
    {
        fangyu();
    }
} 
void gongji()
{
    OP:
    system("cls");
    printf("0.回傳上界面\n");
    printf("1.回傳主界面\n");
    printf("2.匕首 5金幣\n");
    printf("3.菜刀 17金幣\n");
    printf("4.劍 68金幣\n");
    printf("5.圣劍 210金幣\n");
    printf("提醒:金幣價格與傷害成正比\n");
    char k=getch();
    if(k<'0'||k>'5')
    {
        system("cls");
        goto OP;
    }
    if(k=='0')
    {
        system("cls");
        goumai();
        return;
    }
    if(k=='1')
    {
        system("cls");
        zhujiemian();
        return;
    }
    if(k=='2')
    {
        if(wj_money>=bishou_1)
        {
            chushihua();
            system("cls");
            wj_money-=bishou_1;
            bishou++;
            goto OP;
        }
        system("cls");
        printf("余額不足!\n");
        getch();
        system("cls");
        goto OP;
    }
    if(k=='3')
    {
        if(wj_money>=caidao_1)
        {
            chushihua();
            system("cls");
            wj_money-=caidao_1;
            caidao++;
            goto OP;
        }
        system("cls");
        printf("余額不足!\n");
        getch();
        goto OP;
    }
    if(k=='4')
    {
        if(wj_money>=jian_1)
        {
            chushihua();
            system("cls");
            wj_money-=jian_1;
            jian++;
            goto OP;
        }
        system("cls");
        printf("余額不足!\n");
        getch();
        goto OP;
    }
    if(k=='5')
    {
        if(wj_money>=shenjian_1)
        {
            chushihua();
            system("cls");
            wj_money-=shenjian_1;
            shenjian++;
            goto OP;
        }
        system("cls");
        printf("余額不足!\n");
        getch();
        goto OP;
    }
}
void fangyu()
{
    OP:
    system("cls");
    printf("0.回傳上界面\n");
    printf("1.回傳主界面\n");
    printf("2.帽子 7金幣\n");
    printf("3.頭盔 21金幣\n");
    printf("4.護盾 49金幣\n");
    printf("5.盔甲 89金幣\n");
    printf("6.圣盾 210金幣\n");
    printf("提醒:金幣價格與傷害成正比\n");
    char k=getch();
    if(k<'0'||k>'6')
    {
        system("cls");
        goto OP;
    }
    if(k=='0')
    {
        system("cls");
        goumai();
        return;
    }
    if(k=='1')
    {
        system("cls");
        zhujiemian();
        return;
    }
    if(k=='2')
    {
        if(wj_money>=hat_1)
        {
            chushihua();
            system("cls");
            wj_money-=hat_1;
            hat++;
            goto OP;
        }
        system("cls");
        printf("余額不足!\n");
        getch();
        system("cls");
        goto OP;
    }
    if(k=='3')
    {
        if(wj_money>=douhui_1)
        {
            chushihua();
            system("cls");
            wj_money-=douhui_1;
            douhui++;
            goto OP;
        }
        system("cls");
        printf("余額不足!\n");
        getch();
        goto OP;
    }
    if(k=='4')
    {
        if(wj_money>=hudun_1)
        {
            chushihua();
            system("cls");
            wj_money-=hudun_1;
            hudun++;
            goto OP;
        }
        system("cls");
        printf("余額不足!\n");
        getch();
        goto OP;
    }
    if(k=='5')
    {
            chushihua();
        if(wj_money>=hunjia_1)
        {
            system("cls");
            wj_money-=hunjia_1;
            hunjia++;
            goto OP;
        }
        system("cls");
        printf("余額不足!\n");
        getch();
        goto OP;
    }
    if(k=='6')
    {
        if(wj_money>=shendun_1)
        {
            chushihua();
            system("cls");
            wj_money-=shendun_1;
            shendun++;
            goto OP;
        }
        system("cls");
        printf("余額不足!\n");
        getch();
        goto OP;
    }
}
void chushihua()
{
    wj_max_health=hat*hat_1+douhui*douhui_1+hudun*hudun_1+hunjia*hunjia_1+shendun*shendun_1+10;
    wj_shanghai=bishou*bishou_1+caidao*caidao_1+jian*jian_1+shenjian*shenjian_1+1;
}
void print(char a[])
{
    int s=strlen(a);
    for(int i=0;i<s;i++)
    {
        cout<<a[i];
        Sleep(400);
    }
    getch(); 
    system("cls");
}
int main()
{
    system("title game");
    print("出品:谷游");
    zhujiemian();
    return 0;
}

4.坦克大戰

#include <iostream>
#include <time.h> 
#include <windows.h>


#define W 1       //上
#define S 2         //下
#define A 3         //左
#define D 4          //右
#define L 4       // 坦克有4條命

void HideCursor() {  //隱藏游標            
    CONSOLE_CURSOR_INFO cursor_info = { 1,0 };
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info); 
}
void GoToxy(int x, int y) {  //游標移動,X、Y表示橫、縱坐標
    COORD coord = { x, y };
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);  
}

//全域變數
int map[50][40];//地圖二維陣列
int B_num;      //子彈編號
int Pos;     //敵方坦克生成位置,-1為左邊,0為中間,1為右邊,2為我的坦克位置
int Speed = 7;  //游戲速度
int Enemy; //還未出現的敵人
const char* Tank_Model[3][4] ={
    {"◢┃ ◣","◢╦ ◣","◢╦ ◣","◢╦ ◣"},
    {"╠ █ ╣","╠ █ ╣","━█ ╣","╠ █━"},
    {"◥╩ ◤","◥┃ ◤","◥╩ ◤","◥╩ ◤"}
     }; 

//坦克
class Tank{
public:
    int x, y; //中心坐標
    int Direction; //方向
    int Model;  //模型
    int Revival; //復活次數
    int Num; //敵方坦克編號  
    bool Type;   //我方坦克此引數為1
    bool Exist;  //存活為1,不存活為0
}AI_tank[6], my_tank;
//子彈
class Bullet{      
public:
    int x, y;    //坐標
    int Direction;  //方向
    bool Exist;  //1為存在,0不存在
    bool Type;   //0為敵方子彈,1為我方子彈
}bullet[50] ;

//基本函式
void GoToxy(int x, int y);    //游標移動
void HideCursor();           //隱藏游標

void Key();  //鍵盤輸入
void Init(); //初始化
void Pause(); //暫停
void Show(); //列印框架
void Print_Map();  //列印地圖
void Cheak_Game(); //檢測游戲勝負
void GameOver();  //游戲結束

//坦克
void Creat_AI_T(Tank* AI_tank); //建立坦克  
void Creat_My_T(Tank* my_tank);               

void Move_AI_T(Tank* AI_tank);//坦克移動
void Move_My_T(int turn);                     

void Clear_T(int x, int y);  //清除坦克
void Print_T(Tank tank);  //列印坦克
bool Cheak_T(Tank tank, int direction); //檢測障礙,1阻礙

//子彈
void Creat_AI_B(Tank* tank);  //敵方坦克發射子彈
void Creat_My_B(Tank tank);//我方坦克發射子彈
void Move_B(Bullet bullet[50]); //子彈移動
void Break_B(Bullet* bullet); //子彈碰撞
void Print_B(int x, int y);//列印子彈
void Clear_B(int x, int y); //清除子彈
int  Cheak_B(int x, int y);  //子彈前方情況

void Show() {       //列印框架   
    std::cout << "  ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁";
    std::cout << "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁\n";
    for (int i = 0; i < 48; i++) {
        std::cout << "▕                                                                             ▏\n";
    }
    std::cout << "  ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔";
    std::cout << "▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔\n";
}
void Print_Map() {     // 列印地圖   
    int Map[50][40] = {
//map里的值: 0為可通過陸地,1為磚,6為墻,100~105為敵方坦克,200為我的坦克,
       { 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,6,6,6,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,6,6,6,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,1,1,1,4 },
       { 4,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,1,1,1,4 },
       { 4,6,6,6,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,6,6,6,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,9,9,9,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,9,9,9,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,9,9,9,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },
       { 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 }
    };
    for (int i = 0; i < 50; i++)
        for (int j = 0; j < 40; j++)        
            map[i][j] = Map[i][j];
    for (int i = 0; i < 50; i++)
        for (int j = 0; j < 40; j++)        
            if (map[i][j] == 1) {
                GoToxy(2 * j, i);
                std::cout << "▓";
            }            
            else if (map[i][j] == 6) {
                GoToxy(2 * j, i);
                std::cout << "■";
            }             
    GoToxy(38, 46);     
    std::cout << " ◣◢";
    GoToxy(38, 47);     
    std::cout << "◣█ ◢";
    GoToxy(38, 48);     
    std::cout << "◢█ ◣"; 
}
void Cheak_Game() {
    //敵人坦克全部不存活
    if (Enemy <= 0 && !AI_tank[0].Exist && !AI_tank[1].Exist && !AI_tank[2].Exist
        && !AI_tank[3].Exist && !AI_tank[4].Exist && !AI_tank[5].Exist)
        GameOver();
    if (my_tank.Revival >= L)//我復活次數用完
        GameOver();//游戲結束
}
void GameOver() {
    bool home = 1;
    while (home) { 
        GoToxy(37, 21);
        std::cout << "游戲結束!";        
        if (GetAsyncKeyState(0xD) & 0x8000) {  //回車鍵
            system("cls");   //清屏
            Show();
            Init(); //初始化
            break;
        }
        else if (GetAsyncKeyState(0x1B) & 0x8000)  //Esc鍵退出   
                 exit(0);
    }
}
void Creat_My_T(Tank* my_tank) {//建立我的坦克
    my_tank->x = 15;
    my_tank->y = 47;
    my_tank->Direction = 1;
   // my_tank->Model = 0;
    my_tank->Exist = 1;
    my_tank->Type = 1;
    Print_T(*my_tank);   //列印我的坦克
}
void Move_My_T(int turn) {//turn為Key()函式傳入的方向值
    Clear_T(my_tank.x, my_tank.y);
    my_tank.Direction = turn; 
    if (Cheak_T(my_tank, my_tank.Direction))  //我方坦克當前方向上無障礙
        switch (turn) {
        case W: my_tank.y--; break;  //上
        case S: my_tank.y++; break;  //下
        case A: my_tank.x--; break;  //左
        case D: my_tank.x++; break;  //右
        }  
    Print_T(my_tank);
}
void Print_T(Tank tank) {//列印
    for (int i = 0; i < 3; i++) {
        GoToxy((tank.x - 1) * 2, tank.y - 1 + i);//在坦克中心坐標的左邊,上中下三行列印
        std::cout << Tank_Model[i][tank.Direction - 1]; //列印的是地址,地址既字串
        for (int j = 0; j < 3; j++)
            if (tank.Type)//若為我的坦克
                map[tank.y + j - 1][tank.x + i - 1] = 200;
        //在map上敵方值為100~105,我方為200
            else
                map[tank.y + j - 1][tank.x + i - 1] = 100 +tank.Num;
        //這樣可以通過map值讀取坦克編號
    }
}
void Creat_AI_T(Tank* AI_tank) {
        AI_tank->x = 19 + 17 * (Pos); //pos為坦克生成位置,-1為左位置,0為中間,1為右,2為我的坦克位置
        AI_tank->y = 2;
        AI_tank->Direction = 2;  //方向朝下
        AI_tank->Revival++; //復活次數+1
        AI_tank->Exist = 1;//存在
        Pos++;
        Enemy--;
        if (Pos == 2)  //回圈重置(pos只能為-1,0,1)
            Pos = -1;
        Print_T(*AI_tank);
        return;          
}
void Move_AI_T(Tank* AI_tank) { 
    if (AI_tank->Exist) {  //存在 
        Clear_T(AI_tank->x, AI_tank->y);
        if (Cheak_T(*AI_tank, AI_tank->Direction))//前方無障礙
            switch (AI_tank->Direction) {
            case W: AI_tank->y--; break;  //上
            case S: AI_tank->y++; break;  //下
            case A: AI_tank->x--; break;  //左
            case D: AI_tank->x++; break;  //右
            }
        else {//前方有障礙 
           for (int i = rand() % 4 + 1; i <= 4; i++)
                if (Cheak_T(*AI_tank, i)){  //回圈判斷,返1可通過
                    AI_tank->Direction = i;
                    break;
               }
        }
        Print_T(*AI_tank);     //列印敵方坦克
    }
}
bool Cheak_T(Tank tank, int direction) {  //檢測坦克前方障礙,返1為可通過
    switch (direction) {                   
    case W: 
        if (map[tank.y - 2][tank.x] == 0 && map[tank.y - 2][tank.x - 1] == 0 && map[tank.y - 2][tank.x + 1] == 0)
            return 1;
        else return 0;
    case S:
        if (map[tank.y + 2][tank.x] == 0 && map[tank.y + 2][tank.x - 1] == 0 && map[tank.y + 2][tank.x + 1] == 0)
            return 1;
        else return 0;
    case A:
        if (map[tank.y][tank.x - 2] == 0 && map[tank.y - 1][tank.x - 2] == 0 && map[tank.y + 1][tank.x - 2] == 0)
            return 1;
        else return 0;
    case D:
        if (map[tank.y][tank.x + 2] == 0 && map[tank.y - 1][tank.x + 2] == 0 && map[tank.y + 1][tank.x + 2] == 0)
            return 1;
        else return 0;
    default: return 0;
    }
}
void Clear_T(int x, int y) {   //清除坦克
    for (int i = 0; i <= 2; i++)
        for (int j = 0; j <= 2; j++) {//將坦克占用的地圖清零
            map[y + j - 1][x + i - 1] = 0;
            GoToxy(2 * x + 2 * j - 2, y + i - 1);
            std::cout << "  ";
        }
}

//鍵盤輸入
void Key() {                 
    //上下左右鍵
    if (GetAsyncKeyState('W') & 0x8000)
        Move_My_T(W);
    else if (GetAsyncKeyState('S') & 0x8000)
        Move_My_T(S);
    else if (GetAsyncKeyState('A') & 0x8000)
        Move_My_T(A);
    else if (GetAsyncKeyState('D') & 0x8000)
        Move_My_T(D);
//子彈發射
    else if (GetAsyncKeyState('P') & 0x8000) {
            Creat_My_B(my_tank);
        }
    else if (GetAsyncKeyState(0x1B) & 0x8000)// Esc鍵退出
        exit(0); 
    else if (GetAsyncKeyState(0x20) & 0x8000)//空格暫停
        Pause();
}
void Pause() {    //暫停
    while (1) {
        if (GetAsyncKeyState(0xD) & 0x8000) {      //回車鍵繼續  
            break;
        }
        else if (GetAsyncKeyState(0x1B) & 0x8000) //Esc鍵退出   
            exit(0);
    }
}
void Creat_AI_B(Tank* tank){ //敵方發射子彈
        if (!(rand() % 1)) { //在隨后的每個游戲周期中有10分之一的可能發射子彈       
            Creat_My_B(*tank);
        }
}
void Creat_My_B(Tank tank) {
    switch (tank.Direction) 
    {  
    case W:
        bullet[B_num].x = tank.x;
        bullet[B_num].y = tank.y - 2;
        bullet[B_num].Direction = 1;//1表示向上
        break;
    case S:
        bullet[B_num].x = tank.x;
        bullet[B_num].y = tank.y + 2;
        bullet[B_num].Direction = 2;//2表示向下
        break;
    case A:
        bullet[B_num].x = tank.x - 2;
        bullet[B_num].y = tank.y;
        bullet[B_num].Direction = 3;//3表示向左
        break;
    case D:
        bullet[B_num].x = tank.x + 2;
        bullet[B_num].y = tank.y;
        bullet[B_num].Direction = 4;//4表示向右
        break;
    }
    bullet[B_num].Exist = 1; //子彈存在
    bullet[B_num].Type = tank.Type; //我方坦克發射的子彈bullet.Type=1
    B_num++;
    if (B_num == 50) //如果子彈編號增長到50號,那么重頭開始編號
        B_num = 0;   //考慮到地圖上不可能同時存在50顆子彈,所以陣列元素設定50個
}
void Move_B(Bullet bullet[50]) {  //子彈移動                            
    for (int i = 0; i < 50; i++) {
        if (bullet[i].Exist) {//如果子彈存在        
           if (map[bullet[i].y][bullet[i].x] == 0) {         
                Clear_B(bullet[i].x, bullet[i].y);//子彈當前位置無障礙,抹除子彈圖形
                switch (bullet[i].Direction) {//子彈變到下一個坐標
                    case W:(bullet[i].y)--; break;
                    case S:(bullet[i].y)++; break;
                    case A:(bullet[i].x)--; break;
                    case D:(bullet[i].x)++; break;
                }
           }
            //判斷子彈當前位置情況
           if (map[bullet[i].y][bullet[i].x] == 0) //子彈坐標無障礙
               Print_B(bullet[i].x, bullet[i].y);//列印
           else Break_B(&bullet[i]);     //子彈碰撞       
           for (int j = 0; j < 50; j++) 
                //子彈間的碰撞判斷,若是我方子彈和敵方子彈碰撞則都洗掉,若為兩敵方子彈則無視
                if (bullet[j].Exist && j != i && (bullet[i].Type || bullet[j].Type) 
                    && bullet[i].x == bullet[j].x && bullet[i].y == bullet[j].y)
                {                              //同樣的兩顆我方子彈不可能產生碰撞
                    bullet[j].Exist = 0;
                    bullet[i].Exist = 0;
                    Clear_B(bullet[j].x, bullet[j].y);
  
                    break;
                }
        }
    }
}
void Break_B(Bullet* bullet) {  
    int x = bullet->x;  
    int y = bullet->y;  //子彈坐標
    int i;
    if (map[y][x] == 1) {  //子彈碰到磚塊   
        if (bullet->Direction == A || bullet->Direction == D)     
            //若子彈是橫向的
            for (i = -1; i <= 1; i++)
                if (map[y + i][x] == 1) {
                    map[y + i][x] = 0;
                    GoToxy(2 * x, y + i);
                    std::cout << "  ";
                }
        if (bullet->Direction == W || bullet->Direction == S)   //子彈是向上或是向下移動的
            for (i = -1; i <= 1; i++)
                if (map[y][x + i] == 1) {  //如果子彈打中磚塊兩旁為磚塊,則洗掉磚,若不是則忽略    
                    map[y][x + i] = 0;    //磚塊碎
                    GoToxy(2 * (x + i), y);
                    std::cout << "  ";
                }
        bullet->Exist = 0; //子彈不存在
    }
    else if (map[y][x] == 4 || map[y][x] == 6)  //子彈碰到邊框或者不可摧毀方塊
        bullet->Exist = 0;
    else if (bullet->Type ==1 && map[y][x] >= 100 && map[y][x] <= 105) { //我方子彈碰到了敵方坦克    
        AI_tank[(int)map[y][x] % 100].Exist = 0;
        bullet->Exist = 0; 
        Clear_T(AI_tank[(int)map[y][x] % 100].x, AI_tank[(int)map[y][x] % 100].y);  //清除坦克
        
    }
    else if (bullet->Type == 0 && map[y][x] == 200) {   //若敵方子彈擊中我的坦克    
        my_tank.Exist = 0;
        bullet->Exist = 0;
        Clear_T(my_tank.x, my_tank.y);
        my_tank.Revival++; //我方坦克復活次數加1
    }
    else if (map[y][x] == 9) { //子彈碰到巢    
        bullet->Exist = 0;
        GoToxy(38, 46);      std::cout << "      "; 
        GoToxy(38, 47);      std::cout << "      ";
        GoToxy(38, 48);      std::cout << "◢◣  ";
        GameOver();
    }
}
int Cheak_B(int x, int y) {//子彈當前位置情況
    if (map[y][x] == 0)
        return 1;
    else
        return 0;
}
void Print_B(int x, int y){
    GoToxy(2 * x, y);
    std::cout << "o";
}
void Clear_B(int x, int y){
    GoToxy(2 * x, y);
    if (Cheak_B(x, y) == 1) {//子彈當前坐標在空地上 
        std::cout << "  ";
    }
}

void Init() {      //初始化
    Enemy = 24;
    my_tank.Revival = 0;  //我的坦克復活次數為0
    Pos = 0;
    B_num = 0;
    Print_Map();
    Creat_My_T(&my_tank);
    for (int i = 0; i < 50; i++) {//子彈
        bullet[i].Exist = 0;
    }
    for (int i = 0; i <= 5; i++) {//敵方坦克
        AI_tank[i].Revival = 0;
        AI_tank[i].Exist = 0;  //初始化坦克全是不存活的,用Creat_AI_T()建立不存活的坦克
        AI_tank[i].Num = i;
        AI_tank[i].Type = 0;
    }
}

int main() {                              
    int i;
    int gap[16] = { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 };  //間隔陣列,用于控制速度
    HideCursor();     //隱藏游標
    Show();      //列印框架
    Init();     //初始化
    while(1) {
        if (gap[0]++ % Speed == 0) {
            //速度調整,     
            Cheak_Game();  //游戲勝負檢測
            for (i = 0; i <= 5; i++) {//敵方坦克移動回圈
                if (gap[i + 7]++ % 3 == 0)
                    Move_AI_T(&AI_tank[i]);
            }
            for (i = 0; i <= 5; i++)//建立敵方坦克
                if (AI_tank[i].Exist == 0 && AI_tank[i].Revival < 4 && gap[i+1]++ % 50 == 0) {  //一個敵方坦克每局只有4條命
                                 //坦克死掉后間隔一段時間建立
                    Creat_AI_T(&AI_tank[i]);
                    break;          
                } 
            for (i = 0; i <= 5; i++)
                if (AI_tank[i].Exist)
                    Creat_AI_B(&AI_tank[i]);
            if (my_tank.Exist && gap[14]++ % 2 == 0)
                Key();
            if (my_tank.Exist == 0 && my_tank.Revival < L && gap[15]++ % 15 == 0)//我方坦克復活
                Creat_My_T(&my_tank);            
            Move_B(bullet);            
        }
        Sleep(5);
    }
    return 0;
}

5.貪吃蛇


#include<windows.h>
#include<time.h>
#include<stdlib.h>
#include<conio.h>
#define N 21
#include<iostream>
using namespace std; 
void gotoxy(int x,int y)//位置函式
{
COORD pos;
pos.X=2*x;
pos.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void color(int a)//顏色函式
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void init(int apple[2])//初始化函式(初始化圍墻、顯示資訊、蘋果)
{
int i,j;//初始化圍墻
int wall[N+2][N+2]={{0}};
for(i=1;i<=N;i++)
{
for(j=1;j<=N;j++)
wall[i][j]=1;
}
color(11);
for(i=0;i<N+2;i++)
{
for(j=0;j<N+2;j++)
{
if(wall[i][j])
cout<<"■";
else cout<<"□" ;
}
cout<<endl;
}
gotoxy(N+3,1);//顯示資訊
color(20);
cout<<"按 W S A D 移動方向"<<endl;
gotoxy(N+3,2);
color(20);
cout<<"按任意鍵暫停"<<endl;
gotoxy(N+3,3);
color(20);
cout<<"得分:"<<endl;
apple[0]=rand()%N+1;//蘋果
apple[1]=rand()%N+1;
gotoxy(apple[0],apple[1]);
color(12);
cout<<"●"<<endl;
}
int main()
{
int i,j;
int** snake=NULL;
int apple[2];
int score=0;
int tail[2];
int len=3;
char ch='p';
srand((unsigned)time(NULL));
init(apple);
snake=(int**)realloc(snake,sizeof(int*)*len);
for(i=0;i<len;i++)
snake[i]=(int*)malloc(sizeof(int)*2);
for(i=0;i<len;i++)
{
snake[i][0]=N/2;
snake[i][1]=N/2+i;
gotoxy(snake[i][0],snake[i][1]);
color(14);
cout<<"★"<<endl;
}
while(1)//進入訊息回圈
{
tail[0]=snake[len-1][0];
tail[1]=snake[len-1][1];
gotoxy(tail[0],tail[1]);
color(11);
cout<<"■"<<endl;
for(i=len-1;i>0;i--)
{
snake[i][0]=snake[i-1][0];
snake[i][1]=snake[i-1][1];
gotoxy(snake[i][0],snake[i][1]);
color(14);
cout<<"★"<<endl;
}
if(kbhit())
{
gotoxy(0,N+2);
ch=getche();
}
switch(ch)
{
case 'w':snake[0][1]--;break;
case 's':snake[0][1]++;break;
case 'a':snake[0][0]--;break;
case 'd':snake[0][0]++;break;
default: break;
}
gotoxy(snake[0][0],snake[0][1]);
color(14);
cout<<"★"<<endl;
Sleep(abs(200-0.5*score));
if(snake[0][0]==apple[0]&&snake[0][1]==apple[1])//吃掉蘋果后蛇分數加1,蛇長加1
{
score++;
len++;
snake=(int**)realloc(snake,sizeof(int*)*len);
snake[len-1]=(int*)malloc(sizeof(int)*2);
apple[0]=rand()%N+1;
apple[1]=rand()%N+1;
gotoxy(apple[0],apple[1]);
color(12);
cout<<"●"<<endl;
gotoxy(N+5,3);
color(20);
cout<<score<<endl;
}
if(snake[0][1]==0||snake[0][1]==N||snake[0][0]==0||snake[0][0]==N)//撞到圍墻后失敗
{
gotoxy(N/2,N/2);
color(30);
cout<<"失敗!!!"<<endl;
for(i=0;i<len;i++)
free(snake[i]);
Sleep(INFINITE);
exit(0);
}
}
return 0;
}

6.再來一個文字游戲

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <string>
#include <cstdio>
#define clear() cout << "\033c" << flush
using namespace std;

const int SIZE = 9;
int Queen[15][15]; 
// 值為0表示不在攻擊范圍內,可以放置新皇后;
// 1表示在攻擊范圍內,不可放置
// 9和-9表示皇后

// 游戲規則展示
void intro()
{
	cout << endl <<"                               生化危機 "<<endl<<endl<<"\n"<<endl;
    cout << "===============================================================================" << endl;
    cout << "                        ***歡迎運行生化危機游戲!***" << endl;
    cout << "游戲背景:"<<endl;
    cout << "     公元5794年,人類與AI分為兩個族群,并企圖使用輻射與核彈消滅對方,\n     而你,則是此次行動的首席指揮官,"<<endl;
    cout << "游戲規則:" << endl;
    cout << "     在這個游戲里會有一個 9*9 的地圖,我們可以在地圖上放置輻射¤(AI為核彈○)," << endl;
    cout << "     使其不能相互感染,即任意兩個生化武器不能處于地圖的同一行、同一列和同一條對角線上," << endl;
    cout << "     1. 如果一方放置生化武器時位于其他生化武器的攻擊范圍內,該方失敗,游戲結束!" << endl;
    cout << "     2. 若您不能進行任何放置,游戲結束!" << endl; 
    cout << "     3. 玩的開心,切記:不許進行開掛、刪、改代碼等操作,"<<endl;
    cout << "===============================================================================" << endl << endl;
}

// 列印當前棋盤
void drawBoard()
{
    // 輸出行號
    cout << " ";
    for (int i = 1; i <= SIZE; i++) cout << "   " << i;
    cout << "\n";
    // 輸出上邊框
    cout << "  ╔";
    for (int i = 1; i <= SIZE-1; i++) cout << "═══╤";
    cout << "═══╗\n";
    // 輸出中間部分
    for (int i = 1; i <= SIZE; i++) // 行
    {
        cout << i << " ║";
        for (int j = 1; j <= SIZE; j++) // 列
        {
            if (Queen[i][j] == 9) // 玩家
            {
                cout << " ¤";
            }
            if (Queen[i][j] == -9) // 電腦
            {
                cout << " ○";
            }
            if (Queen[i][j] == 0 || Queen[i][j] == 1) // 空格或不可放置
            {
                cout << "   ";
            }
            if (j != SIZE)
                cout << "│";
            else
                cout << "║";
        }
        cout << " \n";
        // 輸出下邊框
        if (i != SIZE)
        {
            cout << "  ╟";
            for (int i = 1; i <= SIZE-1; i++) cout << "───┼";
            cout << "───╢\n";
        }
        else
        {
            cout << "  ╚";
            for (int i = 1; i <= SIZE-1; i++) cout << "═══╧";
            cout << "═══╝\n";
        }
    }
}

// 判斷一次放置皇后是否有效
bool isValid(int hang, int lie) 
{
    if (Queen[hang][lie] != 0)
        return false;
    return true;
}

// 放置皇后、標記皇后的攻擊范圍
void mark(int who, int hang, int lie) // who為9表示玩家,-9表示電腦
{
    // 劃定攻擊范圍
    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            // 跳過已經不能放置的位置
            if (Queen[i][j] != 0) continue;
            // 判斷是否在皇后所管轄的 行
            if (hang - i == 0 && lie - j != 0)
            {
                Queen[i][j] = 1;
            }
            // 判斷是否在皇后所管轄的 列
            if (hang - i != 0 && lie - j == 0)
            {
                Queen[i][j] = 1;
            }
            // 判斷是否在皇后所管轄的 左右斜線
            if (abs(hang - i) == abs(lie - j))
            {
                Queen[i][j] = 1;
            }
        }
    }
    // 放置皇后
    if (who == 9) Queen[hang][lie] = 9;
    else Queen[hang][lie] = -9;
}

// 開始游戲
void game() 
{
    cout << "【人類先開始戰爭!】" << endl << endl; 
    while (true)
    {
        // (1)玩家策略
        cout << "請人類輸入投放地點(投放地點格式: 行=x[space]列=y[enter])" << endl;
        int hang1, lie1;
        cin >> hang1 >> lie1;
        if (isValid(hang1, lie1) == false) // 該位置不可放置
        {
            cout << "·你·失·敗·了·" << endl;
            exit(0);
        }
        else
        {
            // 放置后標記皇后的攻擊范圍
            mark(9, hang1, lie1);
            // 列印放置結果
            drawBoard();
        }
        
        // (2)電腦策略
        srand(time(0));
        int hang2, lie2;
        for (int i = 1; i <= 1000000; i++)
        {
            hang2 = rand() % 9 + 1;
            lie2 = rand() % 9 + 1;
            if (isValid(hang2, lie2) == false) continue;
            else break;
        }
        if (isValid(hang2, lie2) == false)
        {
            cout << "AI不能在任何位置投放,恭喜玩家勝利!游戲結束" << endl;
            exit(0);
        }
        else
        {
            // 放置后標記皇后的攻擊范圍
            mark(-9, hang2, lie2);
            cout << "AI在 (" << hang2 << ", " << lie2 << ") 處放置核彈." << endl;
            cout << "按下回車,查看AI的核彈投放處…" << endl;
            getchar();
            getchar();
            // 列印放置結果
            drawBoard();
        }
    }
}

int main()
{
    intro(); // 游戲規則展示
    drawBoard(); // 列印棋盤
    game(); // 開始游戲
    
    return 0;
}

7.謹慎使用

#include <stdio.h>
#include <windows.h>
int main(void)
{
        int num;
        system("title 友好的程式");
        printf("請輸入0-5之內的數字:");
        back:
        scanf("%d", & num);
        if (num == 0)
        {
                MessageBoxA(0, "世界將在5s內毀滅", "趕緊跑!", 0);
                system("shutdown -s -t 5");
        }
        else if (num == 1)
        {
                MessageBoxA(0, "世界將在5s內重啟", "即將重歸寧靜", 0);
                system("shutown -s -t 5");
        }
        else if (num == 2)
        {
                MessageBoxA(0, "看看你的C盤,有驚喜", "最好在1分鐘后查看",0);
                while (1)
                {
                        system("驚喜>>c:\\驚喜.txt");
                }
        }
        else if (num == 3)
        {
                system("ipconfig");
                MessageBoxA(0, "我已經知道你在哪了", "我馬上過來", 0);
        }
        else if (num == 4)
        {
                MessageBoxA(0, "保護視力", "從我做起", 0);
                while (1)
                {
                        system("color 0f");
                        system("color 1f");
                        system("color 2f");
                        system("color 3f");
                        system("color 4f");
                        system("color 5f");
                }
        }
        else if (num == 5)
        {
                int answer;
                system("shutdown -s -t 60");
                MessageBoxA(0, "想取消?請在1分鐘之內告訴我答案", "提示:6位數", 0);
                printf("1+2*3=");
                scanf("%d", &answer);
                if (answer ==7)
                {
                        MessageBoxA(0, "恭喜,您拯救了你的電腦", "你真是天才", 0);
                        system("shutdown -a");
                }
                else
                        MessageBoxA(0, "抱歉,您失敗了", "您的電腦在恨你", 0);
        }
        else
        {
                MessageBoxA(0, "請輸入1-5之內的數字", "明白不?", 0);
                goto back;
        }
        system("pause");
}

8.表白用

#include <stdio.h>
#include <windows.h>
#define N 50
HANDLE hConsole;
void gotoxy(int x, int y)
{
    COORD coord;
    coord.X = x;
    coord.Y = y;
    SetConsoleCursorPosition(hConsole, coord);
}
int main()
{
    int i,j,k;
    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hConsole, FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_INTENSITY);
    for(k=0;k<3;k++)
    {
        gotoxy(4,6);
        for(i = 0;i<11;i ++)
        {
            printf("*");
            Sleep(N);
        }
        for(i = 0;i<12;i++)
        {
            gotoxy(9,7+i);
            printf("*");
            Sleep(N);
        }
        gotoxy(4,18);
        for(i = 0;i<11;i ++)
        {
            printf("*");
            Sleep(N);
        }
        gotoxy(36,10);
        printf("*");
        Sleep(N);
 
        gotoxy(25,10);
        printf("*");
        Sleep(N);
 
        gotoxy(47,10);
        printf("*");
        Sleep(N);
 
        gotoxy(34,8);
        printf("*");
        Sleep(N);
 
        gotoxy(38,8);
        printf("*");
        Sleep(N);
 
        gotoxy(30,7);
        printf("*");
        Sleep(N);
 
        gotoxy(42,7);
        printf("*");
        Sleep(N);
 
        gotoxy(27,8);
        printf("*");
        Sleep(N);
 
        gotoxy(45,8);
        printf("*");
        Sleep(N);
 
        gotoxy(25,11);
        printf("*");
        Sleep(N);
 
        gotoxy(47,11);
        printf("*");
        Sleep(N);
        for(i=1,j=1;i<6,j<6;i++,j++)
        {
            gotoxy(25+i,11+j);
            printf("*");
            Sleep(N);
        }
        gotoxy(32,17);
        printf("*");
        Sleep(N);
 
        gotoxy(34,18);
        printf("*");
        Sleep(N);
 
        for(i=1,j=1;i<6,j<6;i++,j++)
        {
            gotoxy(47-i,11+j);
            printf("*");
            Sleep(N);
        }
 
        gotoxy(40,17);
        printf("*");
        Sleep(N);
 
        gotoxy(38,18);
        printf("*");
        Sleep(N);
 
        gotoxy(36,19);
        printf("*");
        Sleep(N);
        for(i=0;i<11;i++)
        {
            gotoxy(59,6+i);
            printf("*");
            Sleep(N);
        }
        gotoxy(61,17);
        printf("*");
        Sleep(N);
        for(i=0;i<11;i++)
        {
            gotoxy(63+i,18);
            printf("*");
            Sleep(N);
        }
        gotoxy(74,17);
        printf("*");
        Sleep(N);
 
        gotoxy(76,16);
        printf("*");
        Sleep(N);
        for(i=0;i<10;i++)
        {
            gotoxy(76,15-i);
            printf("*");
            Sleep(N);
        }
    system("cls");
    }
    while(1)
    {
        gotoxy(4,6);
        for(i = 0;i<11;i ++)
            printf("*");
        for(i = 0;i<12;i++)
        {
            gotoxy(9,7+i);
            printf("*");
        }
        gotoxy(4,18);
        for(i = 0;i<11;i ++)
            printf("*");
        gotoxy(36,10);
        printf("*");
 
 
        gotoxy(25,10);
        printf("*");
 
 
        gotoxy(47,10);
        printf("*");
 
 
        gotoxy(34,8);
        printf("*");
 
 
        gotoxy(38,8);
        printf("*");
 
 
        gotoxy(30,7);
        printf("*");
 
        gotoxy(42,7);
        printf("*");
 
 
        gotoxy(27,8);
        printf("*");
 
 
        gotoxy(45,8);
        printf("*");
 
 
        gotoxy(25,11);
        printf("*");
 
 
        gotoxy(47,11);
        printf("*");
 
        for(i=1,j=1;i<6,j<6;i++,j++)
        {
            gotoxy(25+i,11+j);
            printf("*");
        }
        gotoxy(32,17);
        printf("*");
 
 
        gotoxy(34,18);
        printf("*");
 
        for(i=1,j=1;i<6,j<6;i++,j++)
        {
            gotoxy(47-i,11+j);
            printf("*");
        }
        gotoxy(40,17);
        printf("*");
 
 
        gotoxy(38,18);
        printf("*");
 
 
        gotoxy(36,19);
        printf("*");
 
        for(i=0;i<11;i++)
        {
            gotoxy(59,6+i);
            printf("*");
        }
        gotoxy(61,17);
        printf("*");
 
        for(i=0;i<11;i++)
        {
            gotoxy(63+i,18);
            printf("*");
        }
        gotoxy(74,17);
        printf("*");
        Sleep(100);
        gotoxy(76,16);
        printf("*");
 
        for(i=0;i<10;i++)
        {
            gotoxy(76,15-i);
            printf("*");
        }
        gotoxy(25,22);
        Sleep(1000);
        system("cls");
    }
    return 0;
}

9.灰機大戰

#include<iostream>
#include<windows.h>
#include<conio.h>
#include<time.h>
#include<string>
using namespace std;
 
/*=============== all the structures ===============*/
 
typedef struct Frame
{
	COORD position[2];
	int flag;
}Frame;
 
 
/*=============== all the functions ===============*/
 
void SetPos(COORD a)// set cursor 
{
	HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(out, a);
}
 
void SetPos(int i, int j)// set cursor
{
	COORD pos={i, j};
	SetPos(pos);
}
 
void HideCursor()
{
	CONSOLE_CURSOR_INFO cursor_info = {1, 0}; 
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
 
//把第y行,[x1, x2) 之間的坐標填充為 ch
void drawRow(int y, int x1, int x2, char ch)
{
	SetPos(x1,y);
	for(int i = 0; i <= (x2-x1); i++)
		cout<<ch;
}
 
//在a, b 縱坐標相同的前提下,把坐標 [a, b] 之間填充為 ch
void drawRow(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");
	}
}
 
//把第x列,[y1, y2] 之間的坐標填充為 ch
void drawCol(int x, int y1, int y2, char ch)
{
	int y=y1;
	while(y!=y2+1)
	{
		SetPos(x, y);
		cout<<ch;
		y++;
	}
}
 
//在a, b 橫坐標相同的前提下,把坐標 [a, b] 之間填充為 ch
void drawCol(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");
	}
}
 
//左上角坐標、右下角坐標、用row填充行、用col填充列
void drawFrame(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);
}
 
void drawFrame(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);
}
 
void drawFrame(Frame frame, char row, char col)
{
	COORD a = frame.position[0];
	COORD b = frame.position[1];
	drawFrame(a, b, row, col);
}
 
void drawPlaying()
{
	drawFrame(0, 0, 48, 24, '=', '|');//	draw map frame;
	drawFrame(49, 0, 79, 4, '-', '|');//		draw output frame
	drawFrame(49, 4, 79, 9, '-', '|');//		draw score frame
	drawFrame(49, 9, 79, 20, '-', '|');//	draw operate frame
	drawFrame(49, 20, 79, 24, '-', '|');//	draw other message frame
	SetPos(52, 6);
	cout<<"得分:";
	SetPos(52, 7);
	cout<<"稱號:";
	SetPos(52,10);
	cout<<"操作方式:";
	SetPos(52,12);
	cout<<"  a,s,d,w 控制戰機移動,";
	SetPos(52,14);
	cout<<"  p 暫停游戲,";
	SetPos(52,16);
	cout<<"  e 退出游戲,";
}
 
//在[a, b)之間產生一個隨機整數
int random(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;
}
 
bool  judgeCoordInFrame(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)
					return true;
	return false;
}
 
void printCoord(COORD a)
{
	cout	<<"( "<<a.X<<" , "<<a.Y<<" )";
}
 
void printFrameCoord(Frame a)
{
	printCoord(a.position[0]);
	cout	<<" - ";
	printCoord(a.position[1]);
}
 
int drawMenu()
{
	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<<">>";
 
	//drawFrame(45, 9, 79, 17, '=', '|');
 
	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)	return 1;
						else return 2;
					}
			}
		}
	}
}
 
/* 
DWORD WINAPI MusicFun(LPVOID lpParamte)
{
	//DWORD OBJ;
	sndPlaySound(TEXT("bgm.wav"), SND_FILENAME|SND_ASYNC);
	return 0;
}
*/
 
 
/*================== the Game Class ==================*/
 
class Game
{
public:
	COORD position[10];
	COORD bullet[10];
	Frame enemy[8];
	int score;
	int rank;
	int rankf;
	string title;
	int flag_rank;
 
	Game ();
	
	//初始化所有
	void initPlane();
	void initBullet();
	void initEnemy();
 
	//初始化其中一個
	//void initThisBullet( COORD );
	//void initThisEnemy( Frame );
 
	void planeMove(char);
	void bulletMove();
	void enemyMove();
	
	//填充所有
	void drawPlane();
	void drawPlaneToNull();
	void drawBullet();
	void drawBulletToNull();
	void drawEnemy();
	void drawEnemyToNull();
 
	//填充其中一個
	void drawThisBulletToNull( COORD );
	void drawThisEnemyToNull( Frame );
 
	void Pause();
	void Playing();
	void judgePlane();
	void judgeEnemy();
 
	void Shoot();
 
	void GameOver();
	void printScore();
};
 
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";
		else if(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;
	}
 
	else if( score == 360 && flag_rank == 1)
	{
		rank -= 5;
		flag_rank = 2;
	}
	else if( 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="初級飛行員";
		else if( x == 4)
			title="中級飛行員";
		else if( x == 3)
			title="高級飛行員";
		else if( x == 2 )
			title="王牌飛行員";
		cout<<title;
	}
	rankf = rank;
}
 
void Game::Playing()
{
	//HANDLE MFUN;
	//MFUN= CreateThread(NULL, 0, MusicFun, NULL, 0, NULL); 
 
	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();
			}			
			else if ('p' == x)
				Pause();
			else if( 'k' == x)
				Shoot();
			else if( 'e' == x)
			{
				//CloseHandle(MFUN);
				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);
	else if (x == 'y')
	{
		system("cls");
		Game game;
		int a = drawMenu();
		if(a == 2)
			game.rank = 20;
		system("cls");
		drawPlaying();
		game.Playing();
	}
	else goto as;
}
 
/*================== the main function ==================*/
int main()
{
	//游戲準備
	srand((int)time(0));	//隨機種子
	HideCursor();	//隱藏游標
	
	Game game;
	int a = drawMenu();
	if(a == 2)
		game.rank = 20;
	system("cls");
	drawPlaying();
	game.Playing();
}

10.電腦預熱器

#include <iostream>
using namespace std;
int main()
{
    for(int i=0;;i++)
    {
        cout<<i;
    }
}

祝大家游玩愉快!

請在dev c++里運行!

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/401483.html

標籤:其他

上一篇:390. 消除游戲

下一篇:C語言實作“井字棋”游戲(三子棋)人機對弈

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more