private Coordinates EnterInputCoordinates() { string coordinates; while (true) { this.renderer.DisplayMessage(Constants.INVITE_TO_ENTER_COORDINATES_MESSAGE); coordinates = this.renderer.EnterCommand(); if (Validator.IsValidInputCoordinates(coordinates, this.battleField.FieldPositions.GetLength(0))) { break; } this.renderer.Clear(); this.renderer.DrawField(this.battleField.FieldPositions); this.renderer.DisplayMessage(Constants.MINES_COUNT_MESSAGE + this.battleField.CountRemainingMines()); this.renderer.DisplayMessage(Constants.SCORE_MESSAGE + this.currentPlayer.Score); this.renderer.DisplayMessage(Constants.INVALID_MOVE_NOTIFICATION_MESSAGE); } int rowCoord = Convert.ToInt32(coordinates.Substring(0, 1)); int colCoord = Convert.ToInt32(coordinates.Substring(2, 1)); Coordinates currentCoordinates = new Coordinates(rowCoord, colCoord); return currentCoordinates; }
/// <summary> /// Method that validates the coordinates inputed by the current Player. /// </summary> /// <param name="inputCoordinates">Input coordinates to be validated.</param> /// <returns>Return boolean representing the validity of the input coordinates.</returns> public bool ValidateMoveCoordinates(Coordinates inputCoordinates) { int currentFieldSize = this.FieldPositions.GetLength(0); if ((inputCoordinates.Col < 0) || (inputCoordinates.Col > currentFieldSize - 1) || (this.FieldPositions[inputCoordinates.Row, inputCoordinates.Col] is EmptyCell) || (this.FieldPositions[inputCoordinates.Row, inputCoordinates.Col] is DetonatedCell)) { return false; } return true; }
private void OnDetonateCellExecute(object sender) { int row = (sender as ObservableCellDecorator).Row; int col = (sender as ObservableCellDecorator).Col; Coordinates currentCoordinates = new Coordinates(row, col); this.BattleField.FieldPositions = (this.battleField.FieldPositions[row, col] as IExplosive).Detonate( this.BattleField.FieldPositions, currentCoordinates); ReloadPositions(); this.DetonatedMines ++; this.CurrentPlayer.Score += this.CurrentPlayer.CalculateScore(this.RemainingMines, this.battleField.CountRemainingMines()); this.PlayerScore = this.CurrentPlayer.Score; this.RemainingMines = this.battleField.CountRemainingMines(); if (this.RemainingMines == 0) { this.GameVisibility = Visibility.Hidden; this.GameOverVisibility = Visibility.Visible; } }