Esempio n. 1
0
 /// <summary>
 /// Allow player to interact with the overworld.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnOverworldUpdate(object sender, UpdateEventArgs e)
 {
     // Event handler for RLNET's Update event
     didPlayerAct = false;
     keyPress     = console.Keyboard.GetKeyPress();
     if (CommandSystem.IsPlayerTurn)
     {
         if (keyPress != null)
         {
             // User presses a direction
             if (keyPress.Key == RLKey.Keypad1)
             {
                 didPlayerAct = CommandSystem.MovePlayer(Direction.DownLeft);
             }
             else if (keyPress.Key == RLKey.Down || keyPress.Key == RLKey.Keypad2)
             {
                 didPlayerAct = CommandSystem.MovePlayer(Direction.Down);
             }
             else if (keyPress.Key == RLKey.Keypad3)
             {
                 didPlayerAct = CommandSystem.MovePlayer(Direction.DownRight);
             }
             else if (keyPress.Key == RLKey.Left || keyPress.Key == RLKey.Keypad4)
             {
                 didPlayerAct = CommandSystem.MovePlayer(Direction.Left);
             }
             else if (keyPress.Key == RLKey.Right || keyPress.Key == RLKey.Keypad6)
             {
                 didPlayerAct = CommandSystem.MovePlayer(Direction.Right);
             }
             else if (keyPress.Key == RLKey.Keypad7)
             {
                 didPlayerAct = CommandSystem.MovePlayer(Direction.UpLeft);
             }
             else if (keyPress.Key == RLKey.Up || keyPress.Key == RLKey.Keypad8)
             {
                 didPlayerAct = CommandSystem.MovePlayer(Direction.Up);
             }
             else if (keyPress.Key == RLKey.Keypad9)
             {
                 didPlayerAct = CommandSystem.MovePlayer(Direction.UpRight);
             }
             // User exits game
             else if (keyPress.Key == RLKey.Escape)
             {
                 console.Close();
             }
             // User walks down stairs
             else if (keyPress.Key == RLKey.KeypadPeriod || keyPress.Key == RLKey.Period)
             {
                 if (DungeonMap.CanMoveDownToNextLevel())
                 {
                     _mapLevel += 1;
                     if (_mapLevel > DungeonMaps.Count)
                     {
                         MapGenerator mapGenerator = new MapGenerator(
                             Dimensions.WorldWidth,
                             Dimensions.WorldHeight,
                             maxRooms,
                             maxRoomWidth,
                             maxRoomHeight,
                             _mapLevel
                             );
                         DungeonMaps.Add(mapGenerator.CreateMap());
                         DungeonMap = DungeonMaps[_mapLevel - 1];
                     }
                     else
                     {
                         DungeonMap = DungeonMaps[_mapLevel - 1];
                         DungeonMap.PlacePlayerNearEntrance();
                         DungeonMap.RescheduleExistingActors();
                     }
                     MessageLog    = new MessageLog();
                     CommandSystem = new CommandSystem();
                     console.Title = $"L.O.R.S. - Level {_mapLevel}";
                     didPlayerAct  = true;
                 }
                 else
                 {
                     MessageLog.Add("No stairs to walk down.");
                 }
             }
             // User walks up stairs
             else if (keyPress.Key == RLKey.Comma || keyPress.Key == RLKey.Keypad0)
             {
                 if (DungeonMap.CanMoveUpToPreviousLevel())
                 {
                     _mapLevel    -= 1;
                     MessageLog    = new MessageLog();
                     CommandSystem = new CommandSystem();
                     console.Title = $"L.O.R.S. - Level {_mapLevel}";
                     DungeonMap    = DungeonMaps[_mapLevel - 1];
                     DungeonMap.PlacePlayerNearExit();
                     DungeonMap.RescheduleExistingActors();
                     didPlayerAct = true;
                 }
                 else
                 {
                     // if we are in the overworld...
                     if (_mapLevel == 1)
                     {
                         MessageLog.Add("What are you gonna do? Walk to the moon?");
                     }
                     else
                     {
                         MessageLog.Add("No stairs to walk up.");
                     }
                 }
             }
             else
             {
                 didPlayerAct = CommandSystem.HandleKey(keyPress.Key);
             }
         }
         if (didPlayerAct)
         {
             _renderRequired = true;
             CommandSystem.EndPlayerTurn();
         }
     }
     else
     {
         CommandSystem.ActivateMonsters();
         _renderRequired = true;
     }
 }
Esempio n. 2
0
        private static void OnGameUpdate(object sender, UpdateEventArgs e)
        {
            bool       didPlayerAct = false;
            RLKeyPress keyPress     = rootConsole.Keyboard.GetKeyPress();

            if (CommandSystem.IsPlayerTurn)
            {
                if (CommandSystem.PlayerIsDead)
                {
                    time.Stop();
                    ts = time.Elapsed;
                    DeathMenu();
                }
                if (CommandSystem.IsGameEnded)
                {
                    time.Stop();
                    ts = time.Elapsed;
                    WinMenu();
                }
                if (keyPress != null)
                {
                    if (keyPress.Key == RLKey.Up)
                    {
                        didPlayerAct = CommandSystem.MovePlayer(Direction.Up);
                    }
                    else if (keyPress.Key == RLKey.Down)
                    {
                        didPlayerAct = CommandSystem.MovePlayer(Direction.Down);
                    }
                    else if (keyPress.Key == RLKey.Left)
                    {
                        didPlayerAct = CommandSystem.MovePlayer(Direction.Left);
                    }
                    else if (keyPress.Key == RLKey.Right)
                    {
                        didPlayerAct = CommandSystem.MovePlayer(Direction.Right);
                    }
                    else if (keyPress.Key == RLKey.I)
                    {
                        if (Player.Items.Count != 0)
                        {
                            inventoryConsole.Print(0, 2, ">", Colors.Text);
                            renderRequired      = true;
                            rootConsole.Update -= OnGameUpdate;
                            rootConsole.Update += OnItemUpdate;
                        }
                    }
                    else if (keyPress.Key == RLKey.Escape)
                    {
                        rootConsole.Title = "MagiCave";
                        menuConsole.Clear();
                        for (int i = 0; i < 4; i++)
                        {
                            menuConsole.Print((menuConsole.Width - pauseOptions[i].Length) / 2, 40 + i * 5, pauseOptions[i], RLColor.White);
                        }
                        menuConsole.Print((menuConsole.Width - pauseOptions[0].Length) / 2, 40, pauseOptions[0], RLColor.LightRed);
                        Pause();
                    }
                    else if (keyPress.Key == RLKey.Period)
                    {
                        if (DungeonMap.CanMoveDownToNextLevel())
                        {
                            if (CurrentLevel.Next == null)
                            {
                                DungeonMap.SetIsWalkable(Player.X, Player.Y, true);
                                // If this is going to be a final level
                                if (mapLevel == 4)
                                {
                                    SchedulingSystem A_SchedulingSystem = new SchedulingSystem();
                                    CurrentSchedulingSystem = CurrentSchedulingSystem.Next;
                                    CurrentSchedulingSystem = SchedulingSystems.AddLast(A_SchedulingSystem);
                                    SchedulingSystem        = A_SchedulingSystem;

                                    DungeonGenerator mapGenerator = new DungeonGenerator(mapWidth, mapHeight, 20, 15, 7, ++mapLevel);
                                    DungeonMap = mapGenerator.CreateFinalLevel(SchedulingSystem);

                                    rootConsole.Title = $"MagiCave - Level {mapLevel}";
                                    DungeonMap.UpdatePlayerFieldOfView();
                                    didPlayerAct = true;
                                }
                                // Creating generic level
                                else
                                {
                                    SchedulingSystem A_SchedulingSystem = new SchedulingSystem();
                                    CurrentSchedulingSystem = CurrentSchedulingSystem.Next;
                                    CurrentSchedulingSystem = SchedulingSystems.AddLast(A_SchedulingSystem);
                                    SchedulingSystem        = A_SchedulingSystem;

                                    DungeonGenerator mapGenerator = new DungeonGenerator(mapWidth, mapHeight, 20, 15, 7, ++mapLevel);
                                    DungeonMap        = mapGenerator.CreateMap(SchedulingSystem);
                                    rootConsole.Title = $"MagiCave - Level {mapLevel}";
                                    didPlayerAct      = true;
                                    DungeonMap.UpdatePlayerFieldOfView();
                                }
                                CurrentLevel = CurrentLevel.Next;
                                CurrentLevel = Levels.AddLast(DungeonMap);
                            }
                            // Moving to already created level
                            else
                            {
                                DungeonMap.SetIsWalkable(Player.X, Player.Y, true);
                                DungeonMap = CurrentLevel.Next.Value;

                                Player.X = DungeonMap.Rooms.First()[DungeonMap.Rooms.First().Count / 2].X;
                                Player.Y = DungeonMap.Rooms.First()[DungeonMap.Rooms.First().Count / 2].Y;

                                SchedulingSystem        = CurrentSchedulingSystem.Next.Value;
                                CurrentSchedulingSystem = CurrentSchedulingSystem.Next;

                                rootConsole.Title = $"MagiCave - Level {++mapLevel}";
                                didPlayerAct      = true;
                                CurrentLevel      = CurrentLevel.Next;
                                DungeonMap.UpdatePlayerFieldOfView();
                            }
                        }
                        // Moving to the previous level
                        if (DungeonMap.CanMoveUpToPreviousLevel() && !didPlayerAct)
                        {
                            if (CurrentLevel.Previous != null)
                            {
                                DungeonMap.SetIsWalkable(Player.X, Player.Y, true);
                                DungeonMap = CurrentLevel.Previous.Value;

                                SchedulingSystem        = CurrentSchedulingSystem.Previous.Value;
                                CurrentSchedulingSystem = CurrentSchedulingSystem.Previous;

                                Player.X = DungeonMap.Rooms.Last()[DungeonMap.Rooms.Last().Count / 2].X;
                                Player.Y = DungeonMap.Rooms.Last()[DungeonMap.Rooms.Last().Count / 2].Y;

                                rootConsole.Title = $"MagiCave - Level {--mapLevel}";
                                didPlayerAct      = true;
                                CurrentLevel      = CurrentLevel.Previous;
                                DungeonMap.UpdatePlayerFieldOfView();
                            }
                        }
                    }
                }
                if (didPlayerAct)
                {
                    steps++;
                    renderRequired = true;
                    CommandSystem.EndPlayerTurn();
                }
            }
            else
            {
                CommandSystem.ActivateMonsters(SchedulingSystem);
                renderRequired = true;
            }
        }