首先是main.cpp
#include"AllCallFun.h"
using namespace std;
int map[105][105],n,m,x,y;
void clocks(int map[][105],int n,int m,int x,int y);
void create(int map[][105],int n,int m,int x,int y);
int main() {
system("mode con cols=1920 lines=1080");
system("color 02");
cout<<endl<<endl<<endl;
cout<<" 欢迎来到不一样的泰拉瑞亚~"<<endl;
cout<<" ---By 昊树cute"<<endl;
system("pause");
system("cls");
for(int i=1; i<=10; i++) {
cout<<" 正在加载中"<<endl;
cout<<" __________"<<endl;
cout<<" ";
for(int j=1; j<=i; j++) {
cout<<"=";
}
Sleep(100);
system("cls");
}
system("cls");
system("color 90");
cout<<"请选择场地大小(格式:长 高)(最大1000*1000):";
l:
cin>>n>>m;
if(n>100||m>10) {
cout<<"过大,请重新输入:";
goto l;
} else {
system("cls");
cout<<" 加载世界中..."<<endl;
for(int i=1; i<=10; i++) {
for(int j=1; j<=25; j++) {
cout<<"▉";
Sleep(5);
}
cout<<endl;
}
Sleep(500);
system("cls");
cout<<" 加载完成!"<<endl;
Sleep(500);
create(map,n,m,x,y);
clocks(map,n,m,x,y);
}
return 0;
}
AllCallFun.h
#ifndef _COMMON
#define _COMMON
#include<string>
#include<stdlib.h>
#include<iostream>
#include<stdio.h>
#include<windows.h>
#include"test_color.h"
#include"map_print.h"
#include"control_clock.h"
#include"world_creat.h"
#endif
control_clock.h
#ifndef _COMMON
#define _COMMON
#include<iostream>
#include"map_print.h"
using namespace std;
void print(int map[][105],int n,int m,int x,int y);
void clocks(int map[][105],int n,int m,int x,int y) {
char c;
while(cin>>c) {
if(c=='d'||c=='D') {
if(x+1<=n) {
x++;
}
if(map[x][y]!=0) {
x--;
}
print(map,n,m,x,y);
}
if(c=='a'||c=='A') {
if(x-1>=1) {
x--;
}
if(map[x][y]!=0) {
x++;
}
print(map,n,m,x,y);
}
if(c=='w'||c=='W') {
if(y+1<=m) {
y++;
}
if(map[x][y]!=0) {
y--;
}
print(map,n,m,x,y);
}
if(c=='s'||c=='S') {
if(y-1>=1) {
y--;
}
if(map[x][y]!=0) {
y++;
}
print(map,n,m,x,y);
}
if(c=='e'||c=='E') {
//
}
}
}
#endif
world_creat.h
#ifndef _COMMON
#define _COMMON
#include<stdlib.h>
void create(int map[][105],int n,int m,int x,int y) {
x=1,y=1;
for(int i=100-m; i<=100; i++) {
for(int j=1; j<=n; j++) {
map[i][j]=rand()%10;
}
}
}
#endif
map_print.h
#ifndef _COMMON
#define _COMMON
#include<iostream>
#include"test_color.h"
#include<stdio.h>
#include <windows.h>
using namespace std;
void color(const unsigned short textColor);
void print(int map[][105],int n,int m,int x,int y) {
for(int i=1; i<=20-m; i++) {
cout<<endl;
}
for(int i=1; i<=n; i++) {
for(int j=1; j<=m; j++) {
if(map[i][j]!=0) {
color(j);
cout<<map[i][j];
}
}
cout<<endl;
}
}
#endif
test_color.h
#ifndef _COMMON
#define _COMMON
#include<stdio.h>
#include<windows.h>
void color(const unsigned short textColor) {
if(textColor>=0 && textColor<=15) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), textColor);
} else {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
}
}
#endif