Exemplo n.º 1
0
        public void test_RAlert()
        {
            int level, counter = 0;

            int[] turns = new int[4];
            // 4 turns in which combat starts
            turns[0] = 1;
            turns[1] = 10;
            turns[2] = 22;
            turns[3] = 34;
            g        = new Game(5, 2, 30, true);
            gs       = new Gamestate(g);
            savegame = new Savegame(gs);
            path     = @"C:/Users/Gebruiker/Documents/GitHub/Software-Testing-Assignment-2/STVRogue/Gameplays/game9/game9_turn";
            for (int j = 0; j < turns.Length; j++)
            {
                for (int h = j; h < j + 2; h++)
                {
                    data = savegame.OpenFile(h, path);
                    Gamestate gamestate1 = new Gamestate(g, data);
                    data = savegame.OpenFile(h + 1, path);
                    Gamestate gamestate = new Gamestate(g, data);
                    level = gamestate1.g.dungeon.CurrentLevel(gamestate1.g.dungeon.player.location);
                    for (int i = (level * 4); i < (level * 4) + 3; i++)
                    {
                        counter = 0;
                        foreach (Pack pack in gamestate1.g.dungeon.nodeList[i].packs)
                        {
                            Always always = new Always((G => G.dungeon.Shortestpath(pack.location, G.dungeon.player.location).Count() <= G.dungeon.Shortestpath(gamestate.g.dungeon.nodeList[i].packs[counter++].location, G.dungeon.player.location).Count()));
                            Assert.True(always.test(gamestate1.g));
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void SaveFileIsSameAsOpenFile()
        {
            savegame.SaveTurn();
            string savedFile = savegame.OpenFile(0, "");

            Assert.Contains("Bag content", savedFile);
            Assert.Contains("Player location", savedFile);
            Assert.Contains("END", savedFile);
        }
Exemplo n.º 3
0
        public void WriteSaveGameForPackString()
        {
            Game      withPacks   = new Game(5, 2, 10, false);
            Gamestate withPacksGS = new Gamestate(withPacks);
            Savegame  savegame    = new Savegame(withPacksGS);

            savegame.SaveTurn();
            Gamestate openFile = new Gamestate(withPacks, savegame.OpenFile(0, ""));

            Assert.Equal(withPacks.dungeon.packs, openFile.g.dungeon.packs);
        }
Exemplo n.º 4
0
        public void test_RNode()
        {
            int monstersOnNode = 0;
            int l, c, m;

            for (int k = 1; k < 9; k++)
            {
                if (k < 5)
                {
                    l = 5;
                }
                else
                {
                    l = 10;
                }
                if (k % 2 == 0)
                {
                    c = 3;
                }
                else
                {
                    c = 2;
                }
                if (k == 3 || k == 4 || k == 7 || k == 8)
                {
                    m = 50;
                }
                else
                {
                    m = 30;
                }
                g        = new Game(l, c, m, true);
                gs       = new Gamestate(g);
                savegame = new Savegame(gs);
                path     = @"C:/Users/Gebruiker/Documents/GitHub/Software-Testing-Assignment-2/STVRogue/Gameplays/game" + k + "/game" + k + "_turn";
                for (int i = 0; i < gameturns[k - 1]; i++)
                {
                    data = savegame.OpenFile(i, path);
                    Gamestate gamestate = new Gamestate(g, data);
                    foreach (Node node in gamestate.g.dungeon.nodeList)
                    {
                        monstersOnNode = 0;
                        foreach (Pack pack in node.packs)
                        {
                            monstersOnNode += pack.members.Count();
                        }
                        Always always = new Always((G => monstersOnNode <= G.dungeon.multiplier * (G.dungeon.Level(node) + 1)));

                        Assert.True(always.test(gamestate.g));
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void test_player_heal()
        {
            int l, c, m;

            for (int k = 1; k < 9; k++)
            {
                if (k < 5)
                {
                    l = 5;
                }
                else
                {
                    l = 10;
                }
                if (k % 2 == 0)
                {
                    c = 3;
                }
                else
                {
                    c = 2;
                }
                if (k == 3 || k == 4 || k == 7 || k == 8)
                {
                    m = 50;
                }
                else
                {
                    m = 30;
                }
                g        = new Game(l, c, m, true);
                gs       = new Gamestate(g);
                savegame = new Savegame(gs);
                for (int j = 1; j < 6; j++)
                {
                    int previousHP      = g.dungeon.player.HPbase;
                    int previousPotions = 0;
                    path = @"C:/Users/Gebruiker/Documents/GitHub/Software-Testing-Assignment-2/STVRogue/Gameplays/game" + k + "/game" + k + "_turn";
                    Unless unless = new Unless(G => G.dungeon.player.HP <= previousHP, G => G.dungeon.player.HP > previousHP && G.dungeon.player.bag.OfType <HealingPotion>().Count() == previousPotions - 1);
                    for (int i = 0; i < gameturns[k - 1]; i++)
                    {
                        data = savegame.OpenFile(i, path);
                        Gamestate gamestate = new Gamestate(g, data);
                        Assert.True(unless.test(g));
                        previousHP      = gamestate.g.dungeon.player.HP;
                        previousPotions = gamestate.g.dungeon.player.bag.OfType <HealingPotion>().Count();
                    }
                }
            }
        }
Exemplo n.º 6
0
        public void test_RZone()
        {
            int l, c, m;
            int counter = 0;

            for (int k = 1; k < 9; k++)
            {
                if (k < 5)
                {
                    l = 5;
                }
                else
                {
                    l = 10;
                }
                if (k % 2 == 0)
                {
                    c = 3;
                }
                else
                {
                    c = 2;
                }
                if (k == 3 || k == 4 || k == 7 || k == 8)
                {
                    m = 50;
                }
                else
                {
                    m = 30;
                }
                g        = new Game(l, c, m, true);
                gs       = new Gamestate(g);
                savegame = new Savegame(gs);

                path = @"C:/Users/Gebruiker/Documents/GitHub/Software-Testing-Assignment-2/STVRogue/Gameplays/game" + k + "/game" + k + "_turn";
                for (int i = 0; i < gameturns[k - 1]; i++)
                {
                    counter = 0;
                    data    = savegame.OpenFile(i, path);
                    Gamestate gamestate = new Gamestate(g, data);
                    foreach (Pack pack in gamestate.g.dungeon.packs)
                    {
                        Always always = new Always((G => G.dungeon.packs[counter++].zone == G.dungeon.CurrentLevel(pack.location)));
                        Assert.True(always.test(gamestate.g));
                    }
                }
            }
        }
Exemplo n.º 7
0
        public void test_monsters_never_increase()
        {
            int l, c, m;

            for (int k = 1; k < 9; k++)
            {
                if (k < 5)
                {
                    l = 5;
                }
                else
                {
                    l = 10;
                }
                if (k % 2 == 0)
                {
                    c = 3;
                }
                else
                {
                    c = 2;
                }
                if (k == 3 || k == 4 || k == 7 || k == 8)
                {
                    m = 50;
                }
                else
                {
                    m = 30;
                }
                g        = new Game(l, c, m, true);
                gs       = new Gamestate(g);
                savegame = new Savegame(gs);
                for (int j = 1; j < 6; j++)
                {
                    path = @"C:/Users/Gebruiker/Documents/GitHub/Software-Testing-Assignment-2/STVRogue/Gameplays/game" + k + "/game" + k + "_turn";
                    Unless unless = new Unless(G => G.dungeon.numberOfMonsters > G.dungeon.countMonsters(), G => G.dungeon.numberOfMonsters == G.dungeon.countMonsters());
                    for (int i = 0; i < gameturns[k - 1]; i++)
                    {
                        data = savegame.OpenFile(i, path);
                        Gamestate gamestate = new Gamestate(g, data);
                        Assert.True(unless.test(g));
                    }
                }
            }
        }
Exemplo n.º 8
0
        public void GameStateIsSameAsBefore()
        {
            Game withItems = new Game(5, 2, 20, false);

            withItems.dungeon.player.PickUp(new HealingPotion("0"));
            withItems.dungeon.player.PickUp(new HealingPotion("1"));
            withItems.dungeon.player.PickUp(new HealingPotion("2"));
            withItems.dungeon.player.PickUp(new HealingPotion("3"));
            withItems.dungeon.turn = 5;
            Gamestate withItemsGS = new Gamestate(withItems);
            Savegame  save        = new Savegame(withItemsGS);

            save.SaveTurn();
            Gamestate fromFile = new Gamestate(g, save.OpenFile(5, ""));

            Assert.Equal(withItemsGS.g.dungeon.player.location.id, fromFile.g.dungeon.player.location.id);
            Assert.Equal(withItemsGS.BagToString(g.dungeon.player.bag), fromFile.BagToString(g.dungeon.player.bag));

            Assert.Equal(withItemsGS.g.dungeon.turn, fromFile.g.dungeon.turn);
        }
Exemplo n.º 9
0
        public void test_REndZone()
        {
            int  counter = 0;
            int  l, c, m;
            bool REndZone = false;

            for (int k = 1; k < 9; k++)
            {
                if (k < 5)
                {
                    l = 5;
                }
                else
                {
                    l = 10;
                }
                if (k % 2 == 0)
                {
                    c = 3;
                }
                else
                {
                    c = 2;
                }
                if (k == 3 || k == 4 || k == 7 || k == 8)
                {
                    m = 50;
                }
                else
                {
                    m = 30;
                }
                g        = new Game(l, c, m, true);
                gs       = new Gamestate(g);
                savegame = new Savegame(gs);
                path     = @"C:/Users/Gebruiker/Documents/GitHub/Software-Testing-Assignment-2/STVRogue/Gameplays/game" + k + "/game" + k + "_turn";
                for (int j = 0; j < gameturns[k - 1] - 1; j++)
                {
                    counter = 0;
                    data    = savegame.OpenFile(j, path);
                    Gamestate gamestate1 = new Gamestate(g, data);
                    data = savegame.OpenFile(j + 1, path);
                    Gamestate gamestate = new Gamestate(g, data);
                    if (gamestate1.g.dungeon.Level(gamestate1.g.dungeon.player.location) == l)
                    {
                        REndZone = true;
                    }
                    for (int i = gamestate1.g.dungeon.nodeList.Count() - 1; i > gamestate1.g.dungeon.nodeList.Count() - 6; i--)
                    {
                        counter = 0;
                        if (REndZone)
                        {                         // check if packs do not move away from the player when the endzone has been reached
                            foreach (Pack pack in gamestate1.g.dungeon.nodeList[i].packs)
                            {
                                Always always = new Always((G => G.dungeon.Shortestpath(pack.location, G.dungeon.player.location).Count() <= G.dungeon.Shortestpath(gamestate.g.dungeon.nodeList[i].packs[counter++].location, G.dungeon.player.location).Count()));
                                //	Console.WriteLine(gamestate1.g.dungeon.Shortestpath(pack.location, gamestate1.g.dungeon.player.location).Count());
                                Assert.True(always.test(gamestate1.g));
                            }
                        }
                    }
                }
            }
        }