Esempio n. 1
0
        private Road AddAdjacentRoad(TileCtrl tile, Road thisRoad, TileLocation adjTileLocation, RoadLocation adjRoadLocation)
        {
            Road thatRoad = GetRoadAt(tile, adjTileLocation, adjRoadLocation);

            thisRoad.AdjacentRoads.Add(thatRoad);
            return(thatRoad);
        }
Esempio n. 2
0
        private void SelectTile(TileCtrl newTile)
        {
            if (_selectedTile != null)
            {
                bool UnSelected = (newTile == _selectedTile);
                _selectedTile.Selected = false; // you can select a different one w/o closing the first one
                // boost below so you can see the whole focus rect - otherwise the overlappy rectangles make it confusing where mouse events go
                // the UI hides the boost from the UI. Deboost here
                int zIndex = Canvas.GetZIndex(_selectedTile);
                Canvas.SetZIndex(_selectedTile, zIndex - ZINDEX_BOOST);
                _selectedTile = null;
                if (UnSelected)
                {
                    return;
                }
            }

            if (newTile == null)
            {
                //
                //  can we get into this state?
                Debug.Assert(false, "SelectTile(null) called");
                return;
            }

            newTile.Selected = true;
            _selectedTile    = newTile;

            Canvas.SetZIndex(_selectedTile, Canvas.GetZIndex(_selectedTile) + ZINDEX_BOOST);
            //  Debug.WriteLine($"[GameView::SelectTile] Tile.ResourceType={newTile.ResourceType} tile.Index={newTile.Index}");


            EnableInput = true;
            UpdateBindings();
        }
Esempio n. 3
0
 public RoadSegmentData(Polygon rs, TileCtrl tile, RoadLocation loc, RoadState state)
 {
     RoadSegment = rs;
     Tile        = tile;
     Location    = loc;
     RoadState   = state;
 }
Esempio n. 4
0
        //
        //  if you want to set the tiles/harbors, get the current game, set Randomize to False, and then call this ShuffleReosurces()
        public void ShuffleResources()
        {
            foreach (TileGroup tileGroup in _currentGame.TileGroups)
            {
                if (tileGroup.Randomize == false)
                {
                    continue;
                }
                int harborCount = 0;

                if (_currentGame.Randomize)
                {
                    tileGroup.RandomResourceTypeList = GetRandomList(tileGroup.Tiles.Count - 1);
                    if (tileGroup.Harbors.Count > 1)
                    {
                        tileGroup.RandomHarborTypeList = GetRandomList(tileGroup.Harbors.Count - 1);
                    }
                }

                for (int i = 0; i < tileGroup.Tiles.Count; i++)
                {
                    TileCtrl t = tileGroup.Tiles[i];
                    t.ResourceType = tileGroup.ResourceTypes[tileGroup.RandomResourceTypeList[i]];

                    foreach (Harbor h in t.VisibleHarbors)
                    {
                        h.HarborType = tileGroup.HarborTypes[tileGroup.RandomHarborTypeList[harborCount]];
                        harborCount++;
                    }
                }
            }

            AssignNumbers();
        }
Esempio n. 5
0
 public void OnClose()
 {
     if (_selectedTile != null)
     {
         _selectedTile.Selected = false;
         _selectedTile          = null;
     }
 }
Esempio n. 6
0
        public void OnGridRightTapped(TileCtrl tile, RightTappedRoutedEventArgs rte)
        {
            if (_designModeSet)
            {
                if (tile != _selectedTile)
                {
                    SelectTile(tile);
                }

                _menuMain.ShowAt(tile, rte.GetPosition(tile));
            }
        }
Esempio n. 7
0
        internal Road GetRoadAt(TileCtrl tile, RoadLocation roadLocation)
        {
            if (tile == null)
            {
                return(null);
            }
            RoadKey key  = new RoadKey(tile, roadLocation);
            Road    road = null;

            _currentGame.RoadKeyToRoadDictionary.TryGetValue(key, out road);
            return(road);
        }
Esempio n. 8
0
        public void AssignNumbers()
        {
            bool valid      = false;
            int  iterations = 0;

            do
            {
                foreach (TileGroup tileGroup in _currentGame.TileGroups)
                {
                    if (tileGroup.Randomize == false)
                    {
                        continue;
                    }

                    int        numberSeqCount = 0;
                    List <int> RandomNumberSequence;
                    if (_useRandomNumbers)
                    {
                        RandomNumberSequence = GetRandomList(tileGroup.ValidNumbers.Count - DesertCount(tileGroup.Tiles) - 1);
                    }
                    else
                    {
                        RandomNumberSequence = new List <int>();
                        for (int i = 0; i <= (tileGroup.ValidNumbers.Count - DesertCount(tileGroup.Tiles) - 1); i++)
                        {
                            RandomNumberSequence.Add(i); //do it in the order of the saved game
                        }
                    }
                    for (int i = 0; i < tileGroup.Tiles.Count; i++)
                    {
                        TileCtrl t = tileGroup.Tiles[i];
                        if (t.ResourceType != ResourceType.Desert)
                        {
                            t.Number = tileGroup.ValidNumbers[RandomNumberSequence[numberSeqCount++]];
                            t.Baron  = false;
                        }
                        else
                        {
                            t.Number = 7;
                        }
                    }
                    iterations++;
                }


                valid = IsValidNumberLayout(_currentGame);
            } while (!valid);
            if (iterations > 200)
            {
                this.TraceMessage($"tried {iterations} times to find a valid number sequence");
            }
        }
Esempio n. 9
0
 public LogBuildingUpdate(int gameIndex, TileCtrl tileCtrl, BuildingCtrl buildingCtrl, BuildingState oldState, BuildingState newState)
 {
     GameIndex        = gameIndex;
     Tile             = tileCtrl;
     Building         = buildingCtrl;
     OldBuildingState = oldState;
     BuildingIndex    = buildingCtrl.Index;
     NewBuildingState = newState;
     if (tileCtrl != null)
     {
         TileIndex = tileCtrl.Index;
     }
 }
Esempio n. 10
0
        private void Tile_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e)
        {
            TileCtrl tile = sender as TileCtrl;

            if (tile.TileOrientation == TileOrientation.FaceUp)
            {
                tile.TileOrientation = TileOrientation.FaceDown;
            }
            else
            {
                tile.TileOrientation = TileOrientation.FaceUp;
            }
        }
Esempio n. 11
0
        //
        //  given a tile and a location, find the line segment that is in the same road
        public Polygon GetAdjacentRoadSegment(TileCtrl tile, RoadLocation myLocation)
        {
            return(null);
            //TileCtrl adjacent = this.GetAdjacentTile(tile, myLocation);


            //if (adjacent != null)
            //{
            //    return adjacent.GetRoadSegment(GetAdjacentLocation(myLocation));
            //}


            //return null;
        }
Esempio n. 12
0
        public void OnHarborRightTapped(TileCtrl tile, HarborLocation location, RightTappedRoutedEventArgs e)
        {
            if (!_designModeSet)
            {
                return;
            }

            if (tile != _selectedTile)
            {
                SelectTile(tile);
            }

            _clickedHarberLocation = location;
            _menuHarbor.ShowAt(tile, e.GetPosition(tile));
        }
Esempio n. 13
0
        private Road GetRoadAt(TileCtrl startTile, TileLocation adjTileLocation, RoadLocation roadLocation)
        {
            TileCtrl adjTile = null;

            if (adjTileLocation == TileLocation.Self)
            {
                adjTile = startTile;
            }
            else
            {
                adjTile = GetAdjacentTile(startTile, ((RoadLocation)(int)adjTileLocation));
            }

            return(GetRoadAt(adjTile, roadLocation));
        }
Esempio n. 14
0
        internal TileCtrl GetAdjacentTile(TileCtrl tile, RoadLocation adjacentLocation)
        {
            TileCtrl adj = null;
            List <List <TileCtrl> > visualLayout = _currentGame.VisualLayout();

            for (int col = 0; col < visualLayout.Count; col++)
            {
                for (int row = 0; row < visualLayout.ElementAt(col).Count; row++)
                {
                    TileCtrl t = visualLayout.ElementAt(col).ElementAt(row);
                    if (t == tile)
                    {
                        switch (adjacentLocation)
                        {
                        case RoadLocation.TopRight:
                            return(NextUpperRight(row, col));

                        case RoadLocation.TopLeft:
                            return(PreviousUpperLeft(row, col));

                        case RoadLocation.BottomRight:
                            return(NextLowerRight(row, col));

                        case RoadLocation.BottomLeft:
                            return(PreviousLowerLeft(row, col));

                        case RoadLocation.Top:
                            return(AboveTile(row, col));

                        case RoadLocation.Bottom:
                            return(BelowTile(row, col));

                        default:
                            break;
                        }
                    }
                }
            }


            return(adj);
        }
Esempio n. 15
0
        void AddSettlementClonesToDictionary(TileCtrl inputTile, RoadLocation[] roadLocations, SettlementLocation[] settlementLocations)
        {
            //SettlementCtrl adjSettlementCtr = null;
            //TileCtrl adjTile = null;
            //Settlement settlement = new Settlement(); // all SettlementCtrls in the SettlementLocations[] array should map to this Settlement
            //for (int i = 0; i < 3; i++)
            //{
            //    if (roadLocations[i] == RoadLocation.None)
            //        adjTile = inputTile;
            //    else
            //        adjTile = GetAdjacentTile(inputTile, roadLocations[i]);

            //    if (adjTile != null)
            //    {
            //        adjSettlementCtr = adjTile.SettlementAt(settlementLocations[i]);

            //        SettlementCtrlToSettlementData[adjSettlementCtr] = settlement; // so given a control, we can find the Settlement it is a member of

            //        //
            //        //  is this tile/control pair already in the map?
            //        SettlementKey key = new SettlementKey(adjTile, adjSettlementCtr.SettlementLocation);
            //        if (TileLocToSettlementData.ContainsKey(key) == false)  // note: we've implemented IComparer so that the key is looked at by value...
            //        {
            //            //
            //            // we haven't seen it with this key
            //            TileLocToSettlementData[key] = settlement;
            //        }

            //        SettlementData data = new SettlementData(adjTile, adjSettlementCtr); // the next settlement at the same location
            //        if (settlement.Contains(data) == false)
            //        {
            //            //
            //            //  don't add the SettlementData to the list unless it is a unique combo of location and tile
            //            settlement.Settlements.Add(data);
            //        }
            //    }

            //}
        }
Esempio n. 16
0
        //public new void KeyUp(KeyRoutedEventArgs e)
        //{
        //    throw new NotImplementedException();
        //}

        //public void TileSelected(TileCtrl tile)
        //{

        //    SelectTile(tile);
        //}

        //public void UpdateHexLayout()
        //{
        //    ForceHexPanelUpdate();
        //}

        public void OnGridLeftTapped(TileCtrl tile, TappedRoutedEventArgs e)
        {
            if (!_designModeSet)
            {
                return;
            }

            SelectTile(tile);

            if ((bool)SetOrder == true)
            {
                tile.Index = _tileIndex++;
                if (_tileIndex == this.TotalTiles)
                {
                    _tileIndex = 0;
                }

                //for (int i = _tileIndex; i<_tiles.Count; i++)
                //{
                //    _tiles[i].Index = i;
                //}
            }
        }
Esempio n. 17
0
        public LogBaronOrPirate(int gameIndex, PlayerModel targetPlayer, PlayerModel sourcePlayer, TileCtrl startTile, TileCtrl targetTile, TargetWeapon weapon, CatanAction action)
        {
            GameIndex = gameIndex;
            StartTile = startTile;
            Action    = action;
            if (startTile != null)
            {
                StartTileIndex = startTile.Index;
            }
            TargetTile      = targetTile;
            TargetTileIndex = targetTile.Index;
            TargetWeapon    = weapon;
            TargetPlayer    = targetPlayer;
            if (targetPlayer != null)
            {
                TargetPlayerIndex = targetPlayer.AllPlayerIndex;
            }

            SourcePlayer = sourcePlayer;
            if (sourcePlayer != null)
            {
                SourcePlayerIndex = sourcePlayer.AllPlayerIndex;
            }
        }
Esempio n. 18
0
        public Target(PlayerModel p, TileCtrl t)
        {
            Player = p;
            Tile   = t;
            foreach (var building in Tile.OwnedBuilding)
            {
                if (building.BuildingState == BuildingState.Settlement)
                {
                    ResourcePotential++;
                }
                else if (building.BuildingState == BuildingState.City)
                {
                    ResourcePotential += 2;
                }
                else
                {
                    throw new Exception("This building shouldn't be owned");
                }
            }

            ResourcePotential *= Tile.Pips;

            if (ResourcePotential > 0)
            {
                //
                //  check to see if this player has 2:1 in a resource from this tile

                foreach (var harbor in Player.GameData.OwnedHarbors)
                {
                    if (StaticHelpers.HarborTypeToResourceType(harbor.HarborType) == Tile.ResourceType)
                    {
                        ResourcePotential *= 2;
                    }
                }
            }
        }
Esempio n. 19
0
        public static RoadCtrl GetCloneOrCreate(PointCollection pointCollection, RoadLocation location, TileCtrl tile, Grid home, List <RoadCtrl> roads, Dictionary <RoadKey, RoadCtrl> roadKeyDictionary)
        {
            //foreach (RoadCtrl road in roads)
            //{
            //    if (road.Keys.Count > 0)
            //    {
            //        if (location == RoadLocation.Top && road.Keys[0].RoadLocation == RoadLocation.Bottom)
            //        {
            //            //  road.TraceMessage("this one");

            //        }
            //    }


            //    if (RoadCtrl.PolygonClose(road.RoadSegment1.Points, pointCollection, location) == true)
            //    {
            //        //
            //        //  same Road -- add to the list of keys stored inside the road (its "clones")
            //        //  and add it to both the dictionary of keys --> roads that is passed in and to
            //        //  the list of all the roads.

            //        road.RoadSegment2 = road.CreatePolygon(pointCollection, Colors.HotPink, location);
            //        RoadKey key = new RoadKey(tile, location);
            //        road.Keys.Add(key);
            //        roadKeyDictionary[key] = road;
            //        Canvas.SetZIndex(road.RoadSegment2, -1);
            //        home.Children.Add(road.RoadSegment2);
            //        return road;
            //    }
            //}

            ////
            ////  didn't find it -- i'm assuming it is a new road--every road has win or it is on the edge

            //RoadCtrl rd = null;
            //rd = new RoadCtrl();
            //rd.RoadSegment1 = rd.CreatePolygon(pointCollection, Colors.HotPink, location);
            //Canvas.SetZIndex(rd.RoadSegment1, -1);

            //roads.Add(rd);
            //home.Children.Add(rd.RoadSegment1);
            //RoadKey k = new RoadKey(tile, location);
            //rd.Keys.Add(k);
            //roadKeyDictionary[k] = rd;

            //return rd;
            return(null);
        }
Esempio n. 20
0
 public TileCtrl GetAdjacentTile(TileCtrl tile, TileLocation adjacentLocation)
 {
     return(GetAdjacentTile(tile.Row, tile.Col, adjacentLocation));
 }
Esempio n. 21
0
 public SettlementData(TileCtrl t, SettlementCtrl setttlement)
 {
     Tile       = t;
     Location   = setttlement.SettlementLocation;
     Settlement = setttlement;
 }
Esempio n. 22
0
        public async Task FancyTileDistribution()
        {
            List <Task> list = new List <Task>();
            double      ms   = MainPage.GetAnimationSpeed(AnimationSpeed.Fast);;
            int         i    = 0;

            foreach (TileGroup tileGroup in _currentGame.TileGroups)
            {
                if (tileGroup.Randomize == false)
                {
                    continue;
                }
                TileCtrl centerTile = tileGroup.Tiles.Last();;
                foreach (TileCtrl t in tileGroup.Tiles)
                {
                    GeneralTransform gt   = centerTile.HexGrid.TransformToVisual(t.HexGrid);
                    Point            pt   = gt.TransformPoint(new Point(0, 0));
                    Task             task = t.AnimateMoveTask(pt, ms, i * ms);
                    i++;
                    t.zIndex = 1000 - i;
                    list.Add(task);
                }
            }
            await Task.WhenAll(list);

            list.Clear();
            i = 0;
            Random r = new Random(DateTime.Now.Millisecond);

            foreach (TileGroup tileGroup in _currentGame.TileGroups)
            {
                if (tileGroup.Randomize == false)
                {
                    continue;
                }
                foreach (TileCtrl t in tileGroup.Tiles)
                {
                    Task task = t.RotateTask(r.Next(1, 5) * 360, MainPage.GetAnimationSpeed(AnimationSpeed.Fast));
                    list.Add(task);
                }
            }
            await Task.WhenAll(list);

            list.Clear();
            i = 0;


            foreach (TileGroup tileGroup in _currentGame.TileGroups)
            {
                if (tileGroup.Randomize == false)
                {
                    continue;
                }
                foreach (TileCtrl t in tileGroup.Tiles)
                {
                    t.ResetTileRotation();
                }
            }


            foreach (TileGroup tileGroup in _currentGame.TileGroups)
            {
                if (tileGroup.Randomize == false)
                {
                    continue;
                }
                foreach (TileCtrl t in tileGroup.Tiles)
                {
                    Task task = t.AnimateMoveTask(new Point(0, 0), ms, i * ms);
                    i++;
                    list.Add(task);
                }
            }
            await Task.WhenAll(list);

            list.Clear();
            i = 0;
            foreach (TileGroup tileGroup in _currentGame.TileGroups)
            {
                if (tileGroup.Randomize == false)
                {
                    continue;
                }

                foreach (TileCtrl t in tileGroup.Tiles)
                {
                    Task task = t.SetTileOrientation(TileOrientation.FaceUp, false, MainPage.GetAnimationSpeed(AnimationSpeed.Fast), i * MainPage.GetAnimationSpeed(AnimationSpeed.Fast));
                    i++;
                    list.Add(task);
                }
            }

            await Task.WhenAll(list);
        }
Esempio n. 23
0
        public async Task FancyHarborDistribution()
        {
            List <Task> list = new List <Task>();
            double      ms   = MainPage.GetAnimationSpeed(AnimationSpeed.Normal);
            int         i    = 0;



            foreach (TileGroup tileGroup in _currentGame.TileGroups)
            {
                TileCtrl animationMiddle = tileGroup.Tiles[tileGroup.Tiles.Count / 2];

                for (i = 0; i < tileGroup.Harbors.Count; i++)
                {
                    int j = i + 1;
                    if (j == tileGroup.Harbors.Count)
                    {
                        j = 0;
                    }

                    GeneralTransform gt   = animationMiddle.TransformToVisual(tileGroup.Harbors[i]);
                    Point            pt   = gt.TransformPoint(new Point(tileGroup.Harbors[0].Width, tileGroup.Harbors[0].Height));
                    Task             task = tileGroup.Harbors[i].AnimateMoveTask(pt, ms, i * ms);
                    list.Add(task);
                }
            }
            await Task.WhenAll(list);

            list.Clear();
            i = 0;
            Random r = new Random(DateTime.Now.Millisecond);

            ms = MainPage.GetAnimationSpeed(AnimationSpeed.Normal);
            foreach (TileGroup tileGroup in _currentGame.TileGroups)
            {
                foreach (var h in tileGroup.Harbors)
                {
                    Task task = h.RotateTask(r.Next(1, 10) * 360, ms);
                    list.Add(task);
                }
            }
            await Task.WhenAll(list);

            list.Clear();
            i  = 0;
            ms = MainPage.GetAnimationSpeed(AnimationSpeed.Fast);
            foreach (TileGroup tileGroup in _currentGame.TileGroups)
            {
                foreach (var h in tileGroup.Harbors)
                {
                    Task task = h.AnimateMoveTask(new Point(0, 0), ms, i * ms);
                    i++;
                    list.Add(task);
                }
            }
            await Task.WhenAll(list);

            list.Clear();
            i  = 0;
            ms = ms = MainPage.GetAnimationSpeed(AnimationSpeed.Normal);
            foreach (TileGroup tileGroup in _currentGame.TileGroups)
            {
                foreach (var h in tileGroup.Harbors)
                {
                    Task task = h.SetOrientation(TileOrientation.FaceUp, ms, i * ms);
                    i++;
                    list.Add(task);
                }
            }

            await Task.WhenAll(list);
        }
Esempio n. 24
0
 public SettlementCtrl GetSettlement(TileCtrl tile, SettlementLocation loc)
 {
     return(GetSettlement(new SettlementKey(tile, loc)));
 }
Esempio n. 25
0
 public RoadKey(TileCtrl tile, RoadLocation loc)
 {
     Tile         = tile;
     RoadLocation = loc;
 }
Esempio n. 26
0
        //
        //  setup all the Heads and Tails for the Tiles
        //
        //  by convetion Top, TopRight, and BottomRight are "heads" and Bottom, BottomLeft, and TopLeft are "tails"
        //private void BuildRoadBinaryTree()
        //{
        //    List<List<TileCtrl>> visualTiles = CurrentGame.VisualLayout();

        //    for (int col = 0; col < Columns; col++)
        //    {
        //        for (int row = 0; row < visualTiles.ElementAt(col).Count; row++)
        //        {
        //            TileCtrl tile = visualTiles.ElementAt(col).ElementAt(row);
        //            Road thatRoad = null;
        //            Road thisRoad = null;
        //            foreach (TileLocation loc in Enum.GetValues(typeof(TileLocation)))
        //            {
        //                if (loc == TileLocation.Self) continue;

        //                thisRoad = GetRoadAt(tile, (RoadLocation)loc);

        //                switch (loc)
        //                {

        //                    case TileLocation.Top:
        //                        thatRoad = GetRoadAt(tile, TileLocation.Self, RoadLocation.TopRight);
        //                        thisRoad.AddHeads(thatRoad);
        //                        thatRoad?.AddTails(thisRoad);
        //                        thatRoad = GetRoadAt(tile, TileLocation.Self, RoadLocation.TopLeft);
        //                        thisRoad.AddTails(thatRoad);
        //                        thatRoad?.AddHeads(thisRoad);
        //                        if (thatRoad != null) thatRoad.BreakCycleRoad = thisRoad; // only place this is set

        //                        thatRoad = GetRoadAt(tile, TileLocation.Top, RoadLocation.BottomLeft);
        //                        if (thatRoad != null)
        //                        {
        //                            thisRoad.AddTails(thatRoad);
        //                            thatRoad?.AddHeads(thisRoad);
        //                        }
        //                        else
        //                        {
        //                            thatRoad = GetRoadAt(tile, TileLocation.TopLeft, RoadLocation.TopRight);
        //                            thisRoad.AddTails(thatRoad);
        //                            thatRoad?.AddHeads(thisRoad);
        //                        }

        //                        thatRoad = GetRoadAt(tile, TileLocation.Top, RoadLocation.BottomRight);
        //                        if (thatRoad != null)
        //                        {
        //                            thisRoad.AddHeads(thatRoad);
        //                            thatRoad?.AddTails(thisRoad);
        //                        }
        //                        else
        //                        {
        //                            thatRoad = GetRoadAt(tile, TileLocation.TopRight, RoadLocation.TopLeft);
        //                            thisRoad.AddHeads(thatRoad);
        //                            thatRoad?.AddTails(thisRoad);
        //                        }
        //                        break;
        //                    case TileLocation.TopRight:
        //                        thatRoad = GetRoadAt(tile, TileLocation.Self, RoadLocation.BottomRight);
        //                        thisRoad.AddHeads(thatRoad);
        //                        thatRoad?.AddHeads(thisRoad);   // note cycle
        //                        thatRoad = GetRoadAt(tile, TileLocation.Self, RoadLocation.Top);
        //                        thisRoad.AddTails(thatRoad);
        //                        thatRoad?.AddHeads(thisRoad);

        //                        thatRoad = GetRoadAt(tile, TileLocation.Top, RoadLocation.BottomRight);
        //                        if (thatRoad != null)
        //                        {
        //                            thisRoad.AddTails(thatRoad);
        //                            thatRoad?.AddHeads(thisRoad);
        //                        }
        //                        else
        //                        {
        //                            thatRoad = GetRoadAt(tile, TileLocation.TopRight, RoadLocation.TopLeft);
        //                            thisRoad.AddTails(thatRoad);
        //                            thatRoad?.AddHeads(thisRoad);
        //                        }

        //                        thatRoad = GetRoadAt(tile, TileLocation.TopRight, RoadLocation.Bottom);
        //                        if (thatRoad != null)
        //                        {
        //                            thisRoad.AddHeads(thatRoad);
        //                            thatRoad?.AddTails(thisRoad);
        //                        }
        //                        else
        //                        {
        //                            thatRoad = GetRoadAt(tile, TileLocation.BottomRight, RoadLocation.Top);
        //                            thisRoad.AddHeads(thatRoad);
        //                            thatRoad?.AddTails(thisRoad);
        //                        }
        //                        break;

        //                    case TileLocation.BottomRight:
        //                        thatRoad = GetRoadAt(tile, TileLocation.Self, RoadLocation.Bottom);
        //                        thisRoad.AddTails(thatRoad);
        //                        thatRoad?.AddHeads(thisRoad);

        //                        thatRoad = GetRoadAt(tile, TileLocation.Self, RoadLocation.TopRight);
        //                        thisRoad.AddTails(thatRoad);
        //                        thatRoad?.AddHeads(thisRoad);

        //                        thatRoad = GetRoadAt(tile, TileLocation.Bottom, RoadLocation.TopRight);
        //                        if (thatRoad != null)
        //                        {
        //                            thisRoad.AddTails(thatRoad);
        //                            thatRoad?.AddHeads(thisRoad);
        //                        }
        //                        else
        //                        {
        //                            thatRoad = GetRoadAt(tile, TileLocation.BottomLeft, RoadLocation.TopRight);
        //                            thisRoad.AddTails(thatRoad);
        //                            thatRoad?.AddHeads(thisRoad);
        //                        }

        //                        thatRoad = GetRoadAt(tile, TileLocation.Bottom, RoadLocation.TopRight);
        //                        if (thatRoad != null)
        //                        {
        //                            thisRoad.AddHeads(thatRoad);
        //                            thatRoad?.AddTails(thisRoad);
        //                        }
        //                        else
        //                        {
        //                            thatRoad = GetRoadAt(tile, TileLocation.BottomRight, RoadLocation.TopLeft);
        //                            thisRoad.AddTails(thatRoad);
        //                            thatRoad?.AddHeads(thisRoad);
        //                        }
        //                        break;
        //                    case TileLocation.Bottom:
        //                        thatRoad = GetRoadAt(tile, TileLocation.Self, RoadLocation.BottomRight);
        //                        thisRoad.AddHeads(thatRoad);
        //                        thatRoad?.AddTails(thisRoad);
        //                        thatRoad = GetRoadAt(tile, TileLocation.Self, RoadLocation.BottomLeft);
        //                        thisRoad.AddTails(thatRoad);
        //                        thatRoad?.AddHeads(thisRoad);

        //                        thatRoad = GetRoadAt(tile, TileLocation.Bottom, RoadLocation.TopRight);
        //                        if (thatRoad != null)
        //                        {
        //                            thisRoad.AddTails(thatRoad);
        //                            thatRoad?.AddHeads(thisRoad);
        //                        }
        //                        else
        //                        {
        //                            thatRoad = GetRoadAt(tile, TileLocation.BottomRight, RoadLocation.BottomLeft);
        //                            thisRoad.AddTails(thatRoad);
        //                            thatRoad?.AddHeads(thisRoad);
        //                        }

        //                        thatRoad = GetRoadAt(tile, TileLocation.BottomLeft, RoadLocation.Top);
        //                        if (thatRoad != null)
        //                        {
        //                            thisRoad.AddHeads(thatRoad);
        //                            thatRoad?.AddTails(thisRoad);
        //                        }
        //                        else
        //                        {
        //                            thatRoad = GetRoadAt(tile, TileLocation.TopRight, RoadLocation.Bottom);
        //                            thisRoad.AddHeads(thatRoad);
        //                            thatRoad?.AddTails(thisRoad);
        //                        }
        //                        break;
        //                    case TileLocation.BottomLeft:
        //                        //  my first Head (on the same tile)
        //                        thatRoad = GetRoadAt(tile, TileLocation.Self, RoadLocation.TopLeft);
        //                        thisRoad.AddHeads(thatRoad);
        //                        thatRoad?.AddTails(thisRoad);
        //                        // my first tail (on the same tile)
        //                        thatRoad = GetRoadAt(tile, TileLocation.Self, RoadLocation.Bottom);
        //                        thisRoad.AddTails(thatRoad);
        //                        thatRoad?.AddHeads(thisRoad);

        //                        thatRoad = GetRoadAt(tile, TileLocation.Bottom, RoadLocation.TopLeft);
        //                        if (thatRoad != null)
        //                        {
        //                            thisRoad.AddHeads(thatRoad);
        //                            thatRoad?.AddTails(thisRoad);
        //                        }
        //                        else
        //                        {
        //                            thatRoad = GetRoadAt(tile, TileLocation.BottomLeft, RoadLocation.BottomLeft);
        //                            thisRoad.AddHeads(thatRoad);
        //                            thatRoad?.AddTails(thisRoad);
        //                        }

        //                        thatRoad = GetRoadAt(tile, TileLocation.BottomLeft, RoadLocation.Top);
        //                        if (thatRoad != null)
        //                        {
        //                            thisRoad.AddHeads(thatRoad);
        //                            thatRoad?.AddHeads(thisRoad); // this is the cylce!!
        //                        }
        //                        else
        //                        {
        //                            thatRoad = GetRoadAt(tile, TileLocation.TopLeft, RoadLocation.Bottom);
        //                            thisRoad.AddHeads(thatRoad);
        //                            thatRoad?.AddHeads(thisRoad); // this is the cylce!!
        //                        }
        //                        break;
        //                    case TileLocation.TopLeft:
        //                        thatRoad = GetRoadAt(tile, TileLocation.Self, RoadLocation.Top);
        //                        thisRoad.AddHeads(thatRoad);
        //                        thatRoad?.AddTails(thisRoad);
        //                        thatRoad = GetRoadAt(tile, TileLocation.Self, RoadLocation.BottomLeft);
        //                        thisRoad.AddTails(thatRoad);
        //                        thatRoad?.AddHeads(thisRoad);

        //                        thatRoad = GetRoadAt(tile, TileLocation.Top, RoadLocation.BottomLeft);
        //                        if (thatRoad != null)
        //                        {
        //                            thisRoad.AddHeads(thatRoad);
        //                            thatRoad?.AddTails(thisRoad);
        //                        }
        //                        else
        //                        {
        //                            thatRoad = GetRoadAt(tile, TileLocation.TopLeft, RoadLocation.TopRight);
        //                            thisRoad.AddHeads(thatRoad);
        //                            thatRoad?.AddTails(thisRoad);
        //                        }

        //                        thatRoad = GetRoadAt(tile, TileLocation.BottomLeft, RoadLocation.Top);
        //                        if (thatRoad != null)
        //                        {
        //                            thisRoad.AddTails(thatRoad);
        //                            thatRoad?.AddHeads(thisRoad);
        //                        }
        //                        else
        //                        {
        //                            thatRoad = GetRoadAt(tile, TileLocation.TopLeft, RoadLocation.Bottom);
        //                            thisRoad.AddTails(thatRoad);
        //                            thatRoad?.AddHeads(thisRoad);
        //                        }
        //                        break;
        //                    default:
        //                        break;
        //                }

        //            }
        //        }
        //    }
        //}


        private void AddAdjacentRoads()
        {
            List <List <TileCtrl> > visualTiles = CurrentGame.VisualLayout();

            for (int col = 0; col < Columns; col++)
            {
                for (int row = 0; row < visualTiles.ElementAt(col).Count; row++)
                {
                    TileCtrl tile     = visualTiles.ElementAt(col).ElementAt(row);
                    Road     thisRoad = null;
                    Road     adjRoad  = null;
                    foreach (TileLocation loc in Enum.GetValues(typeof(TileLocation)))
                    {
                        if (loc == TileLocation.Self)
                        {
                            continue;
                        }

                        thisRoad = GetRoadAt(tile, (RoadLocation)loc);

                        switch (loc)
                        {
                        case TileLocation.Top:
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Self, RoadLocation.TopRight);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Self, RoadLocation.TopLeft);

                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Top, RoadLocation.BottomLeft);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Top, RoadLocation.BottomRight);

                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.TopLeft, RoadLocation.TopRight);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.TopRight, RoadLocation.TopLeft);
                            break;

                        case TileLocation.TopRight:
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Self, RoadLocation.BottomRight);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Self, RoadLocation.Top);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.TopRight, RoadLocation.TopLeft);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.BottomRight, RoadLocation.Top);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Top, RoadLocation.BottomRight);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.TopRight, RoadLocation.Bottom);

                            break;

                        case TileLocation.BottomRight:
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Self, RoadLocation.Bottom);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Self, RoadLocation.TopRight);

                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Bottom, RoadLocation.TopRight);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.BottomRight, RoadLocation.BottomLeft);

                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.TopRight, RoadLocation.Bottom);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.BottomRight, RoadLocation.Top);

                            break;

                        case TileLocation.Bottom:
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Self, RoadLocation.BottomRight);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Self, RoadLocation.BottomLeft);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Bottom, RoadLocation.TopRight);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Bottom, RoadLocation.TopLeft);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.BottomRight, RoadLocation.BottomLeft);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.BottomLeft, RoadLocation.BottomRight);

                            break;

                        case TileLocation.BottomLeft:

                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Self, RoadLocation.TopLeft);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Self, RoadLocation.Bottom);

                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Bottom, RoadLocation.TopLeft);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.BottomLeft, RoadLocation.BottomRight);

                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.BottomLeft, RoadLocation.Top);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.TopLeft, RoadLocation.Bottom);
                            break;

                        case TileLocation.TopLeft:
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Self, RoadLocation.Top);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Self, RoadLocation.BottomLeft);

                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.Top, RoadLocation.BottomLeft);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.TopLeft, RoadLocation.TopRight);

                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.BottomLeft, RoadLocation.Top);
                            adjRoad = AddAdjacentRoad(tile, thisRoad, TileLocation.TopLeft, RoadLocation.Bottom);
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 27
0
        private void AddSameSettlementLocationToDictionary(TileCtrl tile, SettlementCtrl inputSettlementCtrl)
        {
            RoadLocation[]       adjTileLocations   = null;
            SettlementLocation[] settlementLocation = null;
            SettlementLocation   inputLocation      = inputSettlementCtrl.SettlementLocation;

            switch (inputLocation)
            {
            case SettlementLocation.TopRight:
                adjTileLocations = new RoadLocation[3] {
                    RoadLocation.None, RoadLocation.Top, RoadLocation.TopRight
                };
                settlementLocation = new SettlementLocation[3] {
                    inputLocation, SettlementLocation.BottomRight, SettlementLocation.MiddleLeft
                };
                break;

            case SettlementLocation.MiddleRight:
                adjTileLocations = new RoadLocation[3] {
                    RoadLocation.None, RoadLocation.TopRight, RoadLocation.BottomRight
                };
                settlementLocation = new SettlementLocation[3] {
                    inputLocation, SettlementLocation.BottomLeft, SettlementLocation.TopLeft
                };
                break;

            case SettlementLocation.BottomRight:
                adjTileLocations = new RoadLocation[3] {
                    RoadLocation.None, RoadLocation.BottomRight, RoadLocation.Bottom
                };
                settlementLocation = new SettlementLocation[3] {
                    inputLocation, SettlementLocation.MiddleLeft, SettlementLocation.TopRight
                };
                break;

            case SettlementLocation.BottomLeft:
                adjTileLocations = new RoadLocation[3] {
                    RoadLocation.None, RoadLocation.Bottom, RoadLocation.BottomLeft
                };
                settlementLocation = new SettlementLocation[3] {
                    inputLocation, SettlementLocation.TopRight, SettlementLocation.MiddleRight
                };
                break;

            case SettlementLocation.MiddleLeft:
                adjTileLocations = new RoadLocation[3] {
                    RoadLocation.None, RoadLocation.BottomLeft, RoadLocation.TopLeft
                };
                settlementLocation = new SettlementLocation[3] {
                    inputLocation, SettlementLocation.TopRight, SettlementLocation.BottomRight
                };
                break;

            case SettlementLocation.TopLeft:
                adjTileLocations = new RoadLocation[3] {
                    RoadLocation.None, RoadLocation.TopLeft, RoadLocation.Top
                };
                settlementLocation = new SettlementLocation[3] {
                    inputLocation, SettlementLocation.MiddleRight, SettlementLocation.BottomLeft
                };
                break;

            case SettlementLocation.None:
                break;

            default:
                break;
            }

            AddSettlementClonesToDictionary(tile, adjTileLocations, settlementLocation);
        }