public bool Eat(eda f) { if (body[0].x == f.x && body[0].y == f.y) { return(true); } return(false); }
static void F5(eda food) { FileStream fs = new FileStream("dataF.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(fs, food); fs.Close(); }
static eda F6() { FileStream fs = new FileStream("dataF.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); BinaryFormatter bf = new BinaryFormatter(); eda f = bf.Deserialize(fs) as eda; fs.Close(); return(f); }
static void Main(string[] args) { Thread threa = new Thread(playgame); //zmeika sama dvigaetsya Console.CursorVisible = false; Console.SetWindowSize(80, 30); //threa.Start(); //int x=10, y=10; //koordinati nashei zmeiki snake Sn = new snake(); Wall wall = new Wall(level); eda food = new eda(); bool gameover = false; Console.WriteLine("If you want to start new game press R "); Console.WriteLine("If you want to continue last game press C"); ConsoleKeyInfo key1 = Console.ReadKey(); if (key1.Key == ConsoleKey.C) { Sn = F2(); wall = F4(); points = F7(); food = F6(); score = Sn.cnt; } Console.Clear(); threa.Start(); while (!gameover) //not gameover { ConsoleKeyInfo key = Console.ReadKey(); //podvigaem zmeikoi if (key.Key == ConsoleKey.UpArrow) { direction = 3;//Sn.Move(0, -1);// y--; } if (key.Key == ConsoleKey.DownArrow) { direction = 4;//Sn.Move(0, 1);//y++; } if (key.Key == ConsoleKey.LeftArrow) { direction = 1; //Sn.Move(-1, 0);// x--; } if (key.Key == ConsoleKey.RightArrow) { direction = 2;// Sn.Move(1, 0);//x++; } if (key.Key == ConsoleKey.Escape) { gameover = true; } if (Sn.cnt == 60) { wall = new Wall(2); } if (key.Key == ConsoleKey.R) // new game { Console.Clear(); Sn = new snake(); level = 1; score = 0; wall = new Wall(level); speed = 400; } if (key.Key == ConsoleKey.Spacebar) //probel { Sn.cnt = score; F1(Sn); F3(wall); F5(food); F8(points); } // Console.Clear(); /* Console.SetCursorPosition(x, y);//ustanavlivaet polojenie kursora//esli ne ustanavlivat' kursor(_) stoit na odnom meste * * Console.Write("*");*/ /* Console.Clear(); * Sn.Draw(); * wall.Draw(); * food.Draw();*/ //odin potok otvechaet na pojatie na klavishu //vtoroi za dvijenie //if(sn.Draw()%10) //kajdie 10 shagov /*{ * speed = Math.Max(speed - 100, 1); * /*speed = speed - 100; * if (speed < 0) * speed = 1;*/ //wall.WallDraw(); //snake.Draw(); // food.ShowFood(); } }