Unit 1A-Kithgard Dungeon

Kithgard Dungeon as seen by a new student

Learning Outcomes

By the end of the unit student should be able to:

  • Correctly format code in Python
  • Understand the importance of indentation, capitalization
  • Understand object, method
  • Understand the primitive data types
  • Understand the concept of loop and write While-True loops with proper syntax
  • Understand the concept of variable
  • Understand Python’s variable naming convention
  • Use variable to save and recall to store and recall value, or the result of a method


For most students, this part can be done within 30-60 minutes. It is quite possible that a student may complete all levels required to advance to the Forest without any help from the instructor.

Concepts Covered

Basic Syntax 

Every programming language has its own specific syntax. We need to pay close attention to syntax for code to be properly recognized by the computer.


Not everything in the code are written for the computer. Commentary is only by human and they help us to understand what the code does. In Python commentary is preceded with the hashtag #.


In Python, statements have different indentation (tabs) or indicate how they are structured. Having the correct indentation is extremely important.

Object and Method

Object is a thing; method is what we can do with this thing. When you see a dot, on the left you will find an object, on the right side, a method or property.

Primitive Data Types

When computer process data, it needs to know what type of data it is: three primitive datatypes are shared across virtually all programming languages: string, number, Boolean.


A string is the data type that represents a string of characters. In Python, strings are represented by anything found inside quotes.


Number isthe data type that represents integer or floating number.


Boolean isthe data type that can only by True or False. Remember they need to becapitalized.


A variableis a container that stores a value. It is called variable because more oftenthan not its value can change by assigning new value.


Argument is the information passed into a function/method in order to specify what the function does. In Python, arguments are found inside the parentheses after amethod/function and separated by colon.


Parameter defines the input of a function/method that it takes from its caller. Parameters and arguments need to correspond to each other.

While Loops 

A while loopis used to repeat actions without the player needing to write the same lines ofcode over and over. In Python, the code that is looped must be indented underneath the while true statement.

Levels and their corresponding skills

Levels Programming concepts
1) Dungeons of kithgard, 2) Gems in the deep 3) Shadow Guard 4) Forgetful Gemsmith (optional) 5) Signs and Portents (optional) basic syntax of python; the object: hero and the method: directional movement
6) True Names 7) The Raised sword New method: attack; strings as argument
8) Cell commentary Read commentary
9) Kithgard Librarian Check help guide
10) Fire dancing 11) Loop da loop While true loop
11) Cupboards of Kithgard (blue star) Loop combined with other statements
12) Haunted Kithmaze 13) the second Kithmaze Loop as movement patterns
14) Dread Door Loop with string argument
15) Known enemy 16) Master of Names 17) Lowly Kithmen Variable definition
18) By any other name 19) Closing the distance 20) The final Kithmaze New method: findNearestEnemy (); variable as the result of method
21) A Mayhem of muchkins Simple use of loop and the findNearestEnemy () method.
22) Kithgard Gates New method: buildXY; coordinates

Lesson Plans

Dungeons of Kithgard


  • Understand the CodeCombat interface; understand that your code corresponds to what happens.
  • Understand (at this point intuitively) object and method and how are they related.
    Main Lesson
    Let’s get started! To escape the dungeon, your hero has to move. You can tell them where to move by writing code.
    Type your code into the editor to give your hero instructions. The computer will read and execute these instructions and make your hero move.
    Your hero can act. This is called method. It is a word (or a series of words) followed by parenthesis, like: moveDown() and moveRight(). Don’t forget the parenthesis!
    You only need three lines of code to beat this level.

Gems in the Deep


  • Use argument inside the method
    Main Lesson
    Can you remember the lessons from the last level? This level will be similar, but you will need to move a lot more.

When you move, you only move as far as the next movement square (look for the small tiles on the ground), so you might have to moveUp twice in a row to get to the top of this level from the bottom.
Or you can pass a number as an argument to the movement command, to instruct your hero to move more than one space at a time.

For example, you can move up twice by typing: hero.moveUp(2)

Shadow Guard


  • Reinforce the idea of using argument inside the method
    Main Lesson
    You don’t have a weapon yet, so you can’t fight the ogre munchkin who guards the path.
    Instead, try moving up behind the statue, so he won’t see you. Then you can get the gem undetected.

Enemy Mine


  • Reinforce the idea of using argument inside the method
    Main Lesson
    The floor is littered with Fire Traps, but there’s a safe path through to the gem.

True Names


  • Use arguments with methods
  • Recognize and use strings in the code
    Main Lesson
    Keep in mind a few things to beat this level:
  1. You need to attack each ogre munchkin twice to defeat it.
  2. Spell the names properly, with capitalization! “Brak” and “Treg”.
  3. Put the names in quotes to make them into strings. Strings are a type of programming data. They represent text.
  4. You may notice that while you move, you will ignore the attacks. This is because the statements are executed one by one. Attack cannot happen until the previous statement is concluded. Therefore, you should kill the enemies first and then move right to get the gem.

Fire Dancing


  • Introduce the idea of loop
    Main Lesson
    This level will introduce you to one of the most essential ideas of programming: loop. A loop allows you to repeat a chunk of code many times without having to retype it.
    The simplest kind of loop is While True loop:

You need to use Tab to put your statements behind the blue bar so they will be INSIDE the loop.
It will basically go on forever. Also, notice that anything goes outside the While True loop will never run. Or it will run once if it is put before the loop.

Loop Da Loop


  • Reinforcing the idea of loop, paying attention to the proper syntax: indentation and colon.
  • Read commentary and structure your code

Main Lesson
Notice the goal is to write code that contains less than 6 statements. This tells us that, although you can put whatever you want inside a while True loop, everything in the loop will be repeated so there is no point repeating things inside the loop. Look for ways to have the minimum of code inside the loop. For this level, we only need to repeat four move commands in a correct order.
Pay close attention to your indentation! This tells the computer what are the statements inside the loop and what are not.
Also, remind the students of the “:”. This is important as students tend to omit it.
Finally, you may realize by this point that you have been reading commentaries (in blue color). They are important tools to help you organize your code: try to insert your code directly below the line of comentary that describes what it does, like the following:

Haunted Kithmaze, The Second Kithmaze


  • Recognize patterns of movement
  • Use loop to implemen patterns.
    Main Lesson

You need to traverse a maze; yet you can only use a limited number of movements. The key to success is the recogniztion that a certain combination of movements can be repeated. Then, put them inside a loop!

Dread Door


  • Use arguments with methods
  • Recognizeand use string
  • Write a loopwith proper syntax

Main Lesson

You can combine while True loops and attack statement to easily tackle things thattake more than one hit, such as this door.
You can attack the door by its name, which is “Door”. With looping and attacking, you can do this level in just two lines of code.

Cupboards of Kithgard


  • Use arguments with methods
  • Recognize and use string
    Write a loop with proper syntax
    Main Lesson
    The ogre guards might be too much for you to handle. Maybe you’ll find something useful in the “Cupboard”?
    First, move close to the “Cupboard” (stand on the red X). It looks locked, so you’ll have to attack it repeatedly using a while True loop to break it open.



  • Use arguments with methods
    Main Lesson
    You’ll need that soldier to protect you, so first attack the “Weak Door” to free her.
    Then use a while True loop to attack the “Door” while your new friend holds off the munchkins.

Known Enemy

Use variable to save and recall simple data types
Main Lesson
Up until now, you have been doing three things:

  1. Calling methods (commands like moveRight()
  2. Passing strings (quoted pieces of text like "Treg") as arguments to the methods
  3. Using while True loops to repeat your methods over and over.
    Now you are learning how to use variables. A variable is a container that represents and stores data. The variable’s value can vary as you store new data in it, which is why it’s called a variable.
    It’s a pain to type the names of ogres multiple times, so in this level you use three variables to store the ogre names. Then when you go to attack, you can use the variable (enemy1) to represent the string that is stored in it ( “Kratt” ).
    Declare variables like so:
    `enemy1 = “Kratt”
    The quotation mark around Kratt makes it a string. This is how the computer know it is a string. A variable, however, only stores the value of this value. But its name cannot have quotation marks around it.
    The = sign is not equal; it means “assign”. The right side of the operator will determine the left side, both in terms of data type and value.
    Python doesn’t use explicit variable declaration, so the first time a variable is assigned determines its type. In this case, enemy1 is assigned to a string, therefore it becomes a string variable.

Master of Names

Use variable to save the result of a method
Main Lesson
Remember from the last level, variables ​are assigned to simple/primitive data types. In this level, it is assigned to the result of a method, such as the findNearestEnemy() method.
What does the variable get from this assignment? It gets whatever is returned by the method.
To know what is returned by the method you need to check the method panel and click on the method.


It is also important to know not only what is returned, but also what type does it return. In this case, because the enemy is an object, then enemyX becomes an object.
The point of using the findNearestEnemy() method and store the result in a variable is this: you don’t know in your code who exactly that enemy will be. But you can write code that deals with the unknown! The powerful ability of the method and the variable will find whoever appears nearest to your hero, and do what you ask him/her to do.

A Mayhem of Munchkins

Use variable, method in conjunction with the loop
Main Lesson
This is typical: use a loop and inside the loop, use findNearestEnemy() to find an ogre and kill it. The program can go on forever and kill a million ogres whose names you wouldn’t know and care!

The Gauntlet

Use loop, method, variable, as well as movement to tackle enemies and move forward
Main Lesson
With the power of loop, method and variables, it should be no sweat to take down all these munchkins and get to the exit.

The Final Kithmaze


  • Use loop, method, variable, as well as movement to tackle enemies and move forward.
  • Recognize pattern of the maze and design your movements.
    Main Lesson
    This level combines everything you have learned so far.
    Something to pay attention to: make sure that you call findNearestEnemy() when you can actually see the ogre munchkin. There is such a thing called line of sight. If you cannot see the ogre then the method will return null, which will give you an error!

Kithgard Gates


  • Introducing new method and the coordination system
    Main Lesson
    This level should be taught in conjunction with the first level of the next world.
    When you use a builder’s hammer, instead of the attack method, you get the buildXY() method. BuildXY takes three arguments, instead of one: build type, x, and y so you can decide what to build and where to build it.
  • build type: this is a string that can be “fence”, to build fences, or “fire-trap”.
  • x : the horizontal position at which to build. You can hover over the map to find coordinates.
  • y : the vertical position at which to build. x and y are both numbers.

End of Unit 1A Review

Congratulation on finishing the dungeon world and surfacing to the forest! There are many things you have acomplished in the underworld, and this is a good time to reflect on what you have encountered but not necessarily understood.

Object, method and property

When you see something like hero.moveRight(), you know you are seeing an object and a method associated with it. This is how Codecombat is distinct from other approaches teaching python: we put the idea of object.method in the foreground, from the very first class. In other python classes you have to traverse everything else to get to know what is an object, as an advanced concept; here it is the very basic concept because it is the most natural and intuitive thing for even beginner programmer to understand: a hero performs an action.

The syntax is important: on the left side of the dot you have an object, and on the right side, a method.

How do we know it is a method? Because of the parentheses. It is important to have those parentheses, even if there is nothing in it, because this is where method differs from property.
An object is a thing; and a method is what this thing can do. What is a property? It is an attribute that belongs to the object. Try to come up with examples of object, method and property. And you will see how useful it is to model the real world in programming

Data types

In programming we process data, but this description is not accurate enough. In reality, we need to distinguish from different types of data and process them accordingly. The computer is very strict about it. Different types of data cannot mix. Once a variable has been assigned a type, it cannot be changed.
The so-called primitive data types are number, string and Boolean. The are called primitive because they are the first type that was invented when the computer came to the world, as a computer was designed to computer numbers.
As computers grew more complex, they gained the ability to process data other than number, these are strings. A string is a series of alphanumeric values. It is a text.
Later on we felt the need to make computer do different things according to some given rules. This is when we invented the Boolean type. It can either to True or False.
The object is also a data type, although this type came about much later than the others. It is a compound type, compared to the simple, straightforward three. They are called primitive also because of this reason.
An object can have properties, and each property can be of the primitive types, or itself be an object. This way the object type is able to model the real world much better.


Variable is a central concept in modern computer language. Think about a container that stores something. The content it stores is called its value. The value can often change, hence the name variable.

A more accurate understanding of variable is that it points to where a value is stored. In this sense a variable is like an index that will allow us to find a book in a library. It is a pointer, a link.

In the beginning, when only the most rudimentary language (such as assembly language) exists, you do not have variables but a few registers where you can store the things you compute. You need to know what they are as you cannot name them. This is inconvenient. Hence in modern languages we develop the ability to name a variable. The name of a variable doesn’t matter to the computer. It helps the human programmer to understand what the variable is for.

Before we use a variable, we need to know its type. This is done through a process of declaration. Some programming languages have an explicit declaration statement, such as

integer password

The above statement will declare that a variable is called password and it is of the type integer.

In python this process is simplified. The declaration of a variable is implicit, which means, it is decided the first time it is assigned to something.

When you see the = sign in a statement such as password = "sesame open" you should know that password is a variable of the type of string. Why? Because the right side of the assign operator = is a string. This statement therefore does two things at once: it declares password as a string variable; it also gives it a value.

Returning value

What happens in a statement such as enemy = hero.findNearestEnemy()? How do we know the variable named enemy is of the type object? This is because on the right side of assign operator, we have a method that returns an object.
Click on the middle panel of the CodeCombat interface to check out any method, especially what it returns.
Not all methods will return something. Some, like hero.attack(), does not return anything.

Indentation and code structure

Have you noticed that some statements end by a colon “:”?
This means that there will be a block of codes that follow this statement. We can also say they belong to the statement; they work for it. For example, if you have a while True loop, then what follows belong to the loop, meaning they work inside the loop.
In python, this sense of belonging is indicated by indentation. Those codes that do not belong to any other is on the main level. You will see it does not have any empty spaces before it.
You can have multiple indentation levels, and the deeper indented codes belong to the line that preceeds them, like this:

Leave a Reply