Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Threading;
- namespace snaaaaaaaake
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[,] grid = new int[10, 10];
- Random rng = new Random();
- ConsoleColor snakeColour = ConsoleColor.Green;
- ConsoleColor powerUpColour = ConsoleColor.Red;
- int cRow = 4;
- int cCol = 4;
- int dir = 0;
- int size = 1;
- grid[cRow, cCol] = size;
- AddPowerUp(rng, grid);
- int millisecondsPerUpdate = 200;
- while (true)
- {
- Update(rng, grid, ref cRow, ref cCol, ref dir, ref size, ref millisecondsPerUpdate);
- Thread.Sleep(millisecondsPerUpdate);
- RenderGame(grid, snakeColour, powerUpColour, size);
- }
- }
- public static void AddPowerUp(Random rng, int[,] grid)
- {
- int rRow = rng.Next(grid.GetLength(0));
- int rCol = rng.Next(grid.GetLength(1));
- if (grid[rRow, rCol] > 0)
- {
- AddPowerUp(rng, grid);
- }
- else
- {
- grid[rRow, rCol] = -1;
- }
- }
- public static void RenderGame(int[,] grid, ConsoleColor snakeColour, ConsoleColor powerUpColour, int size)
- {
- Console.Clear();
- Console.WriteLine("score: " + size);
- for (int x = 0; x < grid.GetLength(0); x++)
- {
- for (int y = 0; y < grid.GetLength(1); y++)
- {
- if (grid[x, y] == 0)
- {
- Console.ForegroundColor = ConsoleColor.White;
- Console.Write(" ");
- }
- else if (grid[x, y] < 0)
- {
- Console.ForegroundColor = powerUpColour;
- Console.Write("X");
- }
- else
- {
- Console.ForegroundColor = snakeColour;
- Console.Write("O");
- }
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement