找到了Windows10以下版本错位的原因
并修复了这个BUG
更新了一张地图
#include<iostream>
#include<string>
#include<cstdlib>
#include<ctime>
#include<windows.h>
#include<conio.h>
using namespace std;
const long long dts = 8;
long long wj1x, wj1y, wj2x, wj2y, cs = 0, dtbh;
bool f = 1, t1 = 1, t2 = 1, sy, cxjs = 1;
long long csx[dts + 1] = {
0,
14,
1,
1,
1,
1,
18,
18,
18
};
long long csy[dts + 1] = {
0,
1,
37,
1,
1,
1,
1,
1,
1
};
string dt[dts + 1][21] = {
{
" ",//
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
},
{
" ",//
" ",
" ",
" == === == ",
" === === < ",
" == < ",
" < ",
" == ==^^^^^^^^^^^== < ",
" ====== < ",
" == === ======= < ",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^< ",
" == < ",
" < ",
" == < ",
" ^ $",
" ========> <=== === === == = === = == === ==== ^ ==== === == = == = =====",
" ",
" ",
" ",
" ",
" ",
},
{
" ",//
" > < = = ",
" > < = = ",
" = > < = = = ",
" ^^^^^ = > === < = == = ",
" <= > = =^ = === = ",
" < = ^^^^^^^^^^^^^^^ < =$ = ",
" < = < = === ",
" ^^^< = == ^^^ =^^^^^^^^== = ",
" < = = ^^^ ============= = ",
" < = === == < = ",
" < ======^^^^^^^^^^^^^ ^^^^ ^^ ================ ",
" < ",
" ^^^^ < == == ",
" < = ",
" < = == ",
" ==== ^^^ = ",
" = == ",
" ========== ======= ",
" ",
" "
},
{
" ",//
" =",
" =",
" =",
" ====^=====^=====^=====^=====^=====^=====^=====^=====^=====^=====^=====^== =",
" =",
" ========== <> =",
" = <> <> =",
" ==============================^^^^^^^^^^^^=============================^=",
" < =",
" < == == =",
" < = = =",
" ^^^ < = = =",
" < = = =",
" < = = =",
" ^^^^< = = =",
" < = = =",
" < = = =",
" = = =",
" ============== ===== $=",
" ="
},
{
" ",//
" < =",
" < =",
" < =",
" < =",
" < ============================= =",
" < = = = = ===================== =",
" < == == = $= == = = == =",
" < = = = = = = = =",
" < = == ^^^^== = == = ===",
" < = = = ^^^^^= = = === === =",
" < == = =============== = = =",
" < = =^^ = = == =",
" < = =========================== = === =",
" < = = = =",
" < ^ =============================== = =",
" < => === =",
" ==> ===",
" ==================================================================== =",
" =",
" ="
},
{
" ",//
" < ",
" < ",
" < ",
" < ",
" < ",
" < -- ",
" < == ",
" < ",
" < = -- ",
" < = ",
" < = ",
" < = ",
" < = ",
" < = ",
" < = -- ",
" < = $",
" = ",
" =====---------=^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
" ",
" "
},
{
" ",//
" = < ",
" = < $",
" = < ",
" - = < ",
" = < ",
" < ",
" = ",
" ======-=====-===---=----=-=----========-=======",
" ",
" ",
" - ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ---------------------------------------------------------------------------",
" "
},
{
" ",//
" ",
" ",
" == === ",
" = = ",
" = = ",
" = $ = ",
" = = ",
" = = - ",
" = ",
" -== = ",
" = ",
" == = ",
" === =- ",
" == = ",
" ==== = ",
" === = ",
" == = ",
" === == ",
" = === ======-",
" ",
},
{
" =",//
" =",
" =",
" =",
" =",
" =",
" =",
" =",
" =",
" =",
" =",
" =",
" =",
" =",
" ===================",
" =",
" ==== =",
" = =",
" < > = $=",
" ==== ===^^^^^==================- ======= =",
" ="
}
};
//基础函数
void csh()
{
f = 1, t1 = 1, t2 = 1;
cs = 0;
return;
}
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 gs(long long h, long long l, string z)
{
for (long long i = 1; i <= h; i++)
{
cout << "\n";
}
for (long long i = 1; i <= l; i++)
{
cout << " ";
}
cout << z;
return;
}
void out();
void in();
void lx();
void bd();
//页面函数
void zym();
void yxym();
void smym();
void szsmym();
void wpsmym();
void yxjqym();
//模式函数
void _2run();
int main()
{
srand(time(0));
color(240);
system("mode con cols=76 lines=20");
gb();
while (cxjs)
{
zym();
system("cls");
}
return 0;
}
void zym()
{
char s;
system("cls");
gs(5, 34, "跑酷");
gs(2, 0, "");
gs(1, 30, "0.退出");
gs(1, 30, "1.开始游戏");
gs(1, 30, "2.游戏说明");
s = _getch();
while (s != '0' && s != '1' && s != '2')s = _getch();
switch (s)
{
case '0':
cxjs = 0;
return;
break;
case '1':
yxym();
break;
case '2':
smym();
break;
}
return;
}
void yxym()
{
char s;
system("cls");
gs(0, 0, "0.退出");
gs(1, 0, "1.单人模式(暂未开放)");
gs(1, 0, "2.双人模式");
s = _getch();
while (s != '0' &&/*s!='1'&&*/s != '2')s = _getch();
switch (s)
{
case '0':
return;
case '1':
break;
case '2':
_2run();
break;
}
return;
}
void out()
{
for (long long i = 1; i <= 19; i++)
{
for (long long j = 1; j <= 75; j++)
{
if (i == wj1x && j == wj1y)
{
color(9);
cout << "*";
}
else
if (i == wj2x && j == wj2y)
{
color(12);
cout << "+";
}
else
if (dt[dtbh][i][j] == '$')
{
color(10);
cout << "$";
}
else
{
color(240);
cout << dt[dtbh][i][j];
}
}
cout << endl;
}
return;
}
void in()
{
if (GetKeyState('A') < 0 && (dt[dtbh][wj1x][wj1y - 1] == ' ' || dt[dtbh][wj1x][wj1y - 1] == '$') && wj1y - 1 > 0)
{
wj1y--;
}
if (GetKeyState('D') < 0 && (dt[dtbh][wj1x][wj1y + 1] == ' ' || dt[dtbh][wj1x][wj1y + 1] == '$') && wj1y - 1 <= 100)
{
wj1y++;
}
if (GetKeyState('W') < 0 && (dt[dtbh][wj1x - 1][wj1y] == ' ' || dt[dtbh][wj1x - 1][wj1y] == '$') && wj1x > 1 && t1)
{
wj1x--;
for (long long i = 1; i <= 2; i++)
if (dt[dtbh][wj1x - 1][wj1y] == ' ' && wj1x > 1)wj1x--;
t1 = 0;
}
if (GetKeyState(37) < 0 && (dt[dtbh][wj2x][wj2y - 1] == ' ' || dt[dtbh][wj2x][wj2y - 1] == '$') && wj2y - 1 > 0)
{
wj2y--;
}
if (GetKeyState(39) < 0 && (dt[dtbh][wj2x][wj2y + 1] == ' ' || dt[dtbh][wj2x][wj2y + 1] == '$') && wj1y - 1 <= 100)
{
wj2y++;
}
if (GetKeyState(38) < 0 && (dt[dtbh][wj2x - 1][wj2y] == ' ' || dt[dtbh][wj2x - 1][wj2y] == '$') && wj2x > 1 && t2)
{
wj2x--;
for (long long i = 1; i <= 2; i++)
if (dt[dtbh][wj2x - 1][wj2y] == ' ' && wj2x > 1)wj2x--;
t2 = 0;
}
return;
}
void lx()
{
if (dt[dtbh][wj1x + 1][wj1y] == ' ' || dt[dtbh][wj1x + 1][wj1y] == '$')wj1x++;
else t1 = 1;
if (dt[dtbh][wj2x + 1][wj2y] == ' ' || dt[dtbh][wj2x + 1][wj2y] == '$')wj2x++;
else t2 = 1;
return;
}
void bd()
{
if (dt[dtbh][wj1x][wj1y] == '$')
{
f = 0;
sy = 0;
}
if (dt[dtbh][wj2x][wj2y] == '$')
{
f = 0;
sy = 1;
}
if (wj1x == 20)
{
wj1x = csx[dtbh]; wj1y = csy[dtbh];
}
if (wj2x == 20)
{
wj2x = csx[dtbh]; wj2y = csy[dtbh];
}
if (dt[dtbh][wj1x + 1][wj1y] == '^')
{
wj1x = csx[dtbh]; wj1y = csy[dtbh];
}
if (dt[dtbh][wj2x + 1][wj2y] == '^')
{
wj2x = csx[dtbh]; wj2y = csy[dtbh];
}
if (dt[dtbh][wj1x][wj1y + 1] == '<')
{
wj1x = csx[dtbh]; wj1y = csy[dtbh];
}
if (dt[dtbh][wj2x][wj2y + 1] == '<')
{
wj2x = csx[dtbh]; wj2y = csy[dtbh];
}
if (dt[dtbh][wj1x][wj1y - 1] == '>')
{
wj1x = csx[dtbh]; wj1y = csy[dtbh];
}
if (dt[dtbh][wj2x][wj2y - 1] == '>')
{
wj2x = csx[dtbh]; wj2y = csy[dtbh];
}
if (dt[dtbh][wj1x + 1][wj1y] == '-')
{
for (long long i = 1; i <= 10 && wj1x > 1; i++)
{
if (dt[dtbh][wj1x - 1][wj1y] == ' ' || dt[dtbh][wj1x - 1][wj1y] == '$')
{
wj1x--;
}
else
break;
}
}
if (dt[dtbh][wj2x + 1][wj2y] == '-')
{
for (long long i = 1; i <= 10 && wj2x > 1; i++)
{
if (dt[dtbh][wj2x - 1][wj2y] == ' ' || dt[dtbh][wj2x - 1][wj2y] == '$')
{
wj2x--;
}
else
break;
}
}
return;
}
void _2run()
{
char s;
while (1)
{
csh();
dtbh = rand() % dts + 1;
wj1x = wj2x = csx[dtbh];
wj1y = wj2y = csy[dtbh];
while (f)
{
system("cls");
out();
in();
bd();
if (cs == 1)
lx();
Sleep(10);
if (cs == 1)cs = -1;
cs++;
}
system("cls");
if (!sy)
{
color(9);
system("cls");
cout << "*赢了!";
cout << "\n按Enter结束";
char t = _getch();
while (t != 13)t = _getch();
color(153);
}
else
{
color(12);
system("cls");
cout << "+赢了!";
cout << "\n按Enter结束";
char t = _getch();
while (t != 13)t = _getch();
color(204);
}
color(240);
system("cls");
cout << "是否返回主界面?(y/n)";
s = _getch();
while (s != 'y' && s != 'n')s = _getch();
if (s == 'y')
{
f = 0;
system("cls");
return;
}
system("cls");
}
return;
}
void smym()
{
char s;
system("cls");
cout << "游戏说明:\n";
cout << "0.退出\n";
cout << "1.操作说明\n";
cout << "2.物品说明\n";
cout << "3.游戏技巧\n";
s = _getch();
while (s != '0' && s != '1' && s != '2' && s != '3')s = _getch();
switch (s)
{
case '0':
system("cls");
return;
case '1':
szsmym();
break;
case '2':
wpsmym();
break;
case '3':
yxjqym();
break;
}
return;
}
void szsmym()
{
char s;
system("cls");
gs(1, 0, "操作说明:");
gs(1, 4, "玩家1:");
gs(1, 8, " W ");
gs(1, 8, "A D");
gs(1, 8, "移动");
gs(1, 0, "");
gs(1, 4, "玩家2:");
gs(1, 8, " ^ ");
gs(1, 8, "< >");
gs(1, 8, "移动");
cout << "\n按空格继续";
s = _getch();
while (s != ' ')s = _getch();
system("cls");
return;
}
void wpsmym()
{
char s;
system("cls");
cout << "* 玩家1\n";
cout << "+ 玩家2\n";
cout << "= 砖块\n";
cout << "$ 终点\n";
cout << "- 蹦床\n";
cout << "^ 上刺\n";
cout << "< 左刺\n";
cout << "> 右刺\n";
cout << "按空格继续";
s = _getch();
while (s != ' ')s = _getch();
system("cls");
return;
}
void yxjqym()
{
system("cls");
char s;
system("cls");
gs(1, 4, "游戏技巧:");
gs(1, 8, "1.延迟起跳:");
gs(1, 12, "如果上方有物品,跳起来会挡住");
gs(1, 12, "可以先走过去,等上方无遮挡物时按跳键");
gs(1, 12, "这样就可以跳的远了");
cout << "\n按空格继续";
s = _getch();
while (s != ' ')s = _getch();
system("cls");
return;
}