十三周总结

2019春第一次课程设计实验报告
一、 飞机大战
二、 用c语言写一个简单的打飞机游戏
三、

# include<stdio.h>
# include<stdlib.h>
# include<conio.h>            引入头文件
# include<windows.h>

int positionx, positiony;
int bulletx, bullety;              这一部分为定义全局变量
int enemyx, enemyy;
int high, width;
int score;

void startup(){
    high = 20;
    width = 30;
    positionx = high/2;
    positiony = width/2;
    bulletx = -2;               这一部分为给变量赋初值
    bullety = positiony;
    enemyx = 0;
    enemyy = positiony;
    score = 0;
} 

void show(){
    system("cls");
    int i, j;
    for(i = 0;i < high; i++ ){
        for(j = 0;j < width; j++){
            if((i == positionx) && (j == positiony)){
                printf("*");
            }                                           这一部分为输出飞机敌机和子弹,都没有则输出空格
            
            else if((i == enemyx) && (j == enemyy)){
                printf("@");
            }
            else if((i == bulletx) && (j == bullety)){
                printf("|");
            }
            else{
                printf(" ");
            }
        }
        printf("\n");
    }
    printf("得分 : %d\n",score);
}

void update(){
    if(bulletx > -1){
        bulletx--;
    }
    if((bulletx == enemyx) && (bullety == enemyy)){
        score++;
        enemyx = -1;
        enemyy = rand() % width;
        bulletx = -2;              这一部分为用户输入没用的更新,即打中飞机,分数统计,飞机速度等
    }
    if(enemyx > high){
        enemyx = -1;
        enemyy = rand() % width;
    }
    static int speed = 0;
    if(speed < 10){
        speed++;
    }
    if(speed == 10){
        enemyx++;
        speed = 0;
    }
}

void updateinput(){
    char input;
    if(kbhit()){
        input = getch();
        if(input == 'a'){
            positiony--;
        }                           这一部分为用户输入的更新,即根据用户的输入,判断飞机怎么走,和发出子弹
        if(input == 'd'){
            positiony++;
        }
        if(input == 'w'){
            positionx--;
        }
        if(input == 's'){
            positionx++;
        }
        if(input == ' '){
            bulletx = positionx - 1;
            bullety = positiony; 
        }
    }
}

int main(){
    startup();
    while(1){
        show();
        update();
        updateinput();      这一部分为主函数,起到函数调用的作用
    }
    return 0; 
}

四、实现界面
1580249-20190530102045231-879190465.png

五、代码托管链接
git@gitee.com:jinnitaimei/jifangzuiliangdezai2.git
六实验总结
这个实验让我知道了清屏数,知道了一些新的东西,当然最大的还是git使用的更熟练了,这个git初次使用出现了一些错误,我自己也出现了一些错误,比如提交一次后,第二次我又建了一个仓库。。。。。。,我的组员也出现了一些错误,提交到组织仓库说没有权限,然后我又搞了好久,原来是要他们的密钥添加到我的码云上,不然没有权限,然后就没有什么问题了。

转载于:https://www.cnblogs.com/xiao--liang/p/10948074.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值