游戏(不喜勿喷)
2026-09-29 21:18:05
发布于:浙江
#include<iostream>
#include<windows.h>
#include<conio.h>
#include <cstdio>
#include<time.h>
#include<stdio.h>
#include<string>
#include <vector>
#include <fstream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#define MOVE_CURSOR(x, y) printf("\033[%d;%dH",(x),(y))
using namespace std;
int i,j,x,y,t=1,bushu,n,m,bjx,bjy,xx,ps,ans,sss,xxx,gg,gs,a[1010],k,l,tt,mmin,mmax,mmab,game1=1;
double nnab;
char xz,linshi[1010][1010],gs2[1010],fx,f[1010][1010];
string playerName;
void cmp1(int x, int y){//光标定位
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos = {x, y};
SetConsoleCursorPosition(hConsole, pos);
}
void cmp2(){//清屏
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coordScreen = {0, 0};
DWORD dwWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hConsole, &csbi);
DWORD dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, ' ', dwConSize, coordScreen, &dwWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
}
void cmp3(){//隐藏光标
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void SetColorAndBackground(int ForgC, int BackC) {//染色
WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}
void saveProgress(){// 存档
vector <string> lines;
string line;
bool found = false;
ifstream inFp("Leaderboards.txt");
while (getline(inFp, line)) {
lines.push_back(line);
}
inFp.close();
for (size_t i = 0; i < lines.size(); ++i) {
if (lines[i].find(playerName) != string::npos) {
std::ostringstream oss;
oss << " " << playerName << " " << t << " " << ans;
string newRecord = oss.str();
lines[i] = newRecord;
found=true;
break;
}
}
if (!found) {
ostringstream oss;
oss << " " << playerName << " " << t << " " << ans;
lines.push_back(oss.str());
}
ofstream outFp("Leaderboards.txt", ios::trunc);
for (size_t i = 0; i < lines.size(); ++i) outFp << lines[i] << endl;
outFp.close();
}
void loadSave(){//读档
ifstream fp("Leaderboards.txt");
if(!fp.is_open()) return;
string line;
while(getline(fp, line)) {
size_t namePos = line.find(playerName);
if(namePos != string::npos) {
sscanf(line.c_str(), " %*s %d %d", &t, &ans);
break;
}
}
fp.close();
}
void duqu(){//读取关卡
int i,j;
char buffer[1010];
memset(buffer,' ',sizeof(buffer));
if(t>10){
game1=0;
return ;
}
if(t==0) sprintf(buffer, "新手训练.txt");
else sprintf(buffer, "附件%d.txt",t);
std::string filename(buffer);
std::ifstream infile(filename.c_str());
int tempN, tempM;
if (infile>>tempN>>tempM) {
n=tempN;
m=tempM;
for(i=1;i<=n;++i)
for(j=1;j<=m;++j) infile>>f[i][j];
}
infile.close();
}
void game(){
cmp3();
duqu();
if(game==0) return ;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
if(f[i][j]=='*') f[i][j]=' ';
cout<<"10秒观察地图!\n";
Sleep(2000);
cmp2();
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(f[i][j]=='@'){
SetColorAndBackground(10,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='k'){
SetColorAndBackground(15,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='$'){
SetColorAndBackground(12,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else cout<<f[i][j];
}
cout<<"\n";
}
i=10;
while(i>=1){
cout<<i<<" ";
Sleep(1000);
MOVE_CURSOR(n+1,1);
i--;
}
cmp2();
for(i=1;i<=n;i++){
for(j=1;j<=m;j++)
if(f[i][j]=='k'){
x=i;y=j;break;
}
if(j!=m+1) break;
}
for(i=1;i<=n;i++){
for(j=1;j<=m;j++)
if(f[i][j]=='$'){
bjx=i;bjy=j;break;
}
if(j!=m+1) break;
}
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
MOVE_CURSOR(i,j);
if(!(i>=x-1&&i<=x+1&&j>=y-1&&j<=y+1)){
cout<<" ";
continue;
}
if(f[i][j]=='@'){
SetColorAndBackground(10,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='k'){
SetColorAndBackground(15,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='$'){
SetColorAndBackground(12,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else cout<<f[i][j];
}
cout<<"\n";
}
bushu=0;
Sleep(2000);
cmp3();
while(x!=bjx||y!=bjy){
fx=getch();
if(fx==75||fx=='a'||fx=='A'){
if(f[x][y-1]=='@'){
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
MOVE_CURSOR(i,j);
if(!(i>=x-1&&i<=x+1&&j>=y-1&&j<=y+1)){
cout<<" ";
continue;
}
if(f[i][j]=='@'){
SetColorAndBackground(10,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='k'){
SetColorAndBackground(15,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='$'){
SetColorAndBackground(12,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else cout<<f[i][j];
}
cout<<"\n";
}
}
else if(x<1||y<1||x>n||y>m){
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
MOVE_CURSOR(i,j);
if(!(i>=x-1&&i<=x+1&&j>=y-1&&j<=y+1)){
cout<<" ";
continue;
}
if(f[i][j]=='@'){
SetColorAndBackground(10,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='k'){
SetColorAndBackground(15,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='$'){
SetColorAndBackground(12,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else cout<<f[i][j];
}
cout<<"\n";
}
}
else{
bushu++;
f[x][y-1]='k';f[x][y]=' ';y--;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
MOVE_CURSOR(i,j);
if(!(i>=x-1&&i<=x+1&&j>=y-1&&j<=y+1)){
cout<<" ";
continue;
}
if(f[i][j]=='@'){
SetColorAndBackground(10,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='k'){
SetColorAndBackground(15,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='$'){
SetColorAndBackground(12,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else cout<<f[i][j];
}
cout<<"\n";
}
}
}
if(fx==77||fx=='d'||fx=='D'){
if(f[x][y+1]=='@'){
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
MOVE_CURSOR(i,j);
if(!(i>=x-1&&i<=x+1&&j>=y-1&&j<=y+1)){
cout<<" ";
continue;
}
if(f[i][j]=='@'){
SetColorAndBackground(10,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='k'){
SetColorAndBackground(15,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='$'){
SetColorAndBackground(12,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else cout<<f[i][j];
}
cout<<"\n";
}
}
else if(x<1||y<1||x>n||y>m){
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
MOVE_CURSOR(i,j);
if(!(i>=x-1&&i<=x+1&&j>=y-1&&j<=y+1)){
cout<<" ";
continue;
}
if(f[i][j]=='@'){
SetColorAndBackground(10,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='k'){
SetColorAndBackground(15,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='$'){
SetColorAndBackground(12,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else cout<<f[i][j];
}
cout<<"\n";
}
}
else{
bushu++;
f[x][y+1]='k';f[x][y]=' ';y++;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
MOVE_CURSOR(i,j);
if(!(i>=x-1&&i<=x+1&&j>=y-1&&j<=y+1)){
cout<<" ";
continue;
}
if(f[i][j]=='@'){
SetColorAndBackground(10,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='k'){
SetColorAndBackground(15,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='$'){
SetColorAndBackground(12,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else cout<<f[i][j];
}
cout<<"\n";
}
}
}
if(fx==72||fx=='w'||fx=='W'){
if(f[x-1][y]=='@'){
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
MOVE_CURSOR(i,j);
if(!(i>=x-1&&i<=x+1&&j>=y-1&&j<=y+1)){
cout<<" ";
continue;
}
if(f[i][j]=='@'){
SetColorAndBackground(10,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='k'){
SetColorAndBackground(15,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='$'){
SetColorAndBackground(12,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else cout<<f[i][j];
}
cout<<"\n";
}
}
else if(x<1||y<1||x>n||y>m){
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
MOVE_CURSOR(i,j);
if(!(i>=x-1&&i<=x+1&&j>=y-1&&j<=y+1)){
cout<<" ";
continue;
}
if(f[i][j]=='@'){
SetColorAndBackground(10,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='k'){
SetColorAndBackground(15,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='$'){
SetColorAndBackground(12,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else cout<<f[i][j];
}
cout<<"\n";
}
}
else{
bushu++;
f[x-1][y]='k';f[x][y]=' ';x--;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
MOVE_CURSOR(i,j);
if(!(i>=x-1&&i<=x+1&&j>=y-1&&j<=y+1)){
cout<<" ";
continue;
}
if(f[i][j]=='@'){
SetColorAndBackground(10,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='k'){
SetColorAndBackground(15,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='$'){
SetColorAndBackground(12,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else cout<<f[i][j];
}
cout<<"\n";
}
}
}
if(fx==80||fx=='s'||fx=='S'){
if(f[x+1][y]=='@'){
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
MOVE_CURSOR(i,j);
if(!(i>=x-1&&i<=x+1&&j>=y-1&&j<=y+1)){
cout<<" ";
continue;
}
if(f[i][j]=='@'){
SetColorAndBackground(10,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='k'){
SetColorAndBackground(15,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='$'){
SetColorAndBackground(12,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else cout<<f[i][j];
}
cout<<"\n";
}
}
else if(x<1||y<1||x>n||y>m){
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
MOVE_CURSOR(i,j);
if(!(i>=x-1&&i<=x+1&&j>=y-1&&j<=y+1)){
cout<<" ";
continue;
}
if(f[i][j]=='@'){
SetColorAndBackground(10,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='k'){
SetColorAndBackground(15,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='$'){
SetColorAndBackground(12,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else cout<<f[i][j];
}
cout<<"\n";
}
}
else{
bushu++;
f[x][y]=' ';x++;f[x][y]='k';
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
MOVE_CURSOR(i,j);
if(!(i>=x-1&&i<=x+1&&j>=y-1&&j<=y+1)){
cout<<" ";
continue;
}
if(f[i][j]=='@'){
SetColorAndBackground(10,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='k'){
SetColorAndBackground(15,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else if(f[i][j]=='$'){
SetColorAndBackground(12,0);
cout<<f[i][j];
SetColorAndBackground(7,0);
}
else cout<<f[i][j];
}
cout<<"\n";
}
}
}
}
cmp2();
cout<<"你赢了!\n";
Sleep(1000);system("pause");cmp2();
cout<<"共用了"<<bushu<<"步\n";
Sleep(1000);system("pause");cmp2();
mmin=1000;
mmax=5000;
mmab=rand()%(mmax-mmin+1)+mmin;
nnab=static_cast<double>(mmab)/100.0;
cout<<"获得"<<fixed<<setprecision(2)<<nnab<<"元!!!\n";
ans+=bushu;
system("pause");
}
int main(){
system("mode con cols=40 lines=22");
cmp3();
srand((unsigned int)time(0));
system("pause");
cmp2();
cout<<"开始游戏!\n";
Sleep(2000);
cmp2();
cout<<"----------------------\n";
cout<<"| |\n";
cout<<"----------------------\n";
cout<<"正在加载...";
for(i=2;i<=21;i++){
cmp1(i-1,1);
cout<<"#";
Sleep(300);
}
Sleep(2000);
cmp2();
cout<<"加载成功!";
Sleep(2000);
cmp2();
cout<<"请输入姓名:";
Sleep(2000);
cin>>playerName;
cmp2();
loadSave();
if(t>1){
cout<<"欢迎回来!\n";
Sleep(2000);
cmp2();
}
else{
cout<<"你是新手还是老手?\n";
Sleep(2000);
cout<<"A.新手 B.老手";
xz=getch();
cmp2();
if(xz=='A'){
cout<<"玩法:\n";
Sleep(2000);
cout<<"上下左右控制\n";
Sleep(2000);
cout<<"你是k\n";
Sleep(2000);
cout<<"目标是$\n";
Sleep(2000);
cmp2();
cout<<"进入新手训练!\n";
Sleep(2000);
cmp2();
game();
t=1;
saveProgress();
}
}
cmp2();
cout<<"准备好了吗?\n";
Sleep(2000);
cmp2();
cout<<"游戏要开始了!\n";
Sleep(2000);
cmp2();
while(1){
game();
cmp2();
if(game1==0){
cout<<"恭喜你,你已通关全部关卡!!!\n";
Sleep(2000);
cmp2();
cout<<"记住!!!\n";
Sleep(2000);
cmp2();
cout<<"!!!本游戏作者:陈熠涵!!!\n";
Sleep(2000);
cmp2();
return 0;
}
t++;
saveProgress();
cout<<"游戏结束!\n";
Sleep(1000);
cmp2();
cout<<"是否继续游戏?\n";
Sleep(1000);
cmp2();
cout<<"是.1 否.2\n";
Sleep(1000);
cin>>xx;
cmp2();
if(xx==2){
cout<<"----------------------\n";
cout<<"| |\n";
cout<<"----------------------\n";
cout<<"正在退出...";
for(i=2;i<=21;i++){
cmp1(i-1,1);
cout<<"#";
Sleep(500);
}
cmp2();
return 0;
}
}
return 0;
}
以下是附件:
Leaderboards//排行榜 复制到txt,命名为Leaderboards
新手训练//复制到txt,命名为新手训练
附件1//复制到txt,命名为附件1
附件2//复制到txt,命名为附件2
附件3//复制到txt,命名为附件3
附件4//复制到txt,命名为附件4
附件5//复制到txt,命名为附件5
附件6//复制到txt,命名为附件6
附件7//复制到txt,命名为附件7
附件8//复制到txt,命名为附件8
附件9//复制到txt,命名为附件9
附件10//复制到txt,命名为附件10
本游戏作者:Jason(陈熠涵)
感谢观看!!!


!!!给个赞吧!!!

























!!!谢谢!!!
!!!谢谢!!!
!!!谢谢!!!
全部评论 7
- 置顶
咋玩的
1周前 来自 浙江
3先开一个c++
1周前 来自 浙江
2再开11个txt
1周前 来自 浙江
2咋操作
1周前 来自 浙江
2
吾去,这码风有点像人的!
1周前 来自 浙江
3但也带点AI味
1周前 来自 浙江
3是人写,AI辅助吗
1周前 来自 浙江
3Yes
1周前 来自 浙江
3
不喜勿喷
2026-09-17 来自 浙江
3不喜勿喷
2026-09-17 来自 浙江
3不喜勿喷
2026-09-17 来自 浙江
3HI
2026-09-20 来自 浙江
3
HI
2026-09-20 来自 浙江
2大家好,我是陈熠涵。
你们有什么问题,可以发在评论区,不过得1到2天在回,不好意思。
另外麻烦推广一下,谢谢。1周前 来自 浙江
1能写个不用txt的版本吗
1周前 来自 江苏
1
这是什么游戏啊?现在还没打算玩儿,先问一下。
4小时前 来自 湖北
0看着不错
15小时前 来自 广东
0
































有帮助,赞一个