forked from vadim-job-hg/CodeCombat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuardDuty.js
23 lines (20 loc) · 806 Bytes
/
GuardDuty.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//https://codecombat.com/play/level/guard-duty
// Add a soldier to the level to prevent ogres from crossing the path.
// Command the soldier using an event handler function.
function soldierLogic() {
// Fill in the code for the soldier's actions here.
// Remember to use 'soldier' instead of 'hero'!
while(true) {
var enemy = soldier.findNearestEnemy();
// Attack the enemy, if the enemy exists.
if(enemy)
soldier.attack(enemy);
// Else, move back to the starting position.
else
soldier.moveXY(42, 48);
}
}
// This assigns your spawned unit to the soldier variable.
var soldier = game.spawnXY("soldier", 42, 48);
// This says to run the soldierLogic function when the soldier is spawned.
soldier.on("spawn", soldierLogic);