// 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]); }
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"); }
// 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]); }
// 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]); }
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); }
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); } }
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)); }
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); }
// 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(); } }