一. 项目实验名称:
用空格控制飞动的小鸟
二.实验项目功能描述:
用空格控制飞动的小鸟,并且游戏失败后可选择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("\n"); } printf("score:%d\n", 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\n0.exit\nchoose 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出现了很多的问题,但是都是自行调试,慢慢摸索,才觉得其实并不难使用,在今后的项目设计课程中还需继续努力,加油。