Skip to content

Instantly share code, notes, and snippets.

@sroehrl
Created May 11, 2021 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sroehrl/861796d29862efcf8e51c37e305da8a6 to your computer and use it in GitHub Desktop.
Save sroehrl/861796d29862efcf8e51c37e305da8a6 to your computer and use it in GitHub Desktop.
Beginner scenario for https://neoan.us/game
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