能存档了
可以玩多局
可以刷记录
#include<iostream>
#include<stdio.h>
#include<ctime>
#include<windows.h>
#include<conio.h>
#include<cstdlib>
#include<fstream>
#include<iomanip>
using namespace std;
string q = "o", db = "------", kk[31] = {
"",
" |---------------------------------------------------------------------------------------------------|",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" |---------------------------------------------------------------------------------------------------|"
};
long long x, y, dx, dy, hb = 95, fs = 0, y_x, y_y, y_hb, zgjl;
long double sd;
bool f = 1;
struct cdhs
{
void out()
{
ofstream cda("最高纪录.binggan");
cda << zgjl;
return;
}
void in()
{
ifstream cda("最高纪录.binggan");
cda >> zgjl;
return;
}
}cdhs;
void csh();//初始化
void in();//输入
void out();//输出
void qgx();//球坐标的更新
void pd();//判断结束
void gx();//更新
void color(int c)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), c);
return;
}
void gb()
{
CONSOLE_CURSOR_INFO cursor;
cursor.bVisible = FALSE;
cursor.dwSize = sizeof(cursor);
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(handle, &cursor);
return;
}
void ydgb(long long x, long long y)
{
COORD pos = { y,x };
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
return;
}
int main()
{
char s;
cdhs.in();
gb();
while (1)
{
system("cls");
color(11);
csh();
out();
for (long long i = 1; f; i++)
{
in();
if (i % 5 == 0)
{
qgx();
if (sd > 6)
sd -= 0.2;
}
pd();
Sleep(long(sd));
gx();
if (i == 1)
{
system("cls");
out();
}
}
color(11);
system("cls");
cout << "分数:" << fs << endl;
if (fs == zgjl)
{
cout << "你本次的分数和最高纪录持平!" << endl;
}
else
if (fs > zgjl)
{
cout << "恭喜您破了纪录!!!" << endl;
zgjl = fs;
}
else
{
cout << "最高纪录:" << zgjl << "\n";
cout << "加油!你差最高纪录" << zgjl - fs << "\n";
}
cout << "是否继续游戏?(y/n)";
s = _getch();
while (s != 'y' && s != 'n')s = _getch();
if (s == 'n')
{
system("cls");
cdhs.out();
return 0;
}
}
system("cls");
cdhs.out();
return 0;
}
void csh()
{
system("mode con cols=103 lines=32");
srand(time(0));
x = 4;
y = rand() % 99 + 2;
dx = 1;
dy = 1;
y_x = x, y_y = y;
sd = 70;
f = 1;
fs = 0;
return;
}
void in()
{
if (GetKeyState('A') < 0 || GetKeyState(37) < 0)
{
if (hb > 2)
{
hb -= 1;
}
}
if (GetKeyState('D') < 0 || GetKeyState(39) < 0)
{
if (hb < 99 - 4)
{
hb += 1;
}
}
return;
}
void out()
{
system("cls");
for (long long i = 1; i <= 30; i++)
{
for (long long j = 1; j <= 101; j++)
{
color(11);
cout << kk[i][j];
}
if (i != 30)
cout << "\n";
}
return;
}
void qgx()
{
if (x == 3 || (x == 28 && (hb == y || y + dy == hb + 1 || y + dy == hb + 2 || y + dy == hb + 3 || y + dy == hb + 4 || y == hb + 5)))dx *= -1;
if (y == 2 || y == 100)dy *= -1;
x += dx;
y += dy;
if (x == 28 && (hb == y || y == hb + 1 || y == hb + 2 || y == hb + 3 || y == hb + 4 || y == hb + 5))fs++;
return;
}
void pd()
{
if (x == 31)
f = 0;
return;
}
void gx()
{
ydgb(y_x - 2, y_y);
cout << "\b" << " ";
ydgb(x - 2, y);
color(10);
cout << "\b" << "o";
color(14);
ydgb(27, y_hb + 5);
for (long long i = 1; i <= 6; i++)
cout << "\b";
cout << " ";
ydgb(27, hb + 5);
for (long long i = 1; i <= 6; i++)
cout << "\b";
cout << "------";
y_x = x, y_y = y;
y_hb = hb;
ydgb(30, 1);
cout << "分数:" << fs;
return;
}