Esempio n. 1
0
        /// <summary>
        /// Intial setup Method
        /// Will setup console size, and initial vector positions
        /// </summary>
        private static void Setup()
        {
            Console.WindowHeight = height;
            Console.WindowWidth  = width;

            Rows = Console.WindowHeight - 0;
            Cols = Console.WindowWidth - 1;

            if (Player == null)
            {
                Player = new VecC(Cols / 2, Rows / 2);
            }
            if (Food == null)
            {
                Food = VecC.GetRandomVector();
            }


            // Start the input thread
            InputThread = new Thread(() => GetUserInput());
            InputThread.IsBackground = true;
            InputThread.Start();

            Running = true;

            DrawGrid();
        }
Esempio n. 2
0
        /// <summary>
        /// Update Vector Info
        /// </summary>
        private static void Update()
        {
            //Player.RandomWalk();
            Player.UpdatePosition();
            Player.CheckWallCollision();
            //Player.Bounce();

            if (Player.HasColliedWith(Food))
            {
                Food = VecC.GetRandomVector();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Main Draw Method
        /// Gets total rows & cols. loops through both, and draws chars at each x,y
        /// </summary>
        private static void DrawGrid()
        {
            if (redrawBox && (Console.WindowWidth - 1 != Cols || Console.WindowHeight - 0 != Rows))
            {
                Rows = Console.WindowHeight - 0;
                Cols = Console.WindowWidth - 1;
            }

            for (int x = 0; x < Cols; x++)
            {
                for (int y = 0; y < Rows; y++)
                {
                    VecC vec = new VecC(x, y);
                    // Draw `+` if cursor in any corner.
                    if ((x == 0 && y == 0) || (x == Cols - 1 && y == 0) || (x == Cols - 1 && y == Rows - 1) || (x == 0 && y == Rows - 1))
                    {
                        WriteAt('+', x, y);
                    }
                    // Draw `|` if left or right side
                    else if (x == 0 || x == Cols - 1)
                    {
                        WriteAt('|', x, y);
                    }
                    // Draw `-` if top or bottom row
                    else if (y == 0 || y == Rows - 1)
                    {
                        WriteAt('-', x, y);
                    }
                    // Draw the player
                    else if (vec.x == Player.x && vec.y == Player.y)
                    {
                        WriteAt(playerChar, x, y, ConsoleColor.Cyan);
                    }
                    // Draw the food
                    else if (vec.x == Food.x && vec.y == Food.y)
                    {
                        WriteAt(foodChar, x, y, ConsoleColor.Green);
                    }
                    // Draw whitespace
                    else
                    {
                        WriteAt(blankChar, x, y);
                    }
                }
            }
        }
Esempio n. 4
0
 public bool HasColliedWith(VecC vec)
 {
     return(x == vec.x && y == vec.y);
 }