![]() It is not the same as a line of code, but rather it s each unique piece of information in the code the compiler sees. Sometimes it can be hard for a player to know what counts as a statement, though. So do this: enemy1 = self.findnearestenemy() self.attack(enemy1) self.attack(enemy1) enemy2 = self.findnearestenemy() self.attack(enemy2) self.attack(enemy2) And not this: enemy1 = self.findnearestenemy() enemy2 = self.findnearestenemy() # Bug: this is the same as enemy1 self.attack(enemy1) self.attack(enemy1) self.attack(enemy2) self.attack(enemy2) Some levels limit how many code statements you can use This is to encourage players to learn how to use while loops instead of repeating their code by hand. Otherwise, you might keep attacking the first enemy, because you called findnearestenemy() twice when the nearest enemy was still the same, first enemy. If you don t update your enemy variables, you might keep attacking the first, dead enemy In order to attack a second enemy, you need to call findnearestenemy() again after the first one is dead so that you store the new enemy when the second enemy is the nearest one. ![]() Make sure that you move to within line of sight of the enemy before trying to attack it on levels like The Gauntlet and The Final Kithmaze. You need line of sight to use findnearestenemy() If you can t see an enemy around a corner, then findnearestenemy() will not return the enemy, so when you then attack the enemy variable you created with it, the attack will fail. A strong door (labeled Door ) takes a lot of hits, so students should use a while loop to attack the door indefinitely. Weak doors (ones that are labeled Weak Door ) take one attack action to defeat, so don t use a while loop to attack them. In earlier levels, before variables are introduced, students attack enemies by name using strings (pieces of text in quotes): self.attack("treg") Sometimes it takes more than one attack to defeat an enemy Ogre munchkins each take two attack actions to defeat. In Python, it looks like this: self.attack(enemy) This tells the hero to attack the variable named enemy. Your hero needs to be told what to attack (using parameters) When students use an attack function, they need to specify what will be attacked by putting a parameter inside the parentheses that comes after the attack function. In Javascript, the code that is looped must be enclosed by curly brackets to signify when loops occur, but it s still good practice to indent because it makes code easier to read. In Python, the code that is looped must be indented underneath the while true statement. While Loops A while loop is used to repeat actions without the player needing to write the same lines of code over and over. In Course 1, variables are used to first define an enemy, and then passed along as an argument to the attack method so that the hero can attack the right enemy. Variables A variable is a symbol that represents data, and the value of the variable can change as you store new data in it. In Course 1, strings are used to identify objects for the hero to attack. In both Python and Javascript, strings are represented by text inside quotes. Strings A string is type of programming data that represents text. In Course 1, arguments must be used to define enemies before the hero can attack them, and can also be used to move multiple times without writing new lines of code. In both Python and Javascript, arguments are represented by code that is inside the parentheses after a method. Arguments An argument (also referred to as a parameter) is extra information passed into a method in order to modify what the method does. For example, while Python and Javascript are used to do similar things in Course 1, the syntax for them is noticeably different, because they are different programming languages. Concepts Covered in this Course Basic Syntax Syntax is the basic spelling and grammar of a language, and must be carefully paid attention to in order for code to properly execute. In Course 1, students will learn the basic syntax of Python or Javascript, along with arguments, strings, variables and while loops. By strengthening their typing, syntax and debugging skills, we empower students to feel capable of building real programs successfully. Instead of block based visual programming languages that hinder a student s proper understanding of code, CodeCombat introduces real coding from the very first level. 1 Teacher Guide: Introduction to Computer Science Python Edition Last Updated: Friday, May 20th, 2016 Summary: Introduction to Computer Science With the right environment, learning the basics of formal syntax and typing code can be fun and intuitive for students as early as 3rd grade.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |