Presentation is loading. Please wait.

Presentation is loading. Please wait.

Code Combat.

Similar presentations


Presentation on theme: "Code Combat."— Presentation transcript:

1 Code Combat

2 Review: Boolean Logic True/False logic
Used in conditional expressions, as in: If a condition is true, do this

3 Review: If statements If statements operate off of Boolean Logic.
An if statement will run a sequence of code only if a condition is true

4 Review: If/else Statements

5 10: Woodland Cleaver Two new objects

6 10: Woodland Cleaver

7 10: Woodland Cleaver

8 How do we go about doing this?
10: Woodland Cleaver The object of the level is to use your new “cleaving” skill whenever possible to attack large groups of enemies. How do we go about doing this?

9 10: Woodland Cleaver First things first, we check if there is an enemy. Then we want to check to see if we can cleave, given the cooldown you can only cleave once every several sec. What could we use to check?

10 10: Woodland Cleaver We are going to set up an if/else statement, so that something happens if a condition is true and something else happens if that condition is false. What’s our condition?

11 10: Woodland Cleaver Psuedocode ~ plain language that describes the steps in our code 1. Is there enemy? 2. If there is an enemy, check to see if you can cleave 3. If you can cleave, cleave 4. Otherwise attack 5. Repeat

12 10: Woodland Cleaver

13 If “cleave” is ready, cleave!
10: Woodland Cleaver If “cleave” is ready, cleave! Else, attack!

14 10: Woodland Cleaver Now just add in the setup - find your enemies & stick the whole lot in a loop to check continuously!

15 The movexy method requires 2 pieces of info -
Review (-3, 3) New boots, new move method The movexy method requires 2 pieces of info - Where you want your hero to go on the horizontal, or x axis, and where you want her to go on the vertical, or y axis

16 11: Shield Rush You may have already purchased a shield, but this one comes with a new method - shield()

17 11: Shield Rush Hover your mouse of the x to find where to build your fence

18 11: Shield Rush The goal of this lesson is very similar to the one before, except this time if “cleave” is not ready, shield instead of attack

19 If I try and run this code I get a syntax error!
11: Shield Rush If I try and run this code I get a syntax error! Can you spot why?

20 11: Shield Rush Now we have enemy defined, but I still get an error (this time semantic) Can you spot why?

21 11: Shield Rush We need the loop so that our hero doesn’t just check once - she checks continuously!

22 Wait for now to try out the dueling grounds!

23 12: Peasant Protection Two new methods

24 12: Peasant Protection Our newly upgraded glasses allow us to not just find and name enemies, but tell how far away they are Two new methods

25 12: Peasant Protection Two new methods This allows us to set up if/else statements that have our hero act when an enemy gets too close

26 12: Peasant Protection Two new methods

27 13: The Agrippa Defense For this level you will need several nested if statements Once an enemy is present, you should check and see if the enemy is close enough to attack. If so you check to see if you can “cleave”. Else you will attack.

28 Be careful with your whitespace
13: The Agrippa Defense Be careful with your whitespace

29 13: The Agrippa Defense To check continously Why do we need the loop?

30 13: The Agrippa Defense Can you spot the error?

31 13: The Agrippa Defense If enemy not there (undefined) then distanceTo(enemy) will be a syntax error distanceTo( ) method needs to be after the if statement that checks if an enemy is present - why?

32 14: Munchkin Swarm The goal of this level is very similar to last - can you set up the nested if statements?

33 14: Munchkin Swarm

34 15: Coinucopia

35 15: Coinucopia

36 15: Coinucopia

37 15: Coinucopia

38 15: Coinucopia For now the color of the flags do not matter

39 This time we will need to add a line of code, using the new method
16: Copper Meadows Goals of the lesson: This time we will need to add a line of code, using the new method

40 16: Copper Meadows What does this code do?

41 Then hit submit and use the flags to guide your hero
16: Copper Meadows Then hit submit and use the flags to guide your hero

42 17: Drop the Flag Equip your hammer

43 17: Drop the Flag Goals for this level

44 What does this section do?
17: Drop the Flag This is the section you will need to edit (find the x and y where you need to place the fire-trap) What does this section do? This section has the hero look for and find coins if no flag is present

45 17: Drop the Flag Access the x and y coordinates from the flag’s position. Then use those those for the location of your fire trap

46 17: Drop the Flag

47 Reequip your long sword.
18: Rich Forager Reequip your long sword.

48 18: Rich Forager Hit go back to levels and spend those well earned gems on some new armor!

49 18: Rich Forager Elif is short hand for “else if”.
These statements allow you to check on multiple conditions. Here you want to plan on different actions depending on what your hero encounters

50 18: Rich Forager If there is a flag? Pick up flag!
If no flag but there is an enemy? Cleave if possible, if not attack If no flag and no enemy but there is an item, go to the x/y location of item

51 18: Rich Forager NOTE: These if/else if statements are within the loop

52 Again ensure armor is upgraded as much as possible.
19: Siege of Stonehold Again ensure armor is upgraded as much as possible. While you don’t need a “sense stone” to win, I suggest you go one (Fire Opal, Polished Stone) and get it so you can try it out.

53 19: Siege of Stonehold Sense stone allows you to access different values within the game. These are like sensing blocks in Scratch - very useful when writing conditions for if/else statements. We will use this.health

54 19: Siege of Stonehold The goal of this level is simple - fight and stay alive! We will use if/else if/else statements to make decisions

55 19: Siege of Stonehold What are the different events we need to plan for?

56 19: Siege of Stonehold What are the different events we need to plan for? Attack enemy Go to/pick up a placed flag Cleave enemy Go to healers for health

57 19: Siege of Stonehold It is important that we put these in the correct order though! What is most important? Attack enemy Go to/pick up a placed flag Cleave enemy Go to healers for health

58 19: Siege of Stonehold Go to healers for health Cleave enemy
Attack enemy Go to/pick up a placed flag

59 19: Siege of Stonehold Go to healers for health Cleave enemy
Note: These are not necessarily the order of events, but this will be the order we will check on conditions. Go to healers for health Cleave enemy Attack enemy Go to/pick up a placed flag

60 19: Siege of Stonehold Go to healers for health if health too low, go to x,y Cleave enemy if enemy & cleave is ready, cleave Attack enemy if enemy & cleave not ready, attack Go to/pick up a placed flag if flag exists, go to flag Health takes priority! That’s why it’s #1

61 If / else if / else NOTE: Within an if / else if / else sequence, else if’s are only executed IF the previous if / else if conditions have all been False As soon as one if / else if condition is True, all below all skipped If none are True and an else is in the sequence, the else code block is run

62 If / else if / else Within an if / else if / else sequence, else if’s are only executed IF the previous if / else if conditions have all been False Remember! We are using these within a loop - so just because a condition is temporarily False, doesn’t mean it will stay False

63 If / else if / else As soon as one if / else if condition is True, all below all skipped Remember! We are using these within a loop - so just because a condition is temporarily False, doesn’t mean it will stay False

64 If / else if / else If none are True and an else is in the sequence, the else code block is run Remember! We are using these within a loop - so just because a condition is temporarily False, doesn’t mean it will stay False

65 19: Siege of Stonehold Go to healers for health if health too low, go to x,y Cleave enemy if enemy & cleave ready, cleave Attack enemy if enemy & cleave not ready, attack Go to/pick up a placed flag if flag exists, go to flag

66 19: Siege of Stonehold

67 19: Siege of Stonehold

68 We made it to the next world! Wahoo!


Download ppt "Code Combat."

Similar presentations


Ads by Google