C++游戏制作入门小游戏(迷宫)此篇只适用于新手

  • 最近有些无聊,于是翻了翻以前的代码,找到了之前第一次编的游戏,想起以前学完C++无从下手的感觉,就把它加了点备注,当做一篇入门教程发出来了。
  • 这是用DevC++写的,参考自一位大佬写的贪吃蛇。

下面上图

C++游戏制作入门小游戏(迷宫)此篇只适用于新手_第1张图片PS:开始界面我现在看来是相当的丑_φ(❐_❐✧
C++游戏制作入门小游戏(迷宫)此篇只适用于新手_第2张图片
好吧菜单也不是很好看(/"≡ _ ≡)/~┴┴
C++游戏制作入门小游戏(迷宫)此篇只适用于新手_第3张图片

下面是具体步骤:

1:打开你的编程软件,新建项目Console Application

C++游戏制作入门小游戏(迷宫)此篇只适用于新手_第4张图片
C++游戏制作入门小游戏(迷宫)此篇只适用于新手_第5张图片
2:将各个.h和.cpp的文件加入项目
C++游戏制作入门小游戏(迷宫)此篇只适用于新手_第6张图片
3:编译运行即可,不过我仅在DevC++的C++11标准下运行调试过,另外应该有不少在用VC6.0的朋友,VC6是没有C++11标准的,别试了。(记得把自己的编译器调成C++11标准)

准备完成,接下来让我们看代码吧

main.cpp

#include "controller.h"

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	Controller c;//构造类Controller 
	c.Game();//游戏开始
	return 0;
}

controller.h

#ifndef CONTROLLER_H//#ifndef排除重名 
#define CONTROLLER_H//定义头文件名 

class Controller
{
	public:
		Controller(){}
		
		void Start();
		void Game();
		int Menu();			
};

#endif//CONTROLLER_H

controller.cpp

#include "controller.h"
#include "tools.h"
#include "map.h"
#include "ball.h"
#include "picture.h"

#include 
#include 
#include 
#include 

#define Mapamount 2//地图总数 

void Controller::Start()//开始游戏界面 
{
	SetWindowSize(40,30);//设置40*30的界面窗口(此为定义函数,具体在tools类中,下同) 
	SetColor(3);//字体颜色为湖蓝色 
	
	Picture *start=new Picture();//创造动态Picture类 
	start->PrintStart();//开始动画 
	delete start;//释放start 
	
	SetCursorPosition(14,23);//改变光标位置,此后不在重复提起 
	SetColor(4);//字体颜色为红色 
	system("pause");
}

void Controller::Game()//游戏开始 
{
	char ch;
	int key,MapId;//key为菜单选项,MapId为地图序号 
		
	Controller *menu=new Controller();//创造动态Controller类 
	Ball *ball=new Ball();//创造动态Ball类 
	Picture *interface1=new Picture();//创造动态Picture类(ps:interface是系统变量,无法声明) 
	
	Start();//游戏开始界面 
	MapId=1;//初始化地图ID 
    
	while(true)//在选择退出游戏前无限循环 
	{
	    Map *map=new Map();//创造动态Map类
		
		system("color 70");//黑字白底 
		system("cls");//清除开始界面 
		
		if(key==3) 
		{
			MapId=rand()%Mapamount+1;//在已有地图中随机生成一个 
		}
		map->PrintInitmap();//打印初始地图 
		
		switch(MapId)//选择地图 
		{
			case 1:
			{	
				map->PrintMap1();
		        break;
			}
			case 2:
			{
				map->PrintMap2();
				break; 
			}
			default:
				break;
		}
		Point *Endpoint=new Point(map->endpoint.GetX(),map->endpoint.GetY());//设置一个记录结束点指针判断是否到达终点 

		ball->GetWall(map,MapId);//在球中记录表示墙的点 
		ball->ChangeBall(map->startpoint.GetX(),map->startpoint.GetY());//初始化球的坐标 
		
		delete map;//释放map 
		
	    interface1->PrintInterface1();//打印菜单界面 
	      
	    SetCursorPosition(39,28);//不让光标影响游戏
		key=ball->Move(menu,Endpoint);
		/*此处设计不合理,因不影响游戏,所以太懒不想改 
		   在球的移动函数里调用菜单函数,返回key来决定是否更改地图*/ 

		delete Endpoint;//释放Endpoint 	
	}
	delete menu,ball,interface1;//释放menu,ball,interface1
}

int Controller::Menu()//菜单函数 
{	
    char ch;	
	int key=1;//初始化菜单选项 
	
	for(;ch!=13;)//通过回车来取消循环 
	{ 	
		switch(key)
		{
			case 1:
			{
				SetColor(2);//表示选中(绿字黑底) 
				
				SetCursorPosition(32,16);
	            std::cout<<"1:继续游戏";
	            
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
				FOREGROUND_INTENSITY|FOREGROUND_RED|
	            BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE);//取消选中(红字白底) 
	            
	            SetCursorPosition(32,19);
				std::cout<<"2:重新开始";
				
				SetCursorPosition(32,22);
				std::cout<<"3:更换地图";
	            
	            SetCursorPosition(32,25);
				std::cout<<"4:退出游戏";
	            break;
			}
			case 2:
			{
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
				FOREGROUND_INTENSITY|FOREGROUND_RED|
	            BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE);//取消选中
				
				SetCursorPosition(32,16);
	            std::cout<<"1:继续游戏";
	            
	            SetColor(2);//表示选中 
	            
	            SetCursorPosition(32,19);
				std::cout<<"2:重新开始";
				
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
				FOREGROUND_INTENSITY|FOREGROUND_RED|
	            BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE);//取消选中
	            
	            SetCursorPosition(32,22);
	            std::cout<<"3:更换地图";
	            
				SetCursorPosition(32,25);
				std::cout<<"4:退出游戏";
				break; 
			}
			case 3:
			{
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
				FOREGROUND_INTENSITY|FOREGROUND_RED|
	            BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE);//取消选中
	            
				SetCursorPosition(32,16);
	            std::cout<<"1:继续游戏";
	            
	            SetCursorPosition(32,19);
				std::cout<<"2:重新开始";
				
				SetColor(2);//表示选中 
				
				SetCursorPosition(32,22);
	            std::cout<<"3:更换地图";
	            
	            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
				FOREGROUND_INTENSITY|FOREGROUND_RED|
	            BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE);//取消选中
	            
	            SetCursorPosition(32,25);
				std::cout<<"4:退出游戏";
	            break;
			}
			case 4:
			{
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
				FOREGROUND_INTENSITY|FOREGROUND_RED|
	            BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE);//取消选中
	            
				SetCursorPosition(32,16);
	            std::cout<<"1:继续游戏";
	            
	            SetCursorPosition(32,19);
				std::cout<<"2:重新开始";
				
				SetCursorPosition(32,22);
	            std::cout<<"3:更换地图";
	            
	            SetColor(2);//表示选中 
	            
				SetCursorPosition(32,25);
				std::cout<<"4:退出游戏";
				break; 
			}
			default:
				break;
		}
		ch=getch();
		/*此处说明:键入上下左右键会出现两个ascii码值
		  分别为上:224,72 下:224,80 左:224,75 右:224,77*/
		
		switch(ch)
		{
			case -32:
			{
				ch=getch();
				switch(ch)
				{
					case 72://上移 
					{
						if(key!=1)
							key--;
						else
						    key=4;//超过上限,循环 
						break;	
					}
					case 80://下移 
					{
							
						if(key!=4)
							key++;
						else
						    key=1;//超过下限,循环 
						break;
				    }
				    default:
				    	break;
				}
			}
			default:
				break;
		}
	}
	
	switch(key)//各菜单选项的实现 
	{
		case 1:
		{
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
	        FOREGROUND_INTENSITY|FOREGROUND_RED|
	        BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE);//取消选中 
	
	        SetCursorPosition(32,16);
 	        std::cout<<"1:继续游戏";
            break;
		}
		case 2:
			system("cls");//清除屏幕,重新开始 
			return 2;
		case 3:
			return 3;
		case 4:
		{
			system("cls");
			exit(0);//退出游戏 
		}		
		default:
			break;
	}
	return key;	
}

map.h

#ifndef MAP_H
#define MAP_H

#include "point.h"

#include //不知道的童鞋请百度具体用法 

class Map
{    
	public:
		Map()
		{
			int i,j;
			
			for(i=0;i<=29;i+=29)//利用双重循环向initmap压入各点 
				for(j=0;j<=29;j++)
					initmap.emplace_back(Point(i,j));
					
			for(i=1;i<=28;i++)
			    for(j=0;j<=29;j+=29)
			        initmap.emplace_back(Point(i,j));
		}
		Point startpoint,endpoint;//记录初始点与终点 
		
	    void PrintInitmap();
		void PushMap1();
		void PushMap2();
		void PrintMap1();
		void PrintMap2();
	private:
		std::vector<Point> initmap;
		std::vector<Point> map1;
		std::vector<Point> map2;
		/*这里可以加入新的地图,本项目只演示两张
		(ps:地图其实可以用遍历算法得到,因这里是入门讲解,不做讨论)*/ 
	friend class Ball;//让小球可以调用地图 
 };
 
 #endif//MAP_H

map.cpp

#include "map.h"
#include "tools.h" 
#include "point.h"

#include 

void Map::PrintInitmap()//打印初始地图 
{
	for(auto &point :initmap)
	{
		SetColor(0);//黑字黑底:打印墙 
		point.PrintSquare();//打印方块(ps:为了整齐划,字符还是用的方块,其实不需要) 
		Sleep(10);//利用打印时延来营造动画效果,下同 
	}
}

void Map::PrintMap1()//打印地图一 
{
	PushMap1();//map1中压入各点 
	
	for(auto &point :map1)//不知道auto在for循环中使用的自行百度 
    {
		point.PrintSquare();//打印方块 
		Sleep(10);
	}
	
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
	FOREGROUND_INTENSITY|FOREGROUND_RED|
	BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE);//红字白底 
	
	startpoint.ChangePoint(3,28);
	startpoint.PrintCircular();//打印小初始点 
	endpoint.ChangePoint(28,14);
	endpoint.PrintSquare();//打印 终点 
}

void Map::PrintMap2()//打印地图二 
{
	PushMap2();//map2中压入各点 
	
	for(auto &point :map2)
    {
		point.PrintSquare();
		Sleep(0);
	}
	
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
	FOREGROUND_INTENSITY|FOREGROUND_RED|
	BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE);//红字白底 
	
	startpoint.ChangePoint(1,7); 
	startpoint.PrintCircular();
	endpoint.ChangePoint(28,18);
	endpoint.PrintSquare();
}

/*压入地图一中各点(ps:此处过于繁琐,只用作讲解,各位看官可以无视,
以下代码仅仅是将各点一个个输入map数组中,感兴趣童靴自行百度如何生成迷宫地图)*/
void Map::PushMap1()
{
	map1.clear();
    map1.emplace_back(Point(1,28));
	map1.emplace_back(Point(1,24));
    map1.emplace_back(Point(1,23));
	map1.emplace_back(Point(1,12));
	map1.emplace_back(Point(1,11));
	map1.emplace_back(Point(1,2));
	map1.emplace_back(Point(2,4));
	map1.emplace_back(Point(2,5));
	map1.emplace_back(Point(2,6));
	map1.emplace_back(Point(2,8));
	map1.emplace_back(Point(2,9));
	map1.emplace_back(Point(2,14));
	map1.emplace_back(Point(2,16));
	map1.emplace_back(Point(2,17));
	map1.emplace_back(Point(2,18));
	map1.emplace_back(Point(2,19));
	map1.emplace_back(Point(2,20));
	map1.emplace_back(Point(2,21));
	map1.emplace_back(Point(2,23));
	map1.emplace_back(Point(2,26));
	map1.emplace_back(Point(2,28));
	map1.emplace_back(Point(3,2));
	map1.emplace_back(Point(3,3));
	map1.emplace_back(Point(3,4));
	map1.emplace_back(Point(3,6));
	map1.emplace_back(Point(3,7));
	map1.emplace_back(Point(3,8));
	map1.emplace_back(Point(3,9));
	map1.emplace_back(Point(3,10));
	map1.emplace_back(Point(3,11));
	map1.emplace_back(Point(3,12));
	map1.emplace_back(Point(3,13));
	map1.emplace_back(Point(3,14));
	map1.emplace_back(Point(3,15));
	map1.emplace_back(Point(3,16));
	map1.emplace_back(Point(3,20));
	map1.emplace_back(Point(3,25));
	map1.emplace_back(Point(3,26));
	map1.emplace_back(Point(4,10));
	map1.emplace_back(Point(4,16));
	map1.emplace_back(Point(4,18));
	map1.emplace_back(Point(4,19));
	map1.emplace_back(Point(4,20));
	map1.emplace_back(Point(4,21));
	map1.emplace_back(Point(4,22));
	map1.emplace_back(Point(4,23));
	map1.emplace_back(Point(4,25));
	map1.emplace_back(Point(4,28));
	map1.emplace_back(Point(5,1));
	map1.emplace_back(Point(5,2));
	map1.emplace_back(Point(5,3));
	map1.emplace_back(Point(5,4));
	map1.emplace_back(Point(5,5));
	map1.emplace_back(Point(5,6));
	map1.emplace_back(Point(5,7));
	map1.emplace_back(Point(5,8));
	map1.emplace_back(Point(5,10));
	map1.emplace_back(Point(5,12));
	map1.emplace_back(Point(5,13));
	map1.emplace_back(Point(5,14));
	map1.emplace_back(Point(5,16));
	map1.emplace_back(Point(5,18));
	map1.emplace_back(Point(5,23));
	map1.emplace_back(Point(5,25));
	map1.emplace_back(Point(5,27));
	map1.emplace_back(Point(5,28));
	map1.emplace_back(Point(6,1));
	map1.emplace_back(Point(6,5));
	map1.emplace_back(Point(6,10));
	map1.emplace_back(Point(6,12));
	map1.emplace_back(Point(6,16));
	map1.emplace_back(Point(6,20));
	map1.emplace_back(Point(6,21));
	map1.emplace_back(Point(6,25));
	map1.emplace_back(Point(7,3));
	map1.emplace_back(Point(7,7));
	map1.emplace_back(Point(7,8));
	map1.emplace_back(Point(7,10));
	map1.emplace_back(Point(7,12));
	map1.emplace_back(Point(7,14));
	map1.emplace_back(Point(7,15));
	map1.emplace_back(Point(7,16));
	map1.emplace_back(Point(7,17));
	map1.emplace_back(Point(7,18));
	map1.emplace_back(Point(7,19));
	map1.emplace_back(Point(7,20));
	map1.emplace_back(Point(7,23));
	map1.emplace_back(Point(7,24));
	map1.emplace_back(Point(7,25));
	map1.emplace_back(Point(7,27));
	map1.emplace_back(Point(8,2));
	map1.emplace_back(Point(8,3));
	map1.emplace_back(Point(8,4));
	map1.emplace_back(Point(8,5));
	map1.emplace_back(Point(8,6));
	map1.emplace_back(Point(8,7));
	map1.emplace_back(Point(8,10));
	map1.emplace_back(Point(8,12));
	map1.emplace_back(Point(8,14));
	map1.emplace_back(Point(8,20));
	map1.emplace_back(Point(8,21));
	map1.emplace_back(Point(8,22));
	map1.emplace_back(Point(8,23));
	map1.emplace_back(Point(8,27));
	map1.emplace_back(Point(9,8));
	map1.emplace_back(Point(9,10));
	map1.emplace_back(Point(9,12));
	map1.emplace_back(Point(9,16));
	map1.emplace_back(Point(9,17));
	map1.emplace_back(Point(9,18));
	map1.emplace_back(Point(9,23));
	map1.emplace_back(Point(9,25));
	map1.emplace_back(Point(9,26));
	map1.emplace_back(Point(9,27));
	map1.emplace_back(Point(10,1));
	map1.emplace_back(Point(10,2));
	map1.emplace_back(Point(10,3));
	map1.emplace_back(Point(10,4));
	map1.emplace_back(Point(10,5));
	map1.emplace_back(Point(10,7));
	map1.emplace_back(Point(10,8));
	map1.emplace_back(Point(10,10));
	map1.emplace_back(Point(10,12));
	map1.emplace_back(Point(10,13));
	map1.emplace_back(Point(10,14));
	map1.emplace_back(Point(10,16));
	map1.emplace_back(Point(10,18));
	map1.emplace_back(Point(10,19));
	map1.emplace_back(Point(10,20));
	map1.emplace_back(Point(10,21));
	map1.emplace_back(Point(10,25));
	map1.emplace_back(Point(11,4));
	map1.emplace_back(Point(11,8));
	map1.emplace_back(Point(11,10));
	map1.emplace_back(Point(11,14));
	map1.emplace_back(Point(11,15));
	map1.emplace_back(Point(11,16));
	map1.emplace_back(Point(11,18));
	map1.emplace_back(Point(11,21));
	map1.emplace_back(Point(11,22));
	map1.emplace_back(Point(11,23));
	map1.emplace_back(Point(11,24));
	map1.emplace_back(Point(11,25));
	map1.emplace_back(Point(11,27));
	map1.emplace_back(Point(12,2));
	map1.emplace_back(Point(12,6));
	map1.emplace_back(Point(12,8));
	map1.emplace_back(Point(12,10));
	map1.emplace_back(Point(12,11));
	map1.emplace_back(Point(12,12));
	map1.emplace_back(Point(12,20));
	map1.emplace_back(Point(12,27));
	map1.emplace_back(Point(13,2));
	map1.emplace_back(Point(13,3));
	map1.emplace_back(Point(13,4));
	map1.emplace_back(Point(13,6));
	map1.emplace_back(Point(13,7));
	map1.emplace_back(Point(13,10));
	map1.emplace_back(Point(13,14));
	map1.emplace_back(Point(13,15));
	map1.emplace_back(Point(13,16));
	map1.emplace_back(Point(13,17));
	map1.emplace_back(Point(13,18));
	map1.emplace_back(Point(13,20));
	map1.emplace_back(Point(13,21));
	map1.emplace_back(Point(13,22));
	map1.emplace_back(Point(13,23));
	map1.emplace_back(Point(13,24));
	map1.emplace_back(Point(13,25));
	map1.emplace_back(Point(13,26));
	map1.emplace_back(Point(13,27));
	map1.emplace_back(Point(14,3));
	map1.emplace_back(Point(14,7));
	map1.emplace_back(Point(14,9));
	map1.emplace_back(Point(14,10));
	map1.emplace_back(Point(14,12));
	map1.emplace_back(Point(14,13));
	map1.emplace_back(Point(14,14));
	map1.emplace_back(Point(14,18));
	map1.emplace_back(Point(14,22));
	map1.emplace_back(Point(15,2));
	map1.emplace_back(Point(15,3));
	map1.emplace_back(Point(15,4));
	map1.emplace_back(Point(15,5));
	map1.emplace_back(Point(15,7));
	map1.emplace_back(Point(15,10));
	map1.emplace_back(Point(15,16));
	map1.emplace_back(Point(15,18));
	map1.emplace_back(Point(15,19));
	map1.emplace_back(Point(15,20));
	map1.emplace_back(Point(15,22));
	map1.emplace_back(Point(15,23));
	map1.emplace_back(Point(15,24));
	map1.emplace_back(Point(15,25));
	map1.emplace_back(Point(15,26));
	map1.emplace_back(Point(15,27));
	map1.emplace_back(Point(16,5));
	map1.emplace_back(Point(16,7));
	map1.emplace_back(Point(16,8));
	map1.emplace_back(Point(16,9));
	map1.emplace_back(Point(16,10));
	map1.emplace_back(Point(16,12));
	map1.emplace_back(Point(16,13));
	map1.emplace_back(Point(16,14));
	map1.emplace_back(Point(16,15));
	map1.emplace_back(Point(16,16));
	map1.emplace_back(Point(16,20));
	map1.emplace_back(Point(16,26));
	map1.emplace_back(Point(17,1));
	map1.emplace_back(Point(17,2));
	map1.emplace_back(Point(17,3));
	map1.emplace_back(Point(17,5));
	map1.emplace_back(Point(17,6));
	map1.emplace_back(Point(17,16));
	map1.emplace_back(Point(17,17));
	map1.emplace_back(Point(17,18));
	map1.emplace_back(Point(17,20));
	map1.emplace_back(Point(17,21));
	map1.emplace_back(Point(17,22));
	map1.emplace_back(Point(17,23));
	map1.emplace_back(Point(17,24));
	map1.emplace_back(Point(17,27));
	map1.emplace_back(Point(17,28));
	map1.emplace_back(Point(18,6));
	map1.emplace_back(Point(18,7));
	map1.emplace_back(Point(18,8));
	map1.emplace_back(Point(18,9));
	map1.emplace_back(Point(18,10));
	map1.emplace_back(Point(18,11));
	map1.emplace_back(Point(18,12));
	map1.emplace_back(Point(18,13));
	map1.emplace_back(Point(18,14));
	map1.emplace_back(Point(18,18));
	map1.emplace_back(Point(18,25));
	map1.emplace_back(Point(19,2));
	map1.emplace_back(Point(19,3));
	map1.emplace_back(Point(19,4));
	map1.emplace_back(Point(19,5));
	map1.emplace_back(Point(19,6));
	map1.emplace_back(Point(19,10));
	map1.emplace_back(Point(19,14));
	map1.emplace_back(Point(19,16));
	map1.emplace_back(Point(19,19));
	map1.emplace_back(Point(19,20));
	map1.emplace_back(Point(19,21));
	map1.emplace_back(Point(19,22));
	map1.emplace_back(Point(19,23));
	map1.emplace_back(Point(19,24));
	map1.emplace_back(Point(19,25));
	map1.emplace_back(Point(19,26));
	map1.emplace_back(Point(19,27));
	map1.emplace_back(Point(20,2));
	map1.emplace_back(Point(20,8));
	map1.emplace_back(Point(20,10));
	map1.emplace_back(Point(20,12));
	map1.emplace_back(Point(20,14));
	map1.emplace_back(Point(20,16));
	map1.emplace_back(Point(20,17));
	map1.emplace_back(Point(20,25));
	map1.emplace_back(Point(20,27));
	map1.emplace_back(Point(21,2));
	map1.emplace_back(Point(21,4));
	map1.emplace_back(Point(21,5));
	map1.emplace_back(Point(21,6));
	map1.emplace_back(Point(21,7));
	map1.emplace_back(Point(21,8));
	map1.emplace_back(Point(21,10));
	map1.emplace_back(Point(21,12));
	map1.emplace_back(Point(21,16));
	map1.emplace_back(Point(21,19));
	map1.emplace_back(Point(21,21));
	map1.emplace_back(Point(21,22));
	map1.emplace_back(Point(21,23));
	map1.emplace_back(Point(21,24));
	map1.emplace_back(Point(22,2));
	map1.emplace_back(Point(22,7));
	map1.emplace_back(Point(22,8));
	map1.emplace_back(Point(22,9));
	map1.emplace_back(Point(22,10));
	map1.emplace_back(Point(22,12));
	map1.emplace_back(Point(22,13));
	map1.emplace_back(Point(22,14));
	map1.emplace_back(Point(22,15));
	map1.emplace_back(Point(22,17));
	map1.emplace_back(Point(22,18));
	map1.emplace_back(Point(22,19));
	map1.emplace_back(Point(22,25));
	map1.emplace_back(Point(22,27));
	map1.emplace_back(Point(23,2));
	map1.emplace_back(Point(23,3));
	map1.emplace_back(Point(23,4));
	map1.emplace_back(Point(23,5));
	map1.emplace_back(Point(23,12));
	map1.emplace_back(Point(23,19));
	map1.emplace_back(Point(23,21));
	map1.emplace_back(Point(23,22));
	map1.emplace_back(Point(23,23));
	map1.emplace_back(Point(23,24));
	map1.emplace_back(Point(23,27));
	map1.emplace_back(Point(24,2));
	map1.emplace_back(Point(24,6));
	map1.emplace_back(Point(24,7));
	map1.emplace_back(Point(24,8));
	map1.emplace_back(Point(24,9));
	map1.emplace_back(Point(24,11));
	map1.emplace_back(Point(24,14));
	map1.emplace_back(Point(24,15));
	map1.emplace_back(Point(24,16));
	map1.emplace_back(Point(24,17));
	map1.emplace_back(Point(24,20));
	map1.emplace_back(Point(24,26));
	map1.emplace_back(Point(24,27));
	map1.emplace_back(Point(25,2));
	map1.emplace_back(Point(25,4));
	map1.emplace_back(Point(25,5));
	map1.emplace_back(Point(25,9));
	map1.emplace_back(Point(25,11));
	map1.emplace_back(Point(25,13));
	map1.emplace_back(Point(25,18));
	map1.emplace_back(Point(25,21));
	map1.emplace_back(Point(25,22));
	map1.emplace_back(Point(25,24));
	map1.emplace_back(Point(25,25));
	map1.emplace_back(Point(26,2));
	map1.emplace_back(Point(26,11));
	map1.emplace_back(Point(26,13));
	map1.emplace_back(Point(26,15));
	map1.emplace_back(Point(26,16));
	map1.emplace_back(Point(26,18));
	map1.emplace_back(Point(26,19));
	map1.emplace_back(Point(26,20));
	map1.emplace_back(Point(26,24));
	map1.emplace_back(Point(26,27));
	map1.emplace_back(Point(27,2));
	map1.emplace_back(Point(27,3));
	map1.emplace_back(Point(27,4));
	map1.emplace_back(Point(27,5));
	map1.emplace_back(Point(27,6));
	map1.emplace_back(Point(27,7));
	map1.emplace_back(Point(27,8));
	map1.emplace_back(Point(27,9));
	map1.emplace_back(Point(27,10));
	map1.emplace_back(Point(27,11));
	map1.emplace_back(Point(27,13));
	map1.emplace_back(Point(27,16));
	map1.emplace_back(Point(27,22));
	map1.emplace_back(Point(27,23));
	map1.emplace_back(Point(27,25));
	map1.emplace_back(Point(27,26));
	map1.emplace_back(Point(27,27));
	map1.emplace_back(Point(28,13));
	map1.emplace_back(Point(28,15));
	map1.emplace_back(Point(28,18));
	map1.emplace_back(Point(28,19));
	map1.emplace_back(Point(28,21));
}

void Map::PushMap2()
{
	map2.clear();
	map2.emplace_back(Point(1,16));
	map2.emplace_back(Point(1,17));
	map2.emplace_back(Point(1,18));
	map2.emplace_back(Point(1,19));
	map2.emplace_back(Point(2,2));
	map2.emplace_back(Point(2,3));
	map2.emplace_back(Point(2,4));
	map2.emplace_back(Point(2,6));
	map2.emplace_back(Point(2,8));
	map2.emplace_back(Point(2,9));
	map2.emplace_back(Point(2,10));
	map2.emplace_back(Point(2,12));
	map2.emplace_back(Point(2,13));
	map2.emplace_back(Point(2,14));
	map2.emplace_back(Point(2,19));
	map2.emplace_back(Point(2,21));
	map2.emplace_back(Point(2,22));
	map2.emplace_back(Point(2,24));
	map2.emplace_back(Point(2,26));
	map2.emplace_back(Point(2,27));
	map2.emplace_back(Point(3,2));
	map2.emplace_back(Point(3,5));
	map2.emplace_back(Point(3,10));
	map2.emplace_back(Point(3,15));
	map2.emplace_back(Point(3,17));
	map2.emplace_back(Point(3,18));
	map2.emplace_back(Point(3,19));
	map2.emplace_back(Point(3,22));
	map2.emplace_back(Point(3,25));
	map2.emplace_back(Point(4,2));
	map2.emplace_back(Point(4,4));
	map2.emplace_back(Point(4,6));
	map2.emplace_back(Point(4,7));
	map2.emplace_back(Point(4,8));
	map2.emplace_back(Point(4,11));
	map2.emplace_back(Point(4,12));
	map2.emplace_back(Point(4,13));
	map2.emplace_back(Point(4,14));
	map2.emplace_back(Point(4,16));
	map2.emplace_back(Point(4,20));
	map2.emplace_back(Point(4,22));
	map2.emplace_back(Point(4,24));
	map2.emplace_back(Point(4,27));
	map2.emplace_back(Point(4,28));
	map2.emplace_back(Point(5,2));
	map2.emplace_back(Point(5,4));
	map2.emplace_back(Point(5,9));
	map2.emplace_back(Point(5,16));
	map2.emplace_back(Point(5,18));
	map2.emplace_back(Point(5,20));
	map2.emplace_back(Point(5,22));
	map2.emplace_back(Point(5,24));
	map2.emplace_back(Point(5,26));
	map2.emplace_back(Point(6,2));
	map2.emplace_back(Point(6,4));
	map2.emplace_back(Point(6,5));
	map2.emplace_back(Point(6,6));
	map2.emplace_back(Point(6,8));
	map2.emplace_back(Point(6,10));
	map2.emplace_back(Point(6,12));
	map2.emplace_back(Point(6,13));
	map2.emplace_back(Point(6,14));
	map2.emplace_back(Point(6,16));
	map2.emplace_back(Point(6,18));
	map2.emplace_back(Point(6,20));
	map2.emplace_back(Point(6,22));
	map2.emplace_back(Point(6,24));
	map2.emplace_back(Point(6,27));
	map2.emplace_back(Point(7,2));
	map2.emplace_back(Point(7,6));
	map2.emplace_back(Point(7,11));
	map2.emplace_back(Point(7,14));
	map2.emplace_back(Point(7,18));
	map2.emplace_back(Point(7,20));
	map2.emplace_back(Point(7,22));
	map2.emplace_back(Point(7,24));
	map2.emplace_back(Point(7,26));
	map2.emplace_back(Point(8,2));
	map2.emplace_back(Point(8,3));
	map2.emplace_back(Point(8,4));
	map2.emplace_back(Point(8,7));
	map2.emplace_back(Point(8,9));
	map2.emplace_back(Point(8,10));
	map2.emplace_back(Point(8,13));
	map2.emplace_back(Point(8,15));
	map2.emplace_back(Point(8,16));
	map2.emplace_back(Point(8,18));
	map2.emplace_back(Point(8,20));
	map2.emplace_back(Point(8,22));
	map2.emplace_back(Point(8,24));
	map2.emplace_back(Point(8,27));
	map2.emplace_back(Point(9,6));
	map2.emplace_back(Point(9,7));
	map2.emplace_back(Point(9,9));
	map2.emplace_back(Point(9,12));
	map2.emplace_back(Point(9,17));
	map2.emplace_back(Point(9,20));
	map2.emplace_back(Point(9,20));
	map2.emplace_back(Point(9,22));
	map2.emplace_back(Point(9,24));
	map2.emplace_back(Point(9,26));
	map2.emplace_back(Point(10,1));
	map2.emplace_back(Point(10,2));
	map2.emplace_back(Point(10,3));
	map2.emplace_back(Point(10,5));
	map2.emplace_back(Point(10,11));
	map2.emplace_back(Point(10,13));
	map2.emplace_back(Point(10,14));
	map2.emplace_back(Point(10,15));
	map2.emplace_back(Point(10,17));
	map2.emplace_back(Point(10,19));
	map2.emplace_back(Point(10,20));
	map2.emplace_back(Point(10,22));
	map2.emplace_back(Point(10,24));
	map2.emplace_back(Point(10,27));
	map2.emplace_back(Point(11,4));
	map2.emplace_back(Point(11,7));
	map2.emplace_back(Point(11,8));
	map2.emplace_back(Point(11,9));
	map2.emplace_back(Point(11,10));
	map2.emplace_back(Point(11,17));
	map2.emplace_back(Point(11,22));
	map2.emplace_back(Point(11,24));
	map2.emplace_back(Point(11,26));
	map2.emplace_back(Point(12,2));
	map2.emplace_back(Point(12,6));
	map2.emplace_back(Point(12,12));
	map2.emplace_back(Point(12,13));
	map2.emplace_back(Point(12,14));
	map2.emplace_back(Point(12,15));
	map2.emplace_back(Point(12,17));
	map2.emplace_back(Point(12,18));
	map2.emplace_back(Point(12,19));
	map2.emplace_back(Point(12,20));
	map2.emplace_back(Point(12,21));
	map2.emplace_back(Point(12,22));
	map2.emplace_back(Point(12,24));
	map2.emplace_back(Point(12,27));
	map2.emplace_back(Point(13,2));
	map2.emplace_back(Point(13,5));
	map2.emplace_back(Point(13,8));
	map2.emplace_back(Point(13,9));
	map2.emplace_back(Point(13,10));
	map2.emplace_back(Point(13,11));
	map2.emplace_back(Point(13,15));
	map2.emplace_back(Point(13,23));
	map2.emplace_back(Point(13,24));
	map2.emplace_back(Point(13,26));
	map2.emplace_back(Point(14,3));
	map2.emplace_back(Point(14,4));
	map2.emplace_back(Point(14,7));
	map2.emplace_back(Point(14,13));
	map2.emplace_back(Point(14,15));
	map2.emplace_back(Point(14,16));
	map2.emplace_back(Point(14,17));
	map2.emplace_back(Point(14,18));
	map2.emplace_back(Point(14,19));
	map2.emplace_back(Point(14,20));
	map2.emplace_back(Point(14,21));
	map2.emplace_back(Point(14,27));
	map2.emplace_back(Point(15,1));
	map2.emplace_back(Point(15,5));
	map2.emplace_back(Point(15,7));
	map2.emplace_back(Point(15,9));
	map2.emplace_back(Point(15,10));
	map2.emplace_back(Point(15,11));
	map2.emplace_back(Point(15,12));
	map2.emplace_back(Point(15,23));
	map2.emplace_back(Point(15,24));
	map2.emplace_back(Point(15,25));
	map2.emplace_back(Point(15,26));
	map2.emplace_back(Point(15,27));
	map2.emplace_back(Point(16,2));
	map2.emplace_back(Point(16,3));
	map2.emplace_back(Point(16,5));
	map2.emplace_back(Point(16,7));
	map2.emplace_back(Point(16,9));
	map2.emplace_back(Point(16,13));
	map2.emplace_back(Point(16,14));
	map2.emplace_back(Point(16,15));
	map2.emplace_back(Point(16,16));
	map2.emplace_back(Point(16,17));
	map2.emplace_back(Point(16,18));
	map2.emplace_back(Point(16,19));
	map2.emplace_back(Point(16,20));
	map2.emplace_back(Point(16,21));
	map2.emplace_back(Point(16,22));
	map2.emplace_back(Point(17,5));
	map2.emplace_back(Point(17,7));
	map2.emplace_back(Point(17,10));
	map2.emplace_back(Point(17,11));
	map2.emplace_back(Point(17,22));
	map2.emplace_back(Point(17,24));
	map2.emplace_back(Point(17,25));
	map2.emplace_back(Point(17,26));
	map2.emplace_back(Point(17,27));
	map2.emplace_back(Point(18,2));
	map2.emplace_back(Point(18,3));
	map2.emplace_back(Point(18,5));
	map2.emplace_back(Point(18,7));
	map2.emplace_back(Point(18,8));
	map2.emplace_back(Point(18,12));
	map2.emplace_back(Point(18,14));
	map2.emplace_back(Point(18,16));
	map2.emplace_back(Point(18,17));
	map2.emplace_back(Point(18,18));
	map2.emplace_back(Point(18,19));
	map2.emplace_back(Point(18,20));
	map2.emplace_back(Point(18,22));
	map2.emplace_back(Point(18,27));
	map2.emplace_back(Point(19,4));
	map2.emplace_back(Point(19,5));
	map2.emplace_back(Point(19,9));
	map2.emplace_back(Point(19,10));
	map2.emplace_back(Point(19,13));
	map2.emplace_back(Point(19,14));
	map2.emplace_back(Point(19,16));
	map2.emplace_back(Point(19,20));
	map2.emplace_back(Point(19,23));
	map2.emplace_back(Point(19,24));
	map2.emplace_back(Point(19,25));
	map2.emplace_back(Point(19,27));
	map2.emplace_back(Point(20,1));
	map2.emplace_back(Point(20,2));
	map2.emplace_back(Point(20,4));
	map2.emplace_back(Point(20,6));
	map2.emplace_back(Point(20,7));
	map2.emplace_back(Point(20,11));
	map2.emplace_back(Point(20,14));
	map2.emplace_back(Point(20,16));
	map2.emplace_back(Point(20,18));
	map2.emplace_back(Point(20,20));
	map2.emplace_back(Point(20,22));
	map2.emplace_back(Point(20,27));
	map2.emplace_back(Point(21,4));
	map2.emplace_back(Point(21,8));
	map2.emplace_back(Point(21,9));
	map2.emplace_back(Point(21,12));
	map2.emplace_back(Point(21,15));
	map2.emplace_back(Point(21,16));
	map2.emplace_back(Point(21,18));
	map2.emplace_back(Point(21,20));
	map2.emplace_back(Point(21,22));
	map2.emplace_back(Point(21,24));
	map2.emplace_back(Point(21,25));
	map2.emplace_back(Point(21,26));
	map2.emplace_back(Point(22,2));
	map2.emplace_back(Point(22,3));
	map2.emplace_back(Point(22,4));
	map2.emplace_back(Point(22,6));
	map2.emplace_back(Point(22,9));
	map2.emplace_back(Point(22,10));
	map2.emplace_back(Point(22,13));
	map2.emplace_back(Point(22,16));
	map2.emplace_back(Point(22,18));
	map2.emplace_back(Point(22,20));
	map2.emplace_back(Point(22,22));
	map2.emplace_back(Point(22,27));
	map2.emplace_back(Point(23,6));
	map2.emplace_back(Point(23,7));
	map2.emplace_back(Point(23,10));
	map2.emplace_back(Point(23,11));
	map2.emplace_back(Point(23,14));
	map2.emplace_back(Point(23,18));
	map2.emplace_back(Point(23,20));
	map2.emplace_back(Point(23,23));
	map2.emplace_back(Point(23,24));
	map2.emplace_back(Point(23,25));
	map2.emplace_back(Point(23,27));
	map2.emplace_back(Point(24,1));
	map2.emplace_back(Point(24,2));
	map2.emplace_back(Point(24,3));
	map2.emplace_back(Point(24,4));
	map2.emplace_back(Point(24,5));
	map2.emplace_back(Point(24,9));
	map2.emplace_back(Point(24,12));
	map2.emplace_back(Point(24,15));
	map2.emplace_back(Point(24,16));
	map2.emplace_back(Point(24,17));
	map2.emplace_back(Point(24,18));
	map2.emplace_back(Point(24,20));
	map2.emplace_back(Point(24,22));
	map2.emplace_back(Point(24,27));
	map2.emplace_back(Point(25,6));
	map2.emplace_back(Point(25,8));
	map2.emplace_back(Point(25,10));
	map2.emplace_back(Point(25,12));
	map2.emplace_back(Point(25,13));
	map2.emplace_back(Point(25,15));
	map2.emplace_back(Point(25,20));
	map2.emplace_back(Point(25,22));
	map2.emplace_back(Point(25,24));
	map2.emplace_back(Point(25,25));
	map2.emplace_back(Point(25,26));
	map2.emplace_back(Point(26,2));
	map2.emplace_back(Point(26,4));
	map2.emplace_back(Point(26,10));
	map2.emplace_back(Point(26,15));
	map2.emplace_back(Point(26,17));
	map2.emplace_back(Point(26,18));
	map2.emplace_back(Point(26,19));
	map2.emplace_back(Point(26,22));
	map2.emplace_back(Point(26,27));
	map2.emplace_back(Point(27,3));
	map2.emplace_back(Point(27,5));
	map2.emplace_back(Point(27,6));
	map2.emplace_back(Point(27,7));
	map2.emplace_back(Point(27,8));
	map2.emplace_back(Point(27,9));
	map2.emplace_back(Point(27,11));
	map2.emplace_back(Point(27,12));
	map2.emplace_back(Point(27,13));
	map2.emplace_back(Point(27,14));
	map2.emplace_back(Point(27,15));
	map2.emplace_back(Point(27,17));
	map2.emplace_back(Point(27,19));
	map2.emplace_back(Point(27,21));
	map2.emplace_back(Point(27,23));
	map2.emplace_back(Point(27,24));
	map2.emplace_back(Point(27,25));
	map2.emplace_back(Point(27,26));
	map2.emplace_back(Point(27,27));
	map2.emplace_back(Point(28,1));			
}

picture.h

#ifndef PICTURE_H
#define PICTURE_H

#include "point.h"

#include //之前提到,略过 
#include 

class Picture
{
	public:
		Picture(){}
		
		void PrintStart();
		void PrintInterface1();
		void PushStart();
		void PushInterface1();
	private:
	    std::vector<Point> start;//开始界面 
		std::vector<Point> interface1;//菜单的边框 
};

#endif//PICTURE_H

picture.cpp

#include "picture.h"
#include "tools.h"

#include 
#include 

void Picture::PrintStart()//打印开始界面 
{
	PushStart();//start中压入各点 
	for(auto &point: start)
	{
		point.PrintDiamond();//打印菱形 
		Sleep(10);//之前提到,略过 
	}	
}

void Picture::PrintInterface1()//打印开始菜单界面 
{
	SetCursorPosition(33,4);
	printf("迷");
	
	SetCursorPosition(36,4);
	printf("宫"); 
	
	SetCursorPosition(32,11);
	printf("选择上下左右来");
	
	SetCursorPosition(31,12);
	printf("控制小球的方向,");
	
	SetCursorPosition(31,13);
	printf("使其到达终点。");
	
	SetCursorPosition(32,16);
	printf("1:继续游戏");
	
	SetCursorPosition(32,19);
	printf("2:重新开始");
	
	SetCursorPosition(32,22);
	printf("3:更换地图");
	
	SetCursorPosition(32,25);
	printf("4:退出游戏");
	PushInterface1();

	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
		FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE|
	BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE);//青字白底 
	
	SetCursorPosition(31,8);
	printf(" - - - - - - - -");
	
	for(auto &point :interface1)
		point.PrintDiamond();//打印菱形 
}

/*压入开始界面各点(就是开始的迷宫两个大字,本人艺术细胞有限,
自己看着都觉得不怎么样,喜欢的朋友可以自己修改)*/
void Picture::PushStart()
{
	start.emplace_back(Point(3,4));
    start.emplace_back(Point(4,5));
	start.emplace_back(Point(5,6));
	start.emplace_back(Point(3,7));
    start.emplace_back(Point(4,7));
	start.emplace_back(Point(5,7));
	start.emplace_back(Point(6,7));
    start.emplace_back(Point(6,8));
 	start.emplace_back(Point(5,9));
  	start.emplace_back(Point(4,10));
   	start.emplace_back(Point(4,11));
   	start.emplace_back(Point(5,12));
   	start.emplace_back(Point(6,13));
   	start.emplace_back(Point(6,14));
   	start.emplace_back(Point(5,15));
   	start.emplace_back(Point(4,16));
   	start.emplace_back(Point(3,17));
   	start.emplace_back(Point(4,17));
   	start.emplace_back(Point(5,17));
   	start.emplace_back(Point(6,17));
   	start.emplace_back(Point(7,17));
   	start.emplace_back(Point(8,17));
   	start.emplace_back(Point(9,17));
   	start.emplace_back(Point(10,17));
   	start.emplace_back(Point(11,17));
   	start.emplace_back(Point(12,17));
  	start.emplace_back(Point(13,17));
  	start.emplace_back(Point(14,17));
   	start.emplace_back(Point(15,17));
   	start.emplace_back(Point(16,17));
   	start.emplace_back(Point(17,17));
   	start.emplace_back(Point(18,17));
   	start.emplace_back(Point(19,17));
   	start.emplace_back(Point(20,17));
   	start.emplace_back(Point(7,11));
   	start.emplace_back(Point(8,11));
   	start.emplace_back(Point(9,11));
   	start.emplace_back(Point(10,11));
   	start.emplace_back(Point(11,11));
    start.emplace_back(Point(12,11));
   	start.emplace_back(Point(13,11));
    start.emplace_back(Point(14,11));
   	start.emplace_back(Point(15,11));
   	start.emplace_back(Point(16,11));
   	start.emplace_back(Point(17,11));
   	start.emplace_back(Point(18,11));
   	start.emplace_back(Point(19,11));
	start.emplace_back(Point(13,5));
	start.emplace_back(Point(13,6));
	start.emplace_back(Point(13,7));
	start.emplace_back(Point(13,8));
	start.emplace_back(Point(13,9));
	start.emplace_back(Point(13,10));
	start.emplace_back(Point(13,12));
	start.emplace_back(Point(13,13));
	start.emplace_back(Point(13,14));
	start.emplace_back(Point(13,15));
	start.emplace_back(Point(13,16));
    start.emplace_back(Point(7,5));
    start.emplace_back(Point(8,6));
    start.emplace_back(Point(9,7));
	start.emplace_back(Point(10,8));
	start.emplace_back(Point(11,9));
	start.emplace_back(Point(12,10));
	start.emplace_back(Point(19,5));
	start.emplace_back(Point(18,6));
	start.emplace_back(Point(17,7));
	start.emplace_back(Point(16,8));
	start.emplace_back(Point(15,9));
	start.emplace_back(Point(14,10));
	start.emplace_back(Point(12,12));
	start.emplace_back(Point(11,13));
	start.emplace_back(Point(10,14));
	start.emplace_back(Point(9,15));
	start.emplace_back(Point(8,16));
	start.emplace_back(Point(14,12));
	start.emplace_back(Point(15,13));
	start.emplace_back(Point(16,14));
    start.emplace_back(Point(17,15));
	start.emplace_back(Point(18,16));
	start.emplace_back(Point(29,4));
	start.emplace_back(Point(30,5));
	start.emplace_back(Point(31,6));
    start.emplace_back(Point(25,7));
	start.emplace_back(Point(26,7));
	start.emplace_back(Point(27,7));
	start.emplace_back(Point(28,7));
	start.emplace_back(Point(29,7));
	start.emplace_back(Point(30,7));
	start.emplace_back(Point(31,7));
	start.emplace_back(Point(32,7));
	start.emplace_back(Point(33,7));
	start.emplace_back(Point(34,7));
	start.emplace_back(Point(35,7));
	start.emplace_back(Point(36,7));
	start.emplace_back(Point(37,7));
	start.emplace_back(Point(25,8));
	start.emplace_back(Point(25,9));
	start.emplace_back(Point(25,10));
	start.emplace_back(Point(37,8));
	start.emplace_back(Point(37,9));
	start.emplace_back(Point(37,10));
	start.emplace_back(Point(29,9));
	start.emplace_back(Point(30,9));
	start.emplace_back(Point(31,9));
	start.emplace_back(Point(32,9));
	start.emplace_back(Point(33,9));
	start.emplace_back(Point(29,10));
	start.emplace_back(Point(29,11));
	start.emplace_back(Point(29,12));
	start.emplace_back(Point(33,10));
	start.emplace_back(Point(33,11));
	start.emplace_back(Point(33,12));
	start.emplace_back(Point(30,12));
	start.emplace_back(Point(31,12));
	start.emplace_back(Point(32,12));
	start.emplace_back(Point(29,14));
	start.emplace_back(Point(30,14));
	start.emplace_back(Point(31,14));
	start.emplace_back(Point(32,14));
	start.emplace_back(Point(33,14));
	start.emplace_back(Point(29,15));
	start.emplace_back(Point(29,16));
	start.emplace_back(Point(29,17));
	start.emplace_back(Point(33,15));
	start.emplace_back(Point(33,16));
	start.emplace_back(Point(33,17));
	start.emplace_back(Point(30,17));
	start.emplace_back(Point(31,17));
	start.emplace_back(Point(32,17));
}

/*直到这里,我才想到用循环压入各点,然后把之前的一处代码修改就懒的再改了,
我敲了几百行的地图啊 ,啊啊啊啊啊啊啊啊啊啊 */
void Picture::PushInterface1()
{
	int i,j;
	
	for(i=30;i<=39;i++)
		for(j=0;j<=29;j+=29)
			interface1.emplace_back(Point(i,j));
			
	for(i=30;i<=39;i+=9)
		for(j=1;j<=28;j++)
			interface1.emplace_back(Point(i,j));
			
	for(j=3;j<=5;j+=2)
		for(i=32;i<=37;i++)
			interface1.emplace_back(Point(i,j));
			
	for(i=32,j=4;i<=37;i+=5)
		interface1.emplace_back(Point(i,j));
}

point.h

#ifndef POINT_H
#define POINT_H

class Point
{
	public:
		Point(){}
		Point(const int x,const int y):x(x),y(y){}
		
		int GetX();
		int GetY();
		void PrintSquare();
		void PrintCircular();
		void PrintDiamond();
		void ClearPoint();
		void ChangePoint(const int x,const int y);
	private:
		int x,y;
};

#endif//POINT_H

point.cpp

#include "point.h"
#include "tools.h"

#include 

int Point::GetX()//得到点的横坐标 
{
	return this->x;
}

int Point::GetY()//得到点的纵坐标 
{
	return this->y;
}

void Point::PrintSquare()//打印方块 
{
	SetCursorPosition(x,y);//让光标移动到点的坐标 
	std::cout<<"■";
}

void Point::PrintCircular()//打印圆圈 
{
	SetCursorPosition(x,y);
	std::cout<<"●";
}

void Point::ClearPoint()//打印空格(消除原字符) 
{
	SetCursorPosition(x,y);
	std::cout<<" ";
}

void Point::PrintDiamond()//打印菱形 
{
	SetCursorPosition(x,y);
	std::cout<<"◆";
}

void Point::ChangePoint(const int x,const int y)//改变点的坐标 
{
	this->x=x;
	this->y=y;
}

tools.h

#ifndef TOOLS_H
#define TOOLS_H 

void SetWindowSize(int x,int y);
void SetColor(int colorId);
void SetCursorPosition(int x,int y);

#endif//TOOLS_H

tools.cpp

#include "stdio.h"
#include "tools.h"

#include 

/*
    colorId
	黑色 = 0      蓝色 = 1      绿色 = 2      湖蓝色 = 3
    红色 = 4      紫色 = 5      黄色 = 6      白色 = 7
    灰色 = 8      淡蓝色=9      淡绿色=A      白色=C
    淡紫色=D      淡黄色=E      亮白色=F*/

/*SetConsoleTexeAttribute(GetStdHandle(STD_OUTPUT_HANDLE,颜色)
  白色 BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE);
  红色 BACKGROUND_INTENSITY|BACKGROUND_RED);
  绿色 BACKGROUND_INTENSITY|BACKGROUND_GREEN);
  蓝色 BACKGROUND_INTENSITY|BACKGROUND_BLUE);
  黄色 BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN);
  粉色 BACKGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_BLUE);
  青色 BACKGROUND_INTENSITY|BACKGROUND_GREEN|BACKGROUND_BLUE);
*/
void SetWindowSize(int cols,int lines)//调整窗口大小 
{
	system("title 迷宫");//设置窗口标题
	char cmd[50];//设置命令字符 
	sprintf(cmd,"c:\\windows\\system32\\mode con cols=%d lines=%d",cols*2,lines);//一个图形宽占两字符所以乘二
	system(cmd);//system(mode con cols=x*2,lines=y) 
}


void SetColor(int colorId)//调整字体颜色 
{
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),colorId1);//不知道的童鞋请自行百度 
} 

void SetCursorPosition(int x,int y)//改变光标位置 
{
	COORD pos;//COORD是什么了?自己百度 
	pos.X=x*2;
	pos.Y=y;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);//同上 
}

ball.h

#ifndef BALL_H
#define BALL_H

#include "controller.h"
#include "point.h"
#include "map.h"

#include 

class Ball
{    
	public:
		Ball(){}
		
		int Move(Controller *menu,Point *endpoint);
		void ChangeBall(int x,int y);
		void GetWall(Map *map,int MapId);
		bool Arive(Point *endpoint);//话说bool应该都知道是什么意思吧
		bool UnColide();
	private:
	    Point ball;
	    std::vector<Point> wall;
	
};

#endif//BALL_H

ball.cpp

#include "ball.h"
#include "controller.h"
#include "tools.h"

#include 
#include 
#include  

void Ball::ChangeBall(int x,int y)//改变小球位置 
{
	this->ball.ChangePoint(x,y);
}

int Ball::Move(Controller *menu,Point *endpoint)//
{
	int key=1;//初始化key 
	char ch;
		
	for(;key!=2 && key!=3;)//key=1继续游戏,key=4函数内已经退出程序了 
	{
	    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
	    FOREGROUND_INTENSITY|FOREGROUND_RED|
	    BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE);//红字白底
	    
	    ch=getch();
		switch(ch)
		{
		    
			case -32://Controller类中已做说明 
			{
				ch=getch();
				
				switch(ch)
				{
					case 72://向上
					{
					    ball.ClearPoint();//清除原来的点 
					    this->ChangeBall(ball.GetX(),ball.GetY()-1);//改变坐标 
						if(UnColide())//如果没有碰撞 
						    ball.PrintCircular();
						else//发生碰撞 
						{
						    this->ChangeBall(ball.GetX(),ball.GetY()+1);//回到原来坐标 
							ball.PrintCircular();
					    }  
						break; 
					}
					case 80://向下 
					{
						ball.ClearPoint();
						this->ChangeBall(ball.GetX(),ball.GetY()+1);
						if(UnColide())
						    ball.PrintCircular();
						else
						{
							this->ChangeBall(ball.GetX(),ball.GetY()-1);
							ball.PrintCircular();
						}    
						break;
					}
					case 75://向左 
					{
						ball.ClearPoint();
						this->ChangeBall(ball.GetX()-1,ball.GetY());
						if(UnColide())
						    ball.PrintCircular();
						else
						{
							this->ChangeBall(ball.GetX()+1,ball.GetY());
							ball.PrintCircular();
						}    
						break;
					}
					case 77://向右 
					{
						ball.ClearPoint();
						this->ChangeBall(ball.GetX()+1,ball.GetY());
						if(UnColide())
						    ball.PrintCircular();
						else
						{
							this->ChangeBall(ball.GetX()-1,ball.GetY());
							ball.PrintCircular();
						}    
						break;
					}
					default:
						break;	
				}
				break;
			}
			case 27://键入Esc键 
				{
					key=menu->Menu();//打开菜单选择key 
					break;
				}
			default:
				break;
		}
		if(Arive(endpoint))//如果到达终点 
		{
			system("cls");
	        SetCursorPosition(17,15);
	        std::cout<<"恭喜你,过关了!";
	        getch();//暂停 
	        return key;//其实就是返回1,下同 
		}
	}
	return key;
	
}

void Ball::GetWall(Map *map,int MapId)//将发生碰撞的点记入小球 
{
	wall.clear();//防止上一次的循环,避免重复压入相同的点 
	switch(MapId)//选择当前地图压入 
	{
		case 1:
		{
			for(auto &point :map->map1)
			    wall.emplace_back(point);
			break;
		}
		case 2:
		{
			for(auto &point :map->map2)
			    wall.emplace_back(point);
			break;
		}
		default:
		    break; 
	}
	
	for(auto &point :map->initmap)//压入初始地图的点 
		wall.emplace_back(point);
}

bool Ball::Arive(Point *endpoint)//判断是否到达终点 
{
	if(ball.GetX()==endpoint->GetX() && ball.GetY()==endpoint->GetY())
	    return true;	
	else
		return false;   
}

bool Ball::UnColide()//判断是否碰撞 
{
	for(auto &point :wall)
		if(point.GetX()==ball.GetX() && point.GetY()==ball.GetY())
		    return false;
	return true;
}

PS:我想能看到这的都是勇士,这组代码因当时年少,冗余过多,仅供参考,大家可以复制下来编译运行一遍加深理解

你可能感兴趣的:(游戏开发,C++游戏开发,C++入门,迷宫小游戏)