public void shootTest() { Game target = new Game(); UserAccount user = new UserAccount("Player", 1); Field field = new Field(5, 5); target.shoot(user, field); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
public void setFieldStatusTest() { int size = 5; // TODO: Passenden Wert initialisieren UserAccount user = null; // TODO: Passenden Wert initialisieren Playfield target = new Playfield(size, user); // TODO: Passenden Wert initialisieren Field field = new Field(3, 2); // TODO: Passenden Wert initialisieren FieldStatus status = FieldStatus.HIT; target.setFieldStatus(field, status, null); Assert.AreEqual(FieldStatus.HIT, target.getFieldStatus(field)); }
public void setFieldStatus(UserAccount user, Field field, FieldStatus status, Ship ship) { foreach (Playfield pf in playfields) { if (pf.user.Equals(user)) { pf.setFieldStatus(field, status, ship); } } gameGUI.updateField(user, field, status); }
public Playfield(int size, UserAccount user) { this.fieldlist = new Field[size, size]; this.user = user; for (int i = 0; i < fieldlist.GetLength(0); i++) { for (int j = 0; j < fieldlist.GetLength(1); j++) { fieldlist[i, j] = new Field(i, j); } } }
public Ship shoot(Field field) { foreach (ShipPosition shipPos in shipPositions) { foreach (Field posField in shipPos.fieldList) { if (posField.Equals(field)) { posField.status = FieldStatus.HIT; return shipPos.ship; } } } return null; }
public FieldStatus getFieldStatus(Field field) { return fieldlist[field.xCoordinate, field.yCoordinate].status; }
public void setFieldStatus(Field field, FieldStatus status, Ship ship) { fieldlist[field.xCoordinate, field.yCoordinate].status = status; }
public void updateField(UserAccount user, Field field, FieldStatus fieldStatus) { throw new NotImplementedException(); }
public void shoot(UserAccount user, Field field) { gameWindow.shoot(user, field); }
public void updateField(Field field, FieldStatus fieldStatus) { Assert.AreEqual(1, field.xCoordinate); Assert.AreEqual(2, field.yCoordinate); Assert.AreEqual(FieldStatus.HIT, fieldStatus); }
public void setFieldStatusTest() { Field field = new Field(0, 0); FieldStatus status = FieldStatus.MISS; Ship ship = null; window.setFieldStatus(owner, field, status, ship); // Check fields of all players foreach (Playfield pf in window.playfields) { if (pf.user.Equals(owner)) { // check fields of owner for (int i = 0; i < pf.fieldlist.GetLength(0); i++) { for (int j = 0; j < pf.fieldlist.GetLength(1); j++) { // check if field is Miss if (i == field.xCoordinate && j == field.yCoordinate) { Assert.AreEqual(status, pf.getFieldStatus(field)); } // all other fields are Clear else { Assert.AreEqual(FieldStatus.CLEAR, pf.fieldlist[i, j].status); } } } } else { // fields of all other players must be Clear for (int i = 0; i < pf.fieldlist.GetLength(0); i++) { for (int j = 0; j < pf.fieldlist.GetLength(1); j++) { Assert.AreEqual(FieldStatus.CLEAR, pf.fieldlist[i, j].status); } } } } field = new Field(5, 5); status = FieldStatus.HIT; ship = new Ship(new Shape(4)); window.setFieldStatus(owner, field, status, ship); foreach (Playfield pf in window.playfields) { if (pf.user.Equals(owner)) { // check fields of owner for (int i = 0; i < pf.fieldlist.GetLength(0); i++) { for (int j = 0; j < pf.fieldlist.GetLength(1); j++) { // check if last field is still a Miss if (i == 0 && j == 0) { Assert.AreEqual(FieldStatus.MISS, pf.fieldlist[0, 0].status); } // check if new field is Hit else if (i == field.xCoordinate && j == field.yCoordinate) { Assert.AreEqual(status, pf.getFieldStatus(field)); } // all other fields must be Clear else { Assert.AreEqual(FieldStatus.CLEAR, pf.fieldlist[i, j].status); } } } } else { // fields of all other players must be Clear for (int i = 0; i < pf.fieldlist.GetLength(0); i++) { for (int j = 0; j < pf.fieldlist.GetLength(1); j++) { Assert.AreEqual(FieldStatus.CLEAR, pf.fieldlist[i, j].status); } } } } field = new Field(2, 3); status = FieldStatus.HIT; ship = new Ship(new Shape(3)); window.setFieldStatus(user2, field, status, ship); foreach (Playfield pf in window.playfields) { if (pf.user.Equals(owner)) { for (int i = 0; i < pf.fieldlist.GetLength(0); i++) { for (int j = 0; j < pf.fieldlist.GetLength(1); j++) { // check if first field is Miss if (i == 0 && j == 0) { Assert.AreEqual(FieldStatus.MISS, pf.fieldlist[0, 0].status); } // check if last field is Hit else if (i == 5 && j == 5) { Assert.AreEqual(FieldStatus.HIT, pf.fieldlist[5, 5].status); } // all other fields must be Clear else { Assert.AreEqual(FieldStatus.CLEAR, pf.fieldlist[i, j].status); } } } } else if (pf.user.Equals(user2)) { // check fields of user2 for (int i = 0; i < pf.fieldlist.GetLength(0); i++) { for (int j = 0; j < pf.fieldlist.GetLength(1); j++) { // the last field must be Hit if (i == 2 && j == 3) { Assert.AreEqual(FieldStatus.HIT, pf.getFieldStatus(field)); } // all other fields must be Clear else { Assert.AreEqual(FieldStatus.CLEAR, pf.fieldlist[i, j].status); } } } } else { // fields of all other players must be Clear for (int i = 0; i < pf.fieldlist.GetLength(0); i++) { for (int j = 0; j < pf.fieldlist.GetLength(1); j++) { Assert.AreEqual(FieldStatus.CLEAR, pf.fieldlist[i, j].status); } } } } }
public void shoot(UserAccount user, Field field) { throw new NotImplementedException(); }