public bool canMove(Direction d, TankModel nextMove) { foreach (var i in Program.players) { if (nextMove == i.Value.model) { return false; } } return true; }
public void move(Direction d, bool check = true) { if (check) { Point2D nextMovePoint = new Point2D(point.X, point.Y); TankModel nextMoveModel = new TankModel(); switch (d) { case Direction.up: if (nextMovePoint.Y <= 2) return; --nextMovePoint.Y; break; case Direction.down: if (point.Y >= Program.height - 2) return; ++nextMovePoint.Y; break; case Direction.left: if (nextMovePoint.X <= 2) return; --nextMovePoint.X; break; case Direction.right: if (point.X >= Program.width - 2) return; ++nextMovePoint.X; break; } nextMoveModel.generate(nextMovePoint, d); if (!canMove(d, nextMoveModel)) return; } oldPoint.X = X; oldPoint.Y = Y; oldDirection = direction; switch (d) { case Direction.up: up(); break; case Direction.down: down(); break; case Direction.left: left(); break; case Direction.right: right(); break; } direction = d; model.generate(point, direction); this.Changed = true; }