Session 1 Welcome to Greenfoot & Code Breaker Authored by Brian Cullen

Size: px
Start display at page:

Download "Session 1 Welcome to Greenfoot & Code Breaker Authored by Brian Cullen"

Transcription

1 Session 1 Welcome to Greenfoot & Code Breaker Authored by Brian Cullen (bcullen@rossettschool.co.uk) (c) Copyright 2011 Computing At School. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. See for details.

2 About Code Breaker The Code Breaker competition is being held to celebrate the 100 th birthday of Alan Turing a famous British mathematician and computer scientist. To help others learn about him you are going to make a small presentation about his life and work. Split into 4 groups and each group is to prepare a single slide on one of the following aspects of his life and work. Remember what is on the slide should only be a summary and you should have more information available to answer questions! 1. His early life and interests (where was he born, go to school, etc). 2. His work with codes and cyphers. 3. The Turing Test for artificial intelligence. 4. The Turing Machine Once you have finished your slides make sure you put them together so that they can be presented at the end of the session. Starting with Greenfoot As this is probably one of the first times you have used Greenfoot we are going to spend a little time looking at how to use the program before we do much coding. To help you get started you have been provided with a program (called a scenario in Greenfoot) to begin with. To start open Greenfoot go to the Scenario menu, choose Open and find the ShipGame scenario. Once you have done that you screen should look like this picture. This class represents your world is responsible for adding and removing Actors. The main area of the screen shows you what is happening in the world. Use these buttons to run your code once it s compiled. IMPORTANT: Press compile to check your code and get it ready to run. Your program will NOT run unless you compile it first! You will have to make an Actor class for each type of object (e.g. ship) that you want to have in your world. Adding Actors At the moment if you press the Run button nothing happens because we haven t added anything to the world so let s get started on that.

3 1. To create a new Actor right-click on the Actor class and pick the New Subclass option. 2. Call your new class Ship and choose the ship image provided (as show above). 3. Press the OK button and you have created your actor. 4. You should notice that your new class appears at the right hand side of the screen but it looks shaded out. This means that it needs to be compiled so press the compile button at the bottom of the screen. 5. Right click on the Ship class again and choose the new Ship() option. This will let you up an instance of your Ship class into the World as shown.

4 So far so good although if you press run you will probably notice that there is still nothing happening. This is because you haven t told it to do anything yet! However before we do that lets make another class, called Crate, to represent the crates the ship has to collect. Follow the same steps as before and you should end up with a scenario similar to the one shown below. Controlling Actors It is now time to consider what we want our actors to do. Our ultimate aim is to get the ship to move in response to the arrow keys but for now lets just get the ship to move in a straight line. 1. Double click on the Ship class on the right side of the screen to open the code editor as shown in the screenshot below.

5 This is where your class is named and you declare it as a subclass of Actor. These are comments that describe what your program does. They are not compiled. This is where you put the code that controls the behaviour of your actor 2. The act method is what tells your actor how to behave. For now all the code you write for the actor must go between the and brackets. If you put code outside these brackets it will not compile properly. As an experiment change your code to the following and try running it (remember you will need to compile it and add a new ship to the world before running it). public void act() // Add your action code here. move(10); NOTICE THE SEMICOLON AT THE END OF THE LINE YOU MUST INCLUDE IT Your ship should now move in a straight line. The move method simply moves your ship 10 cells in a straight line. Change the 10 to a larger number to speed up the ship or a lower one to slow it down. A value passed to a method like this is called a parameter as it tells the method something about what you want it to do. 3. Lets try getting the ship to move in a circle next. To do this we only need to tell the ship to turn and, convienently, there is a method called turn to do just that. Like the move method it also needs a parameter although in this case it is the number of degrees that you want to turn the actor. Try the following code. public void act() // Add your action code here. move (10); turn (10);

6 As before try changing the parameters to these methods to get the ship to move in different ways! Reading from the Keyboard We now have the ship moving in nicely but we have no control one the program has started. What we need to do is check when the arrow keys on the keyboard are pressed and then move the ship in the correct way. While you can come up with many different ways for the ship to behave we ll start with the one show in the table below. Key Up Down Left Right Behaviour Move 5 steps forward Move 5 steps backwards Turn 5 degrees to the left Turn 5 degrees to the right So the question is how do we know if one of the arrow keys is being pressed. Well fortunately Greenfoot provides a method for you to check that. It is called iskeydown and it takes one parameter the name of the key you are checking. So to check if the up key is pressed you would need to write the code below. Greenfoot.isKeyDown( up ); You might be wondering why we need to write Greenfoot. in front of the method name. This is because unlike the other methods we have used this one belongs to a different class so we need to tell the computer where it can find the method. On its own this code is still fairly useless because although it will check if the key is pressed it doesn t do anything if it is. To do that we must use something called an if statement. An if statement will check a condition, such as if the key is pressed, and if it is do something about it. So let s look at what the code to check the up arrow should look like. if ( something to check ) do something if ( Greenfoot.isKeyDown( up ) ) move (10); As you can see the code for an if statement is fairly straight forward. It simply checks the condition you put in the () brackets and if necessary does all the instructions you have put between the brackets. Note you don t put a semicolon at the end of an if statement. The final piece of the problem is to figure out how to move the ship backwards and right. The answer is surprisingly simple - use negative numbers. If move(10); moves you 10 cells forward then move(-10); will move you 10 cells back. It is very similar with the turn method. From here you should be able to figure out how to get the ship moving by yourself. You will need one if statement for each key you want to check and all the code will go into the act method don t

7 forget to remove the code you already have there. A solution is shown below but try it yourself first!! Once you have the code working be sure to adjust the parameters to the methods to make the ship move in the way you want! If you want to see something really odd then add more ships to the world and try it out. It looks like synchronised swimming to me! Do you know what is happening? public void act() // Add your action code here. if (Greenfoot.isKeyDown("up")) move (5); if (Greenfoot.isKeyDown("down")) move (-5); if (Greenfoot.isKeyDown("left")) turn(5); if (Greenfoot.isKeyDown("right")) turn(-5); Finished before everyone else? Why not add a quick turn button? You know the feeling there you are in a game you see the enemy coming and you can t quite turn around fast enough to get out of the way! Well this is your game so why not add an extra piece of code to Ships act method that will turn the ship 180 degrees when you press a key allowing you to make a quick escape! Finishing Up Show the presentation your group created at the start of the session. Remember the slide is only a summary and you should be prepared for some questions.

8 Session 2 Collision Detection in Ship World Authored by Brian Cullen (bcullen@rossettschool.co.uk) (c) Copyright 2011 Computing At School. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. See for details.

9 Colossus Super Computer During World War 2 both sides spent a lot of time trying to listen in on each other communications. This was made more difficult because both sides used codes to make it difficult for anyone else to read their messages. It was the job of the people who worked in Bletchley Park to break the German codes and they developed some of the world s earliest computers to help them do this. Of particular importance was a series of computers called Colossus. In pairs you are to find out as much information about the Colossus as you can. You will find a video about Colossus on the Bletchley Park website. It is amazing to think how far computers have come! Ship Game Part 2 In the last session we created two actors (Ship and Crate) and we got the ship moving in response to the keyboard. The next step is to make it so a ship can pick up crates and to do this we will need to check if the ship is touching a crate. Collision Detection Fortunately Greenfoot provides a number of methods that an actor can use to check this. The one we are going to use is called getoneintersectingobject and it takes a single parameter which tells it what type of actor you want it to check for. In our case we are looking for Crate actors so we would write. getoneintersectingobject (Crate.class); If this method finds that there is a crate intersecting (touching) the ship it tells us which one it is so we need to store that answer somewhere. To do this we make a variable - which is just a small piece of memory in the computer we give a name to. The code below tells the computers to set aside enough memory to hold an Actor and to call that piece of memory crate. It then takes the answer from the getoneintersectionobject method and stores it in that piece of memory. Actor crate = getoneintersectingobject (Crate.class); Now that we can store the answer in the computer s memory the next thing we need to do is check if the answer is empty. In Java if nothing is found the variable has a special value stored in it which is called null. So using an if statement we must check that the answer we got is not null (in an if statement!= means is not equal to). Actor crate = getoneintersectingobject (Crate.class); if (crate!= null) // we have hit a crate what do we do? The final step is to decide what we want to do to the crate when we hit it. The easiest thing to do is to just remove the crate from the world so that it is no longer on the screen. The world class has a method called removeobject to do this. However to call that method we must first have access to the world our game is running in and to do this we call the getworld method. The final code is as

10 follows so add it to the bottom of the act method for the ship (underneath where you check for key presses). Add some crates to the world and check that the ship can collect them. Actor crate = getoneintersectingobject (Crate.class); if (crate!= null) // we have hit a crate so we get access to the // world using the getworld() method and then // use the removeobject method to remove the // crate from the game. World shipworld = getworld(); shipworld.removeobject(crate); For a bit of extra flair it would be nice to make a sound every time you collect a crate. A sound file called cash-register.mp3 has been provided for this. To use it put the following line of code immediately after where you remove the crate from the world (it should still be in the brackets of the if statement). Once you have done this test it again to make sure it works. Greenfoot.playSound( cash-register.mp3 ); Adding Enemies A game like this wouldn t be any fun if you weren t avoiding enemies so let s make some. 1. Create a new class called Submarine using the image provided. Do this in the same way that you have created the Ship and Crate class previously. 2. Open up the code for the new Submarine class and get it running in circles like we did previously for the Ship. An example of the instructions you could use in the act method are shown below. move (5); turn (5);

11 3. If our ship is hit by one of the submarines we need the ship (not the submarine) to explode. While we could put the code for this into either the Submarine or the Ship class I recommend that we put it in the Ship class for now to keep all our collision detection code together. The code is the exact same as before except for the two changes noted below. Actor sub = getoneintersectingobject (Submarine.class); if (sub!= null) // we have hit a sub so we get access to the // world using the getworld() method and then // use the removeobject method to remove // the ship from the game. World shipworld = getworld(); shipworld.removeobject(this); You need to change this to the type of actor you are looking for now. This time we are not removing the thing we hit from the game but we are removing this ship. 4. To finish off this piece of code another sound file has been provided called kaboom.wav. You must add the line of code necessary to play the sound every time the ship hits a submarine. 5. Test the games and make sure your code works. Bonus Code: If you want everything to stop once your ship has exploded then use the Greenfoot.stop() method to do so. Automatically Resetting the Game While we still need to make the submarines move more realistically the last thing for today is to set the game up automatically rather than having to put the pieces on every time we reset. As this code will be setting up the world for the start of the game it needs to go in the ShipGameWorld class. 1. Open the ShipGameWorld class by double clicking on it. You will see a method with the same name as the class. This is called a constructor and it is called to setup the ShipGameWorld every time a new world is created. This is where we are going to put our code underneath the line that starts with the word super.

12 2. To add an actor to the world we call the addobject method. You need to provide 3 parameters for the method to work. The first is the new actor you want to add, the second is the how far across the screen you want to put it (x coordinate) and the third how far down the screen (y coordinate). You can see from the constructor that the world is 600 by 400 cells this means that the x coordinate can be between 0 and 600 and the y coordinate can be between 0 and 400. So for example if we wanted the ship to start at the centre of the world we could write the following code. addobject (new Ship(), 300, 200); 3. In the same way we can add submarines and crates wherever we want. An example of adding both is given below but you will want to add more. Once you are done test the game again and see what happens. addobject (new Submarine(), 100, 50); addobject(new Crate(), 400, 350); Finished before everyone else again? Well why not make your game that little bit harder! One way you could get the submarines to grab the crates if they get to them first. All you need to do is to add some collision detection code to the Submarine class to find when it hits a crate. You should know how to do that by now because you have already done it in the Ship class! If you want you could even get a new sound to play when they happens. You can use mp3 or wav files and you will have to save it in the sound folder of your scenario to use it. Comparing Values When you use an if statement in Java it looks at a condition and decides whether or not it is true. For example if you wrote the following the condition would be true because the numbers aren t equal. if (5!= 8) // Your code here When programming it is important to know how you can check values against each other. The most commonly used operators are shown below. It is your job to write a description of what each of them mean I have included the one we used earlier in this session to help you get started. Operator Example Description == value1 == value2!= value1!= value2 True is value1 and value2 are different. < value1 < value2 > value1 > value2 >= value1 >= value2 <= value1 <= value2

13 Session 3 Finishing the Ship Game Authored by Brian Cullen (bcullen@rossettschool.co.uk) (c) Copyright 2011 Computing At School. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. See for details.

14 Comparing Values Let s see what you can remember about comparing values from the last session. For each of the following statement you must figure out whether the statement is true or false. For the purposes of this exercise x = 6 and y = 10. Remember * means multiply and / means divide. Now let s get going Statement True or False? x == y x!= y (x+4)!= y y < x (x*2) > y (y 4) <= x x < y (x+7) >= (y+3) When you are finished compare your answers with a friend and make sure you agree before you present your answers to the rest of the class! Ship Game Part 3 So far our submarines only turn in a circle which really isn t very exciting. It would be much better if they went in a straight line until they hit the edge and then they turned around. So that is the first thing we care going to try and get working today. Making the Submarines Move Randomly To get the submarines to turn we need to be able to tell when they reach the edge of the screen and we can only do this by looking at their X and Y coordinates. Remember we have already seen that our world is defined as being 600 cells wide by 400 cells high. At this corner both X and Y are equal to zero (0,0) At this corner X is at it s biggest (599 in our world because it starts at 0) (599,0) X increases as you go to the right. Y increases as you go down At this corner Y is at it s biggest (399 in our world because it starts at 0) (0,399) At this corner both X and Y are at their biggest (599, 399).

15 So what we want to do is tell the computer to turn the ship 180 degrees if the X coordinate is 0 (which means it is on the left hand side) or 599 (which means it is on the right hand side). To do this we must use an if statement and the code should look like this. Declares a variable to hold a whole number (called an integer in maths which is shortened to int). public void act () move (5); int xcoord = getx(); if (xcoord <= 0 xcoord >= 599) turn (180); Gets the current X coordinate of the actor this must be called AFTER you move the submarine. Checks if the submarine has gone off the edge this is explained more below. There are a few new things in this code. First we are making a variable (a piece of memory) called xcoord and we are saying it is going to hold an integer (a whole number). It is very common to make integer variable so to save time they shortened it to int. The other thing I need to explain is the condition on the if statement it is as follows: xcoord <= 0 xcoord >= 599 XCoord is less than or equal to 0 OR xcoord is greater than or equal to 599 Hopefully you will already be familiar with the < (less than) and > (greater than signs) but the really new thing is using to say OR and this is really handy when you want to check a number of things at once. You can also use && to say AND although we don t need to do that here because the submarine can t be at both sides at the same time! Put this code into the Submarine class and test it. If it works then your ships will be bouncing back and forth across the world. While this is an improvement it isn t good enough because they are too easy to dodge. What we need is for the ships to turn unpredictably when they hit the edge. To do that we need to use random numbers and, again, Greenfoot makes this super easy for us by providing a method called Greenfoot.getRandomNumber. So for example to get a random number between 0 and 9 we would write Greenfoot.getRandomNumber(10); So how do we use this to turn our submarines? Well instead of always turning the submarines 180 degrees why don t we turn them 160 degrees plus a random number between 0 and 40? This will mean that every time a ship hits the edge it will turn a random number of degrees between 160 and 200 degrees. To do this change the code where it says turn(180); to the following. int random = Greenfoot.getRandomNumber (41); turn (160 + random);

16 Once you have changed the code test it and see what happens. Don t know if you have noticed but there is still one problem what happens when your ships reach the top or bottom of the screen or, more accurately, what doesn t happen? The ships don t turn around! This isn t surprising really because we never checked the Y coordinates anywhere. The code to do this will be almost the exact same as that we have just created to check the X coordinates. So, on your own this time, create the code to check if the Y coordinate is less than 0 or greater than 399 and turn the ship if it is. This code should go in the submarine act method just below the code that checks the X coordinate. Once you have done that you should have a fully working game so check it out! You might find the game is too easy or too hard. If that is the case then change the parameters of the game. Things you could try changing are the speed of your ship/the submarines or changing the number of the submarines that you start with. Run Out of Crates? After playing the game for a while I quickly ran out of crates to collect. It would be better to move crates to somewhere else instead of removing them from the game completely. To do this we must look at the code in the Ship class that removes the crates and change it. Currently the code should look like what is shown below and we need to remove the line where we use the removeobject method. Actor crate = getoneintersectingobject (Crate.class); if (crate!= null) World shipworld = getworld(); shipworld.removeobject(crate); Greenfoot.playSound ( cash-register.mp3 ); Instead of removing the crate we are going to use it s setlocation method to give it a new position in the game. Fortunately we have just learnt how to get random number so we can use this technique to make sure that the crate appears somewhere different each time it is created. To do this we use the getrandomnumber method to generate a random x and y coordinate. The final code should look like this. Actor crate = getoneintersectingobject (Crate.class); if (crate!= null) int xcoord = Greenfoot.getRandomNumber(600); int ycoord = Greenfoot.getRandomNumber(400); crate.setlocation(xcoord, ycoord); Greenfoot.playSound ( cash-register.mp3 ); Random Startup At the moment your ship, submarines and crates always start in the same places (the ones you set in the ShipGameWorld constructor). However now that you know how to use random numbers you

17 should be able to go back and change the constructor so that the ships start at different places each time you start the game. Try it on your own and see how you get on! Still looking for a challenge? Well this is a hard one so be warned! One thing you could add to make the game more interesting is to have the submarines change direction when they hit each other. To do this you will have to add some collision detection code to find when the submarines hit each other and then turn the submarines around. Good luck! Variable Types Java lets you store a variety of different types of information. Below is a table of the most common types that you might find yourself using. Use the internet or any resources you have try and find out what type of information you can store in each one. I have already filled in the row for the int data type but you won t need to be that detailed for all of them! Type byte short int long float double boolean char String Description A whole number (no decimal places) that can be either positive or negative. It uses 4 bytes of memory and can have a value from -2,147,483,648 to 2,147,483,647. Once you have collected this information discuss why you think there are so many different ways of storing numbers. The float and double data types need to be treated carefully because they do not store precise values what do you think this means and why could it be a problem?

18 Session 4 Starting the Air Raid Game Authored by Brian Cullen (bcullen@rossettschool.co.uk) (c) Copyright 2011 Computing At School. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. See for details.

19 Naming Conventions When writing code it is important to make it easy to understand and maintain. On most software projects there will be more than one person writing code so having a consistent way to name class, methods and variables makes it easier for them to work together. The Java Naming Conventions provide guidelines on how different names should be formatted and it is your task to find out what the rules are and provide an example for each of the following types of name. You can easily find this information on the web but in case you get stuck try the link provided. I have filled out the first of these as an example. Name Type Rule Example Class or Interface Should be in CamelCase. This is where AirRaidWorld the first letter of each new word is a capital and all spaces are removed. Method Variable Constants Name Conventions: Air Raid Game Today we are going to start a new game. In this game airplanes will fly across the top of the screen dropping supplies to enemy troops. You are in charge of a rocket launcher and it is your responsibility to destroy the crates before they hit the ground. To get started open the Air Raid scenario that you have been provided with. As you can see we already have two classes created for us. You should already be familiar with the purpose of the AirRaidWorld class from what we did before and we will use the StatusBoard class to display the players score but that is a little while off yet so we can ignore it for now. The two classes that have been created for us. The first step is to create classes for each type of object that we are going to have in the game. We will need at least the 4 classes listed below. It is important to realise that we only need a class for

20 each TYPE of object. This means that we only need to have one class for rockets even though we will be firing an awful lot of them. Object Plane Launcher Rocket Crate Description Represents the plan that flies across the top of the screen dropping the crates. Represents the rocket launcher that you control and the bottom of the screen. Represents the rockets you launch to try and shoot the crates and/or planes. Represents the crates that are dropped by the plane. So to get us started right click on the Actor class (on the right hand side) pick the New Subclass option and create a new subclass for each of these objects. You should notice that images have already been provided for each of them. Once you are finished your scenario should look something like that shown below although it won t do anything yet! Moving the Launcher The first job is to get the rocket launcher moving in response to the keys. This should be easier than the ship game because in this game we only want the launcher to move left and right along the bottom of the screen. To do this we must add the code to the act method of the Launcher class (to open the code double click on the class). 1. Write an if statement to check if the right arrow on the keyboard is being pressed exactly like the example below.

21 if ( Greenfoot.isKeyDown( right ) ) // Add your code to do something // if the right arrow is pressed here. 2. If the right arrow is being pressed we want to move the launcher 5 cells note that unless you turn an actor first the move method will move the actor towards the right of the screen. 3. Write an if statement to check if the left arrow on the keyboard is being pressed. 4. If the left arrow is being pressed we want to move the launcher 5 cells backwards (remember this should be a negative number). 5. Test that the code works and that you can move the launcher. Moving the Rocket Now we have got the launcher working we need to make sure that the Rocket class works. When we launch a rocket we want it to go straight up until it hits the top of the screen. Getting the rocket to move in a straight line should be simple for you by now. In the Rocket class act method write a single line of code telling it to move e.g. move(10);. When you test this code you will notice the problem. The rocket goes straight to the right edge of the screen rather than to the top. We should have known this because unless you turn an actor first it will always head towards the right hand side. So what we want to do is change the direction the rocket is pointing every time we make a new one. If you can remember we used a method like this to add actors to the ship game it was called a constructor. The constructor sets up things when we construct a new object of a class. To create a constructor for the Rocket class add the following code before the act method. public Rocket () setrotation (270); Our constructor simply does one thing which is turn the rocket 270 degrees clockwise which leaves it pointing at the top of the screen. If you test this code it should now fire the rocket at the top of the screen. Removing Rockets If, like me, you have fired a number of different rockets at the top of the screen you will have noticed that they get stuck there and don t disappear. That isn t really what we want to happen so let s think about how we can fix it. We already know we can get the world by calling getworld() and then use the removeobject method to remove something from the game. So far so good - but the question is how do we know when it has reached the top of the screen? Again we have done this before when we got the submarines to bounce off the sides of the screen can you remember what we checked to see if it was at the top of the screen?

22 In case you can t the answer is we checked if the y coordinate was less than or equal to zero. So we are going to do the same for the rocket and if it is we will remove it from the game! Remember the parameter for the removeobject method will be this because we want to remove the rocket we are controlling at the time. This code should go into the act method. int ycoord = gety(); if (ycoord <= 0) World airworld = getworld(); airworld.removeobject(this); Whenever you are writing a program it is really important to ensure that you always remove things that you no longer need. If you don t the computer will slow down as it runs out of memory and eventually crash! Anyway lets test this again and make sure it works. Firing from the Launcher Phew! We seem to have looked at a lot today but to finish off let s get the launcher firing the rockets. What we want to happen is that every time we press space a new rocket should be added to the game where the launcher is at that time. So let s give it a go 1. Write an if statement that checks if the space key is being pressed. 2. If the space key is pressed create a new variable called airworld and store the result of using the getworld() method into it. airworld.addobject(new Rocket(), getx(), gety()); 3. Use the addobject method as shown above to add the rocket to the game. This should look familiar from when we added the ships and submarines to the ship game. Notice how we use getx and gety to find the current position of the launcher and use that as the starting position for the rocket. 4. A sound called RocketTakeoff.mp3 has been provided. If you want to use it add the code to play it after the addobject method. 5. Test it it will work but not perfectly. As I have already said the last piece of code that you have created will not work perfectly. Can you explain what is going wrong and how you might try and fix it? Present your ideas to others in the class and see if you agree!

23 Session 5 Making the Planes Work Authored by Brian Cullen (bcullen@rossettschool.co.uk) (c) Copyright 2011 Computing At School. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. See for details.

24 Understanding the Greenfoot API Throughout these sessions we have been using class and methods provided by Greenfoot. It is important for you to be able to find these methods on your own. Java classes are usually documented as a series of linked webpages and the Greenfoot class are no different. To see the documentation for the World class double click on it at the right hand side of the screen. Here you can see a list of all the methods in the World class with a brief explanation of what they do. To see all the classes that Greenfoot provides click the Package link in the top left corner of the browser window that opens. To help you explore I want you to find the following methods and copy the explanation of what they do into the table below. Class Method Description Actor getobjectsinrange Greenfoot getobjects GreenfootImage mirrorhorizontally Greenfoot mouseclicked Air Raid Game Part 2 So did you figure out what was causing the problem with firing the rockets? What is happening is that the act method is called so quickly that it is almost impossible to press and let go of the space key without more than one rocket being fired! The simplest solution to this is to introduce a time delay between firing rockets so that s what we are going to try. However before we think about the code let s say what we want to do in plain English. When we press space to fire a rocket we want to set a delay so that for the next 25 times the act method runs we don t fire again. So let s get on with it 1. Add a class property to hold the delay counter. A class property is just a variable that you make for the entire class to use. You declare it as shown below just after the start of your class. In our case it will be an integer because we just want it to hold numbers between 0 and 25. We say it is private because we don t want any other classes using this information. Finally we give it a starting value of 0. public class Launcher extends Actor private int delay = 0; rest of your class 2. In the act method check if the delay counter is greater than zero and if it is reduce the value of the counter by one.

25 if (delay > 0) delay = delay 1; 3. We now need to make sure that we don t fire a rocket if delay is not zero. The easiest way to do this is to change the if statement above to include an else clause. This means that if delay is greater than zero the delay is reduced otherwise it does what is in the else part of the if statement. if (delay > 0) delay = delay 1; else // What do you want to do if // delay is zero check if space // is pressed. 4. The final step is to set the delay to 25 once you fire a rocket. By changing this number you will change the delay between rockets. The final code is shown below including the code for firing a rocket that you already made (this should replace that code otherwise you will be firing twice). if (delay > 0) delay = delay - 1; else if (Greenfoot.isKeyDown("space")) World airworld = getworld(); airworld.addobject(new Rocket(), getx(), gety()); Greenfoot.playSound("RocketTakeoff.mp3"); delay = 25; 5. Test it and make sure the code works. Falling Crates Having got the launcher and rockets working we now need to change the Crate class so that crates fall to the bottom of the screen and disappear when they hit the bottom. The code will be almost exactly the same as the Rocket class so I m not going to go through it in detail. The main differences

26 are that you want to set the rotation to 90 degrees and you will want to remove the crate when the Y coordinate is greater than or equal to 399 (as opposed to less than or equal to zero for the rocket). Using the Rocket class as a guide try and edit this code yourself and test that it works. Moving the Plane and Dropping Crates The last class we have to edit is the Plane class. As a starting point we simply want the plane to go back and forth across the top of the screen. We have already written the code for this when we initially got the submarines moving so if you are unsure have a look back at that. The final code in the planes act method should look like this. move (5); int xcoord = getx(); if (xcoord <= 0 xcoord >= 599) turn (180); We now need to decide how often we want the plane to drop a crate. We could use a delay and just drop one every few seconds but a better solution would be to drop them randomly. We can do this by generating random numbers and only dropping a crate if the number is a 1. So if we generated a random number between 0 and 100 then there is a 1% chance that we will drop a crate each time the act method is called. The if statement for this would be as follows. int rand = Greenfoot.getRandomNumber(100); if (rand == 1) // Get the world and add a new crate // the same way you added a new // rocket for the launcher. Using the code for creating rockets in the Launcher class as a guide you should be able to add the code to make a new crate to this if statement and add the completed code to the act method of the plane. Once you have test it works. Finished early and looking for something to improve? Why don t you consider changing some of the graphics used in the game? In particular the background could be improved. To change the background you must first get an image of the right size (remember the world is 600 by 400). You must then right click on the AirRaidWorld class and choose the setimage option. Java API Having looked at the Greenfoot API at the start of the lesson why don t you have a look at the Java API to finish up. It is a LOT bigger and more complicated but the layout is the same and you should be able to find your way around. The Java1.7 API is at

27 One class it might be worth looking up is the java.awt.color class as you may need to use it to change the colour of text and backgrounds in the future. See if you can find it!

28 Session 6 Collision Detection and Keeping Score Authored by Brian Cullen (bcullen@rossettschool.co.uk) (c) Copyright 2011 Computing At School. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. See for details.

29 Commenting our Methods In the last session we looked at the API for classes written by other people but we need to provide this type of information for our classes as well. To do this we must write comments into our code to explain the purpose of each method. By default Greenfoot provides the following comment for the act method of each class. /** * Act - do whatever the Actor wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() Change this comment to say what your act method does in each of the classes you have made. You can then view what the documentation looks like by choosing documentation from the drop down list in the top right hand corner of the screen. Continuing with the Air Raid Game Collision Detection We have already done simple collision detection so checking if the rocket is hitting a crate or plane should be something you are familiar with. However because we now have more than one condition that can cause a rocket to be removed from the game we have to make sure we don t try and remove it twice as this will cause our game to crash! In general the code to check if the rocket has hit another object and remove them both from the game will look like this (for this example I have used the Crate class). To make sure we don t remove the rocket twice the rest of the code will be put in an else block so it is only executed if you haven t hit a crate. Actor actor = getoneintersectingobject (Crate.class); if (actor!= null) World airworld = getworld(); airworld.removeobject (actor); // remove the crate airworld.removeobject (this); // remove the rocket // play sounds or anything else else // Code to check if you have hit the plane or the top of // the screen goes here. If you don t get this right it is likely that you game will crash and you will get a nasty looking error message. While you should see if you can construct this code on your own the final version of the act method in my version of the Rocket class is shown below. You will notice that I m playing a sound called explosion.mp3 every time I blow something up so you can add this too if you want.

30 Deal with hitting a crate. Else deal with hitting a plane. Else deal with hitting the top of the screen. Automatic Setup So far we have been putting the plane and launcher into the world manually which is a bit of a pain. To make things easier we are going to edit the constructor of the AirRaidWorld class so that it puts both of these things on automatically (if you haven t done it already). Double click on the AirRaidWorld class and add the following two lines of code to the constructor. addobject (new Launcher(), 300, 375); addobject (new Plane (), 100, 30); Keeping Score One thing we haven t looked at yet is how to keep score something that you need to do in almost every game! Probably the best place to store this information is in the AirRaidWorld class as the score is a piece of information that applies to the entire game. To do scores properly we will need to provide a variable to store the score in, a way to increase the score and a way to check what the current score is. So lets get started 1. In the AirRaidWorld class add a new private property called score. It is private because we want other classes to have to ask us to change the score rather than then changing it themselves. public class AirRaidWorld extends World private int score = 0; rest of your class

31 2. We are now going to write a method that can be used to increase the score. Note that this method must be public because it is to be used by other classes. public void increasescore () score = score + 1; // could just write score++; which does the same thing. 3. The final thing we need to do is provide other classes with a way of seeing what the current score is. To do this we are going to add another public method. Notice that instead of saying void like last time we say int to show that the method is going to return an integer. We use the return statement to say we want to give this value to the class using the method. public int getscore () return score; After you have finished making these changes the final code for your AirRaidWorldClass should look like this. Now that we have a way of keeping score we need to increase it when we hit a crate or plane. To do this we must go back into the Rocket class and change our collision detection code a little. At the moment our collision detection code looks like the example below.

32 Actor act = getoneintersectingobject (Crate.class); if (actor!= null) World airworld = getworld(); airworld.removeobject (actor); // remove the crate airworld.removeobject (this); // remove the rocket // play sounds or anything else What we need to do is call the increasescore method that we have just made when we are removing the objects from the game. Unfortunately it is not quite as simple as writing the following line of code although it is very close. airworld.increasescore(); The problem is that we have said that airworld is made from the World class and the increasescore method is only in the AirRaidWorld class. So what we need to do is tell the computer that the world we are in is actually made from the AirRaidWorld class. We do that by putting (AirRaidWorld) in front of the getworld method. An example of the complete code is shown in the box below. You will need to change this is two places in the Rocket class once for when you are checking for crates and once for when you are checking for planes. Actor act = getoneintersectingobject (Crate.class); if (actor!= null) AirRaidWorld airworld = (AirRaidWorld)getWorld(); airworld.removeobject (actor); // remove the crate airworld.removeobject (this); // remove the rocket airworld.increasescore(); // play sounds or anything else As we haven t hooked up our score board yet the easiest way to check the score is working is to play the game for a while and then pause it. You can then right click on the background and choose getscore, as shown in the screenshot below, to see what your current score is. Try it!

33 Further Documenting Your Code Having written comments explaining what each of your act methods do you should now add comments for each of your other methods. Once finished swap with a partner and see if their comments make sense do they give enough or too much detail? Are the comments helpful?

34 Session 7 Counting Lives and Displaying the Score Authored by Brian Cullen (bcullen@rossettschool.co.uk) (c) Copyright 2011 Computing At School. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. See for details.

35 Commenting the Code Having used comments to explain all your methods in the last session you probably think that is all the comments you could need but you d be wrong. Some methods can do very complicated things that may need to be explained further. Throughout these sessions you might have noticed I have put in comments using starting with two slashes i.e. //. When Java comes across these it will ignore what you have written on the rest of the line so you can write text to explain the code. Working in pairs you should go back over the code you have written so far and see if there is anything that might be hard for someone to understand. If there is put in a comment to help them understand WHY you need that code. Do you think it is possible to have too many comments? Tracking Lives Tracking lives is very like keeping score although instead of counting up you are counting down! As with the score the number of lives you have left should probably be stored in the World and we will need methods to both decrease the number of lives and find out how many you have left. The code is almost exactly the same as for the score and the final code added to my game is as follows. private int lives = 5; // number of lives to start with. public void loselife () lives = lives 1; //could write lives --; public int getlives() return lives; The next decision we need to make is when we lose a life. It seems sensible to lose a life each time a crate makes it to the bottom of the screen. This makes things easy for us because we already have code that checks for when that happens. Remember writing code in the crate class to remove it when it hit the bottom of the screen? So open the Crate class and find where you check if it has hit the bottom of the screen. We need to change this code in a similar way to the way we had to change the collision detection to keep the score. We must first tell the computer that we want an AirRaidWorld and then add a line calling the loselife method. The altered code should look like this. if (ycoord >= 399) AirRaidWorld World airworld = (AirRaidWorld)getWorld(); airworld.removeobject (this); airworld.loselife();

36 Once you have changed the code test it in the same way you tested the score previously. If you have tested it properly you have probably seen the number of lives you have go into negative figures. This is because we have never told the game to stop when we reach zero! The easiest (but maybe not the best) place for us to do this is in the loselife method. All we need to add is a simple if statement that checks if the number of lives left is zero and calls the Greenfoot.stop method if it is. The following lines of code are all you need to add. If you test this code the game should stop after 5 crates have hit the bottom of the screen. if (lives == 0) Greenfoot.stop(); Using the Scoreboard Now that we are keeping track of the score and how many lives are left it would be nice to display that information on the screen. If you remember way back at the start of this game I told you that the StatusBoard class had been provided to show this information on the screen and it is now time that we use it! This class has one method that we are interested in called updatestatus which simply takes the score and number of lives to display on the screen. We will need to call this method every time we change the score or the number of lives we have left. Happily this will be really easy because the only place the score is changed is in the increasescore method and the only place the number of lives is changed is in the loselife method. However to get started we need to create the score board from the class and put it into the world. 1. Create a new private property for the AirRaidWorld class to hold the score board in memory. private StatusBoard scoreboard; 2. In the constructor make the new score board and put in into the world by calling the addobject method. The code required to do this is show below. scoreboard = new StatusBoard (); addobject (scoreboard, 0, 370); scoreboard.updatestatus (score, lives); 3. Add calls to the updatestatus method into both the increasescore and loselife methods. The line you need to add to both methods is shown below. scoreboard.updatestatus(score, lives); 4. Test it and make sure that it works.

Session 4 Starting the Air Raid Game

Session 4 Starting the Air Raid Game Session 4 Starting the Air Raid Game Authored by Brian Cullen (bcullen@rossettschool.co.uk/@mrbcullen) (c) Copyright 2011 Computing At School. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike

More information

Session 8 Finishing Touches to the Air Raid Game

Session 8 Finishing Touches to the Air Raid Game Session 8 Finishing Touches to the Air Raid Game Authored by Brian Cullen (bcullen@rossettschool.co.uk/@mrbcullen) (c) Copyright 2011 Computing At School. This work is licensed under the Creative Commons

More information

Improving the Crab more sophisticated programming

Improving the Crab more sophisticated programming CHAPTER 3 Improving the Crab more sophisticated programming topics: concepts: random behavior, keyboard control, sound dot notation, random numbers, defining methods, comments In the previous chapter,

More information

Improving the crab: more sophisticated programming

Improving the crab: more sophisticated programming Chapter 3 Improving the crab: more sophisticated programming topics: concepts: random behavior, keyboard control, sound dot notation, random numbers, defining methods, comments In the previous chapter,

More information

Constants are named in ALL_CAPS, using upper case letters and underscores in their names.

Constants are named in ALL_CAPS, using upper case letters and underscores in their names. Naming conventions in Java The method signature Invoking methods All class names are capitalized Variable names and method names start with a lower case letter, but every word in the name after the first

More information

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet. Mr G s Java Jive #2: Yo! Our First Program With this handout you ll write your first program, which we ll call Yo. Programs, Classes, and Objects, Oh My! People regularly refer to Java as a language that

More information

Creating Java Programs with Greenfoot

Creating Java Programs with Greenfoot Creating Java Programs with Greenfoot Working with Source Code and Documentation 1 Copyright 2012, Oracle and/or its affiliates. All rights Objectives This lesson covers the following topics: Demonstrate

More information

The first program: Little Crab

The first program: Little Crab Chapter 2 The first program: Little Crab topics: concepts: writing code: movement, turning, reacting to the screen edges source code, method call, parameter, sequence, if-statement In the previous chapter,

More information

[ the academy_of_code] Senior Beginners

[ the academy_of_code] Senior Beginners [ the academy_of_code] Senior Beginners 1 Drawing Circles First step open Processing Open Processing by clicking on the Processing icon (that s the white P on the blue background your teacher will tell

More information

Excel Basics: Working with Spreadsheets

Excel Basics: Working with Spreadsheets Excel Basics: Working with Spreadsheets E 890 / 1 Unravel the Mysteries of Cells, Rows, Ranges, Formulas and More Spreadsheets are all about numbers: they help us keep track of figures and make calculations.

More information

4. Java Project Design, Input Methods

4. Java Project Design, Input Methods 4-1 4. Java Project Design, Input Methods Review and Preview You should now be fairly comfortable with creating, compiling and running simple Java projects. In this class, we continue learning new Java

More information

ISY00245 Principles of Programming. Module 7

ISY00245 Principles of Programming. Module 7 ISY00245 Principles of Programming Module 7 Module 7 Loops and Arrays Introduction This week we have gone through some of the concepts in your lecture, and will be putting them in to practice (as well

More information

XP: Backup Your Important Files for Safety

XP: Backup Your Important Files for Safety XP: Backup Your Important Files for Safety X 380 / 1 Protect Your Personal Files Against Accidental Loss with XP s Backup Wizard Your computer contains a great many important files, but when it comes to

More information

Creating Java Programs with Greenfoot

Creating Java Programs with Greenfoot Creating Java Programs with Greenfoot Using Randomization and Understanding Dot Notation and Constructors 1 Copyright 2012, Oracle and/or its affiliates. All rights Overview This lesson covers the following

More information

BEGINNER PHP Table of Contents

BEGINNER PHP Table of Contents Table of Contents 4 5 6 7 8 9 0 Introduction Getting Setup Your first PHP webpage Working with text Talking to the user Comparison & If statements If & Else Cleaning up the game Remembering values Finishing

More information

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)... Remembering numbers (and other stuff)... Let s talk about one of the most important things in any programming language. It s called a variable. Don t let the name scare you. What it does is really simple.

More information

the NXT-G programming environment

the NXT-G programming environment 2 the NXT-G programming environment This chapter takes a close look at the NXT-G programming environment and presents a few simple programs. The NXT-G programming environment is fairly complex, with lots

More information

How to approach a computational problem

How to approach a computational problem How to approach a computational problem A lot of people find computer programming difficult, especially when they first get started with it. Sometimes the problems are problems specifically related to

More information

Major Assignment: Pacman Game

Major Assignment: Pacman Game Major Assignment: Pacman Game 300580 Programming Fundamentals Week 10 Assignment The major assignment involves producing a Pacman style game with Clara using the Greenfoot files that are given to you.

More information

About Technocamps. We go around schools and show you lots of interesting stuff! We also do things we call bootcamps during holidays!

About Technocamps. We go around schools and show you lots of interesting stuff! We also do things we call bootcamps during holidays! Greenfoot About Technocamps We go around schools and show you lots of interesting stuff! We also do things we call bootcamps during holidays! Pre-day Questionnaires This is a Computer What do computers

More information

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA 1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared

More information

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Table of Contents Introduction!... 1 Part 1: Entering Data!... 2 1.a: Typing!... 2 1.b: Editing

More information

Rescuing Lost Files from CDs and DVDs

Rescuing Lost Files from CDs and DVDs Rescuing Lost Files from CDs and DVDs R 200 / 1 Damaged CD? No Problem Let this Clever Software Recover Your Files! CDs and DVDs are among the most reliable types of computer disk to use for storing your

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

Animation Workshop. Support Files. Advanced CODING CHALLENGE - ADVANCED

Animation Workshop. Support Files. Advanced CODING CHALLENGE - ADVANCED Animation Workshop Support Files Greenfoot Application: Greenfoot.org/download Greenfoot Reference: Greenfoot.org/files/javadoc/Greenfoot/package-summary Template: Scholastic.com/samsungacademy/resources/animation.zip

More information

Variables and Data Representation

Variables and Data Representation You will recall that a computer program is a set of instructions that tell a computer how to transform a given set of input into a specific output. Any program, procedural, event driven or object oriented

More information

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed

More information

Burning CDs in Windows XP

Burning CDs in Windows XP B 770 / 1 Make CD Burning a Breeze with Windows XP's Built-in Tools If your PC is equipped with a rewritable CD drive you ve almost certainly got some specialised software for copying files to CDs. If

More information

Text Input and Conditionals

Text Input and Conditionals Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()

More information

Assignment 6: Dodo keeps getting smarter

Assignment 6: Dodo keeps getting smarter Assignment 6: Dodo keeps getting smarter Algorithmic Thinking and Structured Programming (in Greenfoot) c 2015 Renske Smetsers-Weeda & Sjaak Smetsers Licensed under the Creative Commons Attribution 4.0

More information

MITOCW watch?v=0jljzrnhwoi

MITOCW watch?v=0jljzrnhwoi MITOCW watch?v=0jljzrnhwoi The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To

More information

University of Hull Department of Computer Science C4DI Interfacing with Arduinos

University of Hull Department of Computer Science C4DI Interfacing with Arduinos Introduction Welcome to our Arduino hardware sessions. University of Hull Department of Computer Science C4DI Interfacing with Arduinos Vsn. 1.0 Rob Miles 2014 Please follow the instructions carefully.

More information

These are notes for the third lecture; if statements and loops.

These are notes for the third lecture; if statements and loops. These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern

More information

Your . A setup guide. Last updated March 7, Kingsford Avenue, Glasgow G44 3EU

Your  . A setup guide. Last updated March 7, Kingsford Avenue, Glasgow G44 3EU fuzzylime WE KNOW DESIGN WEB DESIGN AND CONTENT MANAGEMENT 19 Kingsford Avenue, Glasgow G44 3EU 0141 416 1040 hello@fuzzylime.co.uk www.fuzzylime.co.uk Your email A setup guide Last updated March 7, 2017

More information

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

More information

Assignment 4: Dodo gets smarter

Assignment 4: Dodo gets smarter Assignment 4: Dodo gets smarter Algorithmic Thinking and Structured Programming (in Greenfoot) 2017 Renske Smetsers-Weeda & Sjaak Smetsers 1 Contents Introduction 1 Learning objectives 1 Instructions 1

More information

Keep Track of Your Passwords Easily

Keep Track of Your Passwords Easily Keep Track of Your Passwords Easily K 100 / 1 The Useful Free Program that Means You ll Never Forget a Password Again These days, everything you do seems to involve a username, a password or a reference

More information

asteroids-day 3 Class Space

asteroids-day 3 Class Space Class Space // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import greenfoot.*; * Space -- something for rockets to fly in. * * @author Prof. Carl B. Struck * @version November 2010 public class

More information

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014 Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class

More information

Word: Print Address Labels Using Mail Merge

Word: Print Address Labels Using Mail Merge Word: Print Address Labels Using Mail Merge No Typing! The Quick and Easy Way to Print Sheets of Address Labels Here at PC Knowledge for Seniors we re often asked how to print sticky address labels in

More information

Taskbar: Working with Several Windows at Once

Taskbar: Working with Several Windows at Once Taskbar: Working with Several Windows at Once Your Best Friend at the Bottom of the Screen How to Make the Most of Your Taskbar The taskbar is the wide bar that stretches across the bottom of your screen,

More information

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms Faculty of Mathematics Waterloo, Ontario N2L 3G1 Centre for Education in Mathematics and Computing Relations Let s talk about relations! Grade 6 Math Circles November 6 & 7 2018 Relations, Functions, and

More information

(Refer Slide Time: 06:01)

(Refer Slide Time: 06:01) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 28 Applications of DFS Today we are going to be talking about

More information

Lecture 1: Overview

Lecture 1: Overview 15-150 Lecture 1: Overview Lecture by Stefan Muller May 21, 2018 Welcome to 15-150! Today s lecture was an overview that showed the highlights of everything you re learning this semester, which also meant

More information

D - Tic Tac Toe. Let's use our 9 sparkles to build a tic tac toe game! 2017 courses.techcamp.org.uk/ Page 1 of 9

D - Tic Tac Toe. Let's use our 9 sparkles to build a tic tac toe game! 2017 courses.techcamp.org.uk/ Page 1 of 9 D - Tic Tac Toe Let's use our 9 sparkles to build a tic tac toe game! 2017 courses.techcamp.org.uk/ Page 1 of 9 INTRODUCTION Let's use our 9 sparkles to build a tic tac toe game! Step 1 Assemble the Robot

More information

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle Boggle If you are not familiar with the game Boggle, the game is played with 16 dice that have letters on all faces. The dice are randomly deposited into a four-by-four grid so that the players see the

More information

Chapter 1 Operations With Numbers

Chapter 1 Operations With Numbers Chapter 1 Operations With Numbers Part I Negative Numbers You may already know what negative numbers are, but even if you don t, then you have probably seen them several times over the past few days. If

More information

Clean & Speed Up Windows with AWO

Clean & Speed Up Windows with AWO Clean & Speed Up Windows with AWO C 400 / 1 Manage Windows with this Powerful Collection of System Tools Every version of Windows comes with at least a few programs for managing different aspects of your

More information

Printing Envelopes in Microsoft Word

Printing Envelopes in Microsoft Word Printing Envelopes in Microsoft Word P 730 / 1 Stop Addressing Envelopes by Hand Let Word Print Them for You! One of the most common uses of Microsoft Word is for writing letters. With very little effort

More information

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0. L J Howell UX Software Ver. 1.0

VISUAL GUIDE to. RX Scripting. for Roulette Xtreme - System Designer 2.0. L J Howell UX Software Ver. 1.0 VISUAL GUIDE to RX Scripting for Roulette Xtreme - System Designer 2.0 L J Howell UX Software 2009 Ver. 1.0 TABLE OF CONTENTS INTRODUCTION...ii What is this book about?... iii How to use this book... iii

More information

DESIGN YOUR OWN BUSINESS CARDS

DESIGN YOUR OWN BUSINESS CARDS DESIGN YOUR OWN BUSINESS CARDS USING VISTA PRINT FREE CARDS I m sure we ve all seen and probably bought the free business cards from Vista print by now. What most people don t realize is that you can customize

More information

Assignment 3: Optimizing solutions

Assignment 3: Optimizing solutions Assignment 3: Optimizing solutions Algorithmic Thinking and Structured Programming (in Greenfoot) c 2015 Renske Smetsers-Weeda & Sjaak Smetsers Licensed under the Creative Commons Attribution 4.0 license,

More information

Have the students look at the editor on their computers. Refer to overhead projector as necessary.

Have the students look at the editor on their computers. Refer to overhead projector as necessary. Intro to Programming (Time 15 minutes) Open the programming tool of your choice: If you ve installed, DrRacket, double-click the application to launch it. If you are using the online-tool, click here to

More information

Assignment Definition And General Feedback By Michael Panitz at Cascadia Community College (

Assignment Definition And General Feedback By Michael Panitz at Cascadia Community College ( For Loops: Will Tanna Assignment Definition And General Feedback By Michael Panitz at Cascadia Community College (http://www.cascadia.edu) Table of contents: Summary When To Use and Avoid This Example

More information

Assignment 0. Nothing here to hand in

Assignment 0. Nothing here to hand in Assignment 0 Nothing here to hand in The questions here have solutions attached. Follow the solutions to see what to do, if you cannot otherwise guess. Though there is nothing here to hand in, it is very

More information

Table of Laplace Transforms

Table of Laplace Transforms Table of Laplace Transforms 1 1 2 3 4, p > -1 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Heaviside Function 27 28. Dirac Delta Function 29 30. 31 32. 1 33 34. 35 36. 37 Laplace Transforms

More information

(Refer Slide Time: 02.06)

(Refer Slide Time: 02.06) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 27 Depth First Search (DFS) Today we are going to be talking

More information

EEN118 LAB FOUR. h = v t ½ g t 2

EEN118 LAB FOUR. h = v t ½ g t 2 EEN118 LAB FOUR In this lab you will be performing a simulation of a physical system, shooting a projectile from a cannon and working out where it will land. Although this is not a very complicated physical

More information

Animations involving numbers

Animations involving numbers 136 Chapter 8 Animations involving numbers 8.1 Model and view The examples of Chapter 6 all compute the next picture in the animation from the previous picture. This turns out to be a rather restrictive

More information

AN INTRODUCTION PROGRAMMING. Simon Long

AN INTRODUCTION PROGRAMMING. Simon Long AN INTRODUCTION & GUI TO PROGRAMMING Simon Long 2 3 First published in 2019 by Raspberry Pi Trading Ltd, Maurice Wilkes Building, St. John's Innovation Park, Cowley Road, Cambridge, CB4 0DS Publishing

More information

EEN118 LAB FOUR. h = v t ½ g t 2

EEN118 LAB FOUR. h = v t ½ g t 2 EEN118 LAB FOUR In this lab you will be performing a simulation of a physical system, shooting a projectile from a cannon and working out where it will land. Although this is not a very complicated physical

More information

1.7 Limit of a Function

1.7 Limit of a Function 1.7 Limit of a Function We will discuss the following in this section: 1. Limit Notation 2. Finding a it numerically 3. Right and Left Hand Limits 4. Infinite Limits Consider the following graph Notation:

More information

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications Hello World! Computer Programming for Kids and Other Beginners by Warren Sande and Carter Sande Chapter 1 Copyright 2009 Manning Publications brief contents Preface xiii Acknowledgments xix About this

More information

Interface. 2. Interface Adobe InDesign CS2 H O T

Interface. 2. Interface Adobe InDesign CS2 H O T 2. Interface Adobe InDesign CS2 H O T 2 Interface The Welcome Screen Interface Overview The Toolbox Toolbox Fly-Out Menus InDesign Palettes Collapsing and Grouping Palettes Moving and Resizing Docked or

More information

the rules The Goal Get all three of your monkeys around the board and into the Banana Grove before anyone else can!

the rules The Goal Get all three of your monkeys around the board and into the Banana Grove before anyone else can! the rules Equipment Code Monkey Island Gameboard, 12 monkey figurines (three of each color), 54 Guide cards, 16 Fruit cards, 10 Boost in a Bottle cards. The Goal Get all three of your monkeys around the

More information

CS 142 Style Guide Grading and Details

CS 142 Style Guide Grading and Details CS 142 Style Guide Grading and Details In the English language, there are many different ways to convey a message or idea: some ways are acceptable, whereas others are not. Similarly, there are acceptable

More information

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. Today! Build HelloWorld yourself in BlueJ and Eclipse. Look at all the Java keywords. Primitive Types. HelloWorld in BlueJ 1. Find BlueJ in the start menu, but start the Select VM program instead (you

More information

LOOPS. Repetition using the while statement

LOOPS. Repetition using the while statement 1 LOOPS Loops are an extremely useful feature in any programming language. They allow you to direct the computer to execute certain statements more than once. In Python, there are two kinds of loops: while

More information

Mr G s Java Jive. #11: Formatting Numbers

Mr G s Java Jive. #11: Formatting Numbers Mr G s Java Jive #11: Formatting Numbers Now that we ve started using double values, we re bound to run into the question of just how many decimal places we want to show. This where we get to deal with

More information

OrbBasic Lesson 1 Goto and Variables: Student Guide

OrbBasic Lesson 1 Goto and Variables: Student Guide OrbBasic Lesson 1 Goto and Variables: Student Guide Sphero MacroLab is a really cool app to give the Sphero commands, but it s limited in what it can do. You give it a list of commands and it starts at

More information

Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017

Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017 Due: Wednesday, October 18, 11:59 pm Collaboration Policy: Level 1 Group Policy: Pair-Optional Lab 4: Super Sudoku Solver CSCI 2101 Fall 2017 In this week s lab, you will write a program that can solve

More information

HOUR 4 Understanding Events

HOUR 4 Understanding Events HOUR 4 Understanding Events It s fairly easy to produce an attractive interface for an application using Visual Basic.NET s integrated design tools. You can create beautiful forms that have buttons to

More information

Welcome Back! Without further delay, let s get started! First Things First. If you haven t done it already, download Turbo Lister from ebay.

Welcome Back! Without further delay, let s get started! First Things First. If you haven t done it already, download Turbo Lister from ebay. Welcome Back! Now that we ve covered the basics on how to use templates and how to customise them, it s time to learn some more advanced techniques that will help you create outstanding ebay listings!

More information

EEN118 LAB FOUR. h = v t ½ g t 2

EEN118 LAB FOUR. h = v t ½ g t 2 EEN118 LAB FOUR In this lab you will be performing a simulation of a physical system, shooting a projectile from a cannon and working out where it will land. Although this is not a very complicated physical

More information

printf( Please enter another number: ); scanf( %d, &num2);

printf( Please enter another number: ); scanf( %d, &num2); CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

More information

Programming Project 1

Programming Project 1 Programming Project 1 Handout 6 CSCI 134: Fall, 2016 Guidelines A programming project is a laboratory that you complete on your own, without the help of others. It is a form of take-home exam. You may

More information

Introduction to Programming with JES

Introduction to Programming with JES Introduction to Programming with JES Titus Winters & Josef Spjut October 6, 2005 1 Introduction First off, welcome to UCR, and congratulations on becoming a Computer Engineering major. Excellent choice.

More information

Yup, left blank on purpose. You can use it to draw whatever you want :-)

Yup, left blank on purpose. You can use it to draw whatever you want :-) Yup, left blank on purpose. You can use it to draw whatever you want :-) Chapter 1 The task I have assigned myself is not an easy one; teach C.O.F.F.E.E. Not the beverage of course, but the scripting language

More information

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. Lesson 2 VARIABLES Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. WHAT ARE VARIABLES? When you input data (i.e. information) into a computer

More information

Unit 4: Multiplication

Unit 4: Multiplication Math Fundamentals for Statistics I (Math 52) Unit 4: Multiplication By Scott Fallstrom and Brent Pickett The How and Whys Guys This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike

More information

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to:

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to: Get JAVA To compile programs you need the JDK (Java Development Kit). To RUN programs you need the JRE (Java Runtime Environment). This download will get BOTH of them, so that you will be able to both

More information

EEN118 LAB FOUR. h = v t - ½ g t 2

EEN118 LAB FOUR. h = v t - ½ g t 2 EEN118 LAB FOUR In this lab you will be performing a simulation of a physical system, shooting a projectile from a cannon and working out where it will land. Although this is not a very complicated physical

More information

OrbBasic 1: Student Guide

OrbBasic 1: Student Guide OrbBasic 1: Student Guide Sphero MacroLab is a really cool app to give the Sphero commands, but it s limited in what it can do. You give it a list of commands and it starts at the top and goes to the bottom,

More information

Mobile Computing Professor Pushpedra Singh Indraprasth Institute of Information Technology Delhi Andriod Development Lecture 09

Mobile Computing Professor Pushpedra Singh Indraprasth Institute of Information Technology Delhi Andriod Development Lecture 09 Mobile Computing Professor Pushpedra Singh Indraprasth Institute of Information Technology Delhi Andriod Development Lecture 09 Hello, today we will create another application called a math quiz. This

More information

Pong in Unity a basic Intro

Pong in Unity a basic Intro This tutorial recreates the classic game Pong, for those unfamiliar with the game, shame on you what have you been doing, living under a rock?! Go google it. Go on. For those that now know the game, this

More information

Lab 9: Pointers and arrays

Lab 9: Pointers and arrays CMSC160 Intro to Algorithmic Design Blaheta Lab 9: Pointers and arrays 3 Nov 2011 As promised, we ll spend today working on using pointers and arrays, leading up to a game you ll write that heavily involves

More information

Coding Workshop. Learning to Program with an Arduino. Lecture Notes. Programming Introduction Values Assignment Arithmetic.

Coding Workshop. Learning to Program with an Arduino. Lecture Notes. Programming Introduction Values Assignment Arithmetic. Coding Workshop Learning to Program with an Arduino Lecture Notes Table of Contents Programming ntroduction Values Assignment Arithmetic Control Tests f Blocks For Blocks Functions Arduino Main Functions

More information

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING CMPE13/L: INTRODUCTION TO PROGRAMMING IN C SPRING 2012 Lab 3 Matrix Math Introduction Reading In this lab you will write a

More information

6.001 Notes: Section 15.1

6.001 Notes: Section 15.1 6.001 Notes: Section 15.1 Slide 15.1.1 Our goal over the next few lectures is to build an interpreter, which in a very basic sense is the ultimate in programming, since doing so will allow us to define

More information

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Writing a Simple Java Program Intro to Variables Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch

More information

Introduction to Programming Style

Introduction to Programming Style Introduction to Programming Style Thaddeus Aid The IT Learning Programme The University of Oxford, UK 30 July, 2013 Abstract Programming style is the part of the program that the human reads and the compiler

More information

Speed Up Windows by Disabling Startup Programs

Speed Up Windows by Disabling Startup Programs Speed Up Windows by Disabling Startup Programs Increase Your PC s Speed by Preventing Unnecessary Programs from Running Windows All S 630 / 1 When you look at the tray area beside the clock, do you see

More information

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment

More information

15 Minute Traffic Formula. Contents HOW TO GET MORE TRAFFIC IN 15 MINUTES WITH SEO... 3

15 Minute Traffic Formula. Contents HOW TO GET MORE TRAFFIC IN 15 MINUTES WITH SEO... 3 Contents HOW TO GET MORE TRAFFIC IN 15 MINUTES WITH SEO... 3 HOW TO TURN YOUR OLD, RUSTY BLOG POSTS INTO A PASSIVE TRAFFIC SYSTEM... 4 HOW I USED THE GOOGLE KEYWORD PLANNER TO GET 11,908 NEW READERS TO

More information

Post Experiment Interview Questions

Post Experiment Interview Questions Post Experiment Interview Questions Questions about the Maximum Problem 1. What is this problem statement asking? 2. What is meant by positive integers? 3. What does it mean by the user entering valid

More information

Week - 01 Lecture - 04 Downloading and installing Python

Week - 01 Lecture - 04 Downloading and installing Python Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 04 Downloading and

More information

Com S 227 Spring 2018 Assignment points Due Date: Thursday, September 27, 11:59 pm (midnight) "Late" deadline: Friday, September 28, 11:59 pm

Com S 227 Spring 2018 Assignment points Due Date: Thursday, September 27, 11:59 pm (midnight) Late deadline: Friday, September 28, 11:59 pm Com S 227 Spring 2018 Assignment 2 200 points Due Date: Thursday, September 27, 11:59 pm (midnight) "Late" deadline: Friday, September 28, 11:59 pm (Remember that Exam 1 is MONDAY, October 1.) General

More information

How To Upload Your Newsletter

How To Upload Your Newsletter How To Upload Your Newsletter Using The WS_FTP Client Copyright 2005, DPW Enterprises All Rights Reserved Welcome, Hi, my name is Donna Warren. I m a certified Webmaster and have been teaching web design

More information

Math Day 2 Programming: How to make computers do math for you

Math Day 2 Programming: How to make computers do math for you Math Day 2 Programming: How to make computers do math for you Matt Coles February 10, 2015 1 Intro to Python (15min) Python is an example of a programming language. There are many programming languages.

More information

Quick Guide. Choose It Maker 2. Overview/Introduction. ChooseIt!Maker2 is a motivating program at first because of the visual and musical

Quick Guide. Choose It Maker 2. Overview/Introduction. ChooseIt!Maker2 is a motivating program at first because of the visual and musical Choose It Maker 2 Quick Guide Created 09/06 Updated SM Overview/Introduction This is a simple to use piece of software that can be tailored for use by children as an alternative to a pencil and paper worksheet,

More information