Пример #1
0
        public override void AssignTerritoriesRandomly(Random r) 
        {
            while (Game.UnassignedTerritories.Count > 0)
            {
                foreach (RiskPlayer p in Game.Players)
                {
                    BoardTerritory t = Game.UnassignedTerritories[r.Next(Game.UnassignedTerritories.Count)];

                    PlayerTerritory pt = new PlayerTerritory(t, p, 1);

                    Game.PlayerTerritories.Add(pt);
                    Game.UnassignedTerritories.Remove(t);
                }
            }

            Game.State = new FirstReinforcementRound(this, r);
            Game.SetCurrentPlayerIndex(r.Next(Game.Players.Count));
        }
Пример #2
0
        // Game Logic

        public override void TerritorySelected(string territoryName) 
        {
            PlayerTerritory pt = Turn.Game.PlayerTerritories.Where(n => n.boardTerritory.Name == territoryName).Single();

            if (Turn.Player == pt.Player && pt.CanFortify && SourceTerritory == null)
            {
                /// This is the source territory
                SourceTerritory = pt;
            }

            else if (SourceTerritory != null && SourceTerritory.FortifiableTerritories.Contains(pt))
            {
                TargetTerritory = pt;

                ExecuteFortify();
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
Пример #3
0
        /// Recursively determines the valid targets for fortification
        
        private List<PlayerTerritory> GetFortifiable(PlayerTerritory pt, List<PlayerTerritory> excludeList)
        {
            List<PlayerTerritory> lst = new List<PlayerTerritory>();
            excludeList.Add(pt);

            foreach (BoardTerritory bt in pt.boardTerritory.AdjacentTerritories)
            {
                // Search all adjacentTerritories for ones that the same player owns.
                // Exclude ones we've already found

                PlayerTerritory pt_child = Player.Game.PlayerTerritories.Where(n => n.boardTerritory.Name == bt.Name).Single();

                if (!excludeList.Contains(pt_child) && pt_child.Player == pt.Player)
                {
                    lst.Add(pt_child);
                    excludeList.Add(pt_child);
                    lst.AddRange(GetFortifiable(pt_child, excludeList));
                }
            }

            return lst;
        }
Пример #4
0
        // Game Logic

        public override void TerritorySelected(string territoryName) 
        {
            PlayerTerritory pt = Turn.Game.PlayerTerritories.Where(n => n.boardTerritory.Name == territoryName).Single();

            if (Turn.Player == pt.Player && pt.CanAttack)
            {
                /// This is the attacking territory
                AttackingTerritory = pt;
            }
            else if (Turn.Player != pt.Player)
            {
                /// Must choose attacker first

                if (AttackingTerritory == null)
                    throw new InvalidOperationException();

                /// Must be attackable

                if (!AttackingTerritory.AttackableTerritories.Contains(pt))
                    throw new InvalidOperationException();

                DefendingTerritory = pt;

                ExecuteAttack();
            }
            else
            {
                throw new InvalidOperationException();
            }


        }