예제 #1
0
        private static void PlayerTryMoveOffsetTo(int xoffset, int yoffset)
        {
            //this is the proposed new x,y of the player if move is successful.
            int newx = ThePlayer.X + xoffset;
            int newy = ThePlayer.Y + yoffset;

            //perform boundary checking of new location, if it fails then we can't move there just because of boundary issues
            if (newx > -1 && newx < Width && newy > -1 && newy < Height)
            {
                //get the tile that is at the new location
                MapTile t = GetTileAtPos(newx, newy);

                //if the space moving upwards is a blank space then move up
                if (t.IsWalkable)
                {
                    ThePlayer.Dirty = true;
                    Tiles[ThePlayer.Y, ThePlayer.X].IsWalkable = true;  //the space we just moved from
                    ThePlayer.LastX = ThePlayer.X;
                    ThePlayer.LastY = ThePlayer.Y;
                    ThePlayer.X     = newx;
                    ThePlayer.Y     = newy;
                    Tiles[ThePlayer.Y, ThePlayer.X].IsWalkable = false; //make new tile not walkable because you are on it

                    CheckTileForAction(ThePlayer.X, ThePlayer.Y);
                }
                else
                {
                    //if we can't walk onto this space then what is in this space? a wall, door, monster, etc.?
                    //walls do nothing, doors we can check for keys, monsters we attack.
                    var type = GetTileAtPos(newx, newy).GetType();
                    if (type == typeof(MapTileWall))
                    {
                        //do nothing, its a wall
                    }
                    else if (type == typeof(MapTileSpace))
                    {
                        //so if its a space and its not walkable, probably a monster here.
                        var monster = MonsterMgr.GetMonsterAt(newx, newy);
                        if (monster.IsAlive)
                        {
                            var maxdamage = ThePlayer.CanDealDamage();
                            //lets hit the monster for damage
                            monster.TakeDamage(maxdamage);
                            MessageBrd.Add($"Monster took {maxdamage} damage.");
                            if (!monster.IsAlive)
                            {
                                MessageBrd.Add($"Monster is DEAD!");
                            }
                            MonsterMgr.PruneDeadMonsters();
                        }
                    }
                }
            } // end of map boundary check
        }
예제 #2
0
        private void CheckTileForAction(int x, int y)
        {
            //if this tile is stairs, perform stairs action
            if (Tiles[y, x].GetType() == typeof(MapTileStairs))
            {
                var tile = ((MapTileStairs)Tiles[y, x]);
                var str  = tile.Direction < 0 ? "up" : "down";
                MessageBrd.Add($"You are on stairs going {str}.");

                StartLevel(CurrentLevel.Level + tile.Direction);
                Dirty           = true;
                ThePlayer.Dirty = true;
            }

            //TODO check if an object like gold, weapons, traps, etc. is on this tile
        }
예제 #3
0
        private void CheckTileForAction(int x, int y)
        {
            //if this tile is stairs, perform stairs action
            if (Tiles[y, x].GetType() == typeof(MapTileStairs))
            {
                var tile = ((MapTileStairs)Tiles[y, x]);
                var str  = tile.Direction < 0 ? "up" : "down";
                MessageBrd.Add($"You are on stairs going {str}.");

                StartLevel(CurrentLevel.Level + tile.Direction);
                Dirty           = true;
                ThePlayer.Dirty = true;
            }
            else if (Tiles[y, x].GetType() == typeof(MapTileSpace) && Tiles[y, x].pickableObject != null)
            {
                ((MapTileSpace)Tiles[y, x]).OnActionEnter(this);
            }
        }
예제 #4
0
        /// <summary>
        /// Draw the map
        /// </summary>
        static public int Update()
        {
            if (ThePlayer.Life < 1)
            {
                Console.Clear();
                MessageBrd.Add($"You have DIED!");
                MessageBrd.Update();
                return(-1);
            }

            var origRow = Console.CursorTop;
            var origCol = Console.CursorLeft;

            UpdateFogOfWar();

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    Tiles[y, x].Draw();
                }
            }
            Dirty = false;

            //foreach player in players coming soon....
            ThePlayer.Update();

            MonsterMgr.UpdateAll();

            MessageBrd.Update();

            ScoreCard.Update();


            //if there is a keypress available to capture, take it and perform its action
            if (Console.KeyAvailable)
            {
                var ch = Console.ReadKey(true).Key;
                switch (ch)
                {
                case ConsoleKey.Escape:
                    Log.Information("User is quitting.");
                    return(-1);

                case ConsoleKey.F2:
                    CheatToggleFOW();
                    break;

                case ConsoleKey.UpArrow:
                    PlayerTryMoveOffsetTo(0, -1);
                    break;

                case ConsoleKey.DownArrow:
                    PlayerTryMoveOffsetTo(0, 1);
                    break;

                case ConsoleKey.RightArrow:
                    PlayerTryMoveOffsetTo(1, 0);
                    break;

                case ConsoleKey.LeftArrow:
                    PlayerTryMoveOffsetTo(-1, 0);
                    break;
                }
            }

            //Console.SetCursorPosition(0, 0);

            return(0);
        }
예제 #5
0
        /// <summary>
        /// Draw the map
        /// </summary>
        static public int Update()
        {
            switch (GameState)
            {
            case GameStateType.MainMenu:
                if (Dirty)
                {
                    Console.Clear();
                    Console.WriteLine(FiggleFonts.Ogre.Render("Mud2D"));
#if DEBUG
                    Console.WriteLine("DEBUG version");
                    Log.Information("DEBUG version");
#elif RELEASE
                    Console.WriteLine("RELEASE version");
                    Log.Information("RELEASE version");
#endif
                    Console.WriteLine("------===== Main Menu =====-------");
                    Console.WriteLine("Press S to start game");
                    Console.WriteLine("Press L to load last save game");
                    Console.WriteLine("Press ESC to exit");
                    Dirty = false;
                }

                //if there is a keypress available to capture, take it and perform its action
                if (Console.KeyAvailable)
                {
                    var ch = Console.ReadKey(true).Key;
                    switch (ch)
                    {
                    case ConsoleKey.Escape:
                        GameState = GameStateType.Quit;
                        Log.Information("User is quitting game.");
                        return(-1);

                    case ConsoleKey.L:
                        GameState = GameStateType.InGame;
                        LoadLastGame();
                        break;

                    case ConsoleKey.S:
                        GameState = GameStateType.InGame;
                        InitializeGame();
                        break;
                    }
                }
                break;

            case GameStateType.InGame:
                if (ThePlayer.Life < 1)
                {
                    Console.Clear();
                    MessageBrd.Add($"You have DIED!");
                    MessageBrd.Update();
                    return(-1);
                }

                var origRow = Console.CursorTop;
                var origCol = Console.CursorLeft;

                UpdateFogOfWar();

                for (int y = 0; y < Height; y++)
                {
                    for (int x = 0; x < Width; x++)
                    {
                        Tiles[y, x].Draw();
                    }
                }
                Dirty = false;

                //foreach player in players coming soon....
                ThePlayer.Update();

                MonsterMgr.UpdateAll();

                MessageBrd.Update();

                ScoreCard.Update();


                //if there is a keypress available to capture, take it and perform its action
                if (Console.KeyAvailable)
                {
                    var ch = Console.ReadKey(true).Key;
                    switch (ch)
                    {
                    case ConsoleKey.Escape:
                        GameState = GameStateType.MainMenu;
                        Dirty     = true;
                        SaveGame();
                        Log.Information("User is quitting game, going back to main menu.");
                        break;

                    case ConsoleKey.F2:
                        CheatToggleFOW();
                        break;

                    case ConsoleKey.UpArrow:
                        PlayerTryMoveOffsetTo(0, -1);
                        break;

                    case ConsoleKey.DownArrow:
                        PlayerTryMoveOffsetTo(0, 1);
                        break;

                    case ConsoleKey.RightArrow:
                        PlayerTryMoveOffsetTo(1, 0);
                        break;

                    case ConsoleKey.LeftArrow:
                        PlayerTryMoveOffsetTo(-1, 0);
                        break;
                    }
                }

                //Console.SetCursorPosition(0, 0);

                return(0);
            }
            return(0);
        }