예제 #1
0
 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.");
 }
예제 #2
0
 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));
 }
예제 #3
0
 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);
 }
예제 #4
0
 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);
         }
     }
 }
예제 #5
0
        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;
        }
예제 #6
0
 public FieldStatus getFieldStatus(Field field)
 {
     return fieldlist[field.xCoordinate, field.yCoordinate].status;
 }
예제 #7
0
 public void setFieldStatus(Field field, FieldStatus status, Ship ship)
 {
     fieldlist[field.xCoordinate, field.yCoordinate].status = status;
 }
예제 #8
0
 public void updateField(UserAccount user, Field field, FieldStatus fieldStatus)
 {
     throw new NotImplementedException();
 }
예제 #9
0
 public void shoot(UserAccount user, Field field)
 {
     gameWindow.shoot(user, field);
 }
예제 #10
0
 public void updateField(Field field, FieldStatus fieldStatus)
 {
     Assert.AreEqual(1, field.xCoordinate);
     Assert.AreEqual(2, field.yCoordinate);
     Assert.AreEqual(FieldStatus.HIT, fieldStatus);
 }
예제 #11
0
        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);
                        }
                    }
                }
            }
        }
예제 #12
0
 public void shoot(UserAccount user, Field field)
 {
     throw new NotImplementedException();
 }