예제 #1
0
        public Game CloneWithController(BaseController controller)
        {
            Game clonedGame = new Game();

            int numPlayers = m_players.Length;

            clonedGame.m_players = new Player[numPlayers];

            clonedGame.Players = clonedGame.m_players.ToIndexable();
            clonedGame.Random = new Random(Random);
            clonedGame.m_nextCardGuid = m_nextCardGuid;
            clonedGame.ZoneConfigs = ZoneConfigs;

            if (controller != null)
            {
                controller.Game = clonedGame;
                clonedGame.Controller = controller;
            }

            clonedGame.CurrentPhase = CurrentPhase;
            clonedGame.Round = Round;
            clonedGame.m_actingPlayer = m_actingPlayer;
            clonedGame.DidSacrifice = DidSacrifice;
            clonedGame.DidRedeem = DidRedeem;

            // Clone the data structure (Behaviors will only be default-constructed)
            for (int i = 0; i < numPlayers; ++i)
            {
                clonedGame.m_players[i] = m_players[i].Clone(clonedGame);
            }

            // Transfer behaviors to cloned ones
            for (int i = 0; i < numPlayers; ++i)
            {
                clonedGame.m_players[i].TransferCardsFrom(m_players[i]);
            }

            return clonedGame;
        }
예제 #2
0
        public Game(List<string> playerNames, BaseController controller)
        {
            if (playerNames == null)
            {
                throw new ArgumentNullException("playerNames");
            }
            else if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }
            else if (controller.Game != null)
            {
                throw new ArgumentException("The controller is already bound.", "controller");
            }

            int numPlayers = playerNames.Count;
            if (numPlayers != 2)
            {
                //TODO: support game among more than 2 players
                throw new NotSupportedException("Battle of more than two players are not supported.");
            }

            m_players = new Player[numPlayers];
            for (int i = 0; i < numPlayers; ++i)
            {
                m_players[i] = new Player(playerNames[i], i, this);
            }

            controller.Game = this;

            CurrentPhase = "";

            Players = m_players.ToIndexable();
            Random = new Random(controller.GetRandomSeed());
            Controller = controller;
            LetterBox = new Messaging.LetterBox();
        }
예제 #3
0
        public void OverrideController(BaseController controller)
        {
            if (controller == null)
            {
                throw new ArgumentNullException("controller");
            }

            if (Controller != null)
            {
                Controller.Game = null;
            }
            Controller = controller;
            Controller.Game = this;
        }