using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;


namespace Spicy_Test
{
    class Program
    {
        static int screenWidth = 40;
        static int playerX = 18;
        static int playerY = 8;
        static int enemyX = 18; // Posición horizontal del enemigo
        static int enemyY = 2; // Posición vertical del enemigo
        static bool movingRight = true; // Dirección de movimiento del enemigo
        static bool isMovingLeft = false;
        static bool isMovingRight = false;

        static void Main(string[] args)
        {
            Console.CursorVisible = false;
            Timer moveTimer = new Timer(MovePlayer, null, 0, 100);

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    if (key.Key == ConsoleKey.LeftArrow && playerX > 0)
                    {
                        isMovingLeft = true;
                        isMovingRight = false;
                    }
                    else if (key.Key == ConsoleKey.RightArrow && playerX < Console.WindowWidth - 1)
                    {
                        isMovingLeft = false;
                        isMovingRight = true;
                    }
                    else if(key.Key == ConsoleKey.Spacebar)
                    {
                        
                    }
                }

                UpdateEnemyPosition();
                Thread.Sleep(15);
                DrawGame();
                Thread.Sleep(125);
            }
        }

        static void MovePlayer(object state)
        {
            if (isMovingLeft && playerX > 0)
            {
                playerX--;
            }
            else if (isMovingRight && playerX < screenWidth - 1)
            {
                playerX++;
            }

            DrawGame();
        }

        /*static void UpdateEnemyPosition()
        {
            // Cambiar de dirección al llegar a los bordes
            if (enemyX == Console.WindowWidth - 1)
            {
                movingRight = false;
            }
            else if (enemyX == 0)
            {
                movingRight = true;
            }

            // Mover el enemigo
            if (movingRight)
            {
                enemyX++;
            }
            else
            {
                enemyX--;
            }
        }*/

        static void DrawGame()
        {
            Console.CursorVisible = false;
            Console.Clear();

            for (int y = 0; y < 12; y++)
            {
                for (int x = 0; x < Console.WindowWidth; x++)
                {
                    if (y == playerY && x == playerX)
                    {
                        Console.Write("▲"); 
                    }
                    else if (x == enemyX && y == enemyY)
                    {
                        Console.Write(" ■");
                        Console.Write(" ■");
                        Console.Write(" ■");
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
            }
        }
    }
}
