Exemplo n.º 1
0
        public static void StartGame(Player player, Map map, List <Monster> activeMonsters, List <Item> activeItems)
        {
            const bool _keepPlaying = true;

            do
            {
                ConsoleKey aInput            = Console.ReadKey(true).Key; //true hides input
                bool       _moveKeyPressed   = false;
                string     _moveKeyDirection = null;

                if (aInput == ConsoleKey.F5) //reload for testing
                {
                    ActivityLog.ClearLog();
                    map.Reset();
                    Main();
                }

                // move keys
                if (aInput == ConsoleKey.UpArrow || aInput == ConsoleKey.NumPad8)
                {
                    _moveKeyPressed   = true;
                    _moveKeyDirection = "North";
                }
                if (aInput == ConsoleKey.DownArrow || aInput == ConsoleKey.NumPad2)
                {
                    _moveKeyPressed   = true;
                    _moveKeyDirection = "South";
                }
                if (aInput == ConsoleKey.RightArrow || aInput == ConsoleKey.NumPad6)
                {
                    _moveKeyPressed   = true;
                    _moveKeyDirection = "East";
                }
                if (aInput == ConsoleKey.LeftArrow || aInput == ConsoleKey.NumPad4)
                {
                    _moveKeyPressed   = true;
                    _moveKeyDirection = "West";
                }
                if (aInput == ConsoleKey.NumPad9)
                {
                    _moveKeyPressed   = true;
                    _moveKeyDirection = "NorthEast";
                }
                if (aInput == ConsoleKey.NumPad7)
                {
                    _moveKeyPressed   = true;
                    _moveKeyDirection = "NorthWest";
                }
                if (aInput == ConsoleKey.NumPad3)
                {
                    _moveKeyPressed   = true;
                    _moveKeyDirection = "SouthEast";
                }
                if (aInput == ConsoleKey.NumPad1)
                {
                    _moveKeyPressed   = true;
                    _moveKeyDirection = "SouthWest";
                }
                if (_moveKeyPressed) //if a moved key is pressed do this
                {
                    map.MovePlayer(_moveKeyDirection, player, map, activeMonsters, activeItems);
                    map.MoveMonster(map, activeMonsters);
                }

                if (aInput == ConsoleKey.Oem3) // cheat console activation key / for possible cheat codes
                {
                    ActivityLog.AddToLog("cheater!");
                }

                if (aInput == ConsoleKey.I) //inventory
                {
                    Console.Clear();
                    Inventory.Loop(player, map, "all");
                }
                if (aInput == ConsoleKey.Q) //quaff potion
                {
                    Console.Clear();
                    Inventory.Loop(player, map, "potion");
                }
                if (aInput == ConsoleKey.R) //read scroll
                {
                    Console.Clear();
                    Inventory.Loop(player, map, "scroll");
                }

                //! curently broken --> seems fixed - set CurrentTile.IsItem = false on pickup
                if (aInput == ConsoleKey.G) //get item
                {
                    for (int i = 0; i < activeItems.Count; i++)
                    {
                        if (activeItems[i].X == player.X && activeItems[i].Y == player.Y)
                        {
                            ActivityLog.AddToLog("you pick up " + activeItems[i].Name);

                            if (activeItems[i].Type == "Potion")
                            {
                                Inventory.PotionInventory.Add((Health)activeItems[i]);
                            }
                            if (activeItems[i].Type == "Scroll")
                            {
                                Inventory.ScrollInventory.Add((Teleportation)activeItems[i]);
                            }

                            activeItems.RemoveAt(i);     // remove item from active list

                            map.ProcessItemTile(player); //set tile.IsItem to false
                        }
                    }
                }

                //testing
                //for (int i = 0; i < activeMonsters.Count; i++)
                //{
                //    ActivityLog.AddToLog($"{i, 2}) {activeMonsters[i].Name, -10} X: {activeMonsters[i].X, 2} Y: {activeMonsters[i].Y, 2}");
                //}

                map.Display();
                ActivityLog.Display();
                StatBar.Display(player);
            } while (_keepPlaying);
        }
Exemplo n.º 2
0
 public static void MonsterAttacks(Player player, Monster monster)
 {
     player.Health -= 5;
     ActivityLog.AddToLog($"{monster.Name} [{monster.Health}/{monster.HealthMax}] hits {player.Name} for 5 damage.");
     StatBar.Display(player);
 }