Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Stats s = new Stats();

            Player p = new Player("Tuukka Hellman");
            Potion po = new Potion();
            object obj = new object();

            Hero h = new Hero();

            p.

            // Sama kuin IncrementWins

            for (int i = 0; i < 2; i++)
            {
               s.increase(Stats.Kind.Wins);
            }

            for (int i = 0; i < 4; i++)
            {
              s.increase(Stats.Kind.Ties);
            }

            for (int i = 0; i < 8; i++)
            {
               s.increase(Stats.Kind.Losses);
            }

            /*
            Console.WriteLine(s.GetWinPercentage());
            Console.WriteLine(s.GetLossPercentage());
            Console.WriteLine(s.GetTiePercentage());
            */
        }
Exemplo n.º 2
0
 // This will heal the player if you have potions
 public static void Heal(ref Player player)
 {
     for (int i = 0; i < player.storage.Length; i++)
     {
         if (player.storage[i] != null)
         {
             if (player.storage[i].itemType == ItemType.POTION)
             {
                 if (player.health < 100)
                 {
                     Console.Write($"\nWhat potion would you like to use? ");
                     string message = Console.ReadLine();
                     if (player.storage[i].name == message)
                     {
                         if (player.storage[i].itemStack > 1)
                         {
                             Potion tempPotion = (Potion)player.storage[i];
                             player.Heal(ref tempPotion);
                             player.storage[i].itemStack--;
                             Console.WriteLine($"You have healed. You now have {player.health} health left.");
                             FileSetup.PlayerFileWrite(ref player, Game.playerFile);
                         }
                         else
                         {
                             Potion tempPotion = (Potion)player.storage[i];
                             player.Heal(ref tempPotion);
                             player.storage[i] = null;
                             Console.WriteLine($"You have healed. You now have {player.health} health left.");
                             FileSetup.PlayerFileWrite(ref player, Game.playerFile);
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Random         Game_God    = new Random();
            Mob_Program    mob_data    = new Mob_Program();
            Weapon_Program weapon_data = new Weapon_Program();
            Armor_Program  armor_data  = new Armor_Program();
            Potion         new_potion  = new Potion("Зiлля здоров'я", 5);

            karta  mappa  = new karta();
            Player player = new Player("");

            //player.load_player();
            Console.WriteLine("Завантажити гру(1) чи почати нову(2)?");
            int mode = Int16.Parse(Console.ReadLine());

            if (mode == 1)
            {
                mappa.map_load();
                player.load_player();
            }

            if (mode == 2)
            {
                player.Name = "Геральт";
                mappa.map_generate();
                for (int i = 0; i < 25; i++)
                {
                    for (int j = 0; j < 25; j++)
                    {
                        if (mappa.kart[i, j].terra == ".")
                        {
                            player.x = i;
                            player.y = j;
                            mappa.kart[i, j].monster = new Mob("empty", 0, 0, 0);
                            break;
                        }
                    }
                }
            }


            while (true)
            {
                int moved = 0;
                mappa.map_show(player);
                string move = Console.ReadLine();
                if (move == "w" && player.x > 0 && mappa.kart[player.x - 1, player.y].terra != "~")
                {
                    player.x -= 1;
                    if (mappa.kart[player.x, player.y].monster.Name != "empty")
                    {
                        moved = 1;
                        List <string> history1 = FightEngine.InitializeFight(player, mappa.kart[player.x, player.y].monster);
                        foreach (var line in history1)
                        {
                            Console.WriteLine(line);
                        }
                        Console.WriteLine();
                    }
                }
                if (move == "a" && player.y > 0 && mappa.kart[player.x, player.y - 1].terra != "~")
                {
                    player.y -= 1;
                    if (mappa.kart[player.x, player.y].monster.Name != "empty")
                    {
                        moved = 1;
                        List <string> history1 = FightEngine.InitializeFight(player, mappa.kart[player.x, player.y].monster);
                        foreach (var line in history1)
                        {
                            Console.WriteLine(line);
                        }
                        Console.WriteLine();
                    }
                }
                if (move == "d" && player.y < 24 && mappa.kart[player.x, player.y + 1].terra != "~")
                {
                    player.y += 1;
                    if (mappa.kart[player.x, player.y].monster.Name != "empty")
                    {
                        moved = 1;
                        List <string> history1 = FightEngine.InitializeFight(player, mappa.kart[player.x, player.y].monster);
                        foreach (var line in history1)
                        {
                            Console.WriteLine(line);
                        }
                        Console.WriteLine();
                    }
                }
                if (move == "s" && player.x < 24 && mappa.kart[player.x + 1, player.y].terra != "~")
                {
                    player.x += 1;
                    if (mappa.kart[player.x, player.y].monster.Name != "empty")
                    {
                        moved = 1;
                        List <string> history1 = FightEngine.InitializeFight(player, mappa.kart[player.x, player.y].monster);
                        foreach (var line in history1)
                        {
                            Console.WriteLine(line);
                        }
                        Console.WriteLine();
                    }
                }
                if (player.IsAlive == true && moved == 1)
                {
                    mappa.kart[player.x, player.y].monster = new Mob("empty", 0, 0, 0);
                    int loot_type = Game_God.Next(0, 3);
                    if (loot_type == 0)
                    {
                        Weapon new_weapon = weapon_data.weapon_creation()[Game_God.Next(0, 5)];
                        Console.WriteLine("Знайдена зброя " + new_weapon.name + ", що завдає до " + new_weapon.damage + " очок шкоди за удар. Спорядити?");
                        string equip_or_not = Console.ReadLine();
                        if (equip_or_not == "yes")
                        {
                            player.use(new_weapon);
                        }
                    }
                    if (loot_type == 1)
                    {
                        Armor new_armor = armor_data.armor_creation()[Game_God.Next(0, 5)];
                        Console.WriteLine("Знайдено броню " + new_armor.name + ", що поглинає " + new_armor.defence + " очок шкоди за удар. Спорядити?");
                        string equip_or_not = Console.ReadLine();
                        if (equip_or_not == "yes")
                        {
                            player.use(new_armor);
                        }
                    }
                    if (loot_type == 2)
                    {
                        Console.WriteLine("Знайдено зiлля здоров'я.");
                        player.heal_potions += 1;
                    }
                }
                if (move == "heal")
                {
                    if (player.heal_potions > 0)
                    {
                        player.use(new Potion("Зiлля здоров'я", 5));
                        player.heal_potions -= 1;
                        Console.WriteLine("Ви вiдчуваєте, як вашi рани загоюються.");
                    }
                }
                if (player.IsAlive == false)
                {
                    Console.WriteLine("Ваш герой загинув...");
                    break;
                }
                if (move == "exit")
                {
                    break;
                }
            }


            /*//mappa.map_load();
             * mappa.map_show(player);
             * //mappa.map_save();
             *
             * Console.WriteLine();
             * Console.WriteLine($"{player.Name}");
             * Console.WriteLine($"{player.HP}");
             * Console.WriteLine($"{player.current_weapon.name}");
             * Console.WriteLine($"{player.current_armor.name}");
             * Console.WriteLine();
             *
             * Weapon weapon1 = weapon_data.weapon_creation()[Game_God.Next(0, 5)];
             * Armor armor1 = armor_data.armor_creation()[Game_God.Next(0, 5)];
             * player.use(weapon1);
             * player.use(armor1);
             *
             * Console.WriteLine($"{player.Name}");
             * Console.WriteLine($"{player.current_weapon.name}");
             * Console.WriteLine($"{player.current_armor.name}");
             * Console.WriteLine();
             *
             *//*Mob mob1 = mob_data.mob_creation()[Game_God.Next(0,5)];
             *
             * Console.WriteLine($"{player.Name} атакує {mob1.Name}\n");
             * List<string> history1 = FightEngine.InitializeFight(player, mob1);
             * foreach (var line in history1)
             * {
             *  Console.WriteLine(line);
             * }
             * Console.WriteLine();*//*
             *
             * Console.WriteLine($"У {player.Name} залишилося {player.HP} здоров'я");
             * Console.WriteLine(new_potion.Description());
             * player.use(new_potion);
             * Console.WriteLine($"У {player.Name} залишилося {player.HP} здоров'я\n");
             * player.save_player();
             *
             * while(true)
             * {
             *
             * }*/
        }
Exemplo n.º 4
0
        // Reads the values from the txt file to the player storage
        public static void PlayerFileRead(ref Player player, ref NPC npc, string playerFile, string itemFile)
        {
            try
            {
                try
                {
                    // Setting up the objects to create.
                    using (StreamReader sr = new StreamReader(itemFile))
                    {
                        int i = 0;
                        sr.ReadLine();
                        while (!sr.EndOfStream)
                        {
                            Item     tempItem = null;
                            string   line     = sr.ReadLine();
                            string[] value    = line.Split(',');
                            switch (value[0].ToLower())
                            {
                            case "weapon":
                                tempItem = new Weapon(value[1], value[2], Tools.GetInt(value[3]), Tools.GetInt(value[4]));
                                break;

                            case "potion":
                                tempItem = new Potion(value[1], value[2], Tools.GetInt(value[3]), Tools.GetInt(value[4]));
                                break;

                            case "food":
                                tempItem = new Food(value[1], value[2], Tools.GetInt(value[3]), Tools.GetInt(value[4]));
                                break;
                            }
                            npc.storage[i] = tempItem;
                            i++;
                        }
                        sr.Close();
                    }
                    // reads from the txt if it finds the item name is the same  it will give that to the player array and also add a itemstack value to it if it has one.
                    using (StreamReader sr = new StreamReader(playerFile))
                    {
                        string[] value;
                        for (int i = 0; i < npc.storage.Length; i++)
                        {
                            if (npc.storage[i] != null)
                            {
                                value = Files.ReadFile(playerFile, false);
                                if (value != null)
                                {
                                    for (int x = 0; x < value.Length; x++)
                                    {
                                        string[] tempValue = value[x].Split(':');
                                        if (value[x] != null)
                                        {
                                            if (tempValue[0] == npc.storage[i].name)
                                            {
                                                player.storage[i]           = npc.storage[i];
                                                player.storage[i].itemStack = Tools.GetInt(tempValue[1]);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        sr.Close();
                    }
                }
                catch (IndexOutOfRangeException e) { }
            }
            catch (FileNotFoundException e)
            {
                using (StreamWriter sw = new StreamWriter(playerFile))
                    sw.Close();
            }
        }
Exemplo n.º 5
0
 public void use(Potion new_potion)
 {
     HP += new_potion.heal_value;
 }