GMSSCRAFT 1.0 源代码
GMSS_Studio · · 个人记录
先Ctrl+A复制
再删去无用部分
#include<iostream>
#include<fstream>
#include<conio.h>
#include<time.h>
#include<windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
bool jd;
int map[101][201],x=50,y=100,bb[15];
void color(int corcorcor){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),corcorcor);
}
void pm(int mp){
if(mp==1){//空气
color(255);
cout<<" ";
}
if(mp==2){//泥土
color(102);
cout<<"██";
}
if(mp==3){//石头
color(136);
cout<<"██";
}
if(mp==4){//树木
color(246);
cout<<"||";
}
if(mp==5){//木板
color(246);
cout<<"==";
}
if(mp==6){//金子
color(142);
cout<<";:";
}
if(mp==7){//金块
color(142);
cout<<"██";
}
if(mp==8){//钻石
color(139);
cout<<":;";
}
if(mp==9){//钻块
color(139);
cout<<"██";
}
if(mp==10){//我
color(240);
cout<<"GM";
}
}
string getTime(){//该函数如需借鉴请先联系沙兴安
time_t timep;
time (&timep);
char tmp[74];
strftime(tmp, sizeof(tmp), "%m%d",localtime(&timep) );
return tmp;
}
string GetTime(){
time_t timep;
time (&timep);
char tmp[64];
strftime(tmp, sizeof(tmp), "%Y%m%d",localtime(&timep) );
return tmp;
}
bool end_day(){
string tmp=GetTime(),temp="20240101";
if(tmp>=temp){
cout<<"此版本过低,请更新";
getch();
return 1;
}
return 0;
}
bool fool_days(){
string tmp=getTime();
if(tmp=="0401"){
cout<<"你中招了,不允许打开游戏";
getch();
return 1;
}
return 0;
}
bool kd(char chars){
if(!KEY_DOWN(chars)) return 0;
else return 1;
}
void Line(string str){//该函数如需借鉴请先联系沙兴安
int i,l,w;
w=80;
l=str.length();
for(i=0;i<(w-l)/2;i++)
cout<<" ";
cout<<str<<endl;
return ;
}
void line(string str){//该函数如需借鉴请先联系沙兴安
int i,l,w;
w=80;
l=str.length();
for(i=0;i<(w-l)/2;i++)
cout<<" ";
cout<<str;
return ;
}
void havein(){
ifstream fin;
fin.open("GMSSCRAFT存档.gmssdata");
if(fin.fail()){
FILE *fp;
fp=fopen("GMSSCRAFT存档.gmssdata","wb");
fclose(fp);
return ;
}
fin>>x>>y;
fin>>jd;
for(int i=1;i<=100;i++){
for(int j=1;j<=200;j++){
fin>>map[i][j];
}
}
fin>>bb[2]>>bb[3]>>bb[4]>>bb[5]>>bb[6]>>bb[7]>>bb[8]>>bb[9];
}
void haveout(){
ofstream fout;
fout.open("GMSSCRAFT存档.gmssdata");
fout<<x<<" "<<y<<endl;
fout<<jd<<endl;
for(int i=1;i<=100;i++){
for(int j=1;j<=200;j++){
fout<<map[i][j]<<" ";
}
fout<<endl;
}
fout<<bb[2]<<" "<<bb[3]<<" "<<bb[4]<<" "<<bb[5]<<" "<<bb[6]<<" "<<bb[7]<<" "<<bb[8]<<" "<<bb[9]<<endl;
}
void Begin(){
SetConsoleTitle("GMSSCRAFT 1.0"); // 设置窗口的标题
havein();
return ;
}
void cls(){
system("cls");
return ;
}
void maps(int x,int y){
for(int i=max(x-5,1);i<=min(x+5,100);i++){
for(int j=max(y-15,1);j<=min(y+15,200);j++){
pm(map[i][j]);
}
cout<<endl;
}
return ;
}
void make(){
for(int i=1;i<=50;i++){
for(int j=1;j<=200;j++){
int rands=rand()%30+1;
if(rands>=2&&rands<=30){
map[i][j]=1;
}else{
map[i][j]=4;
}
}
}
for(int j=1;j<=200;j++){
map[51][j]=2;
}
for(int i=52;i<=64;i++){
for(int j=1;j<=200;j++){
map[i][j]=3;
}
}
for(int i=65;i<=100;i++){
for(int j=1;j<=200;j++){
int rands=rand()%30+1;
if(rands>=10&&rands<=30){
map[i][j]=3;
}else if(rands>=3){
map[i][j]=6;
}else{
map[i][j]=8;
}
}
}
}
void beibao(){
while(1){
color(240);
cls();
pm(2);
color(240);
cout<<" :"<<bb[2]<<endl;
pm(3);
color(240);
cout<<" :"<<bb[3]<<endl;
pm(4);
color(240);
cout<<" :"<<bb[4]<<endl;
pm(5);
color(240);
cout<<" :"<<bb[5]<<endl;
pm(6);
color(240);
cout<<" :"<<bb[6]<<endl;
pm(7);
color(240);
cout<<" :"<<bb[7]<<endl;
pm(8);
color(240);
cout<<" :"<<bb[8]<<endl;
pm(9);
color(240);
cout<<" :"<<bb[9]<<endl;
color(240);
cout<<"交换:\n";
cout<<"1 - 一个 ";
pm(4);
color(240);
cout<<" → 四个 ";
pm(5);
color(240);
if(bb[4]>=1){
cout<<" 可交换";
}
cout<<"\n2 - 九个 ";
color(240);
pm(6);
color(240);
cout<<" → 一个 ";
color(240);
pm(7);
color(240);
if(bb[6]>=9){
cout<<" 可交换";
}
cout<<"\n3 - 九个 ";
color(240);
pm(8);
color(240);
cout<<" → 一个 ";
color(240);
pm(9);
color(240);
if(bb[8]>=9){
cout<<" 可交换";
}
cout<<"\nEsc - 退出";
char ccc;
ccc=getch();
if(ccc=='1'){
if(bb[4]>=1){
bb[4]--;
bb[5]+=4;
}
}
if(ccc=='2'){
if(bb[6]>=9){
bb[6]-=9;
bb[7]++;
}
}
if(ccc=='3'){
if(bb[8]>=9){
bb[8]-=9;
bb[9]++;
}
}
if(ccc==27){
break ;
}
}
return ;
}
void play(){
if(jd==0){
jd=1;
make();
}
bool moshi=0;
int xuanzhong=2;
for( ; ; ){
color(240);
cls();
map[x][y]=10;
maps(x,y);
color(240);
cout<<"模式:";
if(!moshi){
cout<<"修建 ";
}else{
cout<<"破坏 ";
}
cout<<"J - 切换模式 P - 退出\n";
pm(2);
color(240);
cout<<" :"<<bb[2]<<endl;
pm(3);
color(240);
cout<<" :"<<bb[3]<<endl;
pm(4);
color(240);
cout<<" :"<<bb[4]<<endl;
pm(5);
color(240);
cout<<" :"<<bb[5]<<endl;
pm(6);
color(240);
cout<<" :"<<bb[6]<<endl;
pm(7);
color(240);
cout<<" :"<<bb[7]<<endl;
pm(8);
color(240);
cout<<" :"<<bb[8]<<endl;
pm(9);
color(240);
cout<<" :"<<bb[9]<<endl;
cout<<"选中方块:";
pm(xuanzhong);
color(240);
char gh;
gh=getch();
if(gh=='W'||gh=='w'){
if(x-1>=1&&map[x-1][y]==1){
map[x][y]=1;
x--;
}
}
if(gh=='S'||gh=='s'){
if(x+1<=100&&map[x+1][y]==1){
map[x][y]=1;
x++;
}
}
if(gh=='A'||gh=='a'){
if(y-1>=1&&map[x][y-1]==1){
map[x][y]=1;
y--;
}
}
if(gh=='D'||gh=='d'){
if(y+1<=200&&map[x][y+1]==1){
map[x][y]=1;
y++;
}
}
if(gh=='U'||gh=='u'){
xuanzhong--;
}
if(gh=='I'||gh=='i'){
xuanzhong++;
}
if(xuanzhong>9||xuanzhong<2){
xuanzhong=2;
}
if(gh=='P'||gh=='p'){
return ;
}
if(gh=='J'||gh=='j'){
moshi=!moshi;
}
if(moshi){
if(gh=='T'||gh=='t'){
bb[map[x-1][y]]++;
map[x-1][y]=1;
}
if(gh=='G'||gh=='g'){
bb[map[x+1][y]]++;
map[x+1][y]=1;
}
if(gh=='F'||gh=='f'){
bb[map[x][y-1]]++;
map[x][y-1]=1;
}
if(gh=='H'||gh=='h'){
bb[map[x][y+1]]++;
map[x][y+1]=1;
}
}else{
if(bb[xuanzhong]>=1){
if(gh=='T'||gh=='t'){
if(map[x-1][y]==1){
map[x-1][y]=xuanzhong;
bb[xuanzhong]--;
}
}
if(gh=='G'||gh=='g'){
if(map[x+1][y]==1){
map[x+1][y]=xuanzhong;
bb[xuanzhong]--;
}
}
if(gh=='F'||gh=='f'){
if(map[x][y-1]==1){
map[x][y-1]=xuanzhong;
bb[xuanzhong]--;
}
}
if(gh=='H'||gh=='h'){
if(map[x][y+1]==1){
map[x][y+1]=xuanzhong;
bb[xuanzhong]--;
}
}
}
}
if(gh=='E'||gh=='e'){
beibao();
}
}
}
void GC_main(){
color(240);
for( ; ; ){
cls();
Line("GGGGGG MM MM SSSSSS SSSSSS SSSSSS RRRRRR AA FFFFFF FFFFFF");
Line("GG MMMM MMMM SS SS SS RR RR AA AA FF FF");
Line("GG GG MM MM MM SSSSSS SSSSSS SS RRRRRR AAAAAA FFFFFF FF");
Line("GG GG MM MM SS SS SS RRRR AA AA FF FF");
Line("GGGGGG MM MM SSSSSS SSSSSS SSSSSS RR RR AA AA FF FF");
cout<<endl<<endl;
// Line("G - 个人中心");
// cout<<endl;
Line("K - 开始游戏");
cout<<endl;
Line("R - 人工客服");
cout<<endl;
Line("G - 官方动态");
cout<<endl;
Line("O - 退出");
// if(kd('G')||kd('g')){
// center();
// }
if(kd('K')||kd('k')){
play();
}
if(kd('R')||kd('R')){
system("start https://www.luogu.com.cn/chat?uid=779246");
}
if(kd('G')||kd('g')){
system("start https://779246.blog.luogu.org/#");
}
if(kd('O')||kd('o')){
return ;
}
Sleep(100);
}
GC_main();
}
void End(){
haveout();
}
int main(){
atexit(haveout);//如果退出,自动保存
if(end_day()){
return 0;
}
if(fool_days()){
return 0;
}
Begin();
GC_main();//总函数
End();
return 0;
}