一个小游戏(未完成,招收人写故事线)
RT,为了防颓废,挖个坑(尽管这就是颓废)
刚写好地图保存。故事线还木有>_<,招人写故事线。
刚写好地图存储读取,具体操作明天写。
#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