Improvements to Drone module - each method can now be called in standalone mode.
This commit is contained in:
parent
7d3689db36
commit
dc08abd534
2 changed files with 52 additions and 0 deletions
52
castle.js
Normal file
52
castle.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
load($SCRIPT_DIR + "/fort.js");
|
||||
//
|
||||
// a castle is just a big wide fort with 4 smaller forts at each corner
|
||||
//
|
||||
function castle (side, height, drone)
|
||||
{
|
||||
//
|
||||
// use sensible default parameter values
|
||||
// if no parameters are supplied
|
||||
//
|
||||
if (typeof drone == "undefined")
|
||||
drone = new Drone();
|
||||
if (typeof side == "undefined")
|
||||
side = 24;
|
||||
if (typeof height == "undefined")
|
||||
height = 10;
|
||||
if (height < 8 || side < 20)
|
||||
throw new java.lang.RuntimeException("Castles must be at least 20 wide X 8 tall");
|
||||
//
|
||||
// remember where the drone is so it can return 'home'
|
||||
//
|
||||
drone.chkpt('castle');
|
||||
//
|
||||
// how big the towers at each corner will be...
|
||||
//
|
||||
var towerSide = 10;
|
||||
var towerHeight = height+4;
|
||||
|
||||
//
|
||||
// the main castle building will be front and right of the first tower
|
||||
//
|
||||
drone.fwd(towerSide/2).right(towerSide/2);
|
||||
//
|
||||
// the castle is really just a big fort with 4 smaller 'tower' forts at each corner
|
||||
//
|
||||
drone = fort(side,height,drone);
|
||||
//
|
||||
// move back to start position
|
||||
//
|
||||
drone.move('castle');
|
||||
//
|
||||
// now place 4 towers at each corner (each tower is another fort)
|
||||
//
|
||||
for (var corner = 0; corner < 4; corner++)
|
||||
{
|
||||
// construct a 'tower' fort
|
||||
fort(towerSide,towerHeight,drone);
|
||||
// move forward the length of the castle then turn right
|
||||
drone.fwd(side+towerSide-1).turn();
|
||||
}
|
||||
return drone.move('castle');
|
||||
}
|
BIN
castles-interlocking.png
Normal file
BIN
castles-interlocking.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 470 KiB |
Reference in a new issue