static void Main(string[] args) { Worm worm = new Worm(); Food food = new Food(); Wall wall = new Wall(1); worm.Start(); while (worm.isAlive) { Console.Clear(); worm.Draw(); food.Draw(); int currx = worm.Getheadx(); int curry = worm.Getheady(); int k = wall.Draw(currx, curry); if (k == 1) { break; } ConsoleKeyInfo pressedKey = Console.ReadKey(); switch (pressedKey.Key) { case ConsoleKey.F8: Game q = new Game(worm, wall, food); Serialize(q); break; case ConsoleKey.F9: Game h = Deserialize(); worm = h.worm; food = h.food; wall = h.wall; break; case ConsoleKey.UpArrow: worm.Move(0, -1); break; case ConsoleKey.DownArrow: worm.Move(0, 1); break; case ConsoleKey.LeftArrow: worm.Move(-1, 0); break; case ConsoleKey.RightArrow: worm.Move(1, 0); break; case ConsoleKey.Escape: worm.isAlive = false; break; } if (worm.CanEat(food)) { food = new Food(); } } Console.Clear(); Console.WriteLine("YOU LOSE"); }
static void Main(string[] args) { FileStream fs = new FileStream("save.xml", FileMode.Create); fs.Close(); VeryBegin: Point p; int l = 1; Console.CursorVisible = false; /* while (true) { Console.Clear(); Console.WriteLine("Chose level (1-5)"); l = int.Parse(Console.ReadLine()); if (l > 0 && l <= 5) break; } */ Begin: dx = 0; dy = 0; Console.Clear(); int score = 0; Wall wall = new Wall(l); worm = new Worm(); Food food = new Food(); worm.Start(); way = "none"; bool f0 = true; while (f0 == true) { worm = new Worm(); food = new Food(); worm.Start(); f0 = false; for (int i = 0; i < wall.bricks.Count; i++) if (wall.bricks[i].Equals(worm.body[0])) f0 = true; } bool s0 = true; bool s1 = true; while (s0 == true || s1 == true) { worm = new Worm(); worm.Start(); s0 = false; s1 = false; for (int i = 0; i < wall.bricks.Count; i++) if (wall.bricks[i].Equals(worm.body[0])) s0 = true; if (worm.body[0].Equals(food.location)) s1 = true; } while (worm.isAlive) { p = new Point(worm.body[worm.body.Count - 1].x, worm.body[worm.body.Count - 1].y); worm.Draw(); food.Draw(); wall.Draw(); Console.WriteLine("\n\nScore: {0}", score); if (score >= 10) { Console.WriteLine("\n\n Next level availible"); } Thread.Sleep(200); worm.Move(dx, dy); Thread t = new Thread(new ThreadStart(Keys)); t.Start(); /*ConsoleKeyInfo pressedKey = Console.ReadKey(); switch (pressedKey.Key) { case ConsoleKey.UpArrow: if (way != "down" || worm.body.Count == 1) { worm.Move(0, -1); way = "up"; } break; case ConsoleKey.DownArrow: if (way != "up" || worm.body.Count == 1) { worm.Move(0, 1); way = "down"; } break; case ConsoleKey.LeftArrow: if (way != "right" || worm.body.Count == 1) { worm.Move(-1, 0); way = "left"; } break; case ConsoleKey.RightArrow: if (way != "left" || worm.body.Count == 1) { worm.Move(1, 0); way = "right"; } break; case ConsoleKey.Escape: worm.isAlive = false; Console.Clear(); goto End; case ConsoleKey.F5: Game game = new Game(food, wall, worm, score, l); Serialize(game); break; case ConsoleKey.F9: Game game2 = Deserialize(); food = game2.food; wall = game2.wall; worm = game2.worm; score = game2.score; l = game2.l; Console.Clear(); break; case ConsoleKey.OemPlus: if(score >=10) { l++; goto Begin; } break; case ConsoleKey.OemMinus: if (l > 1) { l--; goto Begin; } break; }*/ Console.SetCursorPosition(p.x, p.y); Console.Write(' '); for (int i = 0; i < wall.bricks.Count; i++) if (wall.bricks[i].Equals(worm.body[0])) { worm.isAlive = false; } for (int i = 1; i < worm.body.Count; i++) { if (worm.body[0].Equals(worm.body[i])) worm.isAlive = false; } if (worm.CanEat(food)) { score++; bool f1 = true; bool f2 = true; while (f1==true || f2==true) { f1 = false; f2 = false; food = new Food(); for (int i = 0; i < worm.body.Count; i++) if (worm.body[i].Equals(food.location)) f1=true; for (int i = 0; i < wall.bricks.Count; i++) if (wall.bricks[i].Equals(food.location)) f2 = true; } } } Console.Clear(); Console.WriteLine("GAME OVER\n\n Again?"); Console.ReadKey(); goto VeryBegin; End: Console.WriteLine("GAME OVER"); }
static void Main(string[] args) { VeryBegin: int l = 1; /* * while (true) * { * Console.Clear(); * Console.WriteLine("Chose level (1-5)"); * l = int.Parse(Console.ReadLine()); * if (l > 0 && l <= 5) * break; * } */ Begin: int score = 0; Wall wall = new Wall(l); Worm worm = new Worm(); Food food = new Food(); worm.Start(); string way = "none"; bool f0 = true; while (f0 == true) { worm = new Worm(); food = new Food(); worm.Start(); f0 = false; for (int i = 0; i < wall.bricks.Count; i++) { if (wall.bricks[i].Equals(worm.body[0])) { f0 = true; } } } bool s0 = true; bool s1 = true; while (s0 == true || s1 == true) { worm = new Worm(); worm.Start(); s0 = false; s1 = false; for (int i = 0; i < wall.bricks.Count; i++) { if (wall.bricks[i].Equals(worm.body[0])) { s0 = true; } } if (worm.body[0].Equals(food.location)) { s1 = true; } } while (worm.isAlive) { Console.Clear(); worm.Draw(); food.Draw(); wall.Draw(); Console.WriteLine("\n\nScore: {0}", score); if (score >= 10) { Console.WriteLine("\n\n Next level availible"); } ConsoleKeyInfo pressedKey = Console.ReadKey(); switch (pressedKey.Key) { case ConsoleKey.UpArrow: if (way != "down" || worm.body.Count == 1) { worm.Move(0, -1); way = "up"; } break; case ConsoleKey.DownArrow: if (way != "up" || worm.body.Count == 1) { worm.Move(0, 1); way = "down"; } break; case ConsoleKey.LeftArrow: if (way != "right" || worm.body.Count == 1) { worm.Move(-1, 0); way = "left"; } break; case ConsoleKey.RightArrow: if (way != "left" || worm.body.Count == 1) { worm.Move(1, 0); way = "right"; } break; case ConsoleKey.Escape: worm.isAlive = false; Console.Clear(); goto End; case ConsoleKey.F5: Game game = new Game(food, wall, worm, score, l); Serialize(game); break; case ConsoleKey.F9: Game game2 = Deserialize(); food = game2.food; wall = game2.wall; worm = game2.worm; score = game2.score; l = game2.l; break; case ConsoleKey.OemPlus: if (score >= 10) { l++; goto Begin; } break; case ConsoleKey.OemMinus: if (l > 1) { l--; goto Begin; } break; } for (int i = 0; i < wall.bricks.Count; i++) { if (wall.bricks[i].Equals(worm.body[0])) { worm.isAlive = false; } } for (int i = 1; i < worm.body.Count; i++) { if (worm.body[0].Equals(worm.body[i])) { worm.isAlive = false; } } if (worm.CanEat(food)) { score++; bool f1 = true; bool f2 = true; while (f1 == true || f2 == true) { f1 = false; f2 = false; food = new Food(); for (int i = 0; i < worm.body.Count; i++) { if (worm.body[i].Equals(food.location)) { f1 = true; } } for (int i = 0; i < wall.bricks.Count; i++) { if (wall.bricks[i].Equals(food.location)) { f2 = true; } } } } } Console.Clear(); Console.WriteLine("GAME OVER\n\n Again?"); Console.ReadKey(); goto VeryBegin; End: Console.WriteLine("GAME OVER"); }