示例#1
0
        static void Main(string[] args)
        {
            string fighter = "";


            List <Fighter> list = new List <Fighter>();

            Console.WriteLine("");
            Console.WriteLine("Welcome to text based Battle Royal!");
            Console.WriteLine("");
            Console.WriteLine("Please select game mode using the arrow keys. (Select with enter):");


            // adds the main menue for game mode
            var mode = new Menu();

            mode.options = new[] { "Solo VS AI", "Player VS Player" };


            mode.Render();



            if (mode.getSelected() == 0)
            {
                Console.Clear();
                Console.WriteLine("You selected 'Solo VS AI'");
                var player = new Fighter();
                var foe    = new Fighter();


                Console.WriteLine("Would you like to make a new fighter or try an exisiting one?");
                var useExsistingdData = new Menu();
                useExsistingdData.options = new[] { "Make New Fighter", "Browse exsisting Fighters" };

                useExsistingdData.Render();


                if (useExsistingdData.getSelected() == 0)
                {
                    player = player.Create();
                }

                if (useExsistingdData.getSelected() == 1)
                {
                    player = player.Load(player);
                }

                // AI opponent mode
                Console.WriteLine("Would you like to have a random AI selected, or choose your own?");

                var aiType = new Menu();
                aiType.options = new[]
                {
                    "Generate Random AI",
                    "Let me pick AI manualy"
                };
                aiType.Render();

                if (aiType.getSelected() == 0)
                {
                    foe = foe.LoadRandom(aiType, foe, player);
                }

                if (aiType.getSelected() == 1)
                {
                    foe = foe.Load(foe);
                }



                // Launch the game Player VS AI
                var match = new Game(player, foe);
                gameInstance = match;
                match.play(player, foe, "1P");


                while (true)
                {
                    var rematch = new Menu();
                    rematch.options = new[] { "Rematch", "Quit" };

                    Console.WriteLine("Would you like a rematch?");

                    rematch.Render();

                    if (rematch.getSelected() == 1)
                    {
                        break;
                    }

                    player.fighterStatus = null;
                    foe.fighterStatus    = null;
                    match.play(player, foe, "1P");
                }
            } // closes "Selected AI"

            if (mode.getSelected() == 1)
            {
                Console.Clear();
                Console.WriteLine("You selected 'Player VS Player'");
                Console.WriteLine();
                var player1 = new Fighter();
                player1.name = "player1";
                player1      = player1.pvpMenus(player1);
                var player2 = new Fighter();
                player2.name = "player2";
                player2      = player2.pvpMenus(player2);


                var match = new Game(player1, player2);
                gameInstance = match;
                match.play(player1, player2, "2P");

                while (true)
                {
                    var rematch = new Menu();
                    rematch.options = new[] { "Rematch", "Quit" };

                    Console.WriteLine("Would you like a rematch?");

                    rematch.Render();

                    if (rematch.getSelected() == 1)
                    {
                        break;
                    }

                    player1.fighterStatus = null;
                    player2.fighterStatus = null;
                    match.play(player1, player2, "2P");
                }
            }
        }
示例#2
0
        public void play(Fighter player, Fighter foe, string mode)
        {
            if (foe.name == player.name)
            {
                foe.name += " the Second";
            }
            Console.Clear();
            Console.WriteLine("How long would you like the match?");

            var gameLength = new Menu();

            gameLength.options = new[]
            {
                "Short (50HP each)",
                "Medium (100HP each)",
                "Long (200HP each)",
                "Custom (Chose the HP yourself)"
            };

            gameLength.Render();

            switch (gameLength.getSelected())
            {
            case 0:
                player.health    = 50;
                player.maxHealth = 50;
                foe.maxHealth    = 50;
                foe.health       = 50;
                break;

            case 1:
                player.health    = 100;
                player.maxHealth = 100;
                foe.maxHealth    = 100;
                foe.health       = 100;
                break;

            case 2:
                player.health    = 200;
                player.maxHealth = 100;
                foe.maxHealth    = 100;
                foe.health       = 200;
                break;

            case 3:
                var health = "";
                int hp;
                while (!int.TryParse(health, out hp))
                {
                    Console.Clear();
                    if (health != "")
                    {
                        Console.WriteLine($"'{health}' is not a valid number");
                    }
                    Console.WriteLine("Please enter the desired health bellow (only numbers):");
                    health = Console.ReadLine();
                }

                player.health    = Int32.Parse(health);
                player.maxHealth = Int32.Parse(health);
                foe.maxHealth    = Int32.Parse(health);
                foe.health       = Int32.Parse(health);
                break;
            }



            fighterReset1 = new List <FighterStatus>();
            writeFighter(player, "name");
            Console.Write(" VS ");
            writeFighter(foe, "name");
            Console.WriteLine("");
            Console.WriteLine("FIGHT!");
            Console.ReadLine();
            fighterReset1.Add(new FighterStatus("Heal", 4));
            fighterReset1.Add(new FighterStatus("Rage", 0));
            fighterReset1.Add(new FighterStatus("Rage soak", 0));
            fighterReset2.Add(new FighterStatus("Heal", 4));
            fighterReset2.Add(new FighterStatus("Rage", 0));
            fighterReset2.Add(new FighterStatus("Rage soak", 0));
            player.fighterStatus = new List <FighterStatus>(fighterReset1);
            foe.fighterStatus    = new List <FighterStatus>(fighterReset2);

            while (true)
            {
                if (player.health < 1)
                {
                    break;
                }

                if (foe.health < 1)
                {
                    break;
                }
                if (mode == "1P")
                {
                    Rnd(player, foe);
                    FoeAttack(foe, player);
                    Console.ReadLine();
                    continue;
                }

                Rnd(player, foe);
                if (player.health < 1)
                {
                    break;
                }

                if (foe.health < 1)
                {
                    break;
                }
                Rnd(foe, player);
            }

            if (player.health > foe.health)
            {
                writeFighter(player, "name");
                Console.Write(" wins over ");
                writeFighter(foe, "name");
                Console.Write(" with ");
                writeFighter(player, "health");
                Console.Write("HP left!");
                Console.WriteLine("");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("CONGRATUALATIONS!");
                Console.ResetColor();
            }

            if (player.health < foe.health)
            {
                writeFighter(foe, "name");
                Console.Write(" wins over ");
                writeFighter(player, "name");
                Console.Write(" with ");
                writeFighter(foe, "health");
                Console.Write("HP left!");
                Console.WriteLine("");
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("Better luck next time!");
                Console.ResetColor();
            }
        }
示例#3
0
        public void Rnd(Fighter fighter, Fighter target)
        {
            Console.Clear();
            if (fighter.name == player.name)
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
            }
            Console.WriteLine($"{fighter.name}: {fighter.health}HP");
            if (target.name == player.name)
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
            }
            Console.WriteLine($"{target.name}: {target.health}HP");
            Console.ResetColor();
            Console.WriteLine();



            if (fighter.findStatus(fighter, "Rage").statusDuration > 0)
            {
                var rageAttackIndex = fighter.attacks.FindIndex(attackEffect => attackEffect.effect == "Rage");

                fighter.attacks[rageAttackIndex].invokeAttacks(fighter, target);
                Console.ReadLine();
                return;
            }
            if (fighter.findStatus(fighter, "Prone") != null)
            {
                if (fighter.findStatus(fighter, "Prone").statusDuration == 1)
                {
                    Console.WriteLine("");
                    writeFighter(fighter, "name");
                    Console.Write("'s starts to get back on their feet...");
                    fighter.findStatus(fighter, "Prone").statusDuration = 2;
                    Console.ReadLine();
                    return;
                }

                Console.WriteLine("");
                writeFighter(fighter, "name");
                Console.ResetColor();
                Console.Write(" is back up again!");
                fighter.fighterStatus.Remove(fighter.findStatus(fighter, "Prone"));
                Console.ReadLine();
                return;
            }

            Console.WriteLine("");
            Console.WriteLine("");
            Console.Write("What will ");
            writeFighter(fighter, "name");
            Console.Write(" do?");

            var selectAction = new Menu();

            Console.ReadLine();
            selectAction.options = new[]
            {
                $"{fighter.attacks[0].attack} ({fighter.attacks[0].effect})",
                $"{fighter.attacks[1].attack} ({fighter.attacks[1].effect})",
                $"{fighter.attacks[2].attack} ({fighter.attacks[2].effect})",
                $"{fighter.attacks[3].attack} ({fighter.attacks[3].effect})",
                "Do nothing",
                "Give up"
            };

            selectAction.Render();
            if (selectAction.getSelected() < 4)
            {
                if (fighter.attacks[selectAction.getSelected()].effect == "Heal")
                {
                    if (fighter.health == fighter.maxHealth)
                    {
                        Console.WriteLine("");
                        writeFighter(fighter, "name");
                        Console.Write("'s health is already full!");
                        Console.ReadLine();
                        Rnd(fighter, target);
                        return;
                    }

                    if (fighter.findStatus(fighter, "Heal").statusDuration < 1)
                    {
                        Console.WriteLine("You're out of Heals!");
                        Console.ReadLine();
                        Rnd(fighter, target);
                        return;
                    }


                    fighter.attacks[selectAction.getSelected()].invokeAttacks(fighter, target);
                    return;
                }
            }


            if (fighter.findStatus(fighter, "Stunned") != null && selectAction.getSelected() < 4)
            {
                if (fighter.attacks[selectAction.getSelected()].StunCheck(fighter, target))
                {
                    return;
                }
            }

            switch (selectAction.getSelected())
            {
            case 0:


                fighter.attacks[0].invokeAttacks(fighter, target);

                break;

            case 1:


                fighter.attacks[1].invokeAttacks(fighter, target);
                break;

            case 2:

                fighter.attacks[2].invokeAttacks(fighter, target);
                break;

            case 3:

                fighter.attacks[3].invokeAttacks(fighter, target);
                break;

            case 4:
                Console.WriteLine("");
                writeFighter(fighter, "name");
                Console.Write(" chose not to attack.");
                break;

            case 5:
                Console.WriteLine("");
                writeFighter(fighter, "name");
                Console.Write(" surrendered!");
                fighter.health = 0;
                break;
            }

            Console.ReadLine();
            Console.Clear();
        }
示例#4
0
        public void FoeAttack(Fighter foe, Fighter target)
        {
            if (foe.health < 1)
            {
                return;
            }
            int attackIndex = foe.randomAttack;

            if (foe.attacks[attackIndex].effect == "Heal")
            {
                if (foe.health == foe.maxHealth)
                {
                    FoeAttack(foe, target);
                    return;
                }

                if (foe.findStatus(foe, "Heal").statusDuration < 1)
                {
                    FoeAttack(foe, target);
                    return;
                }


                foe.attacks[attackIndex].invokeAttacks(foe, target);
                return;
            }
            if (foe.findStatus(foe, "Stunned") != null)
            {
                if (foe.attacks[attackIndex].StunCheck(foe, target))
                {
                    return;
                }
            }

            if (foe.findStatus(foe, "Rage").statusDuration > 0)
            {
                var rageAttackIndex = foe.attacks.FindIndex(attackEffect => attackEffect.effect == "Rage");

                foe.attacks[rageAttackIndex].invokeAttacks(foe, target);
                return;
            }

            if (foe.findStatus(foe, "Prone") != null)
            {
                if (foe.findStatus(foe, "Prone").statusDuration == 1)
                {
                    writeFighter(foe, "name");
                    Console.Write("{'s starts to get back on their feet...");
                    foe.findStatus(foe, "Prone").statusDuration = 2;
                    Console.ReadLine();
                    return;
                }
                writeFighter(foe, "name");
                Console.Write(" is back up again!");
                foe.fighterStatus.Remove(foe.findStatus(foe, "Prone"));
                Console.ReadLine();
                return;
            }

            switch (attackIndex)
            {
            case 0:

                foe.attacks[0].invokeAttacks(foe, target);
                break;

            case 1:

                foe.attacks[1].invokeAttacks(foe, target);
                break;

            case 2:

                foe.attacks[2].invokeAttacks(foe, target);
                break;

            case 3:
                foe.attacks[3].invokeAttacks(foe, target);
                break;
            }
        }
示例#5
0
 public Game(Fighter player, Fighter opponent)
 {
     this.player   = player;
     this.opponent = opponent;
 }
示例#6
0
        public Fighter Create()
        {
            Console.WriteLine("Please type down your fighter bellow:");

            this.name = Console.ReadLine();
            Console.WriteLine($"Type down 4 attacks {this.name} should know. (Add one at a time):");
            List <string> attackList = new List <string>();

            for (int i = 1; i < 5; i++)
            {
                var attack = Console.ReadLine();
                attackList.Add(attack);
                Console.WriteLine($"{attack}, added!");
            }

            Console.WriteLine("Done!");

            Console.Clear();

            foreach (var attack in attackList)
            {
                while (true)
                {
                    Console.WriteLine($"What do you want {attack} to do?:");

                    var attackType = new Menu();
                    attackType.options = new[]
                    {
                        "Attack (enemy -10 HP)",
                        "Heal (player +20 HP, 4 uses/match)",
                        "Stun (Target has 33% to miss his attack, 4 rounds)",
                        "Guard (Player takes 50% less from next attack)",
                        "Trip (Target has a 50% chance to lose 2 attacks.)",
                        "Dodge (Player has 33% to take 0HP damage from next attack)",
                        "Rage (Player waits 1 rnd, then combines his attacks with the damage received)"
                    };

                    attackType.Render();

                    if (attackType.comfirm($"{attack} should {attackType.options[attackType.position]}?"))
                    {
                        Console.WriteLine($"{attack} set to {attackType.options[attackType.position]}");
                        string effect = "";

                        switch (attackType.position)
                        {
                        case 0:
                            effect = "Tackle";

                            break;

                        case 1:
                            effect = "Heal";
                            break;

                        case 2:
                            effect = "Stun";
                            break;

                        case 3:
                            effect = "Guard";
                            break;

                        case 4:
                            effect = "Trip";
                            break;

                        case 5:
                            effect = "Dodge";
                            break;

                        case 6:
                            effect = "Rage";
                            break;
                        }
                        attacks.Add(new Attack(attack, effect));

                        break;
                    }
                    Console.Clear();
                }
            }

            while (true)
            {
                Console.WriteLine("Would you like to change any attacks?");



                var attackEdit = new Menu();

                attackEdit.options = new[]
                {
                    $"Attack: {attacks[0].attack} Effect: {attacks[0].effect}",
                    $"Attack: {attacks[1].attack} Effect: {attacks[1].effect}",
                    $"Attack: {attacks[2].attack} Effect: {attacks[2].effect}",
                    $"Attack: {attacks[3].attack} Effect: {attacks[3].effect}",
                    "Save and Continue."
                };


                attackEdit.Render();

                if (attackEdit.position == 4)
                {
                    // skriv
                    var json = JsonSerializer.Serialize(attacks);

                    File.WriteAllText($"attacks/{this.name}.json", json);

                    break;
                }

                while (true)
                {
                    Console.WriteLine($"What do you want {attacks[attackEdit.position].attack} to do?:");

                    var attackType = new Menu();
                    attackType.options = new[]
                    {
                        "Attack (enemy -10 HP)",
                        "Heal (player +20 HP, 4 uses/match)",
                        "Stun (Target has 33% to miss his attack, 4 rounds)",
                        "Guard (Player takes 50% less from next attack)",
                        "Trip (Target has a 50% chance to lose 2 attacks.)",
                        "Dodge (Player has 33% to take 0HP damage from next attack)",
                        "Rage (Player waits 1 rnd, then combines his attacks with the damage received)"
                    };

                    attackType.Render();

                    if (attackType.comfirm($"{attacks[attackEdit.position].attack} should {attackType.options[attackType.position]}"))
                    {
                        Console.WriteLine($"{attacks[attackEdit.position].attack} set to {attackType.options[attackType.position]}");
                        string effect = "";

                        switch (attackType.position)
                        {
                        case 0:
                            effect = "Tackle";
                            break;

                        case 1:
                            effect = "Heal";
                            break;

                        case 2:
                            effect = "Stun";
                            break;

                        case 3:
                            effect = "Guard";
                            break;

                        case 4:
                            effect = "Trip";
                            break;

                        case 5:
                            effect = "Dodge";
                            break;

                        case 6:
                            effect = "Rage";
                            break;
                        }
                        attacks[attackEdit.position] = new Attack(attacks[attackEdit.position].attack, effect);
                        break;
                    }
                    Console.Clear();
                }
            }

            Console.WriteLine("Fighter saved!");

            Fighter player = new Fighter();

            player.name    = name;
            player.attacks = attacks;
            return(player);
        }