Вторая лабораторная работа
This commit is contained in:
parent
da743af9ba
commit
db827b6e0d
@ -3,7 +3,7 @@ package DoubleDeckerBus.MovementStrategy;
|
|||||||
public class MoveToBorder extends AbstractStrategy {
|
public class MoveToBorder extends AbstractStrategy {
|
||||||
@Override
|
@Override
|
||||||
protected boolean IsTargetDestination() {
|
protected boolean IsTargetDestination() {
|
||||||
ObjectParameters objParams = GetObjectParameters();
|
var objParams = GetObjectParameters();
|
||||||
|
|
||||||
if (objParams == null) {
|
if (objParams == null) {
|
||||||
return false;
|
return false;
|
||||||
@ -14,20 +14,20 @@ public class MoveToBorder extends AbstractStrategy {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void MoveToTarget() {
|
protected void MoveToTarget() {
|
||||||
ObjectParameters objParams = GetObjectParameters();
|
var objParams = GetObjectParameters();
|
||||||
|
|
||||||
if (objParams == null) {
|
if (objParams == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int diffX = objParams.RightBorder - FieldWidth();
|
var diffX = objParams.RightBorder - FieldWidth();
|
||||||
if (Math.abs(diffX) >= GetStep()) {
|
if (Math.abs(diffX) >= GetStep()) {
|
||||||
if (diffX < 0) {
|
if (diffX < 0) {
|
||||||
MoveRight();
|
MoveRight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int diffY = objParams.DownBorder - FieldHeight();
|
var diffY = objParams.DownBorder - FieldHeight();
|
||||||
if (Math.abs(diffY) >= GetStep()) {
|
if (Math.abs(diffY) >= GetStep()) {
|
||||||
if (diffY < 0) {
|
if (diffY < 0) {
|
||||||
MoveDown();
|
MoveDown();
|
||||||
|
@ -3,16 +3,16 @@ package DoubleDeckerBus.MovementStrategy;
|
|||||||
public class MoveToCenter extends AbstractStrategy{
|
public class MoveToCenter extends AbstractStrategy{
|
||||||
@Override
|
@Override
|
||||||
protected boolean IsTargetDestination() {
|
protected boolean IsTargetDestination() {
|
||||||
ObjectParameters objParams = GetObjectParameters();
|
var objParams = GetObjectParameters();
|
||||||
|
|
||||||
if (objParams == null) {
|
if (objParams == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((objParams.ObjectMiddleHorizontal <= FieldWidth() / 2 &&
|
return ((objParams.ObjectMiddleHorizontal <= FieldWidth() / 2 &&
|
||||||
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth() / 2) ||
|
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth() / 2)
|
||||||
(objParams.ObjectMiddleHorizontal >= FieldWidth() / 2 &&
|
||(objParams.ObjectMiddleHorizontal >= FieldWidth() / 2 &&
|
||||||
objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth() / 2)) &&
|
objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth() / 2)) &&
|
||||||
|
|
||||||
((objParams.ObjectMiddleVertical <= FieldHeight() / 2 &&
|
((objParams.ObjectMiddleVertical <= FieldHeight() / 2 &&
|
||||||
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight() / 2) ||
|
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight() / 2) ||
|
||||||
@ -22,13 +22,13 @@ public class MoveToCenter extends AbstractStrategy{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void MoveToTarget() {
|
protected void MoveToTarget() {
|
||||||
ObjectParameters objParams = GetObjectParameters();
|
var objParams = GetObjectParameters();
|
||||||
|
|
||||||
if (objParams == null) {
|
if (objParams == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth() / 2;
|
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth() / 2;
|
||||||
if (Math.abs(diffX) > GetStep()) {
|
if (Math.abs(diffX) > GetStep()) {
|
||||||
if (diffX > 0) {
|
if (diffX > 0) {
|
||||||
MoveLeft();
|
MoveLeft();
|
||||||
@ -37,7 +37,7 @@ public class MoveToCenter extends AbstractStrategy{
|
|||||||
MoveRight();
|
MoveRight();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int diffY = objParams.ObjectMiddleVertical - FieldHeight() / 2;
|
var diffY = objParams.ObjectMiddleVertical - FieldHeight() / 2;
|
||||||
if (Math.abs(diffY) > GetStep()) {
|
if (Math.abs(diffY) > GetStep()) {
|
||||||
if (diffY > 0) {
|
if (diffY > 0) {
|
||||||
MoveUp();
|
MoveUp();
|
||||||
|
Loading…
Reference in New Issue
Block a user