コード例 #1
0
        /**
         * Checks wether this tile belongs to a given face.
         */
        private static void ComputeFace(int x, int y, ref Graph.Graph graph)
        {
            // Check wether this tile is a wall, a vertex, or an empty cell.
            Vector2 position = new Vector2(x, y);

            Tile.Wall    cellWall = graph.GetWallAt(position);
            Graph.Vertex cellVtx  = graph.GetVertexAt(position);
            if (cellWall == null && cellVtx == null)
            {
                // Get the top and left cells.
                Vector2 left = position + new Vector2(-1, 0);
                Vector2 top  = position + new Vector2(0, -1);

                // Get the faces of the cells.
                Graph.Face leftFace = graph.GetFaceFromPoint(left);
                Graph.Face topFace  = graph.GetFaceFromPoint(top);

                Graph.Face pointFace;
                // If both faces are null.
                if (leftFace == null && topFace == null)
                {
                    // Create a new face.
                    pointFace = new Graph.Face();

                    // Add the face to the graph.
                    graph.AddFace(pointFace);

                    // If both faces are different.
                }
                else if (leftFace != topFace)
                {
                      {
                        // Merge both faces together.
                        pointFace = graph.MergeFaces(leftFace, topFace);

                        // If both faces are the same.
                    }
                }
                else
                {
                    // Select it as the point's face.
                    pointFace = leftFace;
                }

                // Add the point to the face.
                pointFace.AddPoint(position);
            }
        }
コード例 #2
0
        /**
         * Computes the resource on the given tile.
         */
        private static void ComputeResource(int x, int y, TileMap map, ref Graph.Graph graph)
        {
            // Get the face of the given resource.
            Graph.Face face = graph.GetFaceFromPoint(new Vector2(x, y));
            if (face != null)
            {
                // Prepare the regex of the tile name.
                RegEx rgx = new RegEx();
                rgx.Compile(".*(House|Well|Grass|Cow|Start|Objective).*");

                // Check the result.
                String     tileName = map.TileSet.TileGetName(map.GetCell(x, y));
                RegExMatch result   = rgx.Search(tileName);
                if (result != null)
                {
                    switch (result.GetString(1))
                    {
                    case "House":
                        face.zone.addHouse();
                        break;

                    case "Well":
                        face.zone.AddWell();
                        break;

                    case "Grass":
                        // Check the value of the grass.
                        rgx.Compile("([0-9])");
                        result = rgx.Search(tileName);
                        if (result != null)
                        {
                            face.zone.AddGrass(new Vector2(x, y), result.GetString(1).ToInt());
                        }
                        break;

                    case "Objective":
                        face.zone.IsObjective = true;
                        break;

                    case "Cow":
                        // Add a cow to the zone.
                        Tile.Cow cow = Tile.Cow.Instance();
                        cow.Position = new Vector2(x, y);
                        World.Instance.AddChild(cow);
                        face.zone.AddCow(cow);

                        // Remove the cow.
                        map.SetCell(x, y, -1);
                        break;

                    case "Start":
                        // Take the zone.
                        face.zone.TakeOver();

                        // Remove the start point.
                        map.SetCell(x, y, -1);
                        break;
                    }
                }
            }
        }