Beginner scenario for https://neoan.us/game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let planetIndex = 1; | |
// the following line does only work on a local system and not online (so only if you check out the repo) | |
spaceStation.cheat(); | |
/* | |
Practice scenario: Retrieve cargo | |
Click on "execute" to start! | |
YOUR TASK: use a second ship to retrieve cargo from a rouge drone! | |
The provided code will "build" a scenario in which the first ship collects resources for a second ship. | |
Depending on the system, this can take some time. However, this gives you the opportunity to see a written program in action. | |
Good players write ONE program that executes their complete game operation. | |
*/ | |
// Place your code here. Whenever you click execute, it applies. | |
/* SETUP code for scenario | |
* Changing code below this line does not guarantee that the scenario remains playable. | |
* However, feel free to hack away if you know what you are doing | |
*/ | |
if(starShips.length === 1){ | |
starShips[0].name = 'broken drone'; | |
mine(starShips[0]) | |
const log = [ | |
'Welcome to a simple adventure!', | |
'In this scenario, we will simulate an emergency:', | |
'Your first drone will run out of fuel and you will have to recover the cargo.', | |
'***', | |
'First, study what is happening while the simulation prepares its prerequisites', | |
'Depending on the system, this might take a few minutes...' | |
]; | |
log.reverse().forEach(l=>logger(l)) | |
} | |
function mine(ship){ | |
// mine | |
starShips[0].setDestination(...planets[planetIndex].getCoords()); | |
starShips[0].on('arrived', ship=>{ | |
ship.extract(planets[planetIndex]) | |
.then(()=> { | |
planetIndex = planetIndex === 1 ? 2 : 1; | |
flyHome(ship) | |
}) | |
}) | |
starShips[0].fly(); | |
starShips[0].setBurnRate(2) | |
} | |
let redirect = false; | |
function flyHome(ship){ | |
if(redirect){ | |
return autopilot(ship) | |
} | |
ship.setDestination(...spaceStation.getCoords()) | |
ship.fly() | |
ship.on("arrived", ship => { | |
if(spaceStation.getFuelTank()<600){ | |
spaceStation.refineFuel(); | |
} | |
ship.unload(spaceStation).then(async ()=>{ | |
if(spaceStation.getResources().iron > 5000 && spaceStation.getResources().o3 > 900){ | |
// build a ship | |
spaceStation.buildShip(); | |
logger('Your second ship should be built momentarily...') | |
logger('Okay, here we go! Remember: you need to retrieve the cargo!') | |
redirect = true; | |
} | |
if(ship.getFuel()<200){ | |
await ship.refuel(); | |
} | |
mine(ship) | |
}) | |
}) | |
} | |
function autopilot(ship){ | |
if(ship.getFuel()<1){ | |
return; | |
} | |
starShips[0].setBurnRate(10) | |
const pos = ship.getPosition(); | |
if(pos[0] === 20){ | |
ship.setDestination(70,70) | |
} else { | |
ship.setDestination(20,70) | |
} | |
ship.fly(); | |
ship.on('arrived', autopilot) | |
} | |
let cancelMe; | |
cancelMe = setInterval(()=>{ | |
if(starShips.length > 1 && starShips[1].getCargo().type !== null && starShips[0].getCargo().type === null){ | |
alert('Good job!') | |
clearInterval(cancelMe) | |
} | |
},2000) | |
document.getElementById('exec').addEventListener('click', ()=> clearInterval(cancelMe)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment