Example #1
0
        public void ShowInformation(FileParser parser)
        {
            Console.Clear();
            Console.WriteLine(String.Format("{0,-20}", "Food") +
                              String.Format("{0,-15}", "HPIncrease") + "Weight");
            Console.WriteLine("-----------------------------------------");
            foreach (Food food in parser.listOfFoods)
            {
                Console.Write(food.Name);
                for (int i = 0; i < 22 - food.Name.Length; i++)
                {
                    Console.Write(" ");
                }
                Console.Write(String.Format("{0,8:00}",
                                            "+" + food.HPIncrease));
                Console.WriteLine(String.Format("{0,11:0.0}", food.Weight));
            }

            Console.WriteLine("\n");
            Console.WriteLine(String.Format("{0,-19}", "Weapon") +
                              String.Format("{0,-16}", "AttackPower") +
                              String.Format("{0,-10}", "Weight") + "Durability");
            Console.WriteLine("-----------------------------------------" +
                              "--------------");
            foreach (Weapon weapon in parser.listOfWeapons)
            {
                Console.Write(weapon.Name);
                for (int i = 0; i < 22 - weapon.Name.Length; i++)
                {
                    Console.Write(" ");
                }
                Console.Write(String.Format("{0,8:0.0}",
                                            weapon.AttackPower));
                Console.Write(String.Format("{0,11:0.0}", weapon.Weight));
                Console.WriteLine(String.Format("{0,14:0.00}", weapon.Durability));
            }

            Console.WriteLine("\n");
            Console.WriteLine(String.Format("{0,-21}", "Trap") + "MaxDamage");
            Console.WriteLine("------------------------------");
            foreach (Trap trp in parser.listOfTraps)
            {
                Console.Write(trp.Name);
                for (int i = 0; i < 22 - trp.Name.Length; i++)
                {
                    Console.Write(" ");
                }
                Console.WriteLine(String.Format("{0,8:0}", trp.MaxDamage));
            }
        }
Example #2
0
        public void ShowHighScores(FileParser parser)
        {
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write(String.Format("{0,7}", "THE"));
            Console.Write(String.Format("{0,4}", parser.listHighScores.Count));
            Console.Write(String.Format("{0,7}", "BEST"));
            Console.Write(String.Format("{0,12}", "PLAYERS\n\n"));
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write(String.Format("{0,7}", "RANK"));
            Console.Write(String.Format("{0,11}", "SCORE"));
            Console.Write(String.Format("{0,12}", "NAME\n\n"));
            for (int i = 0; i < parser.listHighScores.Count; i++)
            {
                string str;

                if ((i + 2) % 2 == 0)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Cyan;
                }

                if (i == 0)
                {
                    str = "1ST";
                }
                else if (i == 1)
                {
                    str = "2ND";
                }
                else if (i == 2)
                {
                    str = "3RD";
                }
                else
                {
                    str = "" + (i + 1) + "TH";
                }
                Console.Write(String.Format("{0,7}", str));
                Console.Write(String.Format("{0,11}",
                                            parser.listHighScores[i].Score));
                Console.Write(String.Format("{0,12}",
                                            parser.listHighScores[i].Name.ToUpper() + "\n\n"));
            }
            Console.ResetColor();
        }
Example #3
0
        public void Options()
        {
            bool  end = false, isError = false;
            short option;

            visualization = new Interface();
            game          = new GameManager();
            parser        = new FileParser();

            do
            {
                if (!isError)
                {
                    visualization.ClearScreen();
                    parser.ReadFromFiles();
                }
                else
                {
                    Console.WriteLine();
                }

                isError = false;
                visualization.ShowMenu();
                Console.WriteLine("\n");
                visualization.AskOption();
                short.TryParse(Console.ReadLine(), out option);

                switch (option)
                {
                case 1:
                    Console.Clear();
                    game.Update(parser);
                    break;

                case 2:
                    visualization.ClearScreen();
                    visualization.ShowHighScores(parser);
                    Console.ReadKey();
                    break;

                case 3:
                    visualization.ClearScreen();
                    visualization.ShowCredits(developers);
                    Console.ReadKey();
                    break;

                case 4:
                    end = true;
                    break;

                default:
                    visualization.ClearScreen();
                    isError = true;
                    visualization.WrongOption(option.ToString());
                    break;
                }
            } while (end == false);

            visualization.Bye();
            return;
        }
        public void Update(FileParser p)
        {
            world         = new World();
            visualization = new Interface();
            levelGen      = new LevelGenerator();
            player        = new Player();
            parser        = p;
            messages      = new List <string>();
            Tuple <int, int>    playerPos;
            Tuple <int, int>    exitPos;
            List <Object>       currentTile;
            List <IDealsDamage> tileDmg;
            List <NPC>          tileNPC;
            List <IItem>        tileItems;
            List <IItem>        inventoryItems;
            int            level = 1;
            bool           quit  = false;
            bool           action;
            ConsoleKeyInfo option;
            HighScore      hS;
            short          itemNum, npcNum;

            if (keyBinds.Count == 0)
            {
                AddKeys();
            }
            messages.Add("Welcome to the game!");

            do
            {
                exitPos   = levelGen.GenerateLevel(world, player, level, parser);
                playerPos = new Tuple <int, int>(player.X, player.Y);

                do
                {
                    // Clear our command flags to update next
                    CommandFlag = Command.None;
                    action      = false;
                    tileItems   = new List <IItem>();
                    tileDmg     = new List <IDealsDamage>();
                    tileNPC     = new List <NPC>();

                    currentTile = world.WorldArray[player.X, player.Y].
                                  GetInfo().ToList();

                    foreach (IItem obj in currentTile.OfType <IItem>())
                    {
                        tileItems.Add(obj);
                    }

                    foreach (IDealsDamage obj in
                             currentTile.OfType <IDealsDamage>())
                    {
                        tileDmg.Add(obj);
                    }

                    foreach (IDealsDamage obj in tileDmg)
                    {
                        if (obj is Trap)
                        {
                            if (!(obj as Trap).FallenInto)
                            {
                                obj.OnDetectingPlayer(this);
                            }
                        }
                        if (obj is NPC)
                        {
                            tileNPC.Add(obj as NPC);
                            if (((obj as NPC).Hostile))
                            {
                                obj.OnDetectingPlayer(this);
                            }
                        }
                    }

                    inventoryItems = player.Inventory.GetInfo().ToList();

                    if (player.HP <= 0)
                    {
                        break;
                    }

                    visualization.ShowWorld(world, player, level);
                    visualization.ShowStats(world, player);
                    visualization.ShowLegend(world);
                    visualization.ShowMessages(world, messages);
                    visualization.ShowSurrounds
                        (world.GetSurroundingInfo(player));
                    visualization.ShowOptions(new
                                              List <ConsoleKey>(keyBinds.Keys));

                    messages.Clear();

                    // Update our input for everything else to use
                    option = Console.ReadKey();
                    if (keyBinds.TryGetValue(option.Key, out var command))
                    {
                        CommandFlag |= command;

                        switch (CommandFlag)
                        {
                        case Command.Quit:
                            string wantsQuit;
                            do
                            {
                                visualization.AskQuit();
                                wantsQuit = Console.ReadLine();
                            } while ((wantsQuit.ToUpper() != "Y") &&
                                     (wantsQuit.ToUpper() != "N"));
                            if (wantsQuit.ToUpper() == "Y")
                            {
                                quit = true;
                            }
                            break;

                        case Command.MoveNorth:
                            if (player.MoveNorth())
                            {
                                playerPos =
                                    world.UpdatePlayer(playerPos, player);
                                action = true;
                                messages.Add("You moved NORTH");
                            }
                            else
                            {
                                messages.Add("You tried to move NORTH." +
                                             " But you hit a wall instead");
                            }
                            break;

                        case Command.MoveSouth:
                            if (player.MoveSouth(world.X))
                            {
                                playerPos =
                                    world.UpdatePlayer(playerPos, player);
                                action = true;
                                messages.Add("You moved SOUTH");
                            }
                            else
                            {
                                messages.Add("You tried to move SOUTH." +
                                             "  But you hit a wall instead");
                            }
                            break;

                        case Command.MoveWest:
                            if (player.MoveWest())
                            {
                                playerPos =
                                    world.UpdatePlayer(playerPos, player);
                                action = true;
                                messages.Add("You moved WEST");
                            }
                            else
                            {
                                messages.Add("You tried to move WEST." +
                                             "  But you hit a wall instead");
                            }
                            break;

                        case Command.MoveEast:
                            if (player.MoveEast(world.Y))
                            {
                                playerPos =
                                    world.UpdatePlayer(playerPos, player);
                                action = true;
                                messages.Add("You moved EAST");
                            }
                            else
                            {
                                messages.Add("You tried to move EAST." +
                                             "  But you hit a wall instead");
                            }
                            break;

                        case Command.AttackNPC:
                            if ((tileNPC.Count > 0))
                            {
                                if (player.SelectedWeapon != null)
                                {
                                    do
                                    {
                                        visualization.ShowNPCsToAttack(
                                            tileNPC);
                                        short.TryParse(
                                            Console.ReadLine(),
                                            out npcNum);
                                    } while ((npcNum < 0) ||
                                             (npcNum > tileItems.Count));

                                    if (npcNum != tileItems.Count)
                                    {
                                        player.AttackNPC(this,
                                                         tileNPC[npcNum]);
                                        action = true;
                                    }
                                }
                                else
                                {
                                    messages.Add("You tried to attack an" +
                                                 " NPC but you don't have a " +
                                                 "weapon equipped");
                                }
                            }
                            else
                            {
                                messages.Add("You tried to attack an NPC" +
                                             " but there are no NPC in the " +
                                             "current tile");
                            }
                            break;

                        case Command.PickUpItem:
                            if (tileItems.Count > 0)
                            {
                                do
                                {
                                    visualization.ShowItems(tileItems,
                                                            "Pick Up");
                                    short.TryParse(
                                        Console.ReadLine(), out itemNum);
                                } while ((itemNum < 0) ||
                                         (itemNum > tileItems.Count));

                                if (itemNum != tileItems.Count)
                                {
                                    tileItems[itemNum].OnPickUp(this);
                                    action = true;
                                }
                            }
                            else
                            {
                                messages.Add("You tried to PICK UP an " +
                                             "item but there are no items " +
                                             "available to be picked up");
                            }
                            break;

                        case Command.UseItem:
                            if (inventoryItems.Count > 0)
                            {
                                do
                                {
                                    visualization.ShowItems(inventoryItems,
                                                            "Use");
                                    short.TryParse(
                                        Console.ReadLine(), out itemNum);
                                } while ((itemNum < 0) ||
                                         (itemNum > inventoryItems.Count));

                                if (itemNum != inventoryItems.Count)
                                {
                                    inventoryItems[itemNum].OnUse(this);
                                    action = true;
                                }
                            }
                            else
                            {
                                messages.Add("You tried to USE an " +
                                             "item but you currently don't have" +
                                             " any items in the inventory");
                            }
                            break;

                        case Command.DropItem:
                            if (inventoryItems.Count > 0)
                            {
                                do
                                {
                                    visualization.ShowItems(inventoryItems,
                                                            "Drop");
                                    short.TryParse(
                                        Console.ReadLine(), out itemNum);
                                } while ((itemNum < 0) ||
                                         (itemNum > inventoryItems.Count));

                                if (itemNum != inventoryItems.Count)
                                {
                                    inventoryItems[itemNum].OnDrop(this);
                                    action = true;
                                }
                            }
                            else
                            {
                                messages.Add("You tried to DROP an " +
                                             "item but you currently don't have" +
                                             " any items in the inventory");
                            }
                            break;

                        case Command.Information:
                            messages.Add("You sought more info in the " +
                                         "elder scrolls");
                            visualization.ShowInformation(parser);
                            Console.ReadKey();
                            break;
                        }

                        if (action)
                        {
                            player.LoseHP(1);
                        }
                    }
                    else
                    {
                        Console.WriteLine();
                        visualization.WrongOption(option.Key.ToString());
                        Console.ReadKey();
                    }
                } while ((!playerPos.Equals(exitPos)) && (!quit) &&
                         (player.HP > 0));

                if (!quit)
                {
                    level++;
                }
            } while ((player.HP > 0) && (!quit));

            if (!quit)
            {
                visualization.ShowWorld(world, player, level);
                visualization.ShowStats(world, player);
                visualization.ShowLegend(world);

                visualization.ShowDeath(level);
            }

            if (CheckHighScore(level))
            {
                visualization.Success(level);
                string name = Console.ReadLine();
                if (name.Length > 3)
                {
                    name = name.Substring(0, 3);
                }
                hS = new HighScore(name, level);
                parser.UpdateHighScores(hS);
            }
            else
            {
                visualization.Failure(level);
                Console.ReadKey();
            }
        }
        public Tuple <int, int> GenerateLevel(World world, Player player,
                                              int level, FileParser parser)
        {
            int    rowPlayer, rowExit;
            int    tempRow, tempCol;
            double maxNum;
            Trap   rndTrap;
            Food   rndFood;
            Weapon rndWeapon;
            int    tempNum;
            double hp, attackPower;
            bool   state;
            Map    map;

            if (level > 1)
            {
                CleanLevel(world);
            }

            // Exit
            rowExit = rnd.Next(world.X);

            world.WorldArray[rowExit, world.Y - 1].IsExit = true;

            // Player
            rowPlayer = rnd.Next(world.X);
            world.WorldArray[rowPlayer, 0].AddTo(player);
            world.WorldArray[rowPlayer, 0].IsVisible = true;
            player.X = rowPlayer;
            player.Y = 0;

            world.UpdateExploredPlaces(player);

            // Map
            do
            {
                tempRow = rnd.Next(world.X);
                tempCol = rnd.Next(world.Y);
            } while ((tempRow == rowExit) && (tempCol == world.Y - 1));

            map = new Map();
            world.WorldArray[tempRow, tempCol].AddTo(map);

            // Traps
            maxNum = Logistic(level, world.X * world.Y + world.TileSize,
                              ((world.X * world.Y + world.TileSize) / 2) -
                              (world.TileSize / 2), 0.07);

            for (int i = 0; i < maxNum; i++)
            {
                do
                {
                    tempRow = rnd.Next(world.X);
                    tempCol = rnd.Next(world.Y);
                } while (((tempRow == rowExit) && (tempCol == world.Y - 1)) ||
                         ((tempRow == rowPlayer) && (tempCol == 0)));

                tempNum = rnd.Next(parser.listOfTraps.Count);

                rndTrap = parser.listOfTraps[tempNum];
                Trap finalTrap = new Trap(rndTrap.Name, rndTrap.MaxDamage);
                if (!world.WorldArray[tempRow, tempCol].AddTo(finalTrap))
                {
                    i--;
                }
            }

            // Food
            maxNum = Logistic(level, world.X * world.Y,
                              ((world.X * world.Y + world.TileSize) / 2) -
                              (world.TileSize / 2), -0.05);

            for (int i = 0; i < maxNum; i++)
            {
                do
                {
                    tempRow = rnd.Next(world.X);
                    tempCol = rnd.Next(world.Y);
                } while ((tempRow == rowExit) && (tempCol == world.Y - 1));

                tempNum = rnd.Next(parser.listOfFoods.Count);

                rndFood = parser.listOfFoods[tempNum];
                Food finalFood = new Food(rndFood.Name, rndFood.HPIncrease,
                                          rndFood.Weight);
                if (!world.WorldArray[tempRow, tempCol].AddTo(finalFood))
                {
                    i--;
                }
            }

            // Weapon
            maxNum = Logistic(level, world.X * world.Y,
                              ((world.X * world.Y + world.TileSize) / 2) -
                              (world.TileSize / 2), -0.05);

            for (int i = 0; i < maxNum; i++)
            {
                do
                {
                    tempRow = rnd.Next(world.X);
                    tempCol = rnd.Next(world.Y);
                } while ((tempRow == rowExit) && (tempCol == world.Y - 1));

                tempNum = rnd.Next(parser.listOfWeapons.Count);

                rndWeapon = parser.listOfWeapons[tempNum];
                Weapon finalWeapon = new Weapon(rndWeapon.Name,
                                                rndWeapon.AttackPower, rndWeapon.Weight,
                                                rndWeapon.Durability);
                if (!world.WorldArray[tempRow, tempCol].AddTo(rndWeapon))
                {
                    i--;
                }
            }

            // NPC
            maxNum = Logistic(level, world.X * world.Y + world.TileSize,
                              ((world.X * world.Y + world.TileSize) / 2) -
                              (world.TileSize / 2), 0.07);

            for (int i = 0; i < maxNum; i++)
            {
                do
                {
                    tempRow = rnd.Next(world.X);
                    tempCol = rnd.Next(world.Y);
                } while ((tempRow == rowExit) && (tempCol == world.Y - 1) ||
                         ((tempRow == rowPlayer) && (tempCol == 0)));

                hp = rnd.NextDouble() *
                     Logistic(level, NPC.maxNumber, NPC.maxNumber / 2, 0.07);

                attackPower = rnd.NextDouble() *
                              Logistic(level, NPC.maxNumber, NPC.maxNumber / 2, 0.07);

                state = rnd.NextDouble() < 0.5 ? true : false;

                NPC npc = new NPC(hp, attackPower, state);
                if (!world.WorldArray[tempRow, tempCol].AddTo(npc))
                {
                    i--;
                }
            }

            return(new Tuple <int, int>(rowExit, world.Y - 1));
        }