zoukankan      html  css  js  c++  java
  • 2019年春第一次程序设计实验报告

    一. 项目实验名称:

    用空格控制飞动的小鸟

    二.实验项目功能描述:

    用空格控制飞动的小鸟,并且游戏失败后可选择1或者0已决定是否重新游戏

    三.项目模块结构介绍:

    模块:本项目有定义坐标函数部分,定义各相关变量函数部分,相关运行小鸟移动操作的函数部分,相关墙体变换,小鸟飞行的函数部分,以及最后游戏失败后,选则是否继续玩的主函数部分!
    总体结构:

    void gotoxy(int x, int y) 
    { 
    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); 
    } 
    
    
    int high; 
    int width; 
    
    int bird_x; 
    int bird_y; 
    
    int bar1_y; 
    int bar1_xTop; 
    int bar1_xDown; 
    int score; 
    
    void startup() 
    { 
    
    high = 15; 
    width = 25; 
    
    bird_x = high / 2; 
    bird_y = width / 4; 
    
    bar1_y = width - 1; 
    bar1_xTop = high / 4; 
    bar1_xDown = high / 2; 
    
    score = 0; 
    } 
    
    void show() 
    { 
    gotoxy(0, 0); 
    int i, j; 
    for (i = 0; i < high; i++) 
    { 
    for (j = 0; j < width; j++) 
    { 
    if ((i == bird_x) && (j == bird_y)) 
    { 
    printf("@"); 
    } 
    else if ((j == bar1_y) && ((i < bar1_xTop) || (i > bar1_xDown))) 
    { 
    printf("*"); 
    } 
    else 
    { 
    printf(" "); 
    } 
    } 
    printf("
    "); 
    } 
    printf("score:%d
    ", score); 
    } 
    
    int updateWithoutInput() 
    { 
    bird_x++; 
    bar1_y--; 
    if (bird_y == bar1_y) 
    { 
    if ((bird_x >= bar1_xTop) && (bird_x <= bar1_xDown)) 
    { 
    score++; 
    } 
    else 
    { 
    printf("Game failed!!!"); 
    return -1; 
    } 
    } 
    else 
    { 
    if (bird_x > high) 
    { 
    printf("gamefailed!!!"); 
    return -1; 
    } 
    } 
    if (bar1_y <= 0) 
    { 
    bar1_y = width - 1; 
    int upside = rand() % (int)(high * 0.6) + 1; 
    bar1_xTop = upside; 
    int opening = rand() % (int)(high * 0.2) + 2; 
    while ((bar1_xDown = bar1_xTop + opening) > high - 2) 
    { 
    opening = rand() % (int)(high * 0.2) + 2; 
    } 
    } 
    Sleep(150); 
    return 0; 
    } 
    
    void updateWithInput() 
    { 
    char input; 
    if (_kbhit()) 
    { 
    input = _getch(); 
    if (input == ' ' && bird_x > 0) 
    { 
    bird_x = bird_x - 2; 
    } 
    } 
    } 
    int main() 
    { 
    srand((unsigned)time(NULL)); 
    HideCursor(); 
    again: 
    startup(); 
    while (1) 
    { 
    show(); 
    int ret = updateWithoutInput(); 
    if (ret == -1) 
    { 
    system("CLS"); 
    printf("1.restard
    0.exit
    choose please:"); 
    int input = 0; 
    scanf("%d", &input); 
    if (input) 
    { 
    goto again; 
    } 
    else 
    return 0; 
    } 
    updateWithInput(); 
    } 
    return 0; 
    }
    

    四.实现页面展示

    五.代码托管链接

    https://gitee.com/WangYaqiong/wang_ya_qiong/blob/master/mayunyouxi.cpp.cpp

    六.实验总结

    本次第一次程序设计是按照教本上的程序练习模板写的,出现的问题较少,以后要继续加油,争取能设计出更有新意的程序。同时本次使用Git出现了很多的问题,但是都是自行调试,慢慢摸索,才觉得其实并不难使用,在今后的项目设计课程中还需继续努力,加油。

  • 相关阅读:
    聊聊Unity2018的LWRP和混合光照
    不能直接获取?聊聊如何在Shader Graph中获取深度图
    还原堆栈信息,分析地形系统使用ASTC格式的纹理导致Crash的问题
    巧妙设置Texture Type,将ShadowMask内存占用变成之前的1/4
    开发自定义ScriptableRenderPipeline,将DrawCall降低180倍
    Signed Distance Field Shadow in Unity
    Daily Pathtracer!安利下不错的Pathtracer学习资料
    聊聊LightProbe原理实现以及对LightProbe数据的修改
    Scala学习笔记(六):本地函数、头等函数、占位符和部分应用函数
    Scala学习笔记(五):内建控制循环
  • 原文地址:https://www.cnblogs.com/linkedashewaixueyuan/p/10991296.html
Copyright © 2011-2022 走看看