#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 << "*";
else
cout << " ";
}
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;
}
}
}