跳到正文

个人记录

一个小游戏(未完成,招收人写故事线)

Hughpig约 3 分钟
原文
文章信息与版本

文章信息

发布
2022年8月18日
收录
2025年12月12日
更新
2026年11月6日
篇幅
约 3 分钟

版本

  1. v1当前

RT,为了防颓废,挖个坑(尽管这就是颓废)

刚写好地图保存。故事线还木有>_<,招人写故事线。

刚写好地图存储读取,具体操作明天写。

C++
#include<iostream>
#include<fstream>
#include<Windows.h>
using namespace std;
typedef long long ll;

ll mx,my,px,py;
char map[100][100];

void Read(string filename)
{
	filename=filename+".in";
	ifstream in(filename.c_str()); 
	in>>mx>>my;
	for(int i=0;i<mx;i++)
	{
		for(int j=0;j<my;j++)
		{
			in>>map[i][j];
			if(map[i][j]=='@')
			{
				px=j;
				py=i;
			}
		}
	}
}

void Save(string filename)
{
	filename=filename+".in";
	ofstream out(filename.c_str());
	out<<mx<<" "<<my<<"\n";
	for(int i=0;i<mx;i++)
	{
		for(int j=0;j<my;j++)
		{
			out<<map[i][j];
		}
		out<<"\n";
	}
}

void gotoxy(int x,int y)//类似于清屏函数
{
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD pos;
    pos.X = x;
    pos.Y = y;
    SetConsoleCursorPosition(handle,pos);
}

void menu()
{
	int ch;
	cout<<"\t\t -------------------------\n";
	cout<<"\t\t|                        |\n";
	cout<<"\t\t|         1.play         |\n";
	cout<<"\t\t|                        |\n";
	cout<<"\t\t|         2.craft        |\n";
	cout<<"\t\t|                        |\n";
	cout<<"\t\t -------------------------\n";
	cin>>ch;
	if(ch==1)
	{
		string s;
		cout<<"输入地图名\n";
		cin>>s;
		Read(s);
		for(int i=0;i<mx;i++)
		{
			puts(map[i]);
		}
		system("pause");
		system("cls");
	}
	if(ch==2)
	{
		string s;
		cout<<"输入x和y\n";
		cin>>mx>>my;
		cout<<"输入地图\n";
		for(int i=0;i<mx;i++)
		{
			for(int j=0;j<my;j++)
			{
				cin>>map[i][j];
			}
		}
		cout<<"输入地图名\n";
		cin>>s;
		Save(s);
	}
}

int main()
{
    menu();
	return 0;
}

qwq

原文
存档评论5 条抓取于