private void Attack(object parameter) { Button button = parameter as Button; int row = (int)button.GetValue(Grid.RowProperty); int column = (int)button.GetValue(Grid.ColumnProperty); ResultOfAttack result = _battleshipGridModel.AttackAtCoordinate(row, column); button.IsEnabled = false; if (result == ResultOfAttack.Hit) { button.Content = TARGET_HIT_CHAR; MessageBox.Show("It's a hit"); } else if (result == ResultOfAttack.Sank) { button.Content = TARGET_HIT_CHAR; MessageBox.Show("It sank"); } else if (result == ResultOfAttack.GameOver) { button.Content = TARGET_HIT_CHAR; MessageBox.Show("It's game over"); } else if (result == ResultOfAttack.Miss) { button.Content = TARGET_MISSED_CHAR; MessageBox.Show("It's a miss"); } }
public ResultOfAttack AttackAtCoordinate(int row, int column) { ResultOfAttack result = _battleshipGrid.Attack(new Coordinate(row, column)); IsNotGameOver = result == ResultOfAttack.GameOver ? false : true; return(result); }
public void Decode(NetIncomingMessage im) { this.Value = (ResultOfAttack) im.ReadInt32(); this.Text = im.ReadString(); this.Row = im.ReadInt32(); this.Col = im.ReadInt32(); }
/// <summary> /// Set the _Value to the PossibleAttack value /// </summary> /// <param name="value">either hit, miss, destroyed, shotalready</param> public AttackResult(ResultOfAttack value, string text, int row, int column) { Value = value; Text = text; Row = row; Column = column; }
/* * Summary: Set the _value to the PossibleAttack value * Parameter: value - Either hit, miss, destroyed, shotalready * Parameter: text - Text to display * Parameter: row - Row to display * Parameter: column - Column to display */ public AttackResult(ResultOfAttack value, string text, int row, int column) { _value = value; _text = text; _ship = null; _row = row; _column = column; }
/// <summary> /// Set the _Value to the PossibleAttack value /// </summary> /// <param name="value">either hit, miss, destroyed, shotalready</param> public AttackResult(ResultOfAttack value, string text, int row, int column) { _Value = value; _Text = text; _Ship = null; _Row = row; _Column = column; }
public void TestAttack_IsMiss() { InitializeTheBattleshipGrid(); Coordinate pointOfAttack = new Coordinate(6, 5); ResultOfAttack result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Miss); }
/// <summary> /// Set the _Value to the PossibleAttack value /// </summary> /// <param name="value">either hit, miss, destroyed, shotalready</param> /// <param name="text">textual description of the result</param> /// <param name="row">row value of the cell attacked</param> /// <param name="column">column value of the cell attacked</param> public AttackResult(ResultOfAttack value, string text, int row, int column) { _Value = value; _Text = text; _Ship = null; _Row = row; _Column = column; }
public void TestAttack_IsSank_OnSmallAssaultShip() { InitializeTheBattleshipGrid(); Coordinate pointOfAttack = new Coordinate(8, 9); ResultOfAttack result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Sank); }
public AttackResult(ResultOfAttack value, string text, int row, int column) { Value = value; Text = text; Ship = 0; Row = row; Column = column; }
public void Attack_IsGameOverReturnTrue_ResultGameOver() { _fleetMock.Setup(x => x.IsGameOver()).Returns(true); ResultOfAttack result = _subjectUnderTest.Attack(_pointOfAttack); Assert.AreEqual(ResultOfAttack.GameOver, result); }
public void Attack_DidSankReturnsTrue_ResultSank() { _fleetMock.Setup(x => x.DidSank(_pointOfAttack)).Returns(true); ResultOfAttack result = _subjectUnderTest.Attack(_pointOfAttack); Assert.AreEqual(ResultOfAttack.Sank, result); }
public void Attack_IsHitReturnsTrue_ResultHit() { _fleetMock.Setup(x => x.IsHit(_pointOfAttack)).Returns(true); ResultOfAttack result = _subjectUnderTest.Attack(_pointOfAttack); Assert.AreEqual(ResultOfAttack.Hit, result); }
public void Attack_IsMissReturnsTrue_ResultMiss() { _fleetMock.Setup(x => x.IsHit(_pointOfAttack)).Returns(false); _fleetMock.Setup(x => x.DidSank(_pointOfAttack)).Returns(false); _fleetMock.Setup(x => x.IsGameOver()).Returns(false); ResultOfAttack result = _subjectUnderTest.Attack(_pointOfAttack); Assert.AreEqual(ResultOfAttack.Miss, result); }
public void TestAttack_IsSank_OnDestroyerShip() { InitializeTheBattleshipGrid(); Coordinate pointOfAttack = new Coordinate(7, 5); ResultOfAttack result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Hit); pointOfAttack.Latitude = 8; pointOfAttack.Longitude = 5; result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Hit); pointOfAttack.Latitude = 9; pointOfAttack.Longitude = 5; result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Sank); }
public ResultOfAttack Attack(Coordinate pointOfAttack) { ResultOfAttack returnValue = ResultOfAttack.None; if (_fleet.IsHit(pointOfAttack)) { returnValue = ResultOfAttack.Hit; } if (_fleet.DidSank(pointOfAttack)) { returnValue = ResultOfAttack.Sank; } if (_fleet.IsGameOver()) { returnValue = ResultOfAttack.GameOver; } if (returnValue == ResultOfAttack.None) { returnValue = ResultOfAttack.Miss; } return(returnValue); }
/// <summary> /// Set the _Value to the PossibleAttack value, and the _Ship to the ship /// </summary> /// <param name="value">either hit, miss, destroyed, shotalready</param> /// <param name="ship">the ship information</param> public AttackResult(ResultOfAttack value, Ship ship, string text, int row, int column) : this(value, text, row, column) { _Ship = ship; }
public AttackResult(ResultOfAttack value, Ship ship, string text, int row, int column, Players pl) : this(value, text, row, column) { _Ship = ship; _pl = pl; }
/// <summary> /// Set the _Value to the PossibleAttack value, and the _Ship to the ship /// </summary> /// <param name="value">either hit, miss, destroyed, shotalready</param> /// <param name="ship">the ship information</param> /// <param name="text">textual description of the result</param> /// <param name="row">row value of the cell attacked</param> /// <param name="column">column value of the cell attacked</param> public AttackResult(ResultOfAttack value, Ship ship, string text, int row, int column) : this(value, text, row, column) { _Ship = ship; }
public void TestAttack_IsGameOver() { InitializeTheBattleshipGrid(); Coordinate pointOfAttack = new Coordinate(7, 5); ResultOfAttack result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Hit); pointOfAttack.Latitude = 8; pointOfAttack.Longitude = 5; result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Hit); pointOfAttack.Latitude = 9; pointOfAttack.Longitude = 5; result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Sank); pointOfAttack.Latitude = 1; pointOfAttack.Longitude = 1; result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Hit); pointOfAttack.Latitude = 1; pointOfAttack.Longitude = 2; result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Hit); pointOfAttack.Latitude = 1; pointOfAttack.Longitude = 3; result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Hit); pointOfAttack.Latitude = 1; pointOfAttack.Longitude = 4; result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Hit); pointOfAttack.Latitude = 1; pointOfAttack.Longitude = 5; result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Sank); pointOfAttack.Latitude = 1; pointOfAttack.Longitude = 7; result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Hit); pointOfAttack.Latitude = 2; pointOfAttack.Longitude = 7; result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Hit); pointOfAttack.Latitude = 3; pointOfAttack.Longitude = 7; result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Hit); pointOfAttack.Latitude = 4; pointOfAttack.Longitude = 7; result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Sank); pointOfAttack.Latitude = 5; pointOfAttack.Longitude = 2; result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Hit); pointOfAttack.Latitude = 5; pointOfAttack.Longitude = 3; result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Hit); pointOfAttack.Latitude = 5; pointOfAttack.Longitude = 4; result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.Sank); pointOfAttack.Latitude = 8; pointOfAttack.Longitude = 9; result = _battleshipGrid.Attack(pointOfAttack); Assert.IsTrue(result == ResultOfAttack.GameOver); }