//TODO: Gamefield object public override void InitGame() { base.InitGame(); //Test ConsoleGameLib.Fonts.SVGALibTFont font = new ConsoleGameLib.Fonts.SVGALibTFont(new Point(15, 8)); font.Text = "Snake"; font.DrawBlankLines = false; font.ForegroundColor = ConsoleColor.Red; font.UseOwnCharAsDrawChar = true; font.Draw(); Console.WriteLine("\nPress any key to start..."); Console.ReadKey(); _targetFrameRate = 1000.0 / 15.0; //15 FPS //DEBUG //_targetFrameRate = 1000.0 * 60.0; //1 Frame per minute _snake = new Snake(new Point(20, 10), Direction.Right); _snake.ForegroundColor = ConsoleColor.White; _random = new Random(); _food = new Food(new Point(_random.Next(1, 79), _random.Next(1, 25))); //Start with 3 pieces (head + 2) _snake.Grow(2); }
static void Main(string[] args) { Console.CursorVisible = false; Snake snake = new Snake(5, 5); snake.Print(); Console.ReadKey(); while (true) { var key = Console.ReadKey().Key; switch (key) { case ConsoleKey.DownArrow: snake.Direction = Direction.Down; break; case ConsoleKey.LeftArrow: snake.Direction = Direction.Left; break; case ConsoleKey.RightArrow: snake.Direction = Direction.Right; break; case ConsoleKey.UpArrow: snake.Direction = Direction.Up; break; } snake.Move(); snake.Print(); } }
static void Main(string[] args) { Console.CursorVisible = false; Snake snake = new Snake(5, 5); Thread t = new Thread(new ThreadStart(snake.Start)); t.IsBackground = true; t.Start(); double time = 400; while (true) { snake.Move(); if (!snake.Print()) { t.Abort(); break; } Thread.Sleep(Convert.ToInt32(time - (time * (snake.Size - 1) / 40))); time *= 0.999; } }