public void Protec(ref Piece piece, ref Field field, ref MovementController control) { LogControl.Log("Star was activated: " + this, LogControl.LogLevel.Information); List <Field> fields = control.Fields; Piece piece1 = piece; Field starField = fields.Find(fld => fld.Type == FieldType.StarField && fld.Id > piece1.GetPosition() + 2); control.PlacePiece(piece, starField, PieceState.InPlay, starField.Id - piece.GetPosition()); control.ResetField(field); }
// Click event for every field in the game private void FieldClick(object sender, RoutedEventArgs e) { // Converts the object using cast Field field = (Field)sender; LogControl.Log(field.ToString(), LogControl.LogLevel.Debug); Player player = this.players[playerTurn]; LogControl.Log(player.ToString(), LogControl.LogLevel.Debug); movement.Move(ref field, ref this.fields, ref player, dice.Value); }
/// <summary> /// Gets the id of the player at the specified index /// </summary> /// <param name="id">the specified index</param> /// <returns>The player object at the index</returns> public Player GetPlayer(int id) { try { return(this.players[id]); } catch (IndexOutOfRangeException e) { LogControl.Log(e.Data.ToString(), LogControl.LogLevel.Error); throw new IndexOutOfRangeException(e.Data.ToString()); } }
public void Protec(ref Piece piece, ref Field field, ref Globe fieldToMove, ref MovementController control, int dieValue) { LogControl.Log("globe was activated: " + this, LogControl.LogLevel.Information); if (piece.Color != fieldToMove.Color && fieldToMove.Color != GameColor.White) { control.KillPiece(ref piece); control.ResetField(field); } else { control.PlacePiece(piece, fieldToMove, PieceState.InPlay, dieValue); control.ResetField(field); } }
/// <summary> /// Validates if the player can move any piece and handles accordingly /// </summary> public void Turn() { Player turn = players[playerTurn]; Piece[] pieces = turn.GetPieces(); int choice = 0; foreach (Piece pcs in pieces) { switch (pcs.State) { case PieceState.Home: if (dice.Value == 6) { pcs.CanMove = true; choice++; } else { pcs.CanMove = false; } break; case PieceState.Finished: pcs.CanMove = false; choice++; break; default: pcs.CanMove = true; choice++; break; } LogControl.Log("Piece: " + pcs, LogControl.LogLevel.Debug); } if (choice == 0) { LogControl.Log("Player: " + turn.Name + " : " + turn.Color + " Could not move any pieces this turn", LogControl.LogLevel.Debug); } }
// Sets the playernames so the players can be instanciated private void DoneButton_Click(object sender, RoutedEventArgs e) { // Hides the playername selector PlayerInput.Visibility = System.Windows.Visibility.Collapsed; // List of playernames List <string> playerNames = new List <string>(4) { Player1Input.Text, Player2Input.Text, Player3Input.Text, Player4Input.Text }; for (int i = 0; i < playerNames.Count; i++) { // Validates if it's a valid player if (String.IsNullOrWhiteSpace(playerNames[i])) { playerNames.Remove(playerNames[i]); } else { Players.Items.Add(playerNames[i]); manager.AddPlayer(playerNames[i], i + 1); } } LogControl.Log("Players:", LogControl.LogLevel.Information); // Debug output foreach (string pn in playerNames) { LogControl.Log("Name: " + pn, LogControl.LogLevel.Information); } this.RollDie.Background = (ImageBrush)FindResource("WhiteField"); this.RollDie.Visibility = Visibility.Visible; // Draws the board manager.DrawBoard(GameBoard); }
/// <summary> /// Event that checks if all of one players pieces are finished /// </summary> /// <param name="sender">The class that fired the event</param> /// <param name="piece">The piece to validate</param> private void OnPieceFinished(object sender, Piece piece) { LogControl.Log("Someone got a piece to the finishline", LogControl.LogLevel.Information); int finished = 0; players.ForEach((player) => { if (player.Color == piece.Color) { foreach (Piece pcs in player.GetPieces()) { if (pcs.State == PieceState.Finished) { finished++; } } } }); if (finished >= 4) { throw new Exception("You Won"); } }
public MainWindow() { InitializeComponent(); LogControl.Init(); LogControl.Log("Log has been created", LogControl.LogLevel.Information); }