• 十三周总结


    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("
    ");
    	}
    	printf("得分 : %d
    ",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; 
    }
    

    四、实现界面

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

  • 相关阅读:
    PHP 多参数方法的重构
    PHP cURL库函数抓取页面内容
    PHP下载远程文件到指定目录
    PHP生成特定长度的纯字母字符串
    PHP提取奇数或偶数下标元素
    Java中的clone()----深复制,浅复制
    LeetCode题解 343.Integer Break
    MySQL学习笔记(四):存储引擎的选择
    存储过程优缺点
    MySQL学习笔记(三):常用函数
  • 原文地址:https://www.cnblogs.com/xiao--liang/p/10948074.html
Copyright © 2020-2023  润新知