Example #1
0
        void PlayerMovement()
        {
            Tile tileToCheck = currentMap[newPlayer.yPos, newPlayer.xPos];
            int  moveId      = 0;
            bool hasMoved    = false;

            playerInfo.Action(newPlayer);
            userCKI = Console.ReadKey(true);

            if (userCKI.Key == ConsoleKey.UpArrow || userCKI.Key == ConsoleKey.NumPad8)
            {
                //North
                newPlayer.sHunger++;
                tileToCheck = currentMap[newPlayer.yPos - 1, newPlayer.xPos];
                moveId      = 1;
                hasMoved    = true;
            }
            else if (userCKI.Key == ConsoleKey.DownArrow || userCKI.Key == ConsoleKey.NumPad2)
            {
                //South
                newPlayer.sHunger--;
                tileToCheck = currentMap[newPlayer.yPos + 1, newPlayer.xPos];
                moveId      = 2;
                hasMoved    = true;
            }
            else if (userCKI.Key == ConsoleKey.LeftArrow || userCKI.Key == ConsoleKey.NumPad4)
            {
                //West
                tileToCheck = currentMap[newPlayer.yPos, newPlayer.xPos - 1];
                moveId      = 3;
                hasMoved    = true;
            }
            else if (userCKI.Key == ConsoleKey.RightArrow || userCKI.Key == ConsoleKey.NumPad6)
            {
                //East
                tileToCheck = currentMap[newPlayer.yPos, newPlayer.xPos + 1];
                moveId      = 4;
                hasMoved    = true;
            }
            else if (userCKI.Key == ConsoleKey.NumPad7)
            {
                //North West
                tileToCheck = currentMap[newPlayer.yPos - 1, newPlayer.xPos - 1];
                moveId      = 5;
                hasMoved    = true;
            }
            else if (userCKI.Key == ConsoleKey.NumPad9)
            {
                //North East
                tileToCheck = currentMap[newPlayer.yPos - 1, newPlayer.xPos + 1];
                moveId      = 6;
                hasMoved    = true;
            }
            else if (userCKI.Key == ConsoleKey.NumPad3)
            {
                //South East
                tileToCheck = currentMap[newPlayer.yPos + 1, newPlayer.xPos + 1];
                moveId      = 7;
                hasMoved    = true;
            }
            else if (userCKI.Key == ConsoleKey.NumPad1)
            {
                //South West
                tileToCheck = currentMap[newPlayer.yPos + 1, newPlayer.xPos - 1];
                moveId      = 8;
                hasMoved    = true;
            }
            else if (userCKI.Key == ConsoleKey.Spacebar)
            {
                tileToCheck = currentMap[newPlayer.yPos, newPlayer.xPos];
                if (tileToCheck.isExit)
                {
                    nextLevel = true;
                }
                //Skip Turn
            }
            else if (userCKI.Key == ConsoleKey.I)
            {
                Console.Clear();
                playerInfo.Inventory();
                Console.ReadKey();
                Console.Clear();
                PrintMap();
            }
            else if (userCKI.Key == ConsoleKey.Q)
            {
                //Consume items
                UseItem(3);
                PlayerMovement();
            }
            else if (userCKI.Key == ConsoleKey.W)
            {
                //Equip weapons
                UseItem(1);
                PlayerMovement();
            }
            else if (userCKI.Key == ConsoleKey.E)
            {
                //Equip Armors
                UseItem(2);
                PlayerMovement();
            }
            else if (userCKI.Key == ConsoleKey.D)
            {
                Dropitems();
            }
            else if (userCKI.Key == ConsoleKey.F)
            {
                //Cheaty cheat
                newPlayer.sHP += 50;
                alert.Action("More Health!");
            }
            else if (userCKI.Key == ConsoleKey.Escape)
            {
                bQuit = true;
            }

            if (hasMoved)
            {
                if (tileToCheck.isPassable)
                {
                    if (tileToCheck.hasItem)
                    {
                        Item itemToCheck = tileToCheck.tItem;
                        int  itemType    = itemToCheck.iCat;

                        if (itemType != 52)
                        {
                            if (newPlayer.inv.Count < 10)
                            {
                                alert.Action("You have found a " + itemToCheck.iName);
                                itemToCheck.Collect(newPlayer);
                                CollectItem(itemToCheck, itemToCheck.iCat);
                                tileToCheck.Removetem();
                            }
                            else
                            {
                                alert.Action("inventory full");
                            }
                        }
                        else
                        {
                            newPlayer.sDiamonds++;
                            CollectItem(itemToCheck, itemToCheck.iCat);
                            tileToCheck.Removetem();
                        }
                    }
                    CharacterMovement(moveId, newPlayer);
                    FogOfWarReveal();
                }
                else if (tileToCheck.hasChar)
                {
                    //Battle
                    battle = new Battle(newPlayer, tileToCheck.tChar);
                }
                else
                {
                    //bump nose
                    alert.Action("Stop trying hit the wall");
                }
            }
        }