Exemple #1
0
 public void Fill(string terrainName)
 {
     for (int x = 0; x < _width; x++)
     {
         for (int y = 0; y < _height; y++)
         {
             this[x, y] = new MapCell(x,y,Provider.Instance.Terrains.FirstOrDefault(a => a.Key == terrainName).Value);
         }
     }
 }
        private int Match(TileMatchPattern pattern, MapData map, MapCell cell)
        {
            int result;
            bool reset = false;

            if (map != null && cell != null && map.IsValid(cell.Point))
            {
                result = CalcScore(pattern.TerrainName, cell) * 8;

                if (result > 0)
                {
                    int i = 0;
                    foreach (HexDirection dir in HexDirection.All)
                    {
                        HexPoint pt = cell.Point;
                        pt = pt.Neighbor(dir);

                        if (map.IsValid(pt)) // on map board, calc score 0-3
                        {
                            int score = CalcScore(pattern.TerrainNameAdjacent[i], map[pt]);

                            if (score == 0)
                                reset = true;
                            else
                                result += score;
                        }
                        else if (pattern.TerrainNameAdjacent[i] == "*" || pattern.TerrainNameAdjacent[i] == "IsOcean") // not at map board but *
                            result += 1;
                        else // no match at all
                            reset = true;

                        i++;
                    }
                }
            }
            else
                return -1;

            return (reset) ? 0 : result;
        }
Exemple #3
0
        public static void TestRiverFlowSouthEast()
        {
            Terrain terrain = new Terrain();
            MapCell d1 = new MapCell(terrain);

            d1.SetNEOfRiver(true, FlowDirectionType.SouthEast);

            Assert.IsTrue(d1.IsNEOfRiver, "Should be river NE");
            Assert.IsFalse(d1.IsNWOfRiver, "Should be no river NW");
            Assert.IsFalse(d1.IsWOfRiver, "Should be no river W");
        }
Exemple #4
0
        public static void TestRiverFlowsNorthAndSouth()
        {
            Terrain terrain = new Terrain();
            MapCell d1 = new MapCell(terrain);

            d1.SetWOfRiver(true, FlowDirectionType.North);
            d1.SetWOfRiver(true, FlowDirectionType.South);

            Assert.IsFalse(d1.IsNEOfRiver, "Should be no river NE");
            Assert.IsFalse(d1.IsNWOfRiver, "Should be no river NW");
            Assert.IsTrue(d1.IsWOfRiver, "Should be river W");
            Assert.AreEqual("000011", d1.FlowString, "FlowString should be 000011");
        }
Exemple #5
0
        public static void TestNoRiver()
        {
            Terrain terrain = new Terrain();
            MapCell d1 = new MapCell(terrain);
            d1.River = 0;

            Assert.IsFalse(d1.IsNEOfRiver, "Should be no river NE");
            Assert.IsFalse(d1.IsNWOfRiver, "Should be no river NW");
            Assert.IsFalse(d1.IsWOfRiver, "Should be no river W");
            Assert.AreEqual("000000", d1.FlowString, "FlowString should be 000000");
        }
        public MapCell.FlowDirectionType TurnFlow(MapCell.FlowDirectionType type, TurnType turn)
        {
            switch (type)
            {
                case MapCell.FlowDirectionType.North:
                    return turn == TurnType.Right
                               ? MapCell.FlowDirectionType.NorthEast
                               : MapCell.FlowDirectionType.NorthWest;
                case MapCell.FlowDirectionType.NorthEast:
                    return turn == TurnType.Right
                               ? MapCell.FlowDirectionType.SouthEast
                               : MapCell.FlowDirectionType.North;
                case MapCell.FlowDirectionType.SouthEast:
                    return turn == TurnType.Right
                               ? MapCell.FlowDirectionType.South
                               : MapCell.FlowDirectionType.NorthEast;
                case MapCell.FlowDirectionType.South:
                    return turn == TurnType.Right
                               ? MapCell.FlowDirectionType.SouthWest
                               : MapCell.FlowDirectionType.SouthEast;
                case MapCell.FlowDirectionType.SouthWest:
                    return turn == TurnType.Right
                              ? MapCell.FlowDirectionType.NorthWest
                              : MapCell.FlowDirectionType.South;
                case MapCell.FlowDirectionType.NorthWest:
                    return turn == TurnType.Right
                               ? MapCell.FlowDirectionType.North
                               : MapCell.FlowDirectionType.SouthWest;
            }

            return MapCell.FlowDirectionType.NoFlowdirection;
        }
 public MapCell.FlowDirectionType Reverse(MapCell.FlowDirectionType type)
 {
     switch (type)
     {
         case MapCell.FlowDirectionType.North:
             return MapCell.FlowDirectionType.South;
         case MapCell.FlowDirectionType.South:
             return MapCell.FlowDirectionType.North;
         case MapCell.FlowDirectionType.SouthEast:
             return MapCell.FlowDirectionType.NorthWest;
         case MapCell.FlowDirectionType.NorthWest:
             return MapCell.FlowDirectionType.SouthEast;
         case MapCell.FlowDirectionType.SouthWest:
             return MapCell.FlowDirectionType.NorthEast;
         case MapCell.FlowDirectionType.NorthEast:
             return MapCell.FlowDirectionType.SouthWest;
         default:
             throw new Exception("Unknown flow " + type.ToString());
     }
 }
        private int CalcScore(string terrainNameAdjacent, MapCell mapCell)
        {
            switch (terrainNameAdjacent)
            {
                // terrain 
                case "Ocean":
                case "Shore":
                case "Coast":
                case "Grassland":
                case "Plains":
                case "Desert":
                case "Tundra":
                case "Snow":
                    if (terrainNameAdjacent == mapCell.Terrain.Name)
                        return 3;
                    break;
                // features
                case "Oasis":
                case "Jungle":
                case "Forest":
                case "Hills":
                case "Mountains":
                    if (mapCell.FeatureStr.ToLower().Contains(terrainNameAdjacent.ToLower()))
                        return 3;
                    break;                
                case "IsLand":
                    if (mapCell.IsLand)
                        return 2;
                    break;
                case "IsOcean":
                    if (mapCell.IsOcean)
                        return 2;
                    break;
                case "IsRiver":
                    if (mapCell.IsRiver)
                        return 2;
                    break;
                case "IsRiver||IsCoast":
                    if (mapCell.IsRiver || mapCell.IsCoast)
                        return 2;
                    break;
                case "*":
                    return 1;
                default:               
                    if (terrainNameAdjacent.StartsWith("River_"))
                    {
                        if (!mapCell.IsRiver)
                            break;

                        byte riverNum = byte.Parse(terrainNameAdjacent.Replace("River_", ""));

                        if (mapCell.RiverTileValue == riverNum)
                            return 3;

                        break;
                    }
                    else
                        throw new Exception(string.Format("Unkown Property: '{0}'", terrainNameAdjacent));
            }

            return 0;
        }
        public TileMatchPattern Match(MapData map, MapCell cell)
        {
            TileMatchPattern match = null;
            int bestScore = int.MinValue;

            foreach (TileMatchPattern pattern in _pattern)
            {
                int score = Match(pattern, map, cell);

                if (score > bestScore)
                {
                    bestScore = score;
                    match = pattern;
                }
            }

            if (match == null)
                throw new Exception("No default TileMatchPattern found!");

            match.Score = bestScore;

            return match;
        }