예제 #1
0
        public void NTest_flee_returnsTruePackFlees()
        {
            Dungeon dungeon = new Dungeon(3, 3);
            Pack    pack1   = new Pack("1", 4, dungeon);

            pack1.location = dungeon.startNode;
            dungeon.startNode.packs.Add(pack1);
            //there is no monster packs in the dungeon so there is no capacity problems
            Assert.IsTrue(pack1.flee());
            Assert.AreNotSame(pack1.location, dungeon.startNode);
            Assert.Contains(pack1.location, dungeon.startNode.neighbors);
        }
예제 #2
0
        public void NTest_flee_returnsFalsePackCantFlee()
        {
            Dungeon dungeon = new Dungeon(3, 3);
            Pack    pack1   = new Pack("1", 4, dungeon);

            pack1.location = dungeon.startNode;
            dungeon.startNode.packs.Add(pack1);
            int packId = 2;

            foreach (Node n in dungeon.startNode.neighbors)
            {
                Pack pack = new Pack("" + packId, 4, dungeon);
                pack.location = n;
                n.packs.Add(pack);
            }
            Assert.IsFalse(pack1.flee());
            Assert.AreSame(pack1.location, dungeon.startNode);
        }
예제 #3
0
        /* Execute a fight between the player and the packs in this node.
         * Such a fight can take multiple rounds as describe in the Project Document.
         * A fight terminates when either the node has no more monster-pack, or when
         * the player's HP is reduced to 0.
         */
        /*
         *  Command List:
         *  1- Move to next node,flee
         *  2- Use Magic Crystal
         *  3- Use Healing Potion
         *  4- Attack
         */
        public int fight(Player player, int state)
        {
            int command = -1;

            if (state == 0)
            {
                //ensure player is not accelerated
                player.accelerated = false;
                Logger.log("Press 1 to flee");
                if (player.containsMagicCrystal())//if player bag contains item type of magic crystal
                {
                    Logger.log("Press 2 to use Magic Crystal");
                }
                if (player.containsHealingPotion()) //only show option if player has the potion
                {
                    Logger.log("Press 3 to use Healing Potion");
                }
                Logger.log("Press 4 to attack");
                command = player.getNextCommand().commandId;
                if (command == 1)
                {
                    //if presses 1 try to flee
                    //if possible game.state = 5
                    //if not game.state = 0
                    if (player.flee())
                    {
                        Logger.log("Player fleed, not contested anymore");
                        return(5); //next state 5
                    }
                    else
                    {
                        Logger.log("Player could not flee, still contested");
                        return(0);
                    }
                }
                else if (command == 2)                  //player wants to use magic crystal
                {
                    if (!player.containsMagicCrystal()) //if player has no magic crystal
                    {
                        Logger.log("Player has no magic crystal, press a valid command");
                        return(0);
                    }
                    //player uses magic crystal
                    foreach (Item i in player.bag)
                    {
                        if (i.GetType() == typeof(Crystal)) //find magic crystal in player's bag
                        {
                            player.use(i);
                            Logger.log("Player used crystal");
                            break; //break the for loop
                        }
                        Logger.log("Could not be able to execute this");
                    }
                    return(2);                           //pass to 2nd state
                }
                else if (command == 3)                   //player wants to use healing potion
                {
                    if (!player.containsHealingPotion()) //if player has no healing potion
                    {
                        Logger.log("Player has no healing potion, press a valid command");
                        return(0);
                    }
                    foreach (Item i in player.bag) //else find healing potion in player's bag
                    {
                        if (i.GetType() == typeof(HealingPotion))
                        {
                            player.use(i); //use that potion
                            Logger.log("Player used potion");
                            break;         //break the for loop
                        }
                    }
                    //player uses healing potion
                    return(1);
                }
                else if (command == 4) //player chooses to attack
                {
                    //player attacks
                    Logger.log("Player is attacking");
                    //player attacks only one pack in the node
                    bool removePack = player.AttackBool(player.location.packs.First().members.First());
                    //attackBool function returns true if that pack is killed and should be removed from the node
                    if (removePack)
                    {
                        player.location.packs.Remove(player.location.packs.First()); //if every monster died in the pack
                                                                                     //it gets removed from the node
                    }
                    if (player.location.packs.Count > 0)                             //if the node is still constested
                    {
                        return(3);                                                   //go to state 3
                    }
                    else
                    {              //if the node is not contested anymore
                        return(6); //go to state 6
                    }
                }
            }
            else if (state == 1) //if combat is at state 1
            {
                //player is not accelerated and
                //there is no other option than player attack
                Logger.log("Player is not accelerated, player is attacking a monster in a pack");
                bool removePack = player.AttackBool(player.location.packs.First().members.FirstOrDefault()); //player attacks one monster in one pack

                //call attack function and check if attacked pack should be removed
                if (removePack)
                {
                    player.location.packs.Remove(player.location.packs.First());
                }
                if (player.location.packs.Count > 0) //still contested
                {
                    return(3);                       //go to state 3
                }
                else
                {
                    return(6); //node is not contested anymore
                }
            }
            else if (state == 2) //if combat is at state 2
            {
                //player is accelerated and
                //there is no other option than player attack
                Logger.log("Player is accelerated, player is attacking all monsters in a pack");
                bool removePack = player.AttackBool(player.location.packs.First().members.FirstOrDefault()); //accelerated check is inside the function
                                                                                                             //call attack function and check if attacked pack should be removed
                if (removePack)                                                                              //if all monsters in the pack die
                {
                    player.location.packs.Remove(player.location.packs.First());                             //remove that pack from the location
                }
                if (player.location.packs.Count > 0)
                {
                    return(3); //still contested
                }
                else
                {
                    return(6); //not contested anymore
                }
            }
            else if (state == 3) //if the combat is at state 3
            {
                Logger.log("Pack flees or attacks");
                Pack pack = player.location.packs.First();
                if (pack.getAction() == 1)                 //pack attacks
                {
                    Logger.log("Pack attacks");
                    pack.Attack(player); //pack attacks to player
                    return(0);
                }
                else if (pack.getAction() == 2)
                {                    //pack flees
                    if (pack.flee()) //if pack can flee
                    {
                        Logger.log("Pack flees");
                        if (player.location.packs.Count > 0) //if the node is still contested
                        {
                            return(4);                       //go to state 4
                        }
                        else
                        {
                            return(6); //node is not contested anymore
                        }
                    }
                    else
                    { //if pack can not flee it attacks
                        Logger.log("Pack tried to flee, not possible. Pack attacks");
                        pack.Attack(player);
                        return(0);
                    }
                }

                //if flee probability> attack
                //pack flees
                //if still contested
                //game.state= 4
                //if not contested
                //game.state = 6
                //else pack attacks
                //game.state=0
            }
            else if (state == 4) //if combat state is 4
            {
                Logger.log("Pack attacks");
                player.location.packs.First().Attack(player); //first pack in the node attacks player
                //TO-DO randomly decide the pack
                return(0);
                //if player is still alive checked in main while
            }

            /*else if (state == 5) //if combat state is 5
             * {
             *  Logger.log("Player successfully fleed, not contested anymore");
             *  return -1;
             *  //return -1; //exit
             * }
             * else if (state == 6)
             * {
             *  Logger.log("Node is not contested anymore");
             *  return -1;
             *  //return -1; //exit
             *
             * }*/
            else
            { //it does not call the function with state 5 or 6
                //since the node is not contested anymore, it does not enter while loop again
                //this part is not executed only put for guarantee.
                Logger.log("Combat ends");
            }
            return(-1);
        }