/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
* Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
* This file is available and licensed under the following license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Oracle Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package sl;
import javafx.fxd.FXDLoader;
import javafx.scene.*;
import javafx.scene.paint.Color;
import javafx.util.Math;
import sl.Board.Squ;
import sl.Main;
import sl.Player;
import javafx.scene.transform.Scale;
public var dim = bind Math.min(Main.sceneheight - Main.sceneheight /10 - Main.sceneheight/20, Main.scenewidth - Main.scenewidth /10 - Main.scenewidth/20);
public var sqSide = bind dim / 10;
var fxdContent:Node ;
public var shiftwidth = bind Math.max(0, (Main.scenewidth - dim - sqSide )/2);
public var shifty = bind (sqSide * 3/4) + Math.max(0, (Main.sceneheight - dim - sqSide )/2);
public class Board extends CustomNode {
public var blocks: Squ[];
public var players: Player[];
public var g: Group;
public override function create(): Node {
fxdContent = FXDLoader.load(
"{__DIR__}Snakes_Ladders_Game_Board.fxz",
);
fxdContent.cache= true;
doLayout1();
var g1:Group = Group{
transforms: [
Scale {
x : bind dim/653
y : bind dim/684
pivotX:0
pivotY:0
}
]
cache:true
translateX:bind sqSide + shiftwidth;
translateY:bind shifty;
content:[
fxdContent
]
};
g = Group {
content: [
g1,
blocks,
players
]
};
return g;
}
function doLayout1(){
var count = 0;
var sq;
sq = Squ{
xPos: bind 0 + shiftwidth
yPos: bind dim - sqSide + shifty
i: count
};
insert sq into blocks;
count = count + 1;
for(row in [0..9]) {
var y = bind dim - (sqSide + row * sqSide) + shifty;
for (col in [0..9]){
if (row mod 2 == 0) {
sq = Squ{
xPos: bind col * sqSide + sqSide + shiftwidth;
yPos: bind y
i: count
}
}
else {
sq = Squ{
xPos: bind dim - ( col * sqSide) + shiftwidth;
yPos: bind y
i: count
}
}
insert sq into blocks;
count = count + 1
}
}
for (cs:Integer in [ 0..99 ]) {
var moveStep:Integer = Main.gd.moves[ cs ];
if (moveStep != cs){
var sq1:Squ = blocks[ cs ];
sq1.start = true;
sq1.stop = moveStep;
}
}
var player1 = Player{
idd: 0;
name: "Player 1";
col: Color.RED;
currentsquare: 0;
};
insert player1 into players;
var player2 = Player{
idd: 1;
name: "Player 2";
col: Color.DARKORANGE;
currentsquare: 0;
};
insert player2 into players;
}
}
public class Squ extends CustomNode {
var i:Integer;
var sqno = String.valueOf(i);
public var xPos:Number;
public var yPos:Number;
public var start:Boolean;
public var stop:Integer;
public override function create():Node {
return Group {
content: [
]
}
}
}