Skip to content

Instantly share code, notes, and snippets.

@a1ip
Last active January 18, 2024 08:38
Show Gist options
  • Save a1ip/2ea627a4bf6067a63634 to your computer and use it in GitHub Desktop.
Save a1ip/2ea627a4bf6067a63634 to your computer and use it in GitHub Desktop.
CodeCombat Kithgard Dungeon Campaign solutions http://codecombat.com/play/dungeon
Grab the gem, but touch nothing else. Start here.
Basic Syntax

Code for plan() method is here:

# Move to the gem.
# Don't touch the walls!
# Type your code below.

@moveRight()
@moveDown()
@moveRight()
Quickly collect the gems, you will need them.
Basic Syntax

Code for plan() method is here:

# Grab all the gems using your movement commands.

@moveRight()
@moveDown()
@moveUp()
@moveUp()
@moveRight()
Evade the Kithgard minion.
Basic Syntax

Code for plan() method is here:

# Evade the munchkin. Grab the gems.

@moveRight()
@moveUp()
@moveRight()
@moveDown()
@moveRight()
Grab even more gems as you practice moving.
Basic Syntax

Code for plan() method is here:

@moveRight()
@moveUp()
@moveRight()
@moveRight()
@moveDown()
@moveDown()
@moveUp()
@moveRight()
Escape the area while your allies hold off waves of ogres!
Basic Syntax

Code for plan() method is here:

# Your goal is to get to the right side of the map alive.
# You don't need to fight the ogres, just move! Your allies will protect you.

@moveRight()
@moveRight()
@moveUp()
@moveRight()
@moveRight()
@moveRight()
@moveDown()
@moveRight()
@moveDown()
@moveRight()
Learn an enemy's true name to defeat it.
Basic Syntax, Strings

Code for plan() method is here:

# Defend against Brak and Treg!
# You must attack small ogres twice.

@moveRight()
@attack "Brak"
@attack "Brak"
@moveRight()
@attack "Treg"
@attack "Treg"
@moveRight()
@moveRight()
Learn to equip yourself for combat.
Basic Syntax, Strings

Code for plan() method is here:

# Defeat the ogres. 
# Remember that they each take two hits.

@attack "Rig"
@attack "Rig"
@attack "Gurt"
@attack "Gurt"
@attack "Ack"
@attack "Ack"
Tread carefully, danger is afoot!
Basic Syntax, Arguments

Code for plan() method is here:

# Use arguments with move statements to move farther.
@moveRight 3
@moveUp()
@moveRight()
@moveDown 3
@moveRight 2
// Use arguments with move statements to move farther.
this.moveRight(3);
this.moveUp();
this.moveRight();
this.moveDown(3);
this.moveRight(2);
Seek help from a friendly Librarian!
Basic Syntax, Strings

Code for plan() method is here:

# You need a password to open the Library Door!
# The password is in the Help Guide!
# Click on the blue "Help" button under the code window to open the Level Help Guide.
# Most levels have a Help Guide with extra information. If you get stuck on a level, be sure to click Help!

@moveRight()
@say "Hush"
@moveRight()
Save typing (and your hero) with loops!
Basic Syntax, Loops

Code for plan() method is here:

# Code normally executes in the order it's written.
# Loops let you to repeat a block of code multiple times.
# Use tab or 4 spaces to indent the move lines under the loop.

loop
  @moveRight()
  # Add a moveLeft command to the loop here
  @moveLeft()
// Code normally executes in the order it's written.
// Loops let you to repeat a block of code multiple times.
while(true) {
this.moveRight();
// Add a moveLeft command to the loop here
this.moveLeft();
}
Loops are a life saver!
Basic Syntax, Loops

Code for plan() method is here:

# The code in this loop will repeat forever.

loop
  # Move right
  @moveRight()
  # Move up
  @moveUp()
  # Move left
  @moveLeft()
  # Move down
  @moveDown()
// The code in this loop will repeat forever.
while(true) {
// Move right
this.moveRight();
// Move up
this.moveUp();
// Move left
this.moveLeft();
// Move down
this.moveDown();
}
Who knows what horrors lurk in the Cupboards of Kithgard?
Basic Syntax, Loops, Strings

Code for plan() method is here:

# There may be something around to help you!

# First, move to the Cupboard.
@moveUp()
@moveRight 2
@moveDown 2
# Then, attack the "Cupboard" inside a loop.
loop
  @attack "Cupboard"
A maze constructed to confuse travelers.
Basic Syntax, Loops

Code for plan() method is here:

# Loops are a better way of doing repetitive things.

loop
  # Add commands in here to repeat.
  @moveRight 2
  @moveUp 2
Many have tried, few have found their way through this maze.
Basic Syntax, Loops

Code for plan() method is here:

# Use a loop to navigate the maze!

loop
  @moveRight()
  @moveUp()
  @moveRight()
  @moveDown()
Behind a dread door lies a chest full of riches.
Basic Syntax, Loops, Strings

Code for plan() spell is here:

# Break down the door!
# It will take many hits, so use a loop.
loop
  @attack "Door"
Using your first variable to achieve victory.
Variables, Basic Syntax, Strings

Code for plan() method is here:

# You can use a variable like a nametag.

enemy1 = "Kratt"
enemy2 = "Gert"
enemy3 = "Ursa"

@attack enemy1
@attack enemy1

@attack enemy2
@attack enemy2

@attack enemy3
@attack enemy3
Use your new coding powers to target nameless enemies.
Basic Syntax, Variables

Code for plan() method is here:

# Your hero doesn't know these enemy's names!
# The glasses give you the findNearestEnemy ability.

enemy1 = @findNearestEnemy()
@attack enemy1
@attack enemy1

enemy2 = @findNearestEnemy()
@attack enemy2
@attack enemy2

enemy3 = @findNearestEnemy()
@attack enemy3
@attack enemy3
Use your glasses to seek out and attack the Kithmen.
Basic Syntax, Variables

Code for plan() method is here:

# Create a second variable and attack it!

enemy1 = @findNearestEnemy()
@attack enemy1
@attack enemy1
enemy2 = @findNearestEnemy()
@attack enemy2
@attack enemy2
@moveRight()
@moveDown()
@moveRight()
Some enemies will require different battle tactics.
Basic Syntax, Variables

Code for plan() method is here:

@moveRight()

# You should recognize this from the last level.
enemy = @findNearestEnemy()
# Now attack the variable.
@attack enemy
@attack enemy
# And there's another room to clear!
@moveRight 2
@moveUp()
enemy = @findNearestEnemy()
@attack enemy
@moveRight()
To escape you must find your way through an elder Kithman's maze.
Basic Syntax, Loops, Variables

Code for plan() method is here:

# Use a loop to both navigate and attack.
loop
    @moveRight()
    @moveUp()
    enemy = @findNearestEnemy()
    @attack enemy
    @attack enemy
    @moveRight()
    @moveDown 2
    @moveUp()
Escape the Kithgard dungeons and don't let the guardians get you.
Basic Syntax, Arguments, Strings

Code for plan() method is here:

# Build 3 fences to keep the ogres at bay!
@moveDown()
@buildXY "fence", 36, 34
@buildXY "fence", 36, 30
@buildXY "fence", 36, 26
loop
  @moveRight()
Survive waves of enemies that get tougher each time you win. But if you lose, you'll have to wait a day to resubmit.
This is an OPTIONAL challenge level! You don't need to play it to continue with the campaign.

Code for level 1 plan() method is here:

# Survive the waves of ogres.
# If you win, the level gets harder, and gives more rewards.
# If you lose, you must wait a day to re-submit.
# Each time you submit gives a new random seed.
loop
  enemy = @findNearestEnemy()
  if enemy
    distance = @distanceTo(enemy)
    if distance < 10 and @isReady('cleave')
      @cleave enemy
    else if distance < 5
      @attack enemy
    else
      @moveXY enemy.pos.x, enemy.pos.y
  else
    item = @findNearestItem()
    if item
      @moveXY item.pos.x, item.pos.y

Code for level 2 plan() method is here:

# Survive the waves of ogres.
# If you win, the level gets harder, and gives more rewards.
# If you lose, you must wait a day to re-submit.
# Each time you submit gives a new random seed.
loop
  enemy = @findNearestEnemy()
  if enemy
    distance = @distanceTo(enemy)
    if distance < 10 and @isReady('cleave')
      @cleave enemy
    else if distance < 3
      @attack enemy
    else
      @move enemy.pos
  else
    item = @findNearestItem()
    if item
      @moveXY item.pos.x, item.pos.y

Code for level 3 plan() method is here:

loop
  flag = @findFlag()
  item = @findNearest(@findItems())
  enemy = @findNearest(@findEnemies())
  thrower = @findNearest(@findByType('thrower'))
  shaman = @findNearest(@findByType('shaman'))
  if flag
    @pickUpFlag flag
  if thrower
    enemy = thrower
  if shaman
    enemy = shaman
  if item and @health < 200
    @moveXY item.pos.x, item.pos.y
  if enemy
    while enemy.health > 0
      if @health < 200
        break
      if @distanceTo(enemy) < 10 and @isReady('cleave')
        @cleave enemy
      else
        @attack enemy
loop {
var flag = this.findFlag();
var item = this.findNearest(this.findItems());
var enemy = this.findNearest(this.findEnemies());
var thrower = this.findNearest(this.findByType("thrower"));
var shaman = this.findNearest(this.findByType("shaman"));
if (flag) {
this.pickUpFlag(flag);
}
if (thrower) {enemy = thrower;}
if (shaman) {enemy = shaman;}
if (item && this.health < 200) {this.moveXY(item.pos.x, item.pos.y);}
if (enemy) {
while (enemy.health > 0) {
if (this.health < 200) {
break;
}
this.attack(enemy);
}
}
}
def moveTo(position, fast = True):
if(self.isReady("jump") and fast):
self.jumpTo(position)
else:
self.move(position)
summonTypes = ['paladin']
def summonTroops():
type = summonTypes[len(self.built)%len(summonTypes)]
if self.gold > self.costOf(type):
self.summon(type)
def commandPaladin(paladin):
enemy = paladin.findNearest(self.findEnemies())
if(paladin.canCast ("heal")):
target = None
if(self.health<self.maxHealth*0.6):
target = self
minHealth = 200
for friend in self.findFriends():
if friend.health < minHealth:
minHealth = friend.health
target = friend
if target:
self.command(paladin, "cast", "heal", target)
if enemy:
self.command(paladin, "attack", enemy)
else:
self.command(paladin, "move", self.pos)
def commandSoldier(soldier):
enemy = self.findNearest(self.findEnemies())
thrower = self.findNearest(self.findByType("thrower"))
if thrower:
enemy = thrower
if enemy:
self.command(soldier, "attack", enemy)
else:
self.command(soldier, "move", self.pos)
def commandTroops():
for friend in self.findFriends():
if friend.type == 'paladin':
commandPaladin(friend)
elif friend.type == 'soldier' or friend.type == 'archer':
commandSoldier(friend)
def attack(target):
if self.canCast("chain-lightning", target) and self.distanceTo(target)<20:
self.cast("chain-lightning", target)
elif self.distanceTo(target)>10:
moveTo(target.pos)
elif self.isReady("bash"):
self.bash(enemy)
else:
self.attack(target)
loop:
item = self.findNearest(self.findItems())
if item and self.health < 200:
self.move(item.pos)
summonTroops()
commandTroops()
enemy = self.findNearest(self.findEnemies())
if enemy:
attack(enemy)
Rescue and escort the tortured peasant out of the dungeon.
This level was created by player Kevin Holland.

Code for plan() method is here:

# Escape the dungeon after you rescue the tortured peasant.
# You can hide behind the gargoyles.
# Killing the guards can have undesirable consequences.
# If you can loot all of the treasure, you may get an extra reward.
@moveXY 29, 83
@moveXY 46, 115
items = @findItems()
doors = @findByType('door')
door = @findNearest(doors)
@attack door
@moveXY 26, 101
@moveXY 66, 101
@moveXY 46, 81
@moveXY 46, 30
items = @findItems()
tar = @findNearest(items)
@moveXY tar.pos.x, tar.pos.y
items = @findItems()
tar = @findNearest(items)
@moveXY tar.pos.x, tar.pos.y
@attack 'South Vault Door'
@moveXY 84, 71
@attack 'Torture Room Door'
@attack 'Torture Master'
@say 'Come with me if you want to live!'
@moveXY 150, 9
@moveXY 84, 9
@moveXY 83, 81
@attack 'Exit Door'
@moveXY 152, 99
// Escape the dungeon after you rescue the tortured peasant.
// You can hide behind the gargoyles.
// Killing the guards can have undesirable consequences.
// If you can loot all of the treasure, you may get an extra reward.
this.moveXY(29, 83);
this.moveXY(46, 115);
var items = this.findItems();
var doors = this.findByType("door");
var door = this.findNearest(doors);
this.attack(door);
this.moveXY(26, 101);
this.moveXY(66, 101);
this.moveXY(46, 81);
this.moveXY(46, 30);
items = this.findItems();
tar = this.findNearest(items);
this.moveXY(tar.pos.x, tar.pos.y);
items = this.findItems();
tar = this.findNearest(items);
this.moveXY(tar.pos.x, tar.pos.y);
this.attack("South Vault Door");
this.moveXY(84, 71);
this.attack("Torture Room Door");
this.attack("Torture Master");
this.say("Come with me if you want to live!");
this.moveXY(150, 9);
this.moveXY(84, 9);
this.moveXY(83, 81);
this.attack("Exit Door");
this.moveXY(152, 99);
# Определите свои собственные простые функции перемещения.
# Определи moveRight
# Примечание: каждая функция должна двигать героя 12 на метров!
def moveRight():
target = { "x": self.pos.x + 12, "y": self.pos.y }
while self.distanceTo(target) > 0:
self.move(target);
# Определи moveLeft
def moveLeft():
target = { "x": self.pos.x - 12, "y": self.pos.y }
while self.distanceTo(target) > 0:
self.move(target);
# Определи moveUp
def moveUp():
target = { "x": self.pos.x, "y": self.pos.y + 12}
while self.distanceTo(target) > 0:
self.move(target);
# Определи moveDown
def moveDown():
target = { "x": self.pos.x, "y": self.pos.y - 12}
while self.distanceTo(target) > 0:
self.move(target);
# Теперь используй эти функции!
moveRight()
moveDown()
moveUp()
moveUp()
moveRight()
Navigate a maze the hard way.
Basic Syntax

Code for plan() method is here:

# This is a long maze...
@moveRight 2
@moveUp 2

# Now you'll have to repeat the above steps two more times to get to the end of the maze...

@moveRight 2
@moveUp 2

@moveRight 2
@moveUp 2
Demonstrate your mastery of the concepts taught in the Kithgard Dungeon!
This is an optional challenge level for experienced programmers who want to skip the early dungeon levels.

Code for plan() method is here:

# Reach the end of the maze using move commands.
# Count how many gems you pick up, and then say the current count when near a fireball trap to disable it.
# The raven at the start will give you a password. Say the password near a door to open it.
# Kill ogres when you get near them.
# You can use a loop to repeat all of the instructions as needed.
# If you beat this level, you can skip to the Forest World!

@moveUp()
@moveRight 3 
@moveUp()
@moveDown()
@moveRight()
@say "Swordfish"
@moveRight 2
@moveUp()
@say "1"
@moveUp 2
enemy = @findNearestEnemy()
@attack enemy
@attack enemy
@moveLeft 4
@moveUp 3
@moveRight 3
@moveUp()
@moveDown()
@moveRight()
@say "Swordfish"
@moveRight 2
@moveUp()
@say "2"
@moveUp 2
enemy = @findNearestEnemy()
@attack enemy
@attack enemy
@moveLeft 4
# Say "Open Sesame" and a door will open.
# Only doors near you will hear you.
# There is only one route without forks.
# The distance between each point is 24m.
sesame = "Open Sesame"
distance = 24
previous = "start"
while True:
self.say(sesame)
# Check each direction to see if the path is clear.
# Be sure to check and record your previous direction!
# Up
if previous != "down" and self.isPathClear(self.pos, {"x": self.pos.x, "y": self.pos.y + distance}):
self.moveXY(self.pos.x,self.pos.y + distance)
previous = "up"
# Down
if previous != "up" and self.isPathClear(self.pos, {"x": self.pos.x, "y": self.pos.y - distance}):
self.moveXY(self.pos.x,self.pos.y - distance)
previous = "down"
# Left
if previous != "right" and self.isPathClear(self.pos, {"x": self.pos.x - distance, "y": self.pos.y}):
self.moveXY(self.pos.x - distance,self.pos.y)
previous = "left"
# Right
if previous != "left" and self.isPathClear(self.pos, {"x": self.pos.x + distance, "y": self.pos.y}):
self.moveXY(self.pos.x + distance,self.pos.y)
previous = "right"
Обратись за помощью к дружелюбному Библиотекарю!
Аргументы, Базовый синтаксис, Строки, Читать документацию

Код метода plan():

# Тебе нужен пароль, чтобы открыть дверь библиотеки.
# Пароль находится в "Советах"!
# Нажми на синюю кнопку "Советы" над окном кода.
# Если испытываешь затруднения, нажми кнопку "Советы"!

@moveRight()
# @say("Я не знаю пароль!")  # ∆
@say "Hush"
@moveRight()
Ты заперт в тюремной камере вместе с Омарном Брюстоном! Скажи пароль, чтобы Омарн помог.
Аргументы, Базовый синтаксис, Строки, Читать документацию

Код метода plan():

# @say "Какой же пароль?"
# Используй  `say()`, чтобы его произнести.
# А пароль такой: "Achoo"
@say "Achoo"
@moveUp 2
Освободи узника и получишь союзника.
Аргументы, Базовый синтаксис, Строки

Код метода plan():

# Освободи Патрика, который находится за "Weak Door".
@attack "Weak Door"
# Победи охранника по имени "Two".
@moveRight 2
@attack "Two"
@attack "Two"
# Собирай самоцветы.
@moveRight()
@moveDown()
Лабиринт, построенный, чтобы запутывать странников.
Базовый синтаксис, Циклы "while"

Код метода plan():

# Циклы удобно использовать для повторяющихся участков кода.

while true
    # Добавь сюда команды для повторения.
    @moveRight 2
    @moveUp 2
За страшной дверью лежит сундук, полный сокровищ.
Аргументы, Базовый синтаксис, Строки, Циклы "while"

Код метода plan():

# Атакуй дверь!
# Потребуется много ударов, используй "while-true" цикл.
loop
    @attack "Door"
# Выживи под напором огров.
# Если ты выиграл, то уровень становится сложнее, а награда за победу больше.
# Если ты проиграл, то следующая попытка даётся только через день.
# С каждым прохождением выполняется новая случайная расстановка.
while True:
flag = hero.findFlag();
enemy = hero.findNearestEnemy()
item = hero.findNearestItem()
if flag:
hero.pickUpFlag(flag)
if item:
if hero.health < hero.maxHealth / 4:
hero.moveXY(item.pos.x, item.pos.y)
if enemy:
if hero.isReady("cleave"):
hero.cleave(enemy)
else:
hero.attack(enemy)
# Выживи под напором огров.
# Если ты выиграл, то уровень становится сложнее, а награда за победу больше.
# Если ты проиграл, то следующая попытка даётся только через день.
# С каждым прохождением выполняется новая случайная расстановка.
summonTypes = ['soldier', 'soldier', 'griffin-rider', 'soldier', 'archer']
def moveTo(position, fast=True):
if (hero.isReady("jump") and hero.distanceTo(position) > 10 and fast):
hero.jumpTo(position)
else:
hero.move(position)
def summonTroops():
type = summonTypes[len(hero.built) % len(summonTypes)]
if hero.gold > hero.costOf(type):
hero.summon(type)
def commandTroops():
for soldier in hero.findFriends():
if enemy:
#hero.command(soldier, "attack", enemy)
hero.command(soldier, "defend", self)
def attack(target):
if (hero.distanceTo(target) > 20):
moveTo(target.pos)
elif hero.isReady("chain-lightning"):
hero.cast("chain-lightning", target)
elif hero.isReady("bash"):
hero.bash(target)
else:
hero.attack(target)
while True:
summonTroops()
commandTroops()
enemy = hero.findNearestEnemy()
item = hero.findNearestItem()
if hero.time < 35:
if item:
if hero.health < hero.maxHealth / 4:
if hero.isReady("jump"):
hero.jumpTo(item.pos)
hero.moveXY(item.pos.x, item.pos.y)
elif (enemy):
attack(enemy)
else:
hero.shield()
Используй цикл для эффективного перемещения.
Аргументы, Базовый синтаксис, Циклы "while"

Код метода plan():

# Пройди лабиринт менее чем за 5 строк кода.
while true
    @moveRight 2
    @moveDown()
Убеги от духа подземелья с помощью зелья скорости.
Аргументы, Базовый синтаксис, Строки, Циклы "while"

Код метода plan():

@moveRight()
@attack "Chest"
@moveDown()
loop
    @moveRight 3
    @moveDown 3
Кто знает, какие ужасы скрыты в шкафах Китгарда?
Аргументы, Базовый синтаксис, Строки, Циклы "while"

Код метода plan():

# Там может оказаться что-то полезное!

# Сначала двигайся к шкафу.
@moveUp()
@moveRight 2
@moveDown 2

# Потом атакуй шкаф ("Cupboard") внутри цикла.
while true
    @attack "Cupboard"
Переменные подобны маркированным бутылкам, в которых хранятся данные.
Базовый синтаксис, Переменные

Код метода plan():

# Переменная - это контейнер с меткой, в которой хранятся данные.

# Эта переменная называется `someVariableName`
# Она содержит значение `"a string"`
someVariableName = "a string"

# Эта переменная называется `lolol`
# Это содержит число `42`
lolol = 42

# Создайте еще две переменные и присвойте им значения:
# Вы можете назвать их, как хотите, и сохранить в них любое значение!
# Используйте `=` для присвоения значения переменной.
book = "Bible"
man = "Christian"
# Переменная - это контейнер с меткой, в которой хранятся данные.
# Эта переменная называется `someVariableName`
# Она содержит значение `"a string"`
someVariableName = "a string"
# Эта переменная называется `lolol`
# Это содержит число `42`
lolol = 42
# Создайте еще две переменные и присвойте им значения:
# Вы можете назвать их, как хотите, и сохранить в них любое значение!
# Используйте `=` для присвоения значения переменной.
book = "Bible"
man = "Christian"
// Используйте все навыки программирования, чтобы не дать мячам приземлиться.
// Ты можешь бить по мячу в воздухе с помощью метода attack()
// Попробуй использовать наименьшее количество строк кода.
for (let i of [3, -3, 3, -3, 3, -3, 3, -3, 3, -3, 3, -3]) {
hero.attack('ball');
hero.attack('ball2');
hero.moveRight(i);
}
# Используйте все навыки программирования, чтобы не дать мячам приземлиться.
# Ты можешь бить по мячу в воздухе с помощью метода attack()
# Попробуй использовать наименьшее количество строк кода.
for i in [3, -3, 3, -3, 3, -3, 3, -3, 3, -3, 3, -3]:
hero.attack('ball')
hero.attack('ball2')
hero.moveRight(i)
// Выйдите из лабиринта, переместившись на отметку X.
// Постарайтесь собрать как можно больше монет.
//
hero.attack("Treasure Chest");
hero.moveRight();
hero.moveLeft(2);
hero.moveDown();
hero.moveRight(3);
hero.attack("Wicket");
hero.moveRight(2);
hero.moveLeft(2);
while(true) {
hero.moveUp(2);
var enemy = hero.findNearestEnemy();
hero.attack(enemy);
hero.moveLeft(2);
hero.moveRight(2);
hero.moveDown();
hero.moveRight();
hero.moveUp();
hero.moveRight();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment