Пример #1
0
 private ContactMap getContactMap(int p_x, int p_y, Tilemap p_roadMap)
 {
     ContactMap contact = new ContactMap();
     if (p_roadMap.getState(p_x, p_y - 1) >= 0)
         contact.m_map[0] = true;
     if (p_roadMap.getState(p_x + 1, p_y) >= 0)
         contact.m_map[1] = true;
     if (p_roadMap.getState(p_x, p_y + 1) >= 0)
         contact.m_map[2] = true;
     if (p_roadMap.getState(p_x - 1, p_y) >= 0)
         contact.m_map[3] = true;
     return contact;
 }
Пример #2
0
 private StringBuilder SaveTheTileMapToFile(Tilemap p_tileMap)
 {
     StartupDialogSystem sys = (StartupDialogSystem)world.SystemManager.GetSystem<StartupDialogSystem>()[0];
     StringBuilder sb = new StringBuilder();
     sb.AppendLine("Width= " + p_tileMap.getColumns());
     sb.AppendLine("Height= " + p_tileMap.getRows());
     sb.AppendLine("TileMapTheme= " + sys.tilemap.Name);
     sb.AppendLine("Data");
     for (int row = 0; row < p_tileMap.getRows(); row++)
     {
         string resultingRow = "";
         for (int col = 0; col < p_tileMap.getColumns(); col++)
         {
             int state = p_tileMap.getState(col, row) + 1;
             resultingRow += state + ",";
         }
         sb.AppendLine(resultingRow);
     }
     return sb;
 }
Пример #3
0
        private bool validateSwitches(Tilemap p_tilemap)
        {
            int[] numSwitches = new int[8]{0,0,0,0,0,0,0,0};
            int[] numBlockades = new int[8]{0,0,0,0,0,0,0,0};

            for (int y = 0; y < p_tilemap.getRows(); y++)
            {
                for (int x = 0; x < p_tilemap.getColumns(); x++)
                {
                    int state = p_tilemap.getState(x, y);
                    if (state >= 6 * 30 && state < 6 * 30 + 8)
                    {
                        numSwitches[state - 6 * 30] += 1;
                    }
                    else if (state >= 7 * 30 && state < 7 * 30 + 8)
                    {
                        numBlockades[state - 7 * 30] += 1;
                    }
                }
            }

            for (int i = 0; i < 8; i++)
            {
                if (numSwitches[i] > 0 || numBlockades[i] > 0)
                {
                    if(numSwitches[i] == 0 || numBlockades[i] == 0)
                        return false;
                }
            }

            return true;
        }
Пример #4
0
        private bool validatePaths(Tilemap p_tilemap)
        {
            List<int[]> walkables = new List<int[]>();
            for (int y = 0; y < p_tilemap.getRows(); y++)
            {
                for (int x = 0; x < p_tilemap.getColumns(); x++)
                {
                    if (p_tilemap.isWalkable(x, y))
                    {
                        walkables.Add(new int[2]{x, y});
                    }
                }
            }

            if (walkables.Count > 0)
            {
                List<int[]> toCheck = new List<int[]>();
                toCheck.Add(walkables[0]);
                walkables.RemoveAt(0);

                while (toCheck.Count > 0)
                {
                    int[] pos = toCheck[0];
                    toCheck.RemoveAt(0);
                    if (p_tilemap.isWalkable(pos[0], pos[1] - 1)) // North
                    {
                        int index = walkables.FindIndex(delegate(int[] p){return p[0]==pos[0] && p[1] == pos[1] - 1;});
                        if (index != -1)
                        {
                            walkables.RemoveAt(index);
                            toCheck.Add(new int[2]{pos[0], pos[1] - 1});
                        }
                    }
                    if (p_tilemap.isWalkable(pos[0] + 1, pos[1])) // West
                    {
                        int index = walkables.FindIndex(delegate(int[] p){return p[0]==pos[0] + 1 && p[1] == pos[1];});
                        if (index != -1)
                        {
                            walkables.RemoveAt(index);
                            toCheck.Add(new int[2]{pos[0] + 1, pos[1]});
                        }
                    }
                    if (p_tilemap.isWalkable(pos[0], pos[1] + 1)) // South
                    {
                        int index = walkables.FindIndex(delegate(int[] p){return p[0]==pos[0] && p[1] == pos[1] + 1;});
                        if (index != -1)
                        {
                            walkables.RemoveAt(index);
                            toCheck.Add(new int[2]{pos[0], pos[1] + 1});
                        }
                    }
                    if (p_tilemap.isWalkable(pos[0] - 1, pos[1])) // West
                    {
                        int index = walkables.FindIndex(delegate(int[] p){return p[0]==pos[0] - 1 && p[1] == pos[1];});
                        if (index != -1)
                        {
                            walkables.RemoveAt(index);
                            toCheck.Add(new int[2]{pos[0] - 1, pos[1]});
                        }
                    }
                }
            }
            else {
                return false;
            }

            int walkableWithoutPills = 0;
            foreach (int[] p in walkables)
            {
                int state = p_tilemap.getState(p[0], p[1]);
                if(state >= 6 * 30) {
                    walkableWithoutPills++;
                }
            }

            if(walkables.Count - walkableWithoutPills == 0)
                return true;
            return false;
        }
Пример #5
0
        private bool validatePlayer(Tilemap p_tilemap)
        {
            int numPlayers = 0;
            bool connectedToRoad = false;
            for (int y = 0; y < p_tilemap.getRows(); y++)
            {
                for (int x = 0; x < p_tilemap.getColumns(); x++)
                {
                    if (p_tilemap.getState(x, y) == 270)
                    {
                        numPlayers ++;
                        if(p_tilemap.connectedTo(x, y, 3 * 30, 5 * 30))
                            connectedToRoad = true;
                    }
                }
            }

            if(numPlayers == 1 && connectedToRoad)
                return true;
            return false;
        }
Пример #6
0
        private void updateTilemapUsingWallmap(Tilemap p_tilemap, Tilemap p_wallMap,
			Tilemap p_roadMap, WallMapper p_wallMapper)
        {
            for (int y = 0; y < p_wallMap.getRows(); y++)
            {
                for (int x = 0; x < p_wallMap.getColumns(); x++)
                {
                    if (p_wallMap.getState(x, y) >= 0)
                    {
                        p_tilemap.setState(x, y, p_wallMapper.getContactType(x, y, p_roadMap));
                    }
                }
            }
        }
Пример #7
0
 private void updateTilemapUsingSingles(Tilemap p_mainTilemap, Tilemap p_singlesTilemap)
 {
     for (int y = 0; y < p_mainTilemap.getRows(); y++)
     {
         for (int x = 0; x < p_mainTilemap.getColumns(); x++)
         {
             if (p_singlesTilemap.getState(x, y) >= 0)
             {
                 p_mainTilemap.setState(x, y, p_singlesTilemap.getState(x, y));
             }
         }
     }
 }
Пример #8
0
 private void updateTilemapUsingRoadmap(Tilemap p_tilemap, Tilemap p_roadMap, RoadMapper p_roadMapper)
 {
     for (int y = 0; y < p_roadMap.getRows(); y++)
     {
         for (int x = 0; x < p_roadMap.getColumns(); x++)
         {
             if (p_roadMap.getState(x, y) >= 0)
             {
                 p_tilemap.setState(x, y, p_roadMapper.getContactType(x, y, p_roadMap));
             }
             else if (p_roadMap.getState(x, y) == -1)
             {
                 p_tilemap.setState(x, y, 31);
             }
         }
     }
 }
Пример #9
0
 private void generateWallmapFromRoadmap(Tilemap p_wallMap, Tilemap p_roadMap)
 {
     p_wallMap.clear();
     // Sweep adding walls
     for (int y = 0; y < p_roadMap.getRows(); y++)
     {
         for (int x = 0; x < p_roadMap.getColumns(); x++)
         {
             if (p_roadMap.getState(x, y) >= 0)
             {
                 p_wallMap.setState(x - 1, y - 1, 1);
                 p_wallMap.setState(x, y - 1, 1);
                 p_wallMap.setState(x + 1, y - 1, 1);
                 p_wallMap.setState(x + 1, y, 1);
                 p_wallMap.setState(x + 1, y + 1, 1);
                 p_wallMap.setState(x, y + 1, 1);
                 p_wallMap.setState(x - 1, y + 1, 1);
                 p_wallMap.setState(x - 1, y, 1);
             }
         }
     }
     // Sweep removing on roads
     for (int y = 0; y < p_roadMap.getRows(); y++)
     {
         for (int x = 0; x < p_roadMap.getColumns(); x++)
         {
             if (p_roadMap.getState(x, y) >= 0)
             {
                 p_wallMap.setState(x, y, -1);
             }
         }
     }
 }