Ejemplo n.º 1
0
        public void Load(String fileName)
        {
            using (StreamReader sr = File.OpenText(fileName))
            {
                String[] sep = { "," };

                String _name = sr.ReadLine(); // map name
                int _width = Int32.Parse(sr.ReadLine()); // mapWidth
                int _height = Int32.Parse(sr.ReadLine()); // mapHeight
                String _textureName = sr.ReadLine();

                Init(_name, _width, _height, _textureName);

                for (int j = 0; j < tiles.GetLength(1); j++)
                {
                    String line = sr.ReadLine();
                    String[] nums = line.Split(sep, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < tiles.GetLength(0); i++)
                    {
                        tiles[i, j] = Int32.Parse(nums[i]) - 1;
                    }
                }

                // Grids
                sr.ReadLine();
                int gCount = Int32.Parse(sr.ReadLine());
                info.playerStarts.Clear();
                for (int i = 0; i < gCount; i++)
                {
                    MapGrid grid = new MapGrid();
                    String baseInfoLine = sr.ReadLine();
                    String[] baseNums = baseInfoLine.Split(sep, StringSplitOptions.RemoveEmptyEntries);
                    grid.x = Int32.Parse(baseNums[0]);
                    grid.y = Int32.Parse(baseNums[1]);
                    grid.eventContainer = baseNums[2];
                    grid.deity = Int32.Parse(baseNums[3]);
                    grid.bank = Boolean.Parse(baseNums[4]);
                    grid.bHospital = Boolean.Parse(baseNums[5]);
                    if (grid.bHospital)
                        info.hospitalExit = new Point(grid.x, grid.y);
                    grid.bJail = Boolean.Parse(baseNums[6]);
                    if (grid.bJail)
                        info.jailExit = new Point(grid.x, grid.y);
                    grid.bPlayerStart = Boolean.Parse(baseNums[7]);
                    if (grid.bPlayerStart)
                        info.playerStarts.Add(new Point(grid.x, grid.y));

                    String esLine = sr.ReadLine();
                    if (esLine != "null")
                    {
                        String[] esNums = esLine.Split(sep, StringSplitOptions.RemoveEmptyEntries);
                        int x = Int32.Parse(esNums[0]);
                        int y = Int32.Parse(esNums[1]);
                        String section = esNums[2];
                        int basePrice = Int32.Parse(esNums[3]);
                        grid.eState = new EState(x, y, section, basePrice);
                        gamePlayes[x, y] = 3;
                        eStates.Add(grid.eState);
                    }

                    String nbLine = sr.ReadLine();
                    String[] nbNums = nbLine.Split(sep, StringSplitOptions.RemoveEmptyEntries);
                    int nbCount = Int32.Parse(nbNums[0]);
                    for (int j = 1; j < nbNums.Length - 1; j += 2)
                    {
                        int x = Int32.Parse(nbNums[j]);
                        int y = Int32.Parse(nbNums[j + 1]);
                        Point pt = new Point(x, y);
                        grid.neighbours.Add(pt);
                    }

                    grids.Add(grid);
                    gamePlayes[grid.x, grid.y] = 2;
                }

            }
        }
Ejemplo n.º 2
0
        private void MainPanel_MouseDown(object sender, MouseEventArgs e)
        {
            bMouseDownMainPanel = true;
            mousePt = getMapMouseLoc(e.X, e.Y);
            if (G.currentMap == null)
                    return;

            if (G.operation == 1)
            {
                if (G.currentTexture == null)
                    return;

                if (G.bAreaBrush)
                {
                    AreaStartI = AreaEndI = mousePt.X / G.tileSize;
                    AreaStartJ = AreaEndJ = mousePt.Y / G.tileSize;
                }
                else
                {
                    updateTile(mousePt.X / G.tileSize, mousePt.Y / G.tileSize);
                }
            }
            else if (G.operation == 2)
            {
                MapGrid grid = new MapGrid(mousePt.X / G.tileSize, mousePt.Y / G.tileSize);
                GridControl gc = new GridControl();
                MainPanel.Controls.Add(gc);
                gc.Location = new Point(mousePt.X, mousePt.Y);
                gc.data = grid;
                G.currentMap.grids.Add(grid);
                G.currentMap.gamePlayes[mousePt.X / G.tileSize, mousePt.Y / G.tileSize] = 2;
            }
            else if (G.operation == 3)
            {
                AreaStartI = AreaEndI = mousePt.X / G.tileSize;
                AreaStartJ = AreaEndJ = mousePt.Y / G.tileSize;
            }
            else if (G.operation == 4)
            {
                MapGrid grid = new MapGrid(mousePt.X / G.tileSize, mousePt.Y / G.tileSize);
                GridControl gc = new GridControl();
                MainPanel.Controls.Add(gc);
                gc.Location = new Point(mousePt.X, mousePt.Y);
                grid.bHospital = true;
                gc.data = grid;
                G.currentMap.grids.Add(grid);
                G.currentMap.gamePlayes[mousePt.X / G.tileSize, mousePt.Y / G.tileSize] = 2;
                G.currentMap.info.hospitalExit = new Point(mousePt.X / G.tileSize, mousePt.Y / G.tileSize);

                G.currentMap.UpdateGrids();
            }
            else if (G.operation == 5)
            {
                MapGrid grid = new MapGrid(mousePt.X / G.tileSize, mousePt.Y / G.tileSize);
                GridControl gc = new GridControl();
                MainPanel.Controls.Add(gc);
                gc.Location = new Point(mousePt.X, mousePt.Y);
                grid.bJail = true;
                gc.data = grid;
                G.currentMap.grids.Add(grid);
                G.currentMap.gamePlayes[mousePt.X / G.tileSize, mousePt.Y / G.tileSize] = 2;
                G.currentMap.info.jailExit = new Point(mousePt.X / G.tileSize, mousePt.Y / G.tileSize);

                G.currentMap.UpdateGrids();
            }
            else if (G.operation == 6)
            {
                MapGrid grid = new MapGrid(mousePt.X / G.tileSize, mousePt.Y / G.tileSize);
                GridControl gc = new GridControl();
                MainPanel.Controls.Add(gc);
                gc.Location = new Point(mousePt.X, mousePt.Y);
                grid.bPlayerStart = true;
                gc.data = grid;
                G.currentMap.grids.Add(grid);
                G.currentMap.gamePlayes[mousePt.X / G.tileSize, mousePt.Y / G.tileSize] = 2;
                G.currentMap.info.playerStarts.Add(new Point(mousePt.X / G.tileSize, mousePt.Y / G.tileSize));

                G.currentMap.UpdateGrids();
            }

            MainPanel.Refresh();
        }