SnakeMove.cs
上传用户:cljx11
上传日期:2022-08-09
资源大小:49k
文件大小:1k
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Drawing;
- namespace Snake_v2
- {
- class SnakeMove
- {
- int _hx, _hy;
- Apple _a = new Apple();
- Block _b = new Block();
- public bool Mov(int dx, int dy,Graphics gp)
- {
- _hx = SnakeBody.GetSnakeHeadX() + dx;
- _hy = SnakeBody.GetSnakeHeadY() + dy;
- if (_hx > 34 || _hx < 0 || _hy > 14 || _hy < 0)
- {
- return false;
- }
- else if (SnakeMap.Map[_hx, _hy] == 1)
- {
- return false;
- }
- else if (SnakeMap.Map[_hx, _hy] == -1)
- {
- SnakeBody.BodyAdd(_hx, _hy);
- _b.SnakeBody(_hx, _hy, gp);
- Apple.NewApple();
- _b.Apple(Apple.GetAppleX(), Apple.GetAppleY(), gp);
- return true;
- }
- else if (SnakeMap.Map[_hx, _hy] == 0)
- {
- SnakeBody.BodyAdd(_hx, _hy);
- _b.SnakeBody(_hx, _hy,gp);
- _b.Clear((int)SnakeBody.BodyX[SnakeBody.BodyX.Count - 1],(int)SnakeBody.BodyY[SnakeBody.BodyY.Count - 1], gp);
- SnakeBody.BodyDel();
- return true;
- }
- return false;
- }
- }
- }