Skip to content

Commit 9aa59f7

Browse files
committed
FONDLED THE CODE
1 parent bc97c16 commit 9aa59f7

6 files changed

+116
-2
lines changed

GameDev2/ArmyTraining.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//https://codecombat.com/play/level/army-training
2+
// Spawn a hero and add a goal.
3+
game.spawnHeroXY(40, 15);
4+
game.addDefeatGoal();
5+
6+
// Spawn at least 2 "munchkin"s.
7+
game.spawnXY("munchkin", 40, 15);
8+
game.spawnXY("munchkin", 40, 18);
9+
// Spawn at least 2 "thrower"s.
10+
game.spawnXY("thrower", 45, 15);
11+
game.spawnXY("thrower", 45, 18);
12+
// Spawn at least 2 "soldier"s.
13+
game.spawnXY("soldier", 65, 15);
14+
game.spawnXY("soldier", 65, 18);
15+
game.spawnXY("soldier", 65, 15);
16+
game.spawnXY("soldier", 65, 18);
17+
// Spawn at least 2 "archer"s.
18+
game.spawnXY("archer", 65, 15);
19+
game.spawnXY("archer", 65, 18);
20+
game.spawnXY("archer", 65, 15);
21+
game.spawnXY("archer", 65, 18);

GameDev2/ArmyTraining2.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//https://codecombat.com/play/level/army-training-2
2+
// Defeat the ogres by spawning and commanding units.
3+
4+
// Spawn 2 "soldier"s.
5+
game.spawnXY("soldier", 35, 20);
6+
game.spawnXY("soldier", 45, 20);
7+
// Spawn 2 "archer"s.
8+
game.spawnXY("archer", 35, 20);
9+
game.spawnXY("archer", 45, 20);
10+
function fightEnemies(event) {
11+
while(true) {
12+
// event.target is the unit that is executing this event handler function!
13+
var friend = event.target;
14+
var enemy = friend.findNearestEnemy();
15+
// If there is an enemy
16+
if(enemy) {
17+
// Then have friend attack the enemy!
18+
friend.attack(enemy);
19+
}
20+
}
21+
}
22+
23+
// This attaches the fightEnemies handler to all soldiers' "spawn" events.
24+
game.setActionFor("soldier", "spawn", fightEnemies);
25+
26+
// Now, attach fightEnemies to the archers' "spawn" events:
27+
game.setActionFor("archer", "spawn", fightEnemies);

GameDev2/ForestIncursion.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//https://codecombat.com/play/level/forest-incursion
2+
// Okar needs to stomp out these annoying little munchkins!
3+
// Unfortunately he is slow, and his attacks do little damage.
4+
// Fortunately, as a game developer, you have full control over the world!
5+
// Set Okar's properties to buff him up for ogre slaying!
6+
7+
game.addDefeatGoal();
8+
game.addSurviveGoal();
9+
var hero = game.spawnHeroXY(12, 10);
10+
// Increase the hero's maxSpeed, so he runs faster.
11+
hero.maxSpeed = 25;
12+
// Increase the hero's maxHealth, so he lasts longer.
13+
hero.maxHealth = 5000;
14+
// Increase the hero's health, so he can actually take the hits.
15+
hero.health = 5000;
16+
// Increase the hero's attackDamage, so he can quickly kill the ogres.
17+
hero.attackDamage = 5000;

GameDev2/GuardDuty.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//https://codecombat.com/play/level/guard-duty
2+
// Add a soldier to the level to prevent ogres from crossing the path.
3+
// Command the soldier using an event handler function.
4+
5+
function soldierLogic() {
6+
// Fill in the code for the soldier's actions here.
7+
// Remember to use 'soldier' instead of 'hero'!
8+
while(true) {
9+
var enemy = soldier.findNearestEnemy();
10+
// Attack the enemy, if the enemy exists.
11+
soldier.attack(enemy);
12+
// Else, move back to the starting position.
13+
soldier.moveXY(42, 48);
14+
}
15+
16+
}
17+
18+
// This assigns your spawned unit to the soldier variable.
19+
var soldier = game.spawnXY("soldier", 42, 48);
20+
// This says to run the soldierLogic function when the soldier is spawned.
21+
soldier.on("spawn", soldierLogic);
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//https://codecombat.com/play/level/standard-operating-procedure
2+
// Events have properties like event.target
3+
// This lets you use the same event handler for many different units.
4+
game.addDefeatGoal();
5+
var soldier1 = game.spawnXY("soldier", 50, 30);
6+
var soldier2 = game.spawnXY("soldier", 50, 35);
7+
var soldier3 = game.spawnXY("soldier", 50, 40);
8+
var munchkin1 = game.spawnXY("munchkin", 25, 30);
9+
var munchkin2 = game.spawnXY("munchkin", 25, 35);
10+
var munchkin3 = game.spawnXY("munchkin", 25, 40);
11+
12+
// This function has munchkin1 attack its enemies.
13+
// Use event.target to make this function work for all units!
14+
function fightEnemies(event) {
15+
while(true) {
16+
// Create a unit variable, and assign event.target to it
17+
var unit = event.target;
18+
// Now change the lines below to use unit instead of munchkin1
19+
var enemy = unit.findNearestEnemy(); // ∆
20+
if(enemy) {
21+
unit.attack(enemy); // ∆
22+
}
23+
}
24+
}
25+
26+
// Use game.setActionFor() to assign event handlers to many units.
27+
game.setActionFor("munchkin", "spawn", fightEnemies);
28+
game.setActionFor("soldier", "spawn", fightEnemies);

todo.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
https://codecombat.com/play/campaign-web-dev-2
2-
https://codecombat.com/play/campaign-game-dev-2
1+
2+
33
http://codecombat.com/play/level/serpent-savings
44
https://direct.codecombat.com/play/level/power-peak?course=56462f935afde0c6fd30fc8c&codeLanguage=python
55
https://codecombat.com/play/level/power-peak?team=ogres&opponent=57acf77b034d0a20008e202a

0 commit comments

Comments
 (0)