public static void StartGame() { player = new Player(); grid = new SnakeGrid(20, 20, player); timer = new Timer(Tick, null, 0, TimerFrequency); bool gameRunning = true; while (gameRunning) { switch (Console.ReadKey(true).Key) { case ConsoleKey.DownArrow: player.TurnTowards(Direction.Down); break; case ConsoleKey.UpArrow: player.TurnTowards(Direction.Up); break; case ConsoleKey.LeftArrow: player.TurnTowards(Direction.Left); break; case ConsoleKey.RightArrow: player.TurnTowards(Direction.Right); break; case ConsoleKey.Escape: gameRunning = false; break; } } }
// Use this for initialization void Start() { path = new List <SnakeGrid.GridNodeRecord>(); gameOver = false; snakeGrid = GameObject.Find("SnakeGrid").GetComponent <SnakeGrid>(); bodyParts = new List <GameObject>(); positions = new List <Vector3>(); positions.Add(transform.position); GeneratePath(); }
/// <summary> /// Draws the game. Please don't judge me. /// </summary> /// <param name="grid"></param> public static void Render(SnakeGrid grid) { int X = grid.Width; int Y = grid.Height; var playerPos = player.GetPosition(); var playerTail = player.GetTail(); Console.SetCursorPosition(0, 0); Console.WriteLine(new string('=', X + 2)); for (int cy = 0; cy < Y; cy++) { var row = new StringBuilder(); row.Append(new string(' ', Y)); foreach (var tail in playerTail) { if (tail.Y == cy) { row[tail.X] = 'o'; } } if (playerPos.Y == cy) { row[playerPos.X] = 'O'; } if (grid.Apple.Y == cy) { row[grid.Apple.X] = '@'; } row.Insert(0, '='); row.Append('='); Console.WriteLine(row); } Console.WriteLine(new string('=', X + 2)); Console.WriteLine($"{playerPos} {playerTail.Count()} "); }
public void Initialize() { _grid = MakeStandardGrid(); }