200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > C++跳高高小游戏初级版 带详细注释 简单易懂

C++跳高高小游戏初级版 带详细注释 简单易懂

时间:2023-05-28 08:25:14

相关推荐

C++跳高高小游戏初级版 带详细注释 简单易懂

#include <iostream>#include <conio.h>#include <windows.h>using namespace std;bool gameOver;//判断游戏开始结束int score,m;//声明函数void Setup();void Draw();void Input();void Logic();地图范围///const int width = 40;const int height = 10;//主角坐标///int x = 8;int y = 6;int n = 38;//地图横向坐标int up = 0;/主函数int main1(void){Setup();while (!gameOver){Draw();Input();Logic();Sleep(20);}return 0;}///初始化程序///void Setup(){gameOver = false;//m = rand() % height;//暂时没用到;score = 0;}//游戏逻辑/void Logic(){n--;if (n == 0)n = 38;if (n == 6)score = score + 1;if (x == 8 && y == n)gameOver = true;if (x == 6 && y == n)gameOver = true;if (x == 7 && y == n)gameOver = true;///主角跳跃实现代码if (up == 1&&x>4){x--;if (x == 4)up = 2;}if (up == 2){x++;if (x == 8)up = 0;}}绘制背景板void Draw(){system("cls");for (int i = 0; i < width + 2; i++)//画顶部边界cout << "*";cout << endl;for (int i = 0; i < height; i++)//画内部图像{for (int j = 0; j <= width; j++){if (j == 0)cout << "*";if (i == x && j == y)cout << "O";else if (i == 8 && j == n)cout << "#";else if (i == 7 && j == n)cout << "#";else if (i == 6 && j == n)cout << "#";else if (i == 8 && j < width)cout << "_";else if (j == width)cout << "*";elsecout << " ";}cout << endl;}for (int i = 0; i < width + 2; i++)//画底部边界cout << "*";cout << endl;//cout << up << endl;cout << "score: " << score << endl;}/输入///void Input(){if (_kbhit()){switch (_getch()){case 72://小键盘↑键,控制跳跃up = 1;break;case 'x'://x键退出游戏gameOver = true;break;}}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。