public void Run(HSInputState state)
        {
            var player = _context.GetPlayer(state.PlayerId.Value);

            // if property isn't yet chosen
            var propertyChoice = _context.GetComponent <HSPropertyChoice>();

            if (propertyChoice == null)
            {
                if (!_context.ContainsComponent <HSPropertyChoiceRequest>())
                {
                    _context.Add(new PrintLine("Choose property to manage", OutputStream.HSInputLog));
                    _context.Add(new PrintProperties(player.Properties.ToList(), OutputStream.HSInputLog));
                    _context.Add(new PrintLine("Print -1 to cancel", OutputStream.HSInputLog));

                    _context.Add(new HSPropertyChoiceRequest(player.Id, player.Properties.ToList()));
                }
                return;
            }

            // if player canceled
            if (!propertyChoice.PropId.HasValue)
            {
                _context.Add(new ClearOutput());
                _context.Remove <HSPropertyChoice>();
                state.CurState = HSState.TurnChoice;
                return;
            }

            // if player is willing to force himself to manage his dreaded property
            state.CurState = HSState.PropManageChooseAction;
        }
コード例 #2
0
        public void Run(HSInputState state)
        {
            var choice = _context.GetComponent <HSCommandChoice>();

            if (choice == null)
            {
                if (!_context.ContainsComponent <HSCommandChoiceRequest>())
                {
                    var commands = new List <MonopolyCommand>
                    {
                        MonopolyCommand.AcceptOffer,
                        MonopolyCommand.DeclineOffer,
                    };

                    _context.Add(new PrintCommands(commands));
                    _context.Add(new HSCommandChoiceRequest(commands, state.PlayerId.Value));
                }
                return;
            }

            switch (choice.Command)
            {
            case MonopolyCommand.AcceptOffer:
                _context.Add(new TradeAccept());
                break;

            case MonopolyCommand.DeclineOffer:
                _context.Add(new TradeRefuse());
                break;
            }

            _context.Remove(choice);
            _context.Add(new ClearOutput());
            state.Nullify();
        }
コード例 #3
0
        public void Run(HSInputState state)
        {
            var commandChoice = _context.GetComponent <HSCommandChoice>();

            if (commandChoice == null)
            {
                return;
            }

            _context.Add(new ClearOutput());
            var player = _context.GetPlayer(state.PlayerId.Value);

            switch (commandChoice.Command)
            {
            case MonopolyCommand.BuyProperty:
                _context.Add(new BuyProperty(player.Id, player.CurTileId));
                break;

            case MonopolyCommand.AuctionProperty:
                _context.Add(new StartAuction(player.CurTileId));
                break;
            }
            _context.Remove <HSCommandChoice>(c => c.Command == commandChoice.Command);

            state.Nullify();
        }
コード例 #4
0
        public void Run(HSInputState state)
        {
            var assets = (PlayerAssets)state.MiscInfo;

            var choice = _context.GetComponent <HSIntChoice>();

            if (choice == null)
            {
                if (!_context.ContainsComponent <HSIntRequest>())
                {
                    var playerCash = _context.GetPlayer(assets.PlayerId).Cash;

                    _context.Add(new PrintLine($"Choose an amount of cash (up to {playerCash}):", OutputStream.HSInputLog));
                    _context.Add(new HSIntRequest(state.PlayerId.Value, 0, playerCash));
                }
                return;
            }

            assets.Cash = choice.Choice;

            state.CurState = HSState.TradeChangeAssets;

            _context.Add(new ClearOutput());
            _context.Remove(choice);
        }
コード例 #5
0
        public void Run(HSInputState state)
        {
            var assets = (PlayerAssets)state.MiscInfo;

            var choice = _context.GetComponent <HSPropertyChoiceMultiple>();

            if (choice == null)
            {
                if (!_context.ContainsComponent <HSPropertyChoiceMultipleRequest>())
                {
                    var tradableProperties = _context.TradableProperties(assets.PlayerId);

                    _context.Add(new PrintLine("Choose properties from the list:", OutputStream.HSInputLog));
                    _context.Add(new PrintProperties(tradableProperties, OutputStream.HSInputLog, indexate: true));
                    _context.Add(new HSPropertyChoiceMultipleRequest(assets.PlayerId, tradableProperties));
                }
                return;
            }

            assets.Properties = choice.PropertiesChosen;

            state.CurState = HSState.TradeChangeAssets;
            _context.Add(new ClearOutput());
            _context.Remove(choice);
        }
コード例 #6
0
        public void Run(HSInputState state)
        {
            var choice = _context.GetComponent <HSPlayerChoice>();

            if (choice == null)
            {
                if (!_context.ContainsComponent <HSPlayerChoiceRequest>())
                {
                    var availablePlayers = _context.GetAllPlayers()
                                           .Select(p => p.Id)
                                           .Where(id => id != state.PlayerId.Value)
                                           .ToList();

                    _context.Add(new PrintLine("Choose a player to trade with:", OutputStream.HSInputLog));
                    _context.Add(new PrintPlayers(availablePlayers, OutputStream.HSInputLog));
                    _context.Add(new PrintLine("Write -1 to cancel", OutputStream.HSInputLog));
                    _context.Add(new HSPlayerChoiceRequest(state.PlayerId.Value, availablePlayers));
                }
                return;
            }

            // if player canceled his choice
            if (!choice.PlayerChoiceId.HasValue)
            {
                _context.Remove <TradeOffer>();
                state.Nullify();
            }
            else
            {
                _context.TradeOffer().ReceiverAssets.PlayerId = choice.PlayerChoiceId.Value;
                state.CurState = HSState.TradeChooseAction;
            }
            _context.Add(new ClearOutput());
            _context.Remove(choice);
        }
コード例 #7
0
        public void Run(HSInputState state)
        {
            var debt   = _context.GetComponent <PlayerDebt>();
            var player = _context.GetPlayer(state.PlayerId.Value);
            var propId = (int)state.MiscInfo;

            var choice = _context.GetComponent <HSCommandChoice>();

            if (choice == null)
            {
                if (!_context.ContainsComponent <HSCommandChoiceRequest>())
                {
                    _context.Add(new PrintLine($"You're in debt. Debt amount: {debt.DebtAmount}; current Cash: {player.Cash}",
                                               OutputStream.HSInputLog));

                    var availableCommands = _context.GetAvailablePropertyActions(player, propId)
                                            .Where(command => IsSuitablePropertyAction(command))
                                            .ToList();

                    availableCommands.Add(MonopolyCommand.CancelAction);
                    if (player.Cash >= debt.DebtAmount)
                    {
                        availableCommands.Add(MonopolyCommand.PayDebt);
                    }

                    _context.Add(new PrintLine("\nProperty to manage:", OutputStream.HSInputLog));
                    _context.Add(new PrintProperties(propId, OutputStream.HSInputLog));
                    _context.Add(new PrintLine("", OutputStream.HSInputLog));
                    _context.Add(new PrintCommands(availableCommands));

                    _context.Add(new HSCommandChoiceRequest(availableCommands, player.Id));
                }

                return;
            }

            switch (choice.Command)
            {
            case MonopolyCommand.MortgageProperty:
                _context.Mortgage(player, propId);
                break;

            case MonopolyCommand.SellHouse:
                _context.SellHouse(player, propId);
                break;

            case MonopolyCommand.CancelAction:
                state.Set(HSState.DebtChooseProperty, player.Id);
                break;

            case MonopolyCommand.PayDebt:
                _context.Add(new PaidOffDebt(player.Id));
                state.Nullify();
                break;
            }

            _context.Remove(choice);
            _context.Add(new ClearOutput());
        }
コード例 #8
0
        public void Run(HSInputState state)
        {
            var offer = _context.TradeOffer();

            var choice = _context.GetComponent <HSCommandChoice>();

            if (choice == null)
            {
                if (!_context.ContainsComponent <HSCommandChoiceRequest>())
                {
                    var commands = new List <MonopolyCommand>
                    {
                        MonopolyCommand.ConfirmTrade,
                        MonopolyCommand.ChangeInitiatorAssets,
                        MonopolyCommand.ChangeReceiverAssets,
                        MonopolyCommand.CancelAction,
                    };

                    _context.Add(new PrintTradeOffer(offer, OutputStream.HSInputLog));
                    _context.Add(new PrintLine("", OutputStream.HSInputLog));
                    _context.Add(new PrintCommands(commands));

                    _context.Add(new HSCommandChoiceRequest(commands, state.PlayerId.Value));
                }
                return;
            }

            switch (choice.Command)
            {
            case MonopolyCommand.ConfirmTrade:
                state.Nullify();
                break;

            case MonopolyCommand.ChangeReceiverAssets:
            case MonopolyCommand.ChangeInitiatorAssets:
                state.CurState = HSState.TradeChangeAssets;
                if (choice.Command == MonopolyCommand.ChangeInitiatorAssets)
                {
                    state.MiscInfo = offer.InitiatorAssets;
                }
                else
                {
                    state.MiscInfo = offer.ReceiverAssets;
                }
                break;

            case MonopolyCommand.CancelAction:
                _context.Remove(offer);
                state.Nullify();
                break;
            }

            _context.Add(new ClearOutput());
            _context.Remove <HSCommandChoice>();
        }
コード例 #9
0
        public void Run(HSInputState state)
        {
            var assets = (PlayerAssets)state.MiscInfo;

            var choice = _context.GetComponent <HSCommandChoice>();

            if (choice == null)
            {
                if (!_context.ContainsComponent <HSCommandChoiceRequest>())
                {
                    var availableCommands = new List <MonopolyCommand>
                    {
                        MonopolyCommand.ChooseCashAmount,
                        MonopolyCommand.ChooseJailCardsAmount,
                    };

                    if (_context.TradableProperties(assets.PlayerId).Count > 0)
                    {
                        availableCommands.Add(MonopolyCommand.ChangeProperties);
                    }

                    availableCommands.Add(MonopolyCommand.CancelAction);

                    _context.Add(new PrintPlayerAssets(assets, OutputStream.HSInputLog));
                    _context.Add(new PrintLine("", OutputStream.HSInputLog));
                    _context.Add(new PrintCommands(availableCommands));

                    _context.Add(new HSCommandChoiceRequest(availableCommands, state.PlayerId.Value));
                }
                return;
            }

            switch (choice.Command)
            {
            case MonopolyCommand.ChooseCashAmount:
                state.CurState = HSState.TradeChooseCash;
                break;

            case MonopolyCommand.ChooseJailCardsAmount:
                state.CurState = HSState.TradeChooseJailCards;
                break;

            case MonopolyCommand.ChangeProperties:
                state.CurState = HSState.TradeChooseProperties;
                break;

            case MonopolyCommand.CancelAction:
                state.CurState = HSState.TradeChooseAction;
                break;
            }

            _context.Add(new ClearOutput());
            _context.Remove(choice);
        }
コード例 #10
0
        public void Run(HSInputState state)
        {
            var player        = _context.GetPlayer(state.PlayerId.Value);
            var propId        = _context.GetComponent <HSPropertyChoice>().PropId.Value;
            var commandChoice = _context.GetComponent <HSCommandChoice>();

            // if command isn't chosen
            if (commandChoice == null)
            {
                if (!_context.ContainsComponent <HSCommandChoiceRequest>())
                {
                    var avilableCommands = _context.GetAvailablePropertyActions(player, propId);
                    avilableCommands.Add(MonopolyCommand.CancelAction);

                    _context.Add(new ClearOutput());
                    _context.Add(new PrintLine("Chosen property:", OutputStream.HSInputLog));
                    _context.Add(new PrintProperties(propId, OutputStream.HSInputLog, indexate: false));

                    _context.Add(new PrintCommands(avilableCommands));
                    _context.Add(new HSCommandChoiceRequest(avilableCommands, player.Id));
                }
                return;
            }

            _context.Add(new ClearOutput());
            switch (commandChoice.Command)
            {
            case MonopolyCommand.MortgageProperty:
                _context.Mortgage(player, propId);
                break;

            case MonopolyCommand.UnmortgageProperty:
                _context.UnMortgage(player, propId);
                break;

            case MonopolyCommand.BuyHouse:
                _context.BuyHouse(player, propId);
                break;

            case MonopolyCommand.SellHouse:
                _context.SellHouse(player, propId);
                break;

            case MonopolyCommand.CancelAction:
                state.CurState = HSState.PropManageChooseProperty;
                _context.Remove <HSPropertyChoice>();
                break;
            }
            _context.Remove <HSCommandChoice>();
        }
コード例 #11
0
        public void Run(HSInputState state)
        {
            var debt   = _context.GetComponent <PlayerDebt>();
            var player = _context.GetPlayer(state.PlayerId.Value);

            var choice = _context.GetComponent <HSCommandChoice>();

            if (choice == null)
            {
                if (!_context.ContainsComponent <HSCommandChoiceRequest>())
                {
                    _context.Add(new PrintLine($"You're in debt. Debt amount: {debt.DebtAmount}; current Cash: {player.Cash}",
                                               OutputStream.HSInputLog));

                    var availableCommands = new List <MonopolyCommand> {
                        MonopolyCommand.ChooseProperty
                    };
                    if (player.Cash >= debt.DebtAmount)
                    {
                        availableCommands.Add(MonopolyCommand.PayDebt);
                    }
                    else
                    {
                        _context.Add(new PrintLine("You can sell houses and mortgage property to stay in the game",
                                                   OutputStream.HSInputLog));
                    }

                    _context.Add(new PrintCommands(availableCommands));
                    _context.Add(new HSCommandChoiceRequest(availableCommands, player.Id));
                }
                return;
            }

            switch (choice.Command)
            {
            case MonopolyCommand.ChooseProperty:
                state.CurState = HSState.DebtChooseProperty;
                break;

            case MonopolyCommand.PayDebt:
                state.Nullify();
                _context.Add(new PaidOffDebt(player.Id));
                break;
            }

            _context.Add(new ClearOutput());
            _context.Remove(choice);
        }
コード例 #12
0
        public void Run(HSInputState state)
        {
            var intChoice = _context.GetComponent <HSIntChoice>();

            if (intChoice == null)
            {
                return;
            }

            if (intChoice == 0)
            {
                _context.Add(new AuctionWithdraw(state.PlayerId.Value));
            }
            else
            {
                _context.Add(new AuctionBid(state.PlayerId.Value, intChoice));
            }

            _context.Add(new ClearOutput());
            _context.Remove(intChoice);
            state.Nullify();
        }
コード例 #13
0
        public void Run(HSInputState state)
        {
            var player = _context.GetPlayer(state.PlayerId.Value);

            var choice = _context.GetComponent <HSPropertyChoice>();

            if (choice == null)
            {
                if (!_context.ContainsComponent <HSPropertyChoiceRequest>())
                {
                    var availableProperties = player.Properties
                                              .Where(propId => !_context.GetTileComponent <Property>(propId).IsMortgaged)
                                              .ToList();

                    _context.Add(new HSPropertyChoiceRequest(player.Id, availableProperties));

                    _context.Add(new PrintLine("Choose property to manage:", OutputStream.HSInputLog));
                    _context.Add(new PrintProperties(availableProperties, OutputStream.HSInputLog));
                    _context.Add(new PrintLine("Write -1 to go back", OutputStream.HSInputLog));
                }
                return;
            }

            if (!choice.PropId.HasValue)
            {
                state.CurState = HSState.Debt;
            }
            else
            {
                state.CurState = HSState.DebtChoosePropertyAction;
                state.MiscInfo = choice.PropId.Value;
            }

            _context.Remove(choice);
            _context.Add(new ClearOutput());
        }
コード例 #14
0
        public void Run(HSInputState state)
        {
            var player = _context.GetPlayer(state.PlayerId.Value);

            var commandChoice = _context.GetComponent <HSCommandChoice>();

            if (commandChoice == null)
            {
                if (!_context.ContainsComponent <HSCommandChoiceRequest>())
                {
                    var commands = GetAvailableCommands(player);
                    _context.Add(new PrintCommands(commands));
                    _context.Add(new HSCommandChoiceRequest(commands, player.Id));
                }
                return;
            }

            _context.Add(new ClearOutput());
            switch (commandChoice.Command)
            {
            case MonopolyCommand.ManageProperty:
                state.Set(HSState.PropManageChooseProperty, player.Id);
                break;

            case MonopolyCommand.CreateTradeOffer:
                var offer = new TradeOffer();
                offer.InitiatorAssets.PlayerId = player.Id;
                _context.Add(offer);
                state.Set(HSState.TradeChoosePlayer, player.Id);
                break;

            case MonopolyCommand.MakeMove:
                _context.Add(new ThrowDice());
                _context.Add(new MoveDice(player.Id));
                state.Nullify();
                break;

            case MonopolyCommand.EndTurn:
                _context.Add(new EndTurn());
                state.Nullify();
                break;

            case MonopolyCommand.PrintPlayerStatus:
                _context.Add(new PrintPlayerStatus(commandChoice.PlayerId));
                break;

            case MonopolyCommand.PrintGameStatus:
                _context.Add(new PrintGameStatus());
                break;

            case MonopolyCommand.PrintMap:
                _context.Add(new PrintMap());
                break;

            case MonopolyCommand.PayJailFine:
                _context.Add(new JailPayFine(player.Id));
                break;

            case MonopolyCommand.JailRollDice:
                _context.Add(new ThrowDice());
                _context.Add(new JailDiceRoll(player.Id));
                break;

            case MonopolyCommand.UseJailCard:
                _context.Add(new JailUseCard(player.Id));
                break;
            }
            _context.Remove <HSCommandChoice>(c => c.Command == commandChoice.Command);
        }