1
0
mirror of https://github.com/klmp200/sarl-fireworks.git synced 2024-11-21 22:33:20 +00:00

reformatting all classes

This commit is contained in:
ngaud 2017-05-02 17:25:05 +02:00
parent 9890daffc8
commit 9316a74f07
10 changed files with 180 additions and 177 deletions

View File

@ -7,7 +7,7 @@ import io.sarl.demos.fireworks.gui.FXMLViewerController
import static io.janusproject.Boot.*
class Firework {
static def main(controller: FXMLViewerController) {
static def main(controller : FXMLViewerController) {
Boot::offline = true
Boot::startJanus(typeof(LaunchingArea), controller)
}

View File

@ -14,8 +14,8 @@ class FireworksFXApplication extends Application {
private var loader : FXMLLoader
@Override
public def start(stage: Stage) throws Exception {
var location : URL = getClass().getResource("FireworksFXApplication.fxml");
public def start(stage : Stage) throws Exception {
var location : URL = getClass().getResource("FireworksFXApplication.fxml");
loader = new FXMLLoader();
loader.setLocation(location);
loader.setBuilderFactory(new JavaFXBuilderFactory());
@ -26,14 +26,14 @@ class FireworksFXApplication extends Application {
stage.show();
}
public static def main(args: String[]) {
public static def main(args : String[]) {
launch(args);
}
@Override
public def stop() throws Exception {
public def stop() throws Exception {
super.stop();
(loader.getController() as FXMLViewerController).cleanExit();
}
}

View File

@ -8,54 +8,54 @@ import java.util.Vector
import javafx.scene.paint.Color
class RocketsPos {
public val ROCKETREFRESHDELAY = 100
var position = new Vector<Double>()
var color: Color
var hidden = false
public def getPosition(){
return position
}
public def setPosition(position: Vector<Double>){
this.position = position
}
public def getColor(){
return color
}
public def setColor(color: Color){
this.color = color
}
public def setHidden(hidden: boolean){
this.hidden = hidden
}
public def getHidden(){
return this.hidden
}
public val ROCKETREFRESHDELAY = 100
var position = new Vector<Double>()
var color : Color
var hidden = false
public def getPosition() {
return position
}
public def setPosition(position : Vector<Double>) {
this.position = position
}
public def getColor() {
return color
}
public def setColor(color : Color) {
this.color = color
}
public def setHidden(hidden : boolean) {
this.hidden = hidden
}
public def getHidden() {
return this.hidden
}
}
class FirePos {
public val FIREREFRESHDELAY = 100
var positions: List<Vector<Double>>
var color: Color
public def getPositions(){
var positions : List<Vector<Double>>
var color : Color
public def getPositions() {
return positions
}
public def setPositions(positions: List<Vector<Double>>){
public def setPositions(positions : List<Vector<Double>>) {
this.positions = positions
}
public def getColor(){
public def getColor() {
return color
}
public def setColor(color: Color){
public def setColor(color : Color) {
this.color = color
}
}
@ -63,20 +63,19 @@ class FirePos {
class Positions {
var rockets = new HashMap<UUID, RocketsPos>()
var fire = new HashMap<UUID, FirePos>()
public def getRockets() : Map<UUID, RocketsPos> {
return rockets.unmodifiableView
}
public def getFire() : Map<UUID, FirePos> {
return fire.unmodifiableView
}
public def setRocketPosition(id: UUID, position: Vector<Double>){
public def setRocketPosition(id : UUID, position : Vector<Double>) {
var pos = new RocketsPos()
pos.setPosition(position)
if (rockets.containsKey(id)){
if (rockets.containsKey(id)) {
pos.setColor(rockets.get(id).getColor)
rockets.replace(id, pos)
} else {
@ -84,19 +83,19 @@ class Positions {
rockets.put(id, pos)
}
}
public def removeRocketPosition(id: UUID){
public def removeRocketPosition(id : UUID) {
rockets.remove(id)
}
public def hideHocketPosition(id: UUID){
public def hideHocketPosition(id : UUID) {
rockets.get(id).setHidden(true)
}
public def setFirePosition(id: UUID, rocketID: UUID, positions: List<Vector<Double>>){
public def setFirePosition(id : UUID, rocketID : UUID, positions : List<Vector<Double>>) {
var pos = new FirePos()
pos.setPositions(positions)
if (fire.containsKey(id)){
if (fire.containsKey(id)) {
pos.setColor(fire.get(id).getColor)
fire.replace(id, pos)
} else {
@ -107,10 +106,9 @@ class Positions {
fire.put(id, pos)
}
}
public def removeFirePosition(id: UUID){
public def removeFirePosition(id : UUID) {
fire.remove(id)
}
}
}

View File

@ -18,23 +18,23 @@ import java.util.List
import java.util.UUID
import java.util.Vector
agent Fire {
agent Fire {
uses Lifecycle, Logging, Behaviors, DefaultContextInteractions, Schedules
var x: List<Double>
var y: List<Double>
var x : List<Double>
var y : List<Double>
var lifetime = 300
var frozen = false
var destroyed = false
var exited = false
var grid: Positions
var xf: Double
var yf: Double
var grid : Positions
var xf : Double
var yf : Double
var id = UUID.randomUUID
var parentID: UUID
var move: AgentTask
var parentAgent: UUID
var parentID : UUID
var move : AgentTask
var parentAgent : UUID
on Freeze {
this.frozen = occurrence.value
if (frozen)
@ -42,11 +42,11 @@ agent Fire {
else
wake(new UpdateFirePosition)
}
on Initialize {
x = new ArrayList()
y = new ArrayList()
if (occurrence.parameters.size.equals(4)){
if (occurrence.parameters.size.equals(4)) {
x.add(occurrence.parameters.get(0) as Double)
y.add(occurrence.parameters.get(1) as Double)
grid = occurrence.parameters.get(2) as Positions
@ -55,60 +55,67 @@ agent Fire {
info("Error in fire Initialize : bad parameter number")
}
parentAgent = occurrence.spawner
xf = Math.random() * 10.0 - Math.random() * 5
yf = Math.random() * 10.0 + 1.0
}
}
on FireReady {
move = atFixedDelay(30)[try{
wake(new UpdateFirePosition);}
catch(e: Exception) {e.printStackTrace}]
move = atFixedDelay(30) [
try {
wake(new UpdateFirePosition);
} catch (e : Exception) {
e.printStackTrace
}
]
}
on UpdateFirePosition [isFromMe(occurrence) && !frozen && !destroyed]{
on UpdateFirePosition [isFromMe(occurrence) && !frozen && !destroyed] {
var newx = x.last + xf
var newy = y.last + yf
x.add(newx)
y.add(newy)
if (grid !== null){
if (grid !== null) {
var list = new ArrayList<Vector<Double>>
x.forEach[pos | {
var nvect = new Vector(2)
nvect.add(pos)
list.add(nvect)
}]
y.forEach[pos, i | {
var nvect = list.get(i)
nvect.add(pos)
list.set(i, nvect)
}]
x.forEach [pos |
{
var nvect = new Vector(2)
nvect.add(pos)
list.add(nvect)
}
]
y.forEach [pos, i |
{
var nvect = list.get(i)
nvect.add(pos)
list.set(i, nvect)
}
]
grid.setFirePosition(id, parentID, list)
}
lifetime = lifetime - 10
if (lifetime <= 0){
if (lifetime <= 0) {
grid.removeFirePosition(id)
this.cleanBeforeExit
in(1000)[killMe]
}
}
def cleanBeforeExit(){
def cleanBeforeExit() {
cancel(move, true)
exited = true
destroyed = true
}
on Exit [!exited && isFrom(getParentID)] {
frozen = true
this.cleanBeforeExit
emit(new Exit, Scopes.addresses(defaultSpace.getAddress(parentAgent)))
killMe
}
}

View File

@ -21,68 +21,68 @@ import java.util.UUID
agent LaunchingArea {
uses DefaultContextInteractions, Lifecycle, Behaviors, Logging, InnerContextAccess
var rocketsQuantity: Integer
var fireQuantity: Integer
var gravity: Double
var grid: Positions = new Positions
var rocketsQuantity : Integer
var fireQuantity : Integer
var gravity : Double
var grid : Positions = new Positions
var maxWidth = 10.0
var exited = false
on SetupSettings {
this.rocketsQuantity = occurrence.rocketsQuantity
this.fireQuantity = occurrence.fireQuatity
this.gravity = occurrence.gravity
this.maxWidth = occurrence.maxWidth
}
on Exit [!hasMemberAgent]{
on Exit [!hasMemberAgent] {
killMe
}
on Exit [hasMemberAgent && !exited] {
exited = true
innerContext.defaultSpace.emit(new Exit)
}
on Initialize [ occurrence.parameters.empty ] {
on Initialize [occurrence.parameters.empty] {
rocketsQuantity = 20
fireQuantity = 30
gravity = 0.5
info("Setup Area")
}
on Initialize [ !occurrence.parameters.empty ]{
on Initialize [!occurrence.parameters.empty] {
var ctrl = occurrence.parameters.get(0) as FXMLViewerController
var ^space = defaultContext.createSpace(OpenEventSpaceSpecification, UUID.randomUUID)
ctrl.setGUISpace(^space)
^space.register(asEventListener)
ctrl.listenAndDraw(grid)
info("Setup Area")
}
on CreateArea {
var x: Double
var i=0
var x : Double
var i = 0
var rnd = new Random()
while (i<rocketsQuantity){
while (i < rocketsQuantity) {
x = rnd.nextDouble() * maxWidth
spawnInContext(RocketLauncher, getInnerContext, x, 0.0, fireQuantity, gravity, grid)
i++;
}
}
on Freeze[!isFromMe(occurrence)] {
on Freeze [!isFromMe(occurrence)] {
innerContext.defaultSpace.emit(occurrence)
}
on MemberJoined [ occurrence.inInnerDefaultSpace && memberAgentCount == rocketsQuantity]{
on MemberJoined [occurrence.inInnerDefaultSpace && memberAgentCount == rocketsQuantity] {
info("Area Ready")
innerContext.defaultSpace.emit(new Launch)
}
}
}

View File

@ -21,8 +21,9 @@ import java.util.UUID
import java.util.Vector
agent Rocket {
uses Lifecycle, Logging, Schedules, Behaviors, DefaultContextInteractions, InnerContextAccess
var x : Double
var y : Double
var gravity : Double
@ -31,26 +32,26 @@ agent Rocket {
var fireQuantity : Integer
var lifetime : Integer
var frozen = false
var exploded = false
var exploded = false
var exited = false
var grid: Positions
var id: UUID
var move: AgentTask
on Exit [!hasMemberAgent]{
var grid : Positions
var id : UUID
var move : AgentTask
on Exit [!hasMemberAgent] {
emit(new Exit)
killMe
}
on Exit [hasMemberAgent && !exited]{
on Exit [hasMemberAgent && !exited] {
exploded = true
frozen = true
exited = true
cancel(move, true)
innerContext.defaultSpace.emit(new Exit)
}
on Freeze {
this.frozen = occurrence.value
if (frozen)
@ -58,11 +59,11 @@ agent Rocket {
if (!frozen)
wake(new UpdateRocketPosition)
}
on Initialize {
info("New rocket launched")
var rnd = new Random()
if (occurrence.parameters.size.equals(7)){
if (occurrence.parameters.size.equals(7)) {
x = occurrence.parameters.get(0) as Double
y = occurrence.parameters.get(1) as Double
speedx = occurrence.parameters.get(2) as Double
@ -75,12 +76,16 @@ agent Rocket {
}
lifetime = rnd.nextInt(5) * 300 + 300
id = UUID.randomUUID
move = atFixedDelay(30)[try{
wake(new UpdateRocketPosition);}
catch(e: Exception) {e.printStackTrace}]
move = atFixedDelay(30) [
try {
wake(new UpdateRocketPosition);
} catch (e : Exception) {
e.printStackTrace
}
]
}
on UpdateRocketPosition [isFromMe(occurrence) && !frozen && !exploded] {
var vect = new Vector(2)
x = x + speedx
@ -89,32 +94,32 @@ agent Rocket {
vect.add(x)
vect.add(y)
lifetime = lifetime - 10
if (grid!==null)
if (grid !== null)
grid.setRocketPosition(id, vect)
if (lifetime <= 0){
if (lifetime <= 0) {
exploded = true
cancel(move, true)
grid.hideHocketPosition(id)
wake(new Explode)
}
}
on Explode {
for (var i=0; i < fireQuantity; i++){
for (var i = 0; i < fireQuantity; i++) {
spawnInContext(Fire, innerContext, x, y, grid, id)
}
// emit(new Launch)
// emit(new Launch)
}
on MemberLeft [!isFromMe(occurrence) && !frozen && !hasMemberAgent] {
exited = true
grid.removeRocketPosition(id)
// emit(new Launch)
// emit(new Launch)
killMe
}
on MemberJoined [!isFromMe(occurrence) && hasMemberAgent && memberAgentCount == fireQuantity]{
on MemberJoined [!isFromMe(occurrence) && hasMemberAgent && memberAgentCount == fireQuantity] {
innerContext.defaultSpace.emit(new FireReady)
}
}

View File

@ -14,21 +14,21 @@ import io.sarl.demos.fireworks.events.Launch
import io.sarl.demos.fireworks.events.RocketReady
agent RocketLauncher {
uses Logging, Behaviors, DefaultContextInteractions, InnerContextAccess, Lifecycle
var x: Double
var y: Double
var x : Double
var y : Double
var fireQuantity : Integer
var gravity : Double
var grid: Positions
var grid : Positions
var exited = false
on Exit [!hasMemberAgent] {
emit(new Exit)
killMe
}
on Exit [hasMemberAgent && !exited] {
exited = true
innerContext.defaultSpace.emit(new Exit)
@ -40,11 +40,11 @@ agent RocketLauncher {
fireQuantity = occurrence.parameters.get(2) as Integer
gravity = occurrence.parameters.get(3) as Double
grid = occurrence.parameters.get(4) as Positions
info("New rocket launcher created")
}
on Initialize [occurrence.parameters.empty]{
on Initialize [occurrence.parameters.empty] {
x = 0.0
y = 0.0
fireQuantity = 30
@ -54,19 +54,19 @@ agent RocketLauncher {
info("New rocket launcher created")
emit(new RocketReady)
}
on Launch {
var vx = Math.random() * 2.0
var vy = Math.random() * 5.5 + 2.0
spawnInContext(Rocket, getInnerContext, x, y, vx, vy, gravity, fireQuantity, grid)
}
on Freeze[!isFromMe(occurrence)] {
on Freeze [!isFromMe(occurrence)] {
innerContext.defaultSpace.emit(occurrence)
}
on MemberLeft [!isFromMe(occurrence) && !exited]{
on MemberLeft [!isFromMe(occurrence) && !exited] {
wake(new Launch)
}
}

View File

@ -36,7 +36,6 @@ event SetupSettings {
}
}
event Freeze {
var value : boolean
@ -44,6 +43,3 @@ event Freeze {
this.value = value
}
}

View File

@ -23,29 +23,26 @@ import javafx.util.Duration
class FXMLViewerController implements EventListener {
private var ispace : OpenEventSpace;
private val id : UUID = UUID.randomUUID();
private var ispace : OpenEventSpace;
private var launched : boolean = false;
private var areaCreated : boolean = false;
@FXML
private var draw_zone : Canvas;
@FXML
private var gravity_display : Label;
@FXML
private var rocket_quantity_display : Label;
@FXML
private var fire_quantity_display : Label;
@FXML
private var gravity_input : ScrollBar;
@FXML
private var rocket_quantity_input : ScrollBar;
@FXML
private var fire_quantity_input : ScrollBar;
@FXML
private var setup_button : Button;
@FXML