【C++小游戏】推箱子代码

注:本程序完全原创,如果有BUG,欢迎私信投诉。
Upd 2023/1/2 : 把代码扔到 LOJ 里格式化了一下,希望代码看起来没原来那么丑陋。
Upd 2023/3/3 : 修复了一个没有测试出来的 bug(箱子推进去后无法立即显示)

一、功能:

  • 共40关,1~6关较为简单,后面的比较难;
  • 可以新建文件作为存档;
  • 关卡内部可以用Z键撤销;
  • 可以跳关。

二、使用:

1.将以下代码编译运行(确保编译器支持 windows.hconio.h 即可,可一键复制):
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
#define red \SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED) // 红色
#define nop \SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY) // 原色
#define white \SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE) // 白色
using namespace std;
void ycgb() {// 光标隐藏部分CONSOLE_CURSOR_INFO cciCursor;HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);if (GetConsoleCursorInfo(hStdOut, &cciCursor)) {cciCursor.bVisible = FALSE;SetConsoleCursorInfo(hStdOut, &cciCursor);}
}
string mapp[50][50] = {{""},{"  ###   ","  #P#   ","  # ####","###o oP#","#P os###","####o#  ","   #P#  ","   ###  ",},{"#####    ","#s  #    ","# oo# ###","# o # #P#","### ###P#"," ##    P#"," #   #  #"," #   ####"," #####   "},{" #######  "," #     ###","##o###   #","# so   o #","# PP# o ##","##PP#   # "," ######## "},{" #### ","##  # ","#so # ","##o ##","## o #","#Po  #","#PP@P#","######"},{" #####  "," #  ### "," #so  # ","### # ##","#P# #  #","#Po  # #","#P   o #","########"},{"   #######   ","####     #   ","#   P### #   ","# # #    ##  ","# # o o#P #  ","# #  @  # #  ","# P#o o # #  ","##    # # ###"," # ###P    s#"," #     ##   #"," ############",},{"   #######","  ##  # s#","  #   #  #","  #o o o #","  # o##  #","### o # ##","#PPPPP  # ","######### "},{"   ###### "," ###    # ","##P o## ##","#PPo o  s#","#PP o o ##","######  # ","     #### "},{" ######### "," #  ##   # "," #   o   # "," #o ### o# "," # #PPP# # ","## #PPP# ##","# o  o  o #","#     # s #","###########"},{"  ######","  #    #","###ooo #","#s oPP #","# oPPP##","####  # ","   #### "},{" ####  #####","##  #  #   #","# o ####o  #","#  oPPPP o #","##    # s ##"," ########## "},{"  ##### ","###  s# ","#  oP ##","#  PoP #","### @o #","  #   ##","  ##### ",},{"  ####  ","  #PP#  "," ## P## "," #  oP# ","## o  ##","#  #oo #","#  s   #","########"},{"########","#  #   #","# oPPo #","#soP@ ##","# oPPo #","#  #   #","########"},{" #######","##    ##","# o oo #","#PPPPPP#","# oo o #","### s###","  ####  "},{"  ######  ","  #    ###","  # o    #","### o ## #","#PPP o   #","#PPPo#o ##","#### # o #","   #  s  #","   #######"},{"######   ","#    #   ","# ooo##  ","#  #PP###","##  PPo #"," # s    #"," ########"},{"  ########","  #   #P #"," ##  oPPP#"," #  o #@P#","## ##o# ##","#   o  o #","#   #    #","#######  #","      ####"},{" #######  "," #PPPP #  ","###PPPo###","#  o#o o #","# oo  #o #","#    #   #","#### s ###","   #####  "},{"#######","#PPoPP#","#PP#PP#","# ooo #","#  o  #","# ooo #","#  #s #","#######"},{"   ######  ","   # PPP#  ","####PPPP#  ","#  ###o ###","# o o  oo #","#s o o    #","#   ###   #","##### #####"},{"######## ","#      # ","# #oo  # ","# PPP# # ","##PPPo ##"," # ## o #"," #o  o  #"," #  #  s#"," ########"},{"  #####   ","###   ####","#   o o  #","# o   o s#","###oo#####","  #  PP#  ","  #PPPP#  ","  ######  "},{"######   #####","#    ### #  P#","#  o o # #PPP#","# #  o ###  P#","#  ooo   o sP#","###  o  o#  P#","  #  o#o #PPP#","  ##     #  P#","   ###########"},{"     ######"," #####P   #"," #  #PP## #"," #  oPP   #"," #  # P# ##","### ##o#  #","# o    oo #","# #o#  #  #","#s  #######","#####      "},{" #########   "," #   ##  ####"," # o        #"," ##o### ##  #"," #  ## @ # ##"," # oPPPPPP # ","## ### P # # ","#     o###o# ","#   #    os# ","#####o# #### ","    #   #    ","    #####    "},{"      #########","      #       #","      # # # # #","      #  o o# #","#######   o   #","#PP#  ## o o# #","#PP   ## o o  #","#PP#  ## ######","#PP# # o o #   ","#PP     o  #   ","#  ### s ###   ","#### #####     "},{"    ####        ","#####  #        ","#  o o # #######","#   o  # #@P@P@#","## o o ###P@P@P#"," #o o  #  @P@P@#"," #so o    P@P@##"," #o o  #  @P@P@#","## o o ###P@P@P#","#   o  # #@P@P@#","#  o o # #######","#####  #        ","    ####        "},{"######## ","#PPPPPP# ","#  o # ##","# o # o #","##o o o #"," #  s   #"," ########"},{"  ##########","###   P    #","#   ##o##  #","# soP P Po##","## o##o## # "," #    P   # "," ########## "},{"   ######","####P  s#","#  ooo  #","#P##P##P#","#   o   #","#  oP# ##","####   # ","   ##### "},{" ###### "," #P PP# "," #P oP# ","###  o##","# o  o #","# #o## #","#   s  #","########"},{"    ######    ","  ###    ###  ","  #   #o   ###","  #   o   oo #","  # oo #o    #","  ##   o   o #","###### #o#####","#PPs #o  #    ","#P#PP  o##    ","#PPPPo# #     ","#PPPP   #     ","#########     "},{"###############","#      #      #","# o #o # o##o #","# #  o #      #","#   ##o#o##oo #","# # # PPP #   #","# o  P # Po # #","# o#soPPP  #  #","#    P # P  o #","# ##Po###oP # #","# # oPPPPP ## #","#             #","###############"},{"######### ","#   ##  # ","# # o o # ","#  @P#  # ","## #PsP## ","##o###@###","#        #","#   ## # #","######   #","     #####"},{"########       ","#      #       ","# oo   ###     ","#  o ooo ##### ","## ## PPP    ##"," # #s#PPP###o #"," # # oPPP     #","## # oPPPo # ##","#  ##### ### # ","#      o   o # ","###########  # ","          #### "},{"   ##### ","   # s # ","   #ooo# ","####   # ","#   P#o##","# oPoP P#","#  #P#P##","######## "},{"############","#PPP #     #","#PP  # ##  #","#PP     #  #","#PP  # o## #","#PPP #o o  #","######  oo #"," ##  o oo  #"," #s ooo  # #"," ## o ##   #","  #        #","  ##########"},{"#########  ","#       #  ","#  o o o#  ","## #o## #  "," # PP PP## "," ##PP PP # ","  # ##o# ##","  #o o o  #","  #      s#","  #########"},{"     #####"," #####   #"," # PP o# #"," # #P@   #","## @P#o ##","# o  o  # ","#   ## s# ","######### "}
};
int hang[50] = {0, 8, 9, 7, 8, 8, 11, 8, 7, 9, 7,6, 7, 8, 7, 7, 9, 7, 9, 8, 8,8, 8, 8, 9, 10, 12, 12, 13, 7, 7,8, 8, 12, 13, 10, 12, 8, 12, 10, 8};
int lie[50] = {0, 8, 9, 10, 6, 8, 13, 10, 10, 11, 8,12, 8, 8, 8, 8, 10, 9, 10, 10, 7,11, 9, 10, 14, 11, 13, 15, 16, 9, 12,9, 8, 14, 15, 10, 15, 9, 12, 11, 10};string zhuyi[50][50] = {{"  ###   ","  #P#   ","  # ####","###o oP#","#P os###","####o#  ","   #P#  ","   ###  ",},{"  ###   ","  #P#   ","  # ####","###o oP#","#P o ###","####s#  ","   #@#  ","   ###  ",},{"  ###   ","  #P#   ","  # ####","###o oP#","#P os###","#### #  ","   #@#  ","   ###  ",},{"  ###   ","  #P#   ","  # ####","###o oP#","#Pos ###","#### #  ","   #@#  ","   ###  ",},{"  ###   ","  #P#   ","  # ####","###o oP#","#@s  ###","#### #  ","   #@#  ","   ###  ",},{"  ###   ","  #P#   ","  # ####","###o oP#","#@ s ###","#### #  ","   #@#  ","   ###  ",},{"  ###   ","  #P#   ","  #o####","###s oP#","#@   ###","#### #  ","   #@#  ","   ###  ",},{"  ###   ","  #@#   ","  #s####","###  oP#","#@   ###","#### #  ","   #@#  ","   ###  ",},{"  ###   ","  #@#   ","  # ####","###s oP#","#@   ###","#### #  ","   #@#  ","   ###  ",},{"  ###   ","  #@#   ","  # ####","### soP#","#@   ###","#### #  ","   #@#  ","   ###  ",},{"  ###   ","  #@#   ","  # ####","###  s@#","#@   ###","#### #  ","   #@#  ","   ###  ",}
};
string s[50];
int n, m;
int bbb, ccc, ex, ey;
string ss[50];
int o[10000][2];
int P[10000][2];
int cnt = 2, flagg = 0;
int zn = 0, tim = 0;
void readcnt() {FILE *pf = fopen("推箱子关卡记录.txt", "r"); // 以只读的方式打开文件if (pf == NULL) {// 打开文件失败pf = fopen("推箱子关卡记录.txt", "w"); // 以只写的方式打开文件fwrite(&cnt, sizeof(int), 1, pf);}fseek(pf, 0, SEEK_SET);          // 使文件指针pf指向文件开头fread(&cnt, sizeof(int), 1, pf); // 读取文件当中的最高得分到max当中fclose(pf);                      // 关闭文件pf = NULL;                       // 文件指针及时置空
}
// 更新最高分到文件
void writecnt() {FILE *pf = fopen("推箱子关卡记录.txt", "w"); // 以只写的方式打开文件if (pf == NULL) {// 打开文件失败printf("写入失败\n");exit(0);}fwrite(&cnt, sizeof(int), 1, pf); // 将本局游戏得分写入文件当中fclose(pf);                       // 关闭文件pf = NULL;                        // 文件指针及时置空cout << "写入成功!";
}
int jieshu() {int flag = 0;for (int i = 0; i < bbb; i++) {for (int j = 0; j < bbb; j++) {if (o[i][0] == P[j][0] && o[i][1] == P[j][1]) {s[o[i][0]][o[i][1]] = '@';flag++;break;}}}if (flag == bbb)return 1;elsereturn 0;
}
void chushihua() {for (int i = 0; i < n; i++)s[i] = ss[i];bbb = ccc = 0;for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) {if (s[i][j] == 'o')o[bbb][0] = i, o[bbb][1] = j, bbb++;if (s[i][j] == 'P')P[ccc][0] = i, P[ccc][1] = j, ccc++;if (s[i][j] == '@')o[bbb][0] = i, o[bbb][1] = j, bbb++, P[ccc][0] = i, P[ccc][1] = j, ccc++;if (s[i][j] == 's')ex = i, ey = j;}}return;
}
char op[1005], xx[1005];
int cc = 0;
void XIANG(int guan) {char t = xx[cc--];if (t == 'w') {s[ex - 1][ey] = ' ';if (mapp[guan][ex][ey] == 'P') {s[ex][ey] = '@';} else {s[ex][ey] = 'o';}++ex;s[ex][ey] = 's';for (int i = 0; i < bbb; i++) {if (o[i][0] == ex - 2 && o[i][1] == ey) {o[i][0]++;break;}}}if (t == 's') {s[ex + 1][ey] = ' ';if (mapp[guan][ex][ey] == 'P') {s[ex][ey] = '@';} else {s[ex][ey] = 'o';}--ex;s[ex][ey] = 's';for (int i = 0; i < bbb; i++) {if (o[i][0] == ex + 2 && o[i][1] == ey) {o[i][0]--;break;}}}if (t == 'a') {s[ex][ey - 1] = ' ';if (mapp[guan][ex][ey] == 'P') {s[ex][ey] = '@';} else {s[ex][ey] = 'o';}++ey;s[ex][ey] = 's';for (int i = 0; i < bbb; i++) {if (o[i][0] == ex && o[i][1] == ey - 2) {o[i][1]++;break;}}}if (t == 'd') {s[ex][ey + 1] = ' ';if (mapp[guan][ex][ey] == 'P') {s[ex][ey] = '@';} else {s[ex][ey] = 'o';}--ey;s[ex][ey] = 's';for (int i = 0; i < bbb; i++) {if (o[i][0] == ex && o[i][1] == ey + 2) {o[i][1]--;break;}}}
}
bool tuixiangzi(int flag, int guan) {if (flag == 1) {cout << "\n          推箱子小游戏第" << guan <<"关重新开始!\n\n       点击空格开始游戏,点击z键退出游戏。\n";while (1) {if (kbhit()) {char gg = getch();if (gg == 'z')return 0;if (gg == ' ') {system("cls");break;}}}}int step = 0;system("cls");cout << "\n\n                   开始游戏!\n";Sleep(1000);system("cls");for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) {char r = s[i][j];if (r == ' ')cout << "  ";if (r == '#')cout << "■";if (r == 's') {red;cout << "♀";white;}if (r == 'o')cout << "□";if (r == 'P')cout << "☆";if (r == '@')cout << "★";}cout << "\n";}cc = 0;cout << "\n  关卡:第" << guan << "关     "<< "步数:0步";char g;while (1) {if (kbhit()) {g = getch();if (g == 'r') {chushihua();system("cls");Sleep(100);return tuixiangzi(1, guan);}// 撤销bool flag = 0;if (g == 'z' && cc > 0) {if (xx[cc] != ' ') {--step;XIANG(guan);} else {flag = 1;g = op[cc];}} else if (!(g == 'a' || g == 75 || g == 'd' || g == 77 || g == 'w' || g == 72 || g == 's' || g == 80)) {continue;} else {if (g == 'a' || g == 75)op[++cc] = 'd';if (g == 'd' || g == 77)op[++cc] = 'a';if (g == 'w' || g == 72)op[++cc] = 's';if (g == 's' || g == 80)op[++cc] = 'w';if (g == 'a' || g == 75)xx[cc] = 'a';if (g == 'd' || g == 77)xx[cc] = 'd';if (g == 'w' || g == 72)xx[cc] = 'w';if (g == 's' || g == 80)xx[cc] = 's';}// 左移if (g == 'a' || g == 75) {if (s[ex][ey - 1] == ' ' || s[ex][ey - 1] == 'P')s[ex][ey] = ' ', ey--, s[ex][ey] = 's', xx[cc] = ' ';else if ((s[ex][ey - 1] == 'o' || s[ex][ey - 1] == '@') && (s[ex][ey - 2] == ' ' || s[ex][ey - 2] == 'P')) {int sx = ex, sy = ey - 1;for (int i = 0; i < bbb; i++) {if (o[i][0] == sx && o[i][1] == sy) {s[sx][sy] = ' ';o[i][1]--;if (s[sx][sy - 1] != 'P')s[sx][sy - 1] = 'o';elses[sx][sy - 1] = '@';break;}}s[ex][ey] = ' ';ey--;s[ex][ey] = 's';step++;} else {--cc;}}//// 右移if (g == 'd' || g == 77) {if (s[ex][ey + 1] == ' ' || s[ex][ey + 1] == 'P')s[ex][ey] = ' ', ey++, s[ex][ey] = 's', xx[cc] = ' ';else if ((s[ex][ey + 1] == 'o' || s[ex][ey + 1] == '@') && (s[ex][ey + 2] == ' ' || s[ex][ey + 2] == 'P')) {int sx = ex, sy = ey + 1;// sx, sy : 当前控制的箱子for (int i = 0; i < bbb; i++) {if (o[i][0] == sx && o[i][1] == sy) {s[sx][sy] = ' ';o[i][1]++;if (s[sx][sy + 1] != 'P')s[sx][sy + 1] = 'o';elses[sx][sy + 1] = '@';break;}}s[ex][ey] = ' ';ey++;s[ex][ey] = 's';step++;} else {--cc;}}//// 上移if (g == 'w' || g == 72) {if (s[ex - 1][ey] == ' ' || s[ex - 1][ey] == 'P')s[ex][ey] = ' ', ex--, s[ex][ey] = 's', xx[cc] = ' ';else if ((s[ex - 1][ey] == 'o' || s[ex - 1][ey] == '@') && (s[ex - 2][ey] == ' ' || s[ex - 2][ey] == 'P')) {int sx = ex - 1, sy = ey;for (int i = 0; i < bbb; i++) {if (o[i][0] == sx && o[i][1] == sy) {s[sx][sy] = ' ';o[i][0]--;if (s[sx - 1][sy] != 'P')s[sx - 1][sy] = 'o';elses[sx - 1][sy] = '@';break;}}s[ex][ey] = ' ';ex--;s[ex][ey] = 's';step++;} else {--cc;}}//// 下移if (g == 's' || g == 80) {if (s[ex + 1][ey] == ' ' || s[ex + 1][ey] == 'P')s[ex][ey] = ' ', ex++, s[ex][ey] = 's', xx[cc] = ' ';else if ((s[ex + 1][ey] == 'o' || s[ex + 1][ey] == '@') && (s[ex + 2][ey] == ' ' || s[ex + 2][ey] == 'P')) {int sx = ex + 1, sy = ey;for (int i = 0; i < bbb; i++) {if (o[i][0] == sx && o[i][1] == sy) {s[sx][sy] = ' ';o[i][0]++;if (s[sx + 1][sy] != 'P')s[sx + 1][sy] = 'o';elses[sx + 1][sy] = '@';break;}}s[ex][ey] = ' ';ex++;s[ex][ey] = 's';step++;} else {--cc;}}if (flag)--cc;system("cls");for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) {if (i == ex && j == ey) {red;cout << "♀";white;} else {for (int k = 0; k < bbb; k++) {int flag = 0;for (int l = 0; l < bbb; l++) {if (o[l][0] != P[k][0] || o[l][1] != P[k][1])flag++;}if (flag == bbb)s[P[k][0]][P[k][1]] = 'P';}char r = s[i][j];if (r == ' ')cout << "  ";if (r == '#')cout << "■";if (r == 's') {red;cout << "♀";white;}if (r == 'o')cout << "□";if (r == 'P')cout << "☆";if (r == '@')cout << "★";}}cout << "\n";}cout << "\n  关卡:第" << guan << "关     "<< "步数:" << step << "步";if (jieshu()) {Sleep(200);break;}}}system("cls");cout << "\n                恭喜你成功了!\n";cout << "         你共用了" << step << "步完成了第" << guan << "关卡。\n\n";cout << "        按z键退出,按空格键进入下一关。\n";while (1) {if (kbhit()) {char gg = getch();if (gg == 'z') {if (guan == cnt)cnt++;flagg++;return 0;}if (gg == ' ') {if (guan == cnt)cnt++;guan++, flagg++;n = hang[guan], m = lie[guan];for (int i = 0; i < n; i++)s[i] = ss[i] = mapp[guan][i];bbb = ccc = 0;for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) {if (s[i][j] == 'o')o[bbb][0] = i, o[bbb][1] = j, bbb++;if (s[i][j] == 'P')P[ccc][0] = i, P[ccc][1] = j, ccc++;if (s[i][j] == '@')o[bbb][0] = i, o[bbb][1] = j, bbb++, P[ccc][0] = i, P[ccc][1] = j, ccc++;if (s[i][j] == 's')ex = i, ey = j;}}return 0;}}}return 1;
}
int sum = 4;
string zhu[15] = {"","         +---------推 箱 子---------+","","                   选择关卡","                -> 游戏规则","                   读取记录","                   保存记录","                   查看记录","                   修改记录","                   查看样例","                   退出游戏","","    按↑(w)和↓(s)选择项目,按空格键确认。"
};
int nn = 13;
void yangli() {while (1) {system("cls");if (kbhit()) {char qqq = getch();if (qqq == 'q') {return;}}cout << "\n";for (int i = 0; i < 8; i++) {cout << "              ";for (int j = 0; j < 8; j++) {char r = zhuyi[zn][i][j];if (r == ' ')cout << "  ";if (r == '#')cout << "■";if (r == 's') {red;cout << "♀";white;}if (r == 'o')cout << "□";if (r == 'P')cout << "☆";if (r == '@')cout << "★";}cout << "\n";}zn = (zn + 1) % 11;cout << "\n按Q键退出";Sleep(500);}
}
int main() {white;ycgb();system("mode con cols=46 lines=18");for (int i = 0; i < nn; i++)cout << zhu[i] << "\n";while (1) {if (kbhit()) {char gg = getch();if ((gg == 's' || gg == 80) && sum != 10) {system("cls");zhu[sum + 1][16] = '-', zhu[sum + 1][17] = '>';zhu[sum][16] = zhu[sum][17] = ' ';for (int i = 0; i < nn; i++) {cout << zhu[i] << "\n";}sum++;}if ((gg == 'w' || gg == 72) && sum != 3) {system("cls");zhu[sum - 1][16] = '-', zhu[sum - 1][17] = '>';zhu[sum][16] = zhu[sum][17] = ' ';for (int i = 0; i < nn; i++) {cout << zhu[i] << "\n";}sum--;}if (gg == ' ') {zn = tim = 0;if (sum == 10) {system("cls");cout << "本游戏原作者为:luogu:481803,由@linziyang1修改\n";cout << "创作不易,请各位大佬多多指教\n\n";system("pause");return 0;}if (sum == 9) {system("cls");yangli();}if (sum == 8) {system("cls");cout << "请输入跳关编号:";cin >> cnt;cout << "正在保存记录...\n";writecnt();Sleep(1000);}if (sum == 5) {system("cls");cout << "正在读取记录...";readcnt();system("cls");cout << "读取记录成功!\n";cout << "当前记录为:";red;cout<< cnt << endl;white;system("pause");}if (sum == 6) {system("cls");cout << "正在写入记录...\n";writecnt();cout << endl;system("pause");}if (sum == 7) {system("cls");cout << "当前记录为:";red;cout << cnt << endl;white;system("pause");}if (sum == 4) {system("cls");cout << "游戏目标:\n";cout << "控制小人(";red;cout << "♀";white;cout << ")将所有箱子(□)推入指定地点(☆)。\n";cout << "若指定地点已有箱子,则显示★。\n\n";cout << "游戏规则:\n";cout << "小人在没有障碍物(■)的情况下只能推动一个箱子。\n";cout << "小人只能推箱子,不能拉。\n\n";cout << "按键设置:\n";cout << "用↑(w)、↓(s)、←(a)、→(d)控制小人移动。\n";cout << "按z键撤销。\n";cout << "按r键重玩或退出。\n";cout << "计步方式:推着箱子走的有效步数\n";if (cnt > 5)cout << "点击v键跳转游戏解答网址\n",cout << "注意,网址内顺序并非本游戏里关卡顺序\n";elsecout << "自行玩到第六关会有游戏解答哦。\n\n";cout << "                按空格键退出。\n";while (1) {if (kbhit()) {char ggg = getch();if (ggg == ' ') {system("cls");for (int i = 0; i < nn; i++)cout << zhu[i] << "\n";break;} else if (ggg == 'v' && cnt > 5) {system("start http://v.4399pk.com/xiaoyouxi/game_1875.htm");}}}}if (sum == 3) {white;system("cls");cout << "\n                   选择关卡\n\n";int k = cnt;for (int i = 1; i <= 40; i++) {if (i > cnt)nop;else if (i == k)red;elsewhite;printf("%8d", i);if (i % 5 == 0)cout << "\n";}white;cout << "\n    按↑(w)、↓(s)、←(a)、→(d)选择关卡。\n           按空格键进入,按z键退出。\n";while (1) {if (kbhit()) {char ggg = getch();if (ggg == 'z') {system("cls");for (int i = 0; i < nn; i++)cout << zhu[i] << "\n";break;}if (ggg == 'a' || ggg == 75) {if (k - 1 >= 1) {k--;white;system("cls");cout << "\n                   选择关卡\n\n";for (int i = 1; i <= 40; i++) {if (i > cnt)nop;else if (i == k)red;elsewhite;printf("%8d", i);if (i % 5 == 0)cout << "\n";}white;cout << "\n    按↑(w)、↓(s)、←(a)、→(d)选择关卡。\n           按空格键进入,按z键退出。\n";}}if (ggg == 'd' || ggg == 77) {if (k + 1 <= cnt) {k++;white;system("cls");cout << "\n                   选择关卡\n\n";for (int i = 1; i <= 40; i++) {if (i > cnt)nop;else if (i == k)red;elsewhite;printf("%8d", i);if (i % 5 == 0)cout << "\n";}white;cout << "\n    按↑(w)、↓(s)、←(a)、→(d)选择关卡。\n           按空格键进入,按z键退出。\n";}}if (ggg == 'w' || ggg == 72) {if (k - 5 >= 1) {k -= 5;white;system("cls");cout << "\n                   选择关卡\n\n";for (int i = 1; i <= 40; i++) {if (i > cnt)nop;else if (i == k)red;elsewhite;printf("%8d", i);if (i % 5 == 0)cout << "\n";}white;cout << "\n    按↑(w)、↓(s)、←(a)、→(d)选择关卡。\n           按空格键进入,按z键退出。\n";}}if (ggg == 's' || ggg == 80) {if (k + 5 <= cnt) {k += 5;white;system("cls");cout << "\n                   选择关卡\n\n";for (int i = 1; i <= 40; i++) {if (i > cnt)nop;else if (i == k)red;elsewhite;printf("%8d", i);if (i % 5 == 0)cout << "\n";}white;cout << "\n    按↑(w)、↓(s)、←(a)、→(d)选择关卡。\n           按空格键进入,按z键退出。\n";}}if (ggg == ' ') {flagg = 0;n = hang[k], m = lie[k];for (int i = 0; i < n; i++)s[i] = ss[i] = mapp[k][i];bbb = ccc = 0;for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) {if (s[i][j] == 'o')o[bbb][0] = i, o[bbb][1] = j, bbb++;if (s[i][j] == 'P')P[ccc][0] = i, P[ccc][1] = j, ccc++;if (s[i][j] == '@')o[bbb][0] = i, o[bbb][1] = j, bbb++, P[ccc][0] = i, P[ccc][1] = j, ccc++;if (s[i][j] == 's')ex = i, ey = j;}}tuixiangzi(0, k);k += flagg;white;system("cls");cout << "\n                   选择关卡\n\n";for (int i = 1; i <= 40; i++) {if (i > cnt)nop;else if (i == k)red;elsewhite;printf("%8d", i);if (i % 5 == 0)cout << "\n";}white;cout << "\n    按↑(w)、↓(s)、←(a)、→(d)选择关卡。\n           按空格键进入,按z键退出。\n";}}}}}system("cls");for (int i = 0; i < nn; i++)cout << zhu[i] << "\n";}}return 0;
}

注:如果有些电脑在编译运行后出现一堆乱码,就在编译指令的后面加一句 -fexec-charset=gbk 即可,比如:

$ g++ 推箱子.cpp -o 推箱子.exe -fexec-charset=gbk

(我家电脑就是出了这个锅)
Dev-C++可以参考这一篇

正常运行效果:
txz

2.点击空格键进入游戏简述:

jian

3. 仔细阅读 \small\color{orange}\texttt{仔细阅读} 仔细阅读简述,并按空格退出:

zhu

4.按上下键选择功能,并按照程序提示操作。如图是推箱子动画样例界面:

hahaha

5.尽情享受推箱子的乐趣吧!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/39281.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

怎么把知网的外文文献翻译成中文_知网查重中文译成英文可行吗?

把中文翻译成英文知网查重是能查出的,最新的版本增加了中英文互译、跨语言检测等功能。因此,中国知网不仅能查重英文论文,还能将中文翻译成英文的论文给查出来。所以说,中文译成英文不是一个好办法。那么,知网查重中文译成英文可行吗? 一、中国知网能否查重英文 目前市场…

开源大模型文档

开源大模型综述 排行榜1.LLaMA资源&#xff1a; 2.Chinese-LLaMA-Alpaca资源&#xff1a; 3.Alpaca资源&#xff1a; 4.Alpaca-LoRA5.Vicuna资源&#xff1a; 6.OpenChatKit资源&#xff1a; 7.GPT4ALL8.Raven RWKV资源&#xff1a; 9.OPT资源&#xff1a; 10.Flan-T5-XXL资源&…

5月份读书学习好文记录

学好C可以采取以下几个步骤&#xff1a; 掌握基本语法&#xff1a;C的语法对于初学者来说可能是一件比较难的事情&#xff0c;所以需要花时间掌握C的语言基础和语法规则&#xff0c;例如数据类型、流程控制、函数等。 学会面向对象编程(OOP)&#xff1a;C是一种面向对象的编程…

多表关联出现重复数据原因

多表联合查询的时候&#xff0c;可能会产生多条重复数据&#xff0c;出现的原因&#xff1a; 1.可能是你用来进行 join的列&#xff0c;具有重复数据。 今天下午在写sql的时候&#xff0c;由于没有注意到该列的值并不是唯一的&#xff0c;所以导致查询出来的有N条重复数据 解决…

数据拼接出现重复

数据拼接出现重复 使用join方法拼接数据出现重复 使用join方法拼接数据出现重复 打印日期和星期&#xff0c;首先获取当前日期毫秒&#xff0c;再通过for循环将毫秒计算出下一日期 如要实现打印如下日期 代码如下 当28行和23行位置互换&#xff0c;就会发生一下情况 原因是…

wechat——解决重试三次产生消息重复的问题

通过上篇成功的接入开发者模式&#xff0c;与微信交互发送文本消息和模板消息&#xff0c;发现消息有的时候会重复发送&#xff0c;最多三次。查看微信公众平台文档发现&#xff1a;微信服务器在五秒内收不到响应会断掉链接&#xff0c;并且重新发起请求&#xff0c;总共重试三…

如何重复对好友发同一条信息

words"期末考试必过" import pyautogui #控制键盘鼠标 import pyperclip #控制电脑的复制截切版 import time #控制时间 time.sleep(5) #设置切换窗口时准备的时间 for i in words.split("/n")*99: #split("/n")把文章分成一句一句的 pr…

GP查询并删除重复数据问题

在数据库中做增删查改时&#xff0c;难免会因为误操作导致数据库中存在一些重复数据&#xff0c;那么如何定位这些重复数据并且删除呢&#xff1f;本文将介绍在Greenplum数据库中如何实现查询并删除重复数据的方法。 目录 PostgreSQL与Greenplum的关系GP查询重复数据1. row_nu…

C++ 查找字符串重复字符和只出现一次的字符

#include <iostream> #include <string>using namespace std;int main() {string temp "";cout << "请输入字符串&#xff1a;";getline(cin,temp);string str ""; //存放只出现一次的字符string str1 ""; //存…

chatgpt赋能python:Python排除字符串中重复字符

Python排除字符串中重复字符 在处理字符串数据时&#xff0c;我们经常需要对字符串中的重复字符进行处理&#xff0c;以便更好地对数据进行分析和处理。在Python编程领域中&#xff0c;有许多方法可以用于排除字符串中的重复字符&#xff0c;从而使数据更加清晰和有用。在本文…

拼音打字时不定时出现重复字母

问题自述&#xff1a; 家里面有一台备用机惠普15-R239TX&#xff0c;东西放久了发现键盘缝隙里面很脏&#xff0c;得空就拆机后彻底清理了一下。 自从上次清理过键盘后&#xff0c;在使用Q Q拼音打字时会不定时出现重字母的情况&#xff0c;重新下载最新版本&#xff0c;默认设…

CPM-Bee本地部署的实战方案

大家好,我是herosunly。985院校硕士毕业,现担任算法研究员一职,热衷于机器学习算法研究与应用。曾获得阿里云天池比赛第一名,CCF比赛第二名,科大讯飞比赛第三名。拥有多项发明专利。对机器学习和深度学习拥有自己独到的见解。曾经辅导过若干个非计算机专业的学生进入到算法…

3分钟部署私人chat-gpt教程

一、注册vercel账号 点击 Vercel 邮箱注册一个号&#xff0c;86的手机号也能注册。需要github账号和openai key 二、创建项目 1. 在首页新建项目 2. 登录你的github账号&#xff0c;然后创建一个仓库 导入第三方的仓库 输入&#xff1a;https://github.com/Yidadaa/ChatGPT…

注册AppStore开发者账号以及收款设置的流程详解(2019最新版)

最近和朋友倒腾了一个APP&#xff0c;想在App Store上架&#xff0c;因此就在注册个人开发者账号的过程中踩了不少坑。 申请App Store的开发者账号果然不是一件容易的事情&#xff0c;并且我发现在设置收款时尤其容易踩坑。期间&#xff0c;我也看了不少分享&#xff0c;但由于…

苹果 company开发者账号注册流程图解分享

苹果开发者账号的注册过程还是比较复杂的&#xff0c;周期拉了一个月&#xff08;漫长啊~~&#xff09;。和大家分享一下过程和细节&#xff0c;以免大家走了弯路。本文由萌虾米492405648编写蛮辛苦的要是对你有用是我最大的欣慰啦 一定要记住申请的过程中遇到问题致电苹果开发…

最新苹果商务管理ABM注册及使用

本文了解苹果商务管理Apple Business Manager(简称ABM)的申请注册流程及应用下载方式 苹果商务管理&#xff0c;Apple Business Manager 简称ABM&#xff0c;用于 定制应用分发公司/组织内部应用分发 如果你的应用是上边两种类型就考虑用ABM分发了&#xff0c;这类应用的特点是…

年度最新!iOS如何申请苹果公司开发者账号流程详细图文介绍

苹果官方参考文章&#xff1a;使用 Apple Developer App 注册和管理您的帐。 申请公司账号&#xff0c;别申请个人账号。以前有家公司就申请错了申请为个人账号了&#xff0c;结果只能显示个人开发者的名字。个人账号和公司账号费用现在一样了。企业账号已经不能申请了。申请网…

iOS 苹果企业账号申请流程

申请需要用到的一些资料&#xff1a;.一张可以付美元的信用卡(如VISA或万事达)、一个企业邮箱账号还有公司的营业执照复印件(申请邓白氏码的时候需要用到)。 1.打开网址https://developer.apple.com&#xff0c;如下图&#xff1a; 2.点击上图中的Account&#xff0c;进入登录页…

发布苹果App有哪些步骤流程

前提&#xff1a; 1.需要一台苹果电脑 2.需要苹果开发者账号 3.已经开发好的App 发布步骤&#xff1a; 1.先创建App ID 登录开发者账号选择Certificates, Identifiers & Profiles进入相应的界面&#xff0c;再选择Identifiers旁边的蓝色&#xff0b;号 然后选择App IDs…

最新2016年苹果公司开发者帐号申请流程

对于刚申请完苹果开发者账号的我来说&#xff0c;我们需要区分一下个人账号、公司账号和企业账号这三种&#xff0c;还有一种是教育账号&#xff0c;这个就不多说了。 个人账号&#xff1a;个人申请用于开发苹果app所使用的账号&#xff0c;仅限于个人使用&#xff0c;申请比较…