public void StartGame() { run = true; wall.LoadLevel(1); // draw it only once wall.Draw(); ThreadStart threadStart = new ThreadStart(DrawAndMoveGameObjects); Thread moveDrawThread = new Thread(threadStart); // run the thread moveDrawThread.Start(); // balance = 10 000 -> 15 000 -> 9000 // op1: add 5000 = (1) get balance; (2) balance = (1) + 5000 // op2: pay 1000 (mobile) = (1) get balance; (2) balance = (1) - 1000 while (run) { // leads to many errors //DrawAndMoveGameObjects(); ConsoleKeyInfo pressedKey = Console.ReadKey(); switch (pressedKey.Key) { case ConsoleKey.UpArrow: // set movement direction serpent.ChangeDirection(Direction.Up); break; case ConsoleKey.DownArrow: serpent.ChangeDirection(Direction.Down); break; case ConsoleKey.LeftArrow: serpent.ChangeDirection(Direction.Left); break; case ConsoleKey.RightArrow: serpent.ChangeDirection(Direction.Right); break; case ConsoleKey.Escape: run = false; break; default: break; } } Console.Clear(); Console.ForegroundColor = ConsoleColor.White; Console.SetCursorPosition(19, 19); Console.Write("GAME OVER"); }
public void StartGame() { Console.Write("Give your name: "); name = Console.ReadLine(); Console.Clear(); run = true; Level(); Gamer(); Score(); ThreadStart threadStart = new ThreadStart(DrawAndMoveGameObjects); Thread moveDrawThread = new Thread(threadStart); // run the thread moveDrawThread.Start(); while (run) { checkscore = score / 3 + 1; //serpent.Draw(); //food.Draw(); //FoodDraw(); //CheckFoodCatch(); ConsoleKeyInfo pressedKey = Console.ReadKey(); switch (pressedKey.Key) { case ConsoleKey.UpArrow: if (serpent.GetDirection() != Direction.Down) { serpent.ChangeDirection(Direction.Up); } run = CatchWall() && SerpentCatchItself(); break; case ConsoleKey.DownArrow: if (serpent.GetDirection() != Direction.Up) { serpent.ChangeDirection(Direction.Down); } run = CatchWall() && SerpentCatchItself(); break; case ConsoleKey.LeftArrow: if (serpent.GetDirection() != Direction.Right) { serpent.ChangeDirection(Direction.Left); } run = CatchWall() && SerpentCatchItself(); break; case ConsoleKey.RightArrow: if (serpent.GetDirection() != Direction.Left) { serpent.ChangeDirection(Direction.Right); } run = CatchWall() && SerpentCatchItself(); break; case ConsoleKey.Escape: run = false; break; default: break; } if (checkscore < score / 3 + 1) { Console.Clear(); //run = true; Level(); Gamer(); Score(); serpent.SerpentOrigin(); } } Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.SetCursorPosition(20, 14); Console.Write("GAME OVER"); Console.ForegroundColor = ConsoleColor.Magenta; Console.SetCursorPosition(10, 16); Console.Write("Your useless achievement: " + score + " scores"); }