Exemple #1
0
        private void AskForMovement()
        {
            Console.WriteLine("Move!");
            ConsoleKeyInfo keyInfo = Console.ReadKey();
            int            x       = player.X;
            int            y       = player.Y;

            switch (keyInfo.Key)
            {
            case ConsoleKey.RightArrow: x++; break;

            case ConsoleKey.LeftArrow: x--; break;

            case ConsoleKey.UpArrow: y--; break;

            case ConsoleKey.DownArrow: y++; break;
            }
            if (x >= 0 && x < WorldWidth && y >= 0 && y < WorldHeight)
            {
                player.X = x;
                player.Y = y;
                if (world[x, y].ItemInRoom != null)
                {
                    if ((player.BackPack.Sum(a => a.Weight) + world[x, y].ItemInRoom.Weight) <= 100)
                    {
                        world[x, y].ItemInRoom.PickUp(player);
                        Console.ForegroundColor = player.BackPack.Last().Color;
                        DelayMessage($"You picked up item!", 20);
                        music.PickUpItemSFX();
                        world[x, y].ItemInRoom  = null;
                        backPackFull            = false;
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else if (world[x, y].ItemInRoom.Name == "Dragon")
                    {
                        music.CantPickUpItemSFX();
                        DelayMessage($"Dragon is to big, can't fit in backpack... You need to obtain truck first!", 20);
                        backPackFull = true;
                    }
                    else
                    {
                        music.CantPickUpItemSFX();
                        DelayMessage($"Backpack is full!", 20);
                        backPackFull = true;
                    }
                }
                if (world[x, y].MonsterInRoom != null)
                {
                    if (world[x, y].MonsterInRoom.Name == "Ogre")
                    {
                        CurrentAction = 2;
                    }
                    else
                    {
                        CurrentAction = 3;
                    }
                    Console.ForegroundColor = world[x, y].MonsterInRoom.Color;
                    DelayMessage(world[x, y].MonsterInRoom.Message(player), 20);
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.ReadLine();

                    player.Fight(world[x, y].MonsterInRoom);
                    if (world[x, y].MonsterInRoom.Health > 0)
                    {
                        world[x, y].MonsterInRoom.Fight(player);
                    }
                    else
                    {
                        player.BackPack.Add(world[x, y].MonsterInRoom);
                        Monster.MonsterCount--;
                        world[x, y].MonsterInRoom = null;
                    }
                }
            }
        }