Test commit

This commit is contained in:
gg12 darfren 2023-10-16 09:54:49 +04:00
parent 523fbaee82
commit c7b13068a1
5 changed files with 116 additions and 0 deletions

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" default="true">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,64 @@
package MonorailHard.MovementStrategy;
import MonorailHard.DirectionType;
public abstract class AbstractStrategy {
private IMoveableObject _moveableObject;
private Status _state = Status.NotInit;
private int FieldWidth;
protected int FieldWidth(){return FieldWidth;}
private int FieldHeight;
protected int FieldHeight(){return FieldWidth;}
public Status GetStatus() { return _state; }
public void SetData(IMoveableObject moveableObject, int width, int
height)
{
if (moveableObject == null)
{
_state = Status.NotInit;
return;
}
_state = Status.InProgress;
_moveableObject = moveableObject;
FieldWidth = width;
FieldHeight = height;
}
public void MakeStep()
{
if (_state != Status.InProgress)
{
return;
}
if (IsTargetDestinaion())
{
_state = Status.Finish;
return;
}
MoveToTarget();
}
protected boolean MoveLeft() {return MoveTo(DirectionType.Left);}
protected boolean MoveRight() {return MoveTo(DirectionType.Right);}
protected boolean MoveUp() {return MoveTo(DirectionType.Up);}
protected boolean MoveDown() {return MoveTo(DirectionType.Down);}
protected ObjectParameters GetObjectParameters(){
if(_moveableObject != null)
return _moveableObject.GetObjectParameters();
else return null;
}
protected Integer GetStep()
{
if (_state != Status.InProgress)
{
return null;
}
return _moveableObject.GetStep();
}
protected abstract void MoveToTarget();
protected abstract boolean IsTargetDestinaion();
private
}

View File

@ -0,0 +1,10 @@
package MonorailHard.MovementStrategy;
import MonorailHard.DirectionType;
public interface IMoveableObject {
public ObjectParameters GetObjectParameters();
public int GetStep();
boolean CheckCanMove(DirectionType direction);
void MoveObject(DirectionType direction);
}

View File

@ -0,0 +1,29 @@
package MonorailHard.MovementStrategy;
public class ObjectParameters {
private final int _x;
private final int _y;
private final int _width;
private final int _height;
public int LeftBorder;
public int TopBorder;
public int RightBorder;
public int DownBorder;
public int ObjectMiddleHorizontal;
public int ObjectMiddleVertical;
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
LeftBorder = _x;
TopBorder = _y;
RightBorder = _x + width;
DownBorder = _y + height;
ObjectMiddleHorizontal = _x + _width / 2;
ObjectMiddleVertical = _y + _height / 2;
}
}

View File

@ -0,0 +1,7 @@
package MonorailHard.MovementStrategy;
public enum Status {
NotInit,
InProgress,
Finish
}