Skip to content
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SnakeGame
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Snake!");

            // Initialize the game board
            int[,] board = new int[10,10];

            // Initialize the snake's starting position
            List<int[]> snake = new List<int[]>();
            snake.Add(new int[] { 0, 0 });

            // Main game loop
            while (true)
            {
                // Draw the game board
                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        if (snake.Contains(new int[] { i, j }))
                        {
                            Console.Write("S");
                        }
                        else
                        {
                            Console.Write("-");
                        }
                    }
                    Console.WriteLine();
                }

                // Get the user's input
                Console.WriteLine("Press the arrow keys to move the snake.");
                ConsoleKeyInfo keyInfo = Console.ReadKey();

                // Update the snake's position based on the user's input
                int[] newPosition = new int[2];
                switch (keyInfo.Key)
                {
                    case ConsoleKey.UpArrow:
                        newPosition[0] = snake[0][0] - 1;
                        newPosition[1] = snake[0][1];
                        break;
                    case ConsoleKey.DownArrow:
                        newPosition[0] = snake[0][0] + 1;
                        newPosition[1] = snake[0][1];
                        break;
                    case ConsoleKey.LeftArrow:
                        newPosition[0] = snake[0][0];
                        newPosition[1] = snake[0][1] - 1;
                        break;
                    case ConsoleKey.RightArrow:
                        newPosition[0] = snake[0][0];
                        newPosition[1] = snake[0][1] + 1;
                        break;
                }
                snake.Insert(0, newPosition);
                snake.RemoveAt(snake.Count - 1);
            }
        }
    }
}