欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C語言實現(xiàn)飛機大戰(zhàn)

 更新時間:2022年06月08日 09:34:22   作者:Object_in_java  
這篇文章主要為大家詳細介紹了C語言實現(xiàn)飛機大戰(zhàn),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C語言實現(xiàn)飛機大戰(zhàn)的具體代碼,供大家參考,具體內容如下

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<Windows.h>

int score = 0;
int plane_col, plane_row;//·é?ú????
int bullet_col,bullet_row;//×óμˉμ?????
int area_height, area_width;//ó??·??óò ?0-n-1
int enemy_col, enemy_row;
int enemy_vh, enemy_vv;
int a[100][100] = { 0 };

void gotoxy(int x, int y) {//?¢D??
?? ?HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
?? ?COORD pos;
?? ?pos.X = x;
?? ?pos.Y = y;
?? ?SetConsoleCursorPosition(handle, pos);
}
void HideCursor() {
?? ?CONSOLE_CURSOR_INFO cursor_info = { 1,0 };
?? ?SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}

void startup()//3?ê??ˉ?
{
?? ?area_height = 20;
?? ?area_width = 30;

?? ?plane_col = 14;
?? ?plane_row = 10;
?? ?
?? ?bullet_col = 0;
?? ?bullet_row = -1;

?? ?enemy_col = rand() % area_width;
?? ?enemy_row = 0;
?? ?enemy_vh = 0;
?? ?enemy_vv = 1;
}

//int[][] planeArray() {
//?? ?
//?? ?a[plane_col][plane_row] = 1;
//?? ?for (int i = plane_col - 2; i < plane_col + 2; i++)
//?? ??? ?a[i][plane_row + 1] = 1;
//?? ?a[plane_col - 1][plane_row + 2] = 1; a[plane_col + 1][plane_row + 2] = 1;
//
//?? ?return a;
//}

void show()//?e??×?·?é¨?è2¢′òó??
{
?? ?gotoxy(0, 0);
?? ?int i, j;
?? ?//??ê?
?? ?//system("cls");
?? ?for (i = 0; i < area_height; i++)//DD񂅣
?? ?{
?? ??? ?for (j = 0; j < area_width; j++)//áD±éàú
?? ??? ?{
?? ??? ??? ?if (i == plane_row && j == plane_col)
?? ??? ??? ?{
?? ??? ??? ??? ?printf("*");
?? ??? ??? ?}
?? ??? ??? ?else if (i == bullet_row && j == bullet_col)
?? ??? ??? ??? ?printf("|");
?? ??? ??? ?else if (i == enemy_row && j == enemy_col)
?? ??? ??? ??? ?printf("@");
?? ??? ??? ?else printf(" ");
?? ??? ?}
?? ??? ?printf("\n");
?? ?}
?? ?printf("score:%d\n",score);
}
void updateWithInput()//???¥£?????·é?úò??ˉ£?é??÷
{?
?? ?char input;
?? ?//μè′yó??§μ?ê?è?£????¥
?? ?if (kbhit()) {
?? ??? ?input = getch();
?? ??? ?switch (input)
?? ??? ?{
?? ??? ?case 'w':
?? ??? ??? ?if(plane_row != 0)
?? ??? ??? ?plane_row--; break;
?? ??? ?case 'a':
?? ??? ??? ?if(plane_col != 0)
?? ??? ??? ?plane_col--; break;
?? ??? ?case 'd':
?? ??? ??? ?if(plane_col != area_width)
?? ??? ??? ?plane_col++; break;
?? ??? ?case 's':
?? ??? ??? ?if(plane_row != area_height)
?? ??? ??? ?plane_row++; break;
?? ??? ?case ' ':
?? ??? ??? ?if (bullet_row < 0)//?á??à???óD×óμˉ
?? ??? ??? ?{
?? ??? ??? ??? ?bullet_row = plane_row - 1;
?? ??? ??? ??? ?bullet_col = plane_col;
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?default:
?? ??? ??? ?break;
?? ??? ?}
?? ?}
}

int IsCrash() {
?? ?//?D???ò·?·é?úê?·?×1?ù?
?? ?if (enemy_col == plane_col && enemy_row == plane_row) {
?? ??? ?return 1;
?? ?}
?? ?return 0;
}

void updateWithourInput()//×óμˉò??ˉó?μDè?ò??ˉ?
{
?? ?//?üD?
?? ?bullet_row--;
?? ?static int count = 0;
?? ?count ++;
?? ?if (count == 40) {
?? ??? ?enemy_row += enemy_vv;
?? ??? ?enemy_col += enemy_vh;
?? ??? ?count = 0;
?? ?}
?? ?
}

void crack() {//?÷?ùμDè??

?? ?if(enemy_row > area_height){
?? ??? ?bullet_row = -1;
?? ??? ?enemy_row = -1;
?? ??? ?enemy_col = rand() % area_height;
?? ?}
?? ?else if (bullet_col == enemy_col && bullet_row == enemy_row) {
?? ??? ?score += 10;
?? ??? ?bullet_row = -1;
?? ??? ?enemy_row = -1;
?? ??? ?enemy_col = rand() % area_height;
?? ?}

}

int IsFinish() {//ó??·ê?·??áê??
?? ?if (score == 100) {
?? ??? ?system("cls");
?? ??? ?printf("congretulations!!!");
?? ??? ?score = 0;
?? ??? ?_sleep(500);//?è?Yí£?ú??êμ·?o?è?D??ˉ?
?? ??? ?system("pause");
?? ??? ?return 1;
?? ?}
?? ?else if (IsCrash() == 1) {
?? ??? ?system("cls");
?? ??? ?printf("you have lost!!!");
?? ??? ?score = 0;
?? ??? ?_sleep(500);
?? ??? ?system("pause");
?? ??? ?return 1;
?? ?} ? ? ? ? ?
?? ?
?? ?return 0;
}

int main()
{
?? ?HideCursor();
?? ?startup();
?? ?while (1)
?? ?{
?? ??? ?show();
?? ??? ?updateWithInput();
?? ??? ?updateWithourInput();
?? ??? ?crack();
?? ??? ?if(IsFinish()==1){
?? ??? ??? ?startup();
?? ??? ??? ?continue;
?? ??? ?}
?? ?}
?? ?return 0;
}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • C++中的函數(shù)返回值與拷貝用法

    C++中的函數(shù)返回值與拷貝用法

    這篇文章主要介紹了C++中的函數(shù)返回值與拷貝用法,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • C++進階練習刪除鏈表的倒數(shù)第N個結點詳解

    C++進階練習刪除鏈表的倒數(shù)第N個結點詳解

    這篇文章主要給大家介紹了關于如何利用C++刪除鏈表的倒數(shù)第N個結點,文中通過實例代碼介紹的非常詳細,對大家學習或者使用C++具有一定的參考學習價值,需要的朋友可以參考下
    2022-05-05
  • C語言實現(xiàn)推箱子小游戲

    C語言實現(xiàn)推箱子小游戲

    這篇文章主要為大家詳細介紹了C語言實現(xiàn)推箱子小游戲,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • 優(yōu)先隊列(priority_queue)的C語言實現(xiàn)代碼

    優(yōu)先隊列(priority_queue)的C語言實現(xiàn)代碼

    本文簡要介紹一種基于數(shù)組二叉堆實現(xiàn)的優(yōu)先隊列,定義的數(shù)據(jù)結構和實現(xiàn)的函數(shù)接口說明如下
    2013-10-10
  • C++實現(xiàn)職工工資管理系統(tǒng)課程設計

    C++實現(xiàn)職工工資管理系統(tǒng)課程設計

    這篇文章主要為大家詳細介紹了C++實現(xiàn)職工工資管理系統(tǒng)課程設計,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • 詳解Qt中QStackedWidget控件的使用

    詳解Qt中QStackedWidget控件的使用

    這篇文章主要為大家詳細介紹了Qt中QStackedWidget控件的具體使用,文中的示例代碼講解詳細,具有一定的借鑒價值,需要的可以參考一下
    2023-02-02
  • c/c++內存分配大小實例講解

    c/c++內存分配大小實例講解

    在本篇文章里小編給大家整理了一篇關于c/c++內存分配大小實例講解內容,有需要的朋友們可以跟著學習參考下。
    2021-11-11
  • C語言自定義類型詳解(結構體、枚舉、聯(lián)合體和位段)

    C語言自定義類型詳解(結構體、枚舉、聯(lián)合體和位段)

    這篇文章主要給大家介紹了關于C語言中結構體、枚舉、聯(lián)合體和位段自定義類型的相關資料,分別介紹了結構體、枚舉、聯(lián)合體和位段等四種自定義類型,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下
    2021-08-08
  • C語言算法練習之佩奇存錢方案

    C語言算法練習之佩奇存錢方案

    這篇文章主要該大家分享C語言算法佩奇存錢的練習,文章主要通過描述佩奇存錢的問題然后確定程序框架將結果運算出來,下面來看詳細內容吧,需要的朋友可以參考一下
    2022-04-04
  • C++中的幾種排序算法

    C++中的幾種排序算法

    這篇文章主要介紹了C++中的幾種排序算法,需要的朋友可以參考下
    2014-02-02

最新評論