C++的移动游戏第一版,想要中文版的在评论区里和我说!
#include<iostream>
#include<string>
#include<windows.h>
#include<cstdlib>
#include<time.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
class display{
public:
void JC();
void game_page();
};
string G_name=" Mobile Code_t",map[21][31];
void Initialization();
void ShowCursor(bool visible){
CONSOLE_CURSOR_INFO cursor_info={20,visible};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}
void gotoxy(int x,int y){
int xx=0x0b;
HANDLE hOutput;
COORD loc;
loc.X=x;
loc.Y=y;
hOutput=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOutput,loc);
}
void creation_move(){
display d;
int x=1,y=1;
Initialization();
system("cls");
system("color 8");
while(1){
if(KEY_DOWN('N')){
d.game_page();
}
gotoxy(0,0);
if(KEY_DOWN('W')&&(y-1)!=0) y--;
if(KEY_DOWN('S')&&(y+1)!=21) y++;
if(KEY_DOWN('A')&&(x-1)!=0) x--;
if(KEY_DOWN('D')&&(x+1)!=31) x++;
if(KEY_DOWN('I')&&x!=1&&y!=1) map[y][x]='I';
for(int i=1;i<=20;i++){
for(int j=1;j<=30;j++){
if(y==i&&j==x) cout<<'A';
else cout<<map[i][j];
}
cout<<endl;
}
Sleep(40);
}
}
void display::game_page(){
system("cls");
system("color 1");
printf(
" Mobile Code_t\n"
"\n"
" 1.Creation mode(only)\n"
"\n"
" Press i"
);
while(1){
if(KEY_DOWN('I')){
creation_move();
}
}
}
void move_JC(){
system("color 8");
printf(
" First, press the wasd key to move up\n"
",down, left, right . Press n to exit\n"
);
int x=1,y=x;
ShowCursor(false);
while(1){
if(KEY_DOWN('N')){
break;
}
gotoxy(0,3);
if(KEY_DOWN('W')) y--;
if(KEY_DOWN('S')) y++;
if(KEY_DOWN('A')) x--;
if(KEY_DOWN('D')) x++;
for(int i=1;i<=20;i++){
for(int j=1;j<=30;j++){
if(y==i&&j==x) cout<<'A';
else cout<<map[i][j];
}
cout<<endl;
}
Sleep(40);
}
system("cls");
printf(
"Press the I key to generate walls.\n"
);
cout<<endl;
x=y=1;
while(1){
if(KEY_DOWN('N')){
break;
}
gotoxy(0,2);
if(KEY_DOWN('W')) y--;
if(KEY_DOWN('S')) y++;
if(KEY_DOWN('A')) x--;
if(KEY_DOWN('D')) x++;
if(KEY_DOWN('I')&&x!=1&&y!=1) map[y][x]='I';
for(int i=1;i<=20;i++){
for(int j=1;j<=30;j++){
if(y==i&&j==x) cout<<'A';
else cout<<map[i][j];
}
cout<<endl;
}
Sleep(40);
}
system("cls");
printf(
"To prevent players from rushing out of\nthe boundary, add a boundary system\n"
);
cout<<endl;
x=y=1;
while(1){
if(KEY_DOWN('N')){
break;
}
gotoxy(0,2);
if(KEY_DOWN('W')&&(y-1)!=0) y--;
if(KEY_DOWN('S')&&(y+1)!=21) y++;
if(KEY_DOWN('A')&&(x-1)!=0) x--;
if(KEY_DOWN('D')&&(x+1)!=31) x++;
if(KEY_DOWN('I')&&x!=1&&y!=1) map[y][x]='I';
for(int i=1;i<=20;i++){
for(int j=1;j<=30;j++){
if(y==i&&j==x) cout<<'A';
else cout<<map[i][j];
}
cout<<endl;
}
Sleep(40);
}
system("cls");
printf(
"Add anti-collision wall system.\n"
);
cout<<endl;
x=y=1;
while(1){
if(KEY_DOWN('N')){
break;
}
gotoxy(0,2);
if(KEY_DOWN('W')&&(y-1)!=0&&map[y-1][x]!="I") y--;
if(KEY_DOWN('S')&&(y+1)!=21&&map[y+1][x]!="I") y++;
if(KEY_DOWN('A')&&(x-1)!=0&&map[y][x-1]!="I") x--;
if(KEY_DOWN('D')&&(x+1)!=31&&map[y][x+1]!="I") x++;
if(KEY_DOWN('I')&&x!=1&&y!=1) map[y][x]='I';
for(int i=1;i<=20;i++){
for(int j=1;j<=30;j++){
if(y==i&&j==x) cout<<'A';
else cout<<map[i][j];
}
cout<<endl;
}
Sleep(40);
}
system("cls");
system("color 6");
printf(
"Game is start !"
);
Sleep(1000);
}
void display::JC(){
display d;
system("color 1");
printf(
"\n"
" Whether to enter the tutorial ?\n"
"\n"
" Y:enter N:exit"
);
while(1){
if(KEY_DOWN('Y')){
system("cls");
move_JC();
}else if(KEY_DOWN('N')){
d.game_page();
}
}
}
void show(){
system("color 4");
while(1){
ShowCursor(false);
if(KEY_DOWN('I')) break;
int p=rand()%(25-13+1)+13;
cout<<endl<<endl;
for(int i=0;i<=25;i++){
if(i==p){
cout<<' ';
continue;
}
cout<<G_name[i];
}
cout<<endl<<endl<<" press i 1.5 (m) to enter the game";
Sleep(30);
gotoxy(0,0);
}
system("cls");
display d;
d.JC();
}
int main(){
srand(time(NULL));
/*Initialization*/{
Initialization();
gotoxy(0,0);
}
/*reproduction and move*/{
show();
}
return 0;
}
void Initialization(){
for(int i=1;i<=20;i++){
for(int j=1;j<=30;j++){
map[i][j]=".";
}
}
}
/*
符号 表示颜色 符号 表示颜色
0 黑色 8 灰色
1 蓝色 9 淡蓝色
2 绿色 A 淡绿色
3 浅绿色 B 淡浅绿色
4 红色 C 淡红色
5 紫色 D 淡紫色
6 黄色 E 淡黄色
7 白色 F 亮白色
*/