/* void CheckFood() * { * if (w.CheckCollision(f.body)) * { * w.Eat(f.body[0]); * score++; * do * { * f.Generate(); * } * while (!CheckFoodSnake()); * Console.SetCursorPosition(5, 32); * Console.Write("Score:" + score); * } * else if (w.CheckCollisionwithItself()) * { * gameOver = true; * Console.Clear(); * Console.SetCursorPosition(10, 20); * * Console.WriteLine("Game over!"); * } * } * * bool CheckFoodSnake() * { * for (int i = 0; i < w.body.Count; i++) * { * if (w.body[i].X == f.body[0].X && w.body[i].Y == f.body[0].Y) * { * return false; * } * } * return true; * } * void CheckWall() * { * * if (w.CheckCollision(b.body)) * { * gameOver = true; * Console.Clear(); * Console.SetCursorPosition(5, 33); * * Console.WriteLine("Game over!"); * } * * if (score > MaxScore) * { * // b.LoadLevel(3); * } * } */ public void PressedKey(ConsoleKeyInfo consoleKeyInfo) { switch (consoleKeyInfo.Key) { case ConsoleKey.UpArrow: w.Move(0, -1); break; case ConsoleKey.DownArrow: w.Move(0, 1); break; case ConsoleKey.LeftArrow: w.Move(-1, 0); break; case ConsoleKey.RightArrow: w.Move(1, 0); break; case ConsoleKey.F2: w.Save(); f.Save(); break; case ConsoleKey.F3: w = w.Load() as Worm; f = f.Load() as Food; break; } CheckFood(); }
public void KeyPressed(ConsoleKeyInfo pressedKey) { if (cnt > 3) { wall = new Wall('#', ConsoleColor.DarkYellow, @"Levels/level2.txt"); } change = false; switch (pressedKey.Key) { case ConsoleKey.UpArrow: w.ChangeDirection(0, -1); break; case ConsoleKey.DownArrow: w.ChangeDirection(0, 1); break; case ConsoleKey.LeftArrow: w.ChangeDirection(-1, 0); break; case ConsoleKey.RightArrow: w.ChangeDirection(1, 0); break; case ConsoleKey.S: w.Save("worm"); break; case ConsoleKey.L: wormTimer.Stop(); w.Clear(); f = new Food('@', ConsoleColor.Yellow); wall = new Wall('#', ConsoleColor.DarkYellow, @"Levels/level1.txt"); w = Worm.Load("worm"); wormTimer.Start(); break; case ConsoleKey.Escape: IsRunning = false; // wormTimer.Stop(); break; case ConsoleKey.Spacebar: if (!pause) { wormTimer.Stop(); pause = true; } else { wormTimer.Start(); pause = false; } break; } }
public void Process(ConsoleKeyInfo pressedButton) { switch (pressedButton.Key) { case ConsoleKey.LeftArrow: worm.DY = 0; worm.DX = -1; break; case ConsoleKey.RightArrow: worm.DY = 0; worm.DX = 1; break; case ConsoleKey.UpArrow: worm.DY = -1; worm.DX = 0; break; case ConsoleKey.DownArrow: worm.DY = 1; worm.DX = 0; break; case ConsoleKey.Spacebar: if (isPaused) { isPaused = false; Start(); } else { isPaused = true; Stop(); } break; case ConsoleKey.F1: if (isPaused) { pts = points; l = lev; worm.Save(); food.Save(); wall.Save(); } break; case ConsoleKey.F2: if (isPaused) { Console.Clear(); DrawField(); points = pts; lev = l; worm = worm.Load() as Worm; food = food.Load() as Food; wall = wall.Load() as Wall; Draw(); } break; case ConsoleKey.Escape: alive = false; Stop(); DrawGameOver(); break; default: break; } }
public void Save() { worm.Save(); wall.Save(); }
public void Process(ConsoleKeyInfo pressedButton) { switch (pressedButton.Key) { case ConsoleKey.UpArrow: worm.Clear(); worm.Move(0, -1); worm.Draw(); break; case ConsoleKey.DownArrow: worm.Clear(); worm.Move(0, 1); worm.Draw(); break; case ConsoleKey.LeftArrow: worm.Clear(); worm.Move(-1, 0); worm.Draw(); break; case ConsoleKey.RightArrow: worm.Clear(); worm.Move(1, 0); worm.Draw(); break; case ConsoleKey.Escape: break; case ConsoleKey.F2: worm.Save(); food.Save(); break; case ConsoleKey.F1: worm = worm.Load() as Worm; food = food.Load() as Food; break; } if (worm.body[0].Equals(food.body[0])) { worm.body.Add(new Point { X = food.body[0].X, Y = food.body[0].Y }); food.Draw(); } else { foreach (Point p in wall.body) { if (p.Equals(worm.body[0])) { Console.Clear(); Console.WriteLine("GAME OVER!!!"); isAlive = false; break; } } } }