top of page
463CC5F0-4DDC-47F7-88C2-32166E212C93.heic

Island 6 
Code Combat/Ozaria: Introduction to Python

Software Engineering

POP students will learn how to use Python Script coding language to program their hero in Code Combat to defeat villains and collect gems. 

84A78552-95F4-4BFC-8AF3-F1641205426D.heic

Island 6 Code Combat/Ozaria: Introduction to Python

POP students will learn how to control a character in a computer game.

Writing Code

Like people, computers have their own language they use to communicate. Computers use a written language called source code  to work, and humans can tell computers to do things by writing source code. Source code is a language that contains numbers, symbols, and words. In Code Combat players are able to explore, learn, and practice three different script languages including the popular Python and JavaScript, and an experimental code called CoffeeScript. 

Python Script Language

Python is one of the easiest script languages to use because it looks a lot like the text in books. Python uses commands that are easy to read and leaves spaces for comments about the code for the code writers. Python has many different commands including methods, arguments, strings, variables, and loops. Each command tells the computer to do something.  In this Liftoff Challenge, POP students will program commands to help their hero avoid traps and defeat ogres.

Commands

Methods are actions a hero can do with their gear. POP students create a  hero that has feet so he can move up, down, right, or left. At the end of each method there are parenthesis where an argument can go.

Arguments and Strings

Arguments in Python  tell the computer details about a method or action. For example, one could tell the computer to move the hero right with hero.moveRight(), or one could use an argument to be more specific about how far one wants their hero to move right. One could tell the computer to move the hero one space, two spaces, or even farther.

A string is a special piece of text information. To tell the computer about a string, surround text with quotation marks.

One can combine arguments and strings. If one writes hero.moveRight(4), the hero will move to the right 4 spaces. In another example, one could tell the computer to have the hero attack with hero.attack(), if one want their hero to attack the enemy Treg, the command would be hero.attack("Treg"). be hero.attack("Treg").

Variables 

Variables are symbols that represent data, but unlike arguments, variables can change. When you are fighting ogres such as Treg, it takes a long time to type in their names one by one. Imagine if one had to fight a whole army of ogres! Instead of typing their names one by one like hero.attack("Treg"), one can use variables to attack the closest ogre and then attack the next closest ogre with hero.findNearestEnemy().

Loops

Sometimes a certain piece of code needs to be repeated over and over. Maybe one needs their hero to dodge a fireball or  need them to travel in a circle around and around. One can use a "while-true" loop and tell the computer to repeat an action however many times one wants. In the example below, the hero needs to move through a maze with the same moves over and over. Instead of writing out each step, one can write out the series and tell the computer to repeat or loop any number of times. 

bottom of page