Пример #1
0
        // This method moves player in n steps
        private void MovePlayer(MonopolyPlayer player, int steps)
        {
            bool startPassed = false;
            var  currentCell = _playersPosition[player];
            int  next        = currentCell.ID + steps;

            if (next > _board.ListOfMonopolyCell.Count)
            {
                next = next - _board.ListOfMonopolyCell.Count;
            }

            if (steps > 0 && next < currentCell.ID)
            {
                startPassed = true;
            }

            _playersPosition[player] = _board.ListOfMonopolyCell[next];

            Console.WriteLine("Moving " + player.Username + " to " + _playersPosition[player].Name);

            if (startPassed)
            {
                MonopolyCell cell = _board.ListOfMonopolyCell[0];
                ((StartCell)cell).Step();
            }


            CallCellEvent(_playersPosition[player]);
        }
Пример #2
0
        public void JailOnCellStepped(object sender, EventArgs evt)
        {
            MonopolyCell   cell   = (MonopolyCell)sender;
            MonopolyPlayer player = GetPlayerFromCell((MonopolyCell)sender);

            Console.WriteLine(player.Username + " stepped in " + cell.Name);
            Console.WriteLine("No event");
        }
Пример #3
0
        // This method moves player directly to a cell
        private void MovePlayer(MonopolyPlayer player, MonopolyCell cell)
        {
            _playersPosition[player] = cell;

            Console.WriteLine("Moving " + player.Username + " to " + _playersPosition[player].Name);

            CallCellEvent(_playersPosition[player]);
        }
Пример #4
0
        // Cell event handlers
        public void GoToJailOnCellStepped(object sender, EventArgs evt)
        {
            MonopolyCell   cell   = (MonopolyCell)sender;
            MonopolyPlayer player = GetPlayerFromCell(cell);

            Console.WriteLine(player.Username + " stepped in " + cell.Name);
            Console.WriteLine("Your position will move to jail");

            // Move to jail cell
            MovePlayer(player, _board.ListOfMonopolyCell[10]);
        }
Пример #5
0
        private MonopolyPlayer GetPlayerFromCell(MonopolyCell cell)
        {
            foreach (MonopolyPlayer player in _playersPosition.Keys)
            {
                if (_playersPosition[player].Equals(cell))
                {
                    return(player);
                }
            }

            Console.WriteLine("Cell " + cell.Name + " isnt stepped by anyone");
            return(null);
        }
Пример #6
0
        public void PayTaxOnCellStepped(object sender, EventArgs evt)
        {
            int            price  = ((PayTaxCell)sender).Price;
            MonopolyPlayer player = GetPlayerFromCell((MonopolyCell)sender);
            MonopolyCell   cell   = (MonopolyCell)sender;

            Console.WriteLine(player.Username + " stepped in " + cell.Name);
            Console.WriteLine("Please pay " + price);

            if (!TransferMoneyToBank(player, price))
            {
                GameLose(player);
            }
        }
Пример #7
0
        public void ActionOnCellStepped(object sender, EventArgs evt)
        {
            MonopolyCell      cell   = (MonopolyCell)sender;
            MonopolyPlayer    player = GetPlayerFromCell(cell);
            ActionCellEvtArgs args   = (ActionCellEvtArgs)evt;

            Console.WriteLine(player.Username + " stepped in " + cell.Name);

            // Get action
            IActionCard             card       = GetActionCard(args.TypeCard);
            Action <MonopolyPlayer> cardAction = card.Action;

            // Do action
            cardAction(GetPlayerFromCell((MonopolyCell)sender));
        }
Пример #8
0
        private void ChanceCard5Action(MonopolyPlayer p)
        {
            // Advance to Cell 19 : Collect 200 if pass Start
            Console.WriteLine("Advance to Cell 19 : Collect {0} if pass Start", _moneyAtStartCell);

            MonopolyCell curretPosition = _playersPosition[p];
            int          step           = 0;

            if (curretPosition.ID >= 19)
            {
                step = 19 + (_board.ListOfMonopolyCell.Count - curretPosition.ID);
            }
            else
            {
                step = 19 - curretPosition.ID;
            }
            // change position
            MovePlayer(p, step);
        }
Пример #9
0
 // This method call cell events
 private void CallCellEvent(MonopolyCell cell)
 {
     if (cell.GetType().Equals(typeof(ActionCell)))
     {
         ((ActionCell)cell).Step();
     }
     else if (cell.GetType().Equals(typeof(LandCell)))
     {
         ((LandCell)cell).Step();
     }
     else if (cell.GetType().Equals(typeof(PayTaxCell)))
     {
         ((PayTaxCell)cell).Step();
     }
     else
     {
         cell.Step();
     }
 }