Exemplo n.º 1
0
		public void Move(ConsoleKeyInfo c, Map m)
		{
			bool move = false;
			
			if ((c.Key == ConsoleKey.UpArrow) && (Y>0))
			{
				move = m.location[X,Y-1].CanMoveTo();
				m.location[X,Y-1].AutomaticAction(this);
				if (move)
					Y--;
			}
			else if ((c.Key == ConsoleKey.DownArrow) && (Y<(m.Heigth-1)))
			{
				move = m.location[X,Y+1].CanMoveTo();
				m.location[X,Y+1].AutomaticAction(this);
				if (move)
					Y++;
			}
			else if ((c.Key == ConsoleKey.LeftArrow) && (X>0))
			{
				move = m.location[X-1,Y].CanMoveTo();
				m.location[X-1,Y].AutomaticAction(this);
				if (move)
					X--;
			}
			else if ((c.Key == ConsoleKey.RightArrow) && (X<(m.Width-1)))
			{
				move = m.location[X+1,Y].CanMoveTo();
				m.location[X+1,Y].AutomaticAction(this);
				if (move)
					X++;
			}
		}
Exemplo n.º 2
0
        public World()
        {
            Random rnd = new Random();

            #if SILVERLIGHT
            Res.SearchPath.addPath("file://K:/Projects/steel/moora/Resources");
            //            dirs.Add("http://division.kindex.lv/moora/terrain");
            #else
            Res.SearchPath.addPath("../../../Resources");
            Res.SearchPath.addPath("Resources");
            #endif
            terrain = new Terrain(rnd);
            //            map = new RandomMap(21, 18, terrain, rnd);

            List<string> file = Res.TextFile.GetTextFile("map.txt");

            map = new FileMap(terrain, file);

            int char_x;
            int char_y;

            int try_number = 0;
            do
            {
                char_x = rnd.Next(0, map.X);
                char_y = rnd.Next(0, map.Y);
                if (try_number++ > 1000)
                {
                    break;
                }
            }
            while (map.getTerrain(char_x, char_y) != TerrainType.Sand);

            character = new Character(char_x, char_y, map);
        }
Exemplo n.º 3
0
        public Room(int _id, string newRoomName, Map _map, int _nUsers)
        {
            id = _id;
            this.roomName = newRoomName;
            this.map = _map;// newMap;

            for(int i=0; i<_nUsers; ++i)
                users.Add( new User() );
        }
Exemplo n.º 4
0
        public static int getMapID(Map _map)
        {
            for(int i=0; i<maps.Length; ++i)
            {
                if( _map == maps[i] )
                    return i;
            }

            return -1;
        }
Exemplo n.º 5
0
 void LoadMap()
 {
     using (var reader = new System.IO.BinaryReader(System.IO.File.OpenRead("test.map"))) {
         var width  = reader.ReadInt32();
         var height = reader.ReadInt32();
         map = new Game.Map(width, height);
         map.ReadData(reader);
         navi = new Game.Navigation(map);
         navi.ReadData(reader);
     }
 }
Exemplo n.º 6
0
 void Awake()
 {
     map = new Game.Map(1024, 1024);
     for (int i = 0; i < 64; i += 1)
     {
         for (int j = 0; j < 1024; j += 1)
         {
             map.SetRawHeight(i + 512, j, 32);
             map.SetRawHeight(j, i + 512, 32);
         }
     }
 }
        public override void afterChanged()
        {
            List<PacketType_SC> packetList = new List<PacketType_SC>();
            packetList.Add( PacketType_SC.Room_PlayerArrive );
            packetList.Add( PacketType_SC.Room_PlayerLeave );
            packetList.Add( PacketType_SC.GameStart );

            networkManager.register(this, packetList);

            room = (Room)data["RoomInfo"];
            user = (User)data["UserInfo"];

            map = room.getMap();
        }
Exemplo n.º 8
0
        protected override void OnLoad(EventArgs e)
        {
            keyboard = new GameKeyboard(Keyboard);
            currentMap = new Map(AssetDirectory + "/DATA/MAPS4/MAP01.SWD");
            GL.ClearColor(Color.Black);
            float zoom = 1.0f;
            cameraPosition = new Vector3(0, -((cameraHeight * TerrainRenderer.triangleWidth) / TerrainRenderer.triangleHeight), cameraHeight);//new Vector3(0, -cameraHeight * (float)Math.Tan(Math.Asin(TerrainRenderer.triangleHeight / TerrainRenderer.triangleWidth)), cameraHeight);
            cameraTarget = new Vector3(0, 0, 0);
            //projection = Matrix4.CreatePerspectiveFieldOfView((float)(Math.PI / 2.0), (float)ClientSize.Width / (float)ClientSize.Height, 0.001f, 1000.0f);
            projection = Matrix4.CreateOrthographic((float)ClientSize.Width / (50 * zoom), (float)ClientSize.Height / (50 * zoom), 0.001f, 1000.0f);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadMatrix(ref projection);
            terrainRenderer = new TerrainRenderer(currentMap);
        }
Exemplo n.º 9
0
    void RegenerateMap()
    {
        var dim = 1024;

        map = new Game.Map(dim, dim);
        for (int i = 0; i < 32; i += 1)
        {
            for (int j = 0; j < dim; j += 1)
            {
                // Walls. Sloped'+' shape in the middle.
                map.SetRawHeight(i + dim / 2 - 32, j, i * 2);
                map.SetRawHeight(j, i + dim / 2 - 32, i * 2);
                map.SetRawHeight(32 - i + dim / 2, j, i * 2);
                map.SetRawHeight(j, 32 - i + dim / 2, i * 2);
            }
        }
        for (int j = 0; j < dim; j += 1)
        {
            // Wall midline.
            map.SetRawHeight(dim / 2, j, 64);
            map.SetRawHeight(j, dim / 2, 64);
        }
        for (int i = 0; i < 64; i += 1)
        {
            for (int j = 0; j < 64; j += 1)
            {
                var dist = Mathf.Sqrt(j * j + i * i);
                if (dist < 64)
                {
                    // Circular pool at the corners.
                    map.SetRawHeight(i, j, -(int)(64 - dist) / 2);
                    map.SetRawHeight(i, -j, -(int)(64 - dist) / 2);
                    map.SetRawHeight(-i, j, -(int)(64 - dist) / 2);
                    map.SetRawHeight(-i, -j, -(int)(64 - dist) / 2);
                }
            }
        }

        navi = new Game.Navigation(map);
        navi.ComputeReachability();

        using (var writer = new System.IO.BinaryWriter(System.IO.File.Create("test.map"))) {
            writer.Write(map.width);
            writer.Write(map.depth);
            map.WriteData(writer);
            navi.WriteData(writer);
        }
    }
Exemplo n.º 10
0
        private Map CreateMap1()
        {
            Map map = new Map(this, new System.Drawing.RectangleF());

            Door door1 = new Door(new Vector2(0, 50), Direction.Up);
            Door door2 = new Door(new Vector2(0, 200), Direction.Down);

            door1.Destination = door2;
            door2.Destination = door1;

            map.AddEntity(new NPC(new Vector2(50, 0)));

            map.AddEntity(door1);
            map.AddEntity(door2);

            return map;
        }
Exemplo n.º 11
0
        public static void InitializeMap(bool newgame, string dungeonName)
        {
            string mapname = "players/" + player.Name.ToLower() + "/" + dungeonName;

            try
            {
                if (newgame)
                {
                    dungeon = LoadMapFromXml("dungeons/" + dungeonName);
                    //SetCurrentDungeon("dungeon1");
                }
                else
                    dungeon = LoadMapFromXml(mapname);
            }
            catch
            {
                //Console.WriteLine("Couldn't load map.");
                dungeon = LoadMapFromXml("dungeons/" + dungeonName);
            }
        }
Exemplo n.º 12
0
        public static void On_Map_Created(Map self, TileSet set)
        {
            if (DataChanged)
                return;

            //var f = typeof(Map).GetFields(BindingFlags.Instance | BindingFlags.NonPublic).Single(field => field.FieldType == typeof(MaterialProperty[]));

            //var items = GnomanEmpire.Instance.Fortress.StockManager.ItemsByItemID(ItemID.RawHide);

            //var mats = (MaterialProperty[])f.GetValue(GnomanEmpire.Instance.Map);

            //mats.ToArray();
            //items.ToString();

            //var state = new Microsoft.Xna.Framework.Graphics.DepthStencilState();
            //state.DepthBufferFunction = Microsoft.Xna.Framework.Graphics.CompareFunction.Less;
            //state.DepthBufferWriteEnable =
            var bla = new List<MapCell>();
            DataChanged = true;
        }
 public static void On_Map_Created(Map self, TileSet set, System.IO.BinaryReader reader)
 {
     On_Map_Created(self, set);
 }
Exemplo n.º 14
0
        /// <summary>
        /// Modify terrain property colors
        /// </summary>
        /// <param name="m"></param>
        private static void UpdateColors(Map m)
        {
            var colors = ParseColors();

            foreach (var color in colors)
                m.TerrainProperties.Where(p => p.Name == color.Key).Single().Color = color.Value;
        }
Exemplo n.º 15
0
        public static void Main()
        {
            System.Diagnostics.Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr) (System.Environment.ProcessorCount); //Assign the process to the last CPU-core of the System
            Console.WriteLine("We have " + System.Environment.ProcessorCount + " CPU-Cores.");
            Random rnd = new Random();
            using (var game = new GameWindow())
            {
                game.Load += (sender, e) =>
                {
                    // setup settings, load textures, sounds
                    FormWindow();
                    game.X = 32;
                    game.Y = 16;
                    game.VSync = VSyncMode.On;
                    game.Width = windowX;
                    game.Height = windowY;
                    game.WindowBorder = WindowBorder.Fixed; //Disables the resizable windowframe
                    GL.Enable(EnableCap.Blend);                                                     //These lines
                    GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);  //enable transparency using alpha-channel

                    //////////////////////////////////////////////////////////////////////////////////////////////// Load all Background-Objects from the Folder
                    int i = 0;
                    foreach (string bmpFile in Directory.GetFiles((exePath + @"\gfx\backgrounds\tiles"), "*.bmp"))  //get all background tiles and load them
                    {
                        Texture.bgTilesArray[i, 0] = MyImage.LoadTexture(bmpFile);
                        string framesCount = (bmpFile.Replace((exePath + @"\gfx\backgrounds\tiles\"), "").Substring(4, 2));   //get Animation FrameCount ( "<id><id><id>_<frameCount><frameCount>.bmp")
                        if (!int.TryParse(framesCount, out Texture.bgTilesArray[i, 1]))
                            Texture.bgTilesArray[i, 1] = 1;
                        i++;
                    }
                    foreach (string bmpFile in Directory.GetFiles((exePath + @"\gfx\backgrounds\tiles"), "*.png"))  //get all background tiles and load them
                    {
                        Texture.bgTilesArray[i, 0] = MyImage.LoadTexture(bmpFile);
                        string framesCount = (bmpFile.Replace((exePath + @"\gfx\backgrounds\tiles\"), "").Substring(4, 2));   //get Animation FrameCount ( "<id><id><id>_<frameCount><frameCount>.bmp")
                        if (!int.TryParse(framesCount, out Texture.bgTilesArray[i, 1]))
                            Texture.bgTilesArray[i, 1] = 1;
                        i++;
                    }
                    ////////////////////////////////////////////////////////////////////////////////////////////////

                };

                //string s = "---4";
                //Console.WriteLine("3" + s[3]);
                //Console.ReadKey();

                Map karte = new Map(16);

                game.Resize += (sender, e) =>
                {
                    //sceneX = game.Height;
                    //sceneY = game.Width;

                    GL.Viewport(0, 0, windowX, windowY);  //unZoomed

                };
                var mouse = Mouse.GetState();
                game.UpdateFrame += (sender, e) =>
                {
                    // add game logic, input handling
                    mouse = Mouse.GetState();

                    keyboard = Keyboard.GetState();

                    if (keyboard[Key.Escape])
                    {
                        game.Exit();
                    }

                    game.Title = (("FPS: " + (int)(game.RenderFrequency) +" ; "+ Math.Round(game.RenderTime*1000,2)+"ms/frame  Zoom="+zoom));

                    Map.fpsLine.Insert(0,(int)game.RenderFrequency);
                    while (Map.fpsLine.Count > 230)
                        Map.fpsLine.RemoveAt(Map.fpsLine.Count - 1);

                };

                game.RenderFrame += (sender, e) =>
                {
                    // render graphics
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                    //GL.Scale(Map.temp, Map.temp, 0);
                    GL.MatrixMode(MatrixMode.Projection);
                    //GL.MatrixMode(MatrixMode.Modelview);
                    GL.LoadIdentity();

                    //GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                    //Console.WriteLine("Cam (X:" + camX + " |Y:" + camY + ")");

                    GL.Viewport((int)(0), (int)(0), windowX, windowY);
                    GL.LineWidth(1.0f);
                    game.Width = windowX;
                    game.Height = windowY;
                    Vector2d mouseVector = new Vector2d(game.Mouse.X, game.Mouse.Y);

                    if (zoomed)
                    {
                        GL.Ortho((int)(-sceneX / 2), (int)(sceneX / 2), (int)(sceneY / 2), (int)(-sceneY / 2), -1000, 1000);  //Render  distant objects smaller
                        GL.MatrixMode(MatrixMode.Modelview);

                        GL.PopMatrix();
                        GL.PushMatrix();
                        zoom = Map.temp;

                        GL.Scale(zoom, zoom, 1);        //glZomm the scene
                        GL.Translate(-camX, -camY, 0);  //glTranslate (add offset) the zoomed scene

                        GL.Vertex2(mouseVector.X, mouseVector.Y);

                        mouseVector.X -= (sceneX / 2);// + camX;
                        mouseVector.Y -= (sceneY / 2);// + camY;

                        mouseVector.X /= zoom * 2*(1.6);
                        mouseVector.Y /= zoom * 2*(0.9);
                    }
                    else
                    {
                        GL.Ortho((int)0, (int)windowX, (int)windowY, (int)0, -1000, 1000);  //Render  distant objects smaller
                        GL.MatrixMode(MatrixMode.Modelview);
                        GL.PopMatrix();
                        GL.PushMatrix();
                    }

                    karte.draw();    ///////////////////////////////////////// MAP-Object
                    karte.process((int)(mouseVector.X), (int)(mouseVector.Y));

                    game.SwapBuffers();
                };

                // Run the game at 60 updates per second
                game.Run(199.0);
            }
        }
Exemplo n.º 16
0
 public static void MapConstructed(Map m, TileSet t, BinaryReader r)
 {
     UpdateColors(m);
 }
Exemplo n.º 17
0
        public static bool contact(Map carte, Coordonnée newBloc, List<Coordonnée> listeB, int bloc) //détermine si tout les cases vides (sans mur) sont en contact
        {
            List<Coordonnée> listeBloc = new List<Coordonnée>();
            for(int i = 0; i < listeB.Count; i++)
            {
                listeBloc.Add(new Coordonnée(listeB[i].getX(), listeB[i].getY()));
            }

            List<Coordonnée> listeContact = new List<Coordonnée>();

            Coordonnée baseCoor = new Coordonnée(1, 1);
            listeContact.Add(baseCoor);     //on peut commencer a chercher les contacts à partir de n'importe quel case
            listeBloc.Remove(baseCoor);     //on commence donc toujours par une case que l'on sait toujours vide

            int maxi = listeBloc.Count;

            listeBloc.Remove(newBloc);

            int a = 0;
            while ((a < listeContact.Count) && (maxi != listeContact.Count))
            {
                int b = 0;
                while (b < listeBloc.Count)
                {
                    if ( ((listeBloc[b].getX() == listeContact[a].getX()) && ((listeBloc[b].getY() == ((listeContact[a].getY()) - 1)) || (listeBloc[b].getY() == (listeContact[a].getY() + 1))) ) || ( (listeBloc[b].getY() == listeContact[a].getY()) && ((listeBloc[b].getX() == (listeContact[a].getX() - 1)) || (listeBloc[b].getX() == (listeContact[a].getX() + 1)))) )
                    {
                        listeContact.Add(new Coordonnée(listeBloc[b].getX(), listeBloc[b].getY() ) );
                        
                        listeBloc.RemoveAt(b);
                        b--;


                    }
                    b++;
                }
                a++;
            }
            return maxi == listeContact.Count;
        }
Exemplo n.º 18
0
 public Tileset(Map map, XElement element)
 {
     this.Map = map;
     Parse(element);
 }
Exemplo n.º 19
0
 private void NextLevel()
 {
     while (Data.NextMaps.Count == 0)
         Thread.Sleep(100);
     map = Data.NextMaps.Dequeue();
     player = new Player();
     camera = new Camera(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
     this.camera.Zoom = (float)(Data.Windowsize / 256f);
     Data.Levels++;
 }
Exemplo n.º 20
0
 public Layer(Map map, int order, XElement element)
 {
     this.Map = map;
     this.Order = order;
     Parse(element);
 }
Exemplo n.º 21
0
 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
     // Create a new SpriteBatch, which can be used to draw textures.
     Data.SetNull();
     World.CreateWorld();
     spriteBatch = new SpriteBatch(GraphicsDevice);
     tex = Content.Load<Texture2D>("pix");
     font = Content.Load<SpriteFont>("sf");
     map = new Map(DateTime.Now.Second * DateTime.Now.Millisecond * DateTime.Now.Hour, Data.BlockPerLevel, 0);
     Data.Levels += 1;
     oks = Keyboard.GetState();
     pause = false;
     showMap = false;
     if (Data.NextMaps != null)
     {
         worker = new Thread(MapBuilder.CreateNextMap);
         worker.Start();
     }
 }
Exemplo n.º 22
0
 private void Load()
 {
     Data.Load(); ;
     int blocks = (Data.BlockPerLevel + (Data.Levels / 10) * 25) * Data.Levels;
     map = new Map(Data.LastSeed, Data.BlockPerLevel + blocks, Data.Levels);
     Data.NextMaps.Clear();
     player = new Player();
     camera = new Camera(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
     Data.Levels++;
 }
Exemplo n.º 23
0
        public static Map LoadMapFromXml(string mapname)
        {
            string path = filePath + mapname.ToLower() + ".xml";

            XmlDocument doc = new XmlDocument();
            doc.Load(path);

            XmlNode root = doc.DocumentElement;

            // get attributes of map - width and heigth
            int x = int.Parse(root.Attributes["width"].Value);
            int y = int.Parse(root.Attributes["heigth"].Value);
            int playerX = int.Parse(root.Attributes["playerX"].Value);
            int playerY = int.Parse(root.Attributes["playerY"].Value);

            Map newmap = new Map();
            newmap.CreateMapField(x,y);
            newmap.PlayerX = playerX;
            newmap.PlayerY = playerY;

            foreach (XmlNode node in root.ChildNodes)
            {
                Location l = LoadLocationFromXml((XmlElement)node);
                newmap.AddLocation(l);
                l.UpdateSymbol();
            }

            return newmap;
        }
Exemplo n.º 24
0
 public static bool quickContact(Map carte, Coordonnée newBloc)
 {
     
     int x = newBloc.getX();
     int y = newBloc.getY();
     for (int i = x-1; i < x+2; i++)
     {
         for(int j = y-1; j < y+2; j++)
         {
             if(i != x || j != y)
             {
                 if (carte.getVal(i, j) == 1) return false;
             }
         }
     }
     return true;
 }
Exemplo n.º 25
0
 public TerrainRenderer(Map map)
 {
     this.map = map;
     generateNormals();
     generateTriangles();
     generateTextures();
     //generateTextureCoordinates();
     generateSortedVertices();
     generateVBOs();
 }
Exemplo n.º 26
0
 public void Use(Map parrent)
 {
     switch(this.type)
     {
         case FieldTypes.Button:
             if (connection != null)
                 this.connection.Use(parrent);
             break;
         case FieldTypes.Trap:
             if (connection != null)
                 this.connection.Use(parrent);
             this.type = FieldTypes.Death;
             break;
         case FieldTypes.Coin:
             Data.Coins++;
             this.type = FieldTypes.Path;
             break;
         case FieldTypes.Energy:
             Data.Energy++;
             this.type = FieldTypes.Path;
             break;
         case FieldTypes.Destination:
             this.type = FieldTypes.NewGame;
             break;
         default:
             break;
     }
 }
        void Window_CreateGame(int windowId)
        {
            GUILayout.BeginVertical();
            GUI.DragWindow(new Rect (0,0,10000,20));
            // name of Room //
            GUI.Label(new Rect(50,100,100,30),"Name", labelStyle);
            creatingRoomName = GUI.TextField(new Rect(50+100+5, 100, 200, 30), creatingRoomName, 16, fieldStyle);
            // map of room//
            GUI.Label(new Rect(50,100+30+5,100,30), "Map", labelStyle);
            GUI.TextArea(new Rect(50+100+5, 100+30+5, 200, 30 ), currentCreatingMap.getName());
            GUI.Box(new Rect(50, 180, 310, 300 ),"");
            GUILayout.Space(8);
            for(int i=0; i<Map.getMapsCount(); ++i)
            {
                Map tMap = Map.getMap(i);
                if( GUI.Toggle(new Rect(60+100*(i%3), 190+100*(i/3), 90, 90), false, "", "box") )
                {
                    currentCreatingMap = tMap;
                }
                //GUI.Label(new Rect( 100+80*(i%3), 195+120*(i/3), 70, 20), tMap.getName(), "BoldOutlineText" );
                GUI.DrawTexture(new Rect( 70+100*(i%3), 200+100*(i/3), 70, 70), tMap.getThumbnailImage() );
            }

            // description of current map
            GUI.Label(new Rect(380, 100, 330, 30), currentCreatingMap.getName()  );
            GUI.Box(new Rect(380, 130, 330, 350 ),"");
            GUI.TextArea(new Rect(390, 140, 310, 130), currentCreatingMap.getDescription(), "OutlineText");//--------------------------- custom
            GUI.TextArea(new Rect(390, 320, 310, 150), "" );//--------------------------- custom
            GUI.DrawTexture(new Rect(395, 325, 300, 140), currentCreatingMap.getGlanceImage() );

            // button
            if( GUI.Button(new Rect(110,490,100,40),"Create") ) // making button on real game screen
            {
                byte[] packet = new byte[2+16+4];

                PacketWriter.write(packet, 0, PacketType_CS.RequestCreateRoom);//2

                Encoding.ASCII.GetBytes(creatingRoomName, 0,
                    ((creatingRoomName.Length>16)?16:creatingRoomName.Length),
                    packet, 2);

                PacketWriter.write(packet, 18, Map.getMapID(currentCreatingMap) );

                networkManager.write( packet );

                //user.setFlag_Own(true); // 방장//
                //uRoom.setCreator(user); // 방장 //

                //uMap= new Map("Room as creator",1);
                //uRoom.setMap(uMap); // map setting

                //data.Add("RoomInfo",uRoom);

                //gameStateMachine.changeState(enum_States.ROOM,data); // login state -> lobby state//

            }
            if( GUI.Button(new Rect(210,490,100,40),"Cancel") )
                flag_Box_CreatingGame = !flag_Box_CreatingGame;

            GUILayout.EndVertical();
        }
Exemplo n.º 28
0
 public void setMap(Map newMap)
 {
     this.map = newMap;
 }
Exemplo n.º 29
0
 public static void MapConstructed(Map m, TileSet t)
 {
     UpdateColors(m);
 }
Exemplo n.º 30
0
 public Character(int x, int y, Map map)
 {
     destination = position = new Vector2(x + 0.5f, y + 0.5f);
     this.map = map;
 }
Exemplo n.º 31
0
        public static Map creerLabyrinthe(int largeur, int hauteur)
        {
            //on rend les dimensions impaire si elles ne le sont pas déjà
            int x = largeur - (largeur % 2) + 1;
            int y = hauteur - (hauteur % 2) + 1;
            Coordonnée taille = new Coordonnée(x, y);

            Map carte = new Map(taille);

            for (int i = 0; i < x; i++)
            {
                carte.setVal(i, 0, 4);
                carte.setVal(i, y - 1, 4);
            }

            for (int j = 0; j < y; j++)
            {
                carte.setVal(0, j, 4);
                carte.setVal(x - 1, j, 4);
            }

            //on calcule le nombre de mur à créer avec une formule magique
            int arret = (x - 3) * (y - 3) / 2;

            //on crée la liste des blocs dans lesquels il est possible de faire un mur
            List<Coordonnée> listeLibre = new List<Coordonnée>();
            for (int i1 = 1; i1 < x - 1; i1++)
            {
                for (int j1 = 1; j1 < y - 1; j1++)
                {
                    if (i1 % 2 == 0 || j1 % 2 == 0)
                    {
                        listeLibre.Add(new Coordonnée(i1, j1));
                    }
                }
            }

            List<Coordonnée> listeBloc = new List<Coordonnée>();
            for (int i = 1; i < carte.getSize().getX() - 1; i++)
            {
                for (int j = 1; j < carte.getSize().getY() - 1; j++)
                {
                    if (carte.getVal(i, j) == 0)
                    {
                        listeBloc.Add(new Coordonnée(i, j));
                    }
                }
            }

            int mur = 0;

            int iteration = 0;
            
            while (mur < arret && listeLibre.Count != 0)   //boucle de création des murs
            {
                int nbRand = Random.Range(0, listeLibre.Count);
                Coordonnée bloc = listeLibre[nbRand];

                carte.setVal(bloc.getX(), bloc.getY(), 1);
                mur++;
                if(!quickContact(carte, bloc))
                {
                    if (!contact(carte, bloc, listeBloc, 0))
                    {
                        carte.setVal(bloc.getX(), bloc.getY(), 0);
                        mur--;
                    }
                    else listeBloc.Remove(bloc);
                }
                else listeBloc.Remove(bloc);
                
                listeLibre.RemoveAt(nbRand);
                iteration++;
            }

            //on change les murs extérieurs en murs normaux
            for (int i = 0; i < x; i++)
            {
                carte.setVal(i, 0, 1);
                carte.setVal(i, y - 1, 1);
            }

            for (int j = 0; j < x; j++)
            {
                carte.setVal(0, j, 1);
                carte.setVal(x - 1, j, 1);
            }

            Coordonnée depart = new Coordonnée();
            Coordonnée arrivee = new Coordonnée();
            caseDA(taille, ref depart, ref arrivee);
            carte.setVal(depart.getX(), depart.getY(), 2);
            carte.setVal(arrivee.getX(), arrivee.getY(), 3);
            
            return carte;
        }
Exemplo n.º 32
0
 public PostGenerateMapEventArgs(Map map, CreateWorldOptions createWorldOptions)
 {
     Map = map;
     CreateWorldOptions = createWorldOptions;
 }
Exemplo n.º 33
0
        public static bool CreateSafeMineJob(Map map, Vector3 position, Character character = null)
        {
            // Is this a valid mining location?
            MapCell mapCell = map.GetCell(position);
            if (!mapCell.HasNaturalWall())
                return false;

            // Make sure surrounding cells are safe
            if (!IsSafeMiningLocation(map, position, character))
                return false;

            GnomanEmpire.Instance.Fortress.JobBoard.AddJob(new MineJob(position));
            return true;
        }