Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //умные повороты
- public void TurnUp()
- {
- if (direction != 3 && !Check(HeadX(), (HeadY() - 1 + NY) % NY))
- ChangeDirection(1);
- else if (direction != 2 && !Check((HeadX() - 1 + NX) % NX, HeadY()))
- ChangeDirection(4);
- else if (direction != 4 && !Check((HeadX() + 1) % NX, HeadY()))
- ChangeDirection(2);
- else
- ChangeDirection(3);
- }
- public void TurnRight()
- {
- if (direction != 4 && !Check((HeadX() + 1) % NX, HeadY()))
- ChangeDirection(2);
- else if (direction != 3 && !Check(HeadX(), (HeadY() - 1 + NY) % NY))
- ChangeDirection(1);
- else if (direction != 1 && !Check(HeadX(), (HeadY() + 1) % NY))
- ChangeDirection(3);
- else
- ChangeDirection(4);
- }
- public void TurnDown()
- {
- if (direction != 1 && !Check(HeadX(), (HeadY() + 1) % NY))
- ChangeDirection(3);
- else if (direction != 2 && !Check((HeadX() - 1 + NX) % NX, HeadY()))
- ChangeDirection(4);
- else if (direction != 4 && !Check((HeadX() + 1) % NX, HeadY()))
- ChangeDirection(2);
- else
- ChangeDirection(1);
- }
- public void TurnLeft()
- {
- if (direction != 2 && !Check((HeadX() - 1 + NX) % NX, HeadY()))
- ChangeDirection(4);
- else if (direction != 3 && !Check(HeadX(), (HeadY() - 1 + NY) % NY))
- ChangeDirection(1);
- else if (direction != 1 && !Check(HeadX(), (HeadY() + 1) % NY))
- ChangeDirection(3);
- else
- ChangeDirection(2);
- }
- public void AI(int X, int Y)
- {
- Random rnd = new Random();
- if (rnd.Next(1, 11)>=3)
- {
- if (rnd.Next(1, 3) == 2)
- {
- if (X > HeadX())
- {
- if (NX - X + HeadX() > X - HeadX())
- TurnRight();
- else
- TurnLeft();
- }
- else if (X < HeadX())
- {
- if (NX - HeadX() + X > HeadX() - X)
- TurnLeft();
- else if (NX - X + HeadX() < X - HeadX())
- TurnRight();
- }
- }
- else
- {
- if (Y > HeadY())
- {
- if (NY - Y + HeadY() > Y - HeadY())
- TurnDown();
- else
- TurnUp();
- }
- else if (Y < HeadY())
- {
- if (NY - HeadY() + Y > HeadY() - Y)
- TurnUp();
- else
- TurnDown();
- }
- }
- }
- else
- {
- ChangeDirection(rnd.Next(1, 5));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement