Getting to know Greenfoot

Slides:



Advertisements
Similar presentations
Mouse Tutorial for Win XP In this tutorial you will learn to: Move the mouse Click and double click Make selections Manage windows Use menus Click the.
Advertisements

Microsoft Word 2010 Lesson 1: Introduction to Word.
Games and Simulations O-O Programming in Java The Walker School
Chapter 2 - The First Program: Little Crab
Program: Little Crab Mr Gano.
Asteroids Games and Simulations O-O Programming in Java The Walker School The Walker School – Games and Simulations
Microsoft ® Office Word 2007 Training Bullets, Numbers, and Lists ICT Staff Development presents:
Greenfoot Asteroids Mrs. C. Furman August 16, 2010.
Code Club Session 3 Shark Eats Fish. Picture of finished product here.
Wombats Creating Games with Greenfoot The Walker School – Games and Simulations
Section 2.3 Gauss-Jordan Method for General Systems of Equations
Chapter 1 - Getting to know Greenfoot Bruce Chittenden.
Chapter 1 - Getting to know Greenfoot Acknowledgement: Michael Kolling & Bruce Chittenden.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
A tour around Java General introduction to aspects of the language (these will be covered in more detail later) After this tour you should have a general.
Calvin and Hobbes Teach Properties and Functions Created by Daniel MacDonald under the direction of Professor Susan Rodger Duke University June 2013.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Alice Learning to program: Part Two by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Created by NW 2012 – please note all copyright on images used is property of copyright holder. Note: some of the more complicated descriptions are taken.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
Github & Arduino How To: Post On Github How To: Download from Github How To: Upload Code Downloaded from Github to Arduino Tommy Sanchez EE400D Spring.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Karel J Robot An introduction to BlueJ and Object- Oriented Programming.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Greenfoot. Getting Started Open the Greenfoot download site: Select Greenfoot
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Getting started with Alice Adapted from presentations by Jenna Hayes, Duke University Donna Gavin, UWP Computer Science and Software Engineering.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
EET 2259 Unit 7 Case Structures; Sequence Structures  Read Bishop, Sections 5.4 and 5.5.  Lab #7 and Homework #7 due next week.  Quiz #3 next week.
Changing Color, Using Text Objects, and Random Selection in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Chapter 1 - Getting to know Greenfoot
Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University.
Moving Around in Scratch The Basics… -You do want to have Scratch open as you will be creating a program. -Follow the instructions and if you have questions.
Lecture 4. Greenfoot 1 Pablo Romero, Department of Informatics Greenfoot Programming simulations and games in Java.
1 CSC 221: Computer Programming I Spring 2008 Objects and classes: a broad view  software objects, classes, object-oriented design  BlueJ IDE, compilation.
 When you receive a new you will be shown a highlighted in yellow box where your can be found  To open your new just double click.
Greenfoot Game Programming Club.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
Lesson 1: Writing a program. Java Java is a programming language Computer cannot understand it, though it can be translated ( compiled ) so a computer.
Advanced Stuff Learning by example: Responding to the mouse.
Kakihijau.googlepages.com Introduction To Greenfoot Part-1.
Learning PowerPoint Presenting your ideas as a slide show… …on the computer!
The Essentials of Alice Mrs. Jayne Slease SBMS CTE Computer Science and Animation Credit to Duke Students under the direction of Professor Susan Rodger.
Variables and Functions Alice. Naming is Important If you get a new pet one of the first things you do is name it Gives you a way to refer to the new.
Tutorial for Arrays and Lists. Description This presentation will cover the basics of using Arrays and Lists in an Alice world It uses a set of chickens.
Lesson 2: Reading a program. Remember: from yesterday We learned about… Precise language is needed to program Actors and Classes Methods – step by step.
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
Introduction To Greenfoot
Chapter 2 – The Little Crab Program:. Little Crab Scenario Inheritance: The Arrows Denote Hierarchy Crab is an Animal Animal is an Actor Therefore, It.
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
Adding and Eating Worms Mrs. C. Furman August 23, 2010.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Greenfoot.
Chapter 4 - Finishing the Crab Game
Scratch for Interactivity
Important terms Black-box testing White-box testing Regression testing
Creating Games with Greenfoot
Important terms Black-box testing White-box testing Regression testing
The Little Crab Scenario
Methods, Data and Data Types
Greenfoot November 8, 2009.
Classes, Objects and Methods
creating a ecosystems model in net logo
1.7 A Second Example.
EET 2259 Unit 7 Case Structures; Sequence Structures
Presentation transcript:

Getting to know Greenfoot Mr. Gano

Desktop Icon

Greenfoot Programming Interface The world. The largest area covering most of the screen (a sand-colored grid in this case) is called the world. This is where the program will run and we will see things happen. The class diagram. The area on the right with the beige-colored boxes and arrows is the class diagram. We shall discuss this in more detail shortly. The execution controls. The Act, Run, and Reset buttons and the speed slider at the bottom are the execution controls. We’ll come back to them in a little while, too.

This is the Greenfoot interface World Class Diagram Execution Controls

Objects and Classes We shall discuss the class diagram first. The class diagram shows us the classes involved in this scenario. In this case, they are World, WombatWorld, Actor, Leaf, and Wombat. We shall be using the Java programming language for our projects. Java is an object-oriented language. The concepts of classes and objects are fundamental in object orientation. Let us start by looking at the Wombat class. The class Wombat stands for the general concept of a wombat—it describes all wombats. Once we have a class in Greenfoot, we can create objects. from it. (Objects are also often referred to as instances in programming—the two terms are synonyms.)

Objects and Classes Once we have placed some objects into the world, we can interact with these objects by rightclicking them. This will pop up the object menu (Figure 1.4). The object menu shows us all the operations this specific object can perform. For example, a wombat’s object menu shows us what this wombat can do (plus two additional functions, Inspect and Remove, which we shall discuss later). In Java, these operations are called methods. It cannot hurt to get used to standard terminology straightaway, so we shall also call them methods from now on. We can invoke a method by selecting it from the menu.

Objects and Classes Right Click on Wombat Drag to World Click New Wombat() This is how to make a wombat appear in the game world. A wombat is an object of the Actor class. The game world for the wombat is part of the world class.

Make three wombats and three leaves as shown here.

Right Click on the Wombat Interact with objects through the contextual menu by right clicking on the object to see what methods can be called. Right Click on the Wombat Invoke the Move method

Return Types The word at the beginning is called the return type. It tells us what the method returns to us when we invoke it. The word void means “nothing” in this context: Methods with a void return type do not return any information. They just carry out their action, and then stop.

The return type of a method specifies what a method call will return The return type of a method specifies what a method call will return. This example shows a return type of true, which is a boolean return type. In this case the methods is telling us that the wombat can move if we want it to move.

Here we see the Greenfoot interface with the method canMove() returning true. This means the wombat can move forward.

This example shows the canMove() method call returning false since the wombat cannot move since it is at the edge of the game world.

Here we have the getLeavesEaten() method returning 0 since the wombat has not eaten any leaves. When the wombat eats a leaf the int (integer) will increase to 1.

Parameters The other bit in the method menu that we have not yet discussed are the parentheses after the method name. int getLeavesEaten() void setDirection(int direction) The parentheses after the method name hold the parameter list. This tells us whether the method requires any additional information to run, and if so, what kind of information. If we see only a pair of parentheses without anything else within it (as we have in all methods so far), then the method has an empty parameter list. In other words, it expects no parameters—when we invoke the method it will just run. If there is anything within the parenthesis, then the method expects one or more parameters—additional information that we need to provide.

Parameters Here we are setting the direction in which the Wombat is facing.

Setting the Direction of the Wombat

Result of setting direction to 3

Numbers indicating direction of the Wombat as the computer understands directions 2 1 3

Parameter > 3 Does Nothing If we insert a value greater than 3 there is no effect since the parameter we enter must be between or including 0 – 3. Parameter > 3 Does Nothing

Non-Integer Returns Error Here is an example of a non integer value entered into the setDirection() method. The value 2.5 will not work. Non-Integer Returns Error

Greenfoot Execution Activity Place a wombat and a good number of leaves into the world, and then invoke a wombat’s act() method several times. What does this method do? How does it differ from the move method? Make sure to try different situations, for example, the wombat facing the edge of the world, or sitting on a leaf. With a wombat and some leaves in the world, click the Act button in the execution controls near the bottom of the Greenfoot window. What does this do?.

Act() method All objects in a Greenfoot world have this act method. Invoking act is essentially giving the object the instruction “Do whatever you want to do now”. If you tried it out for our wombat, you will have seen that the wombat’s act does something like the following: If we’re sitting on a leaf, eat the leaf. Otherwise, if we can move forward, move forward. Otherwise, turn left.

Wombat and leaves in the game world

When act is clicked the wombat will follow instructions included in the act() method. Wombat Moves toward the Leaves

Wombat will move over the leaf when act() method is clicked again and again. Wombat Moves to Leaves

Wombat will move over the leaf Wombat will move over the leaf. Instructions in the act() method will enact the eat() method so the leaf will be ‘eaten’ or rather disappear. Wombat Eats Leaf

Right click on a wombat and select the act() method to invoke the instructions contained within that method.

Click the Act button to inoke the act() method Click the Act button to inoke the act() method. How does the result differ from invoking the act() method by right clicking on a wombat? The >Act Execution Control Affects All the Wombats

Click the Run button and see what happens to the wombat. Wombat Runs Around the Edge of the World

Act() method for Wombat If we’re sitting on a leaf, eat the leaf Otherwise, if we can move forward, move forward Otherwise, turn left

Asteroids Game Example

Understanding the Class Diagram World Class is always there in Greenfoot scenarios, it is built-in. Space represents a specific world for this scenario Arrows show relationships Explosion and Mover are subclasses of Actor Bullet, Rocket, and Asteroid are subclasses of Mover. Vector is a helper class

Class Diagram Let us first have a closer look at the class diagram seen in the previous slide. At the top, you see the two classes called World and Space, connected by an arrow. The World class is always there in all Greenfoot scenarios—it is built into Greenfoot. The class under it, Space in this case, represents the specific world for this particular scenario. Its name can be different in each scenario, but every scenario will have a specific world here. The arrow shows an is-a relationship: Space is a World (in the sense of Greenfoot worlds: Space, here, is a specific Greenfoot world). We also sometimes say that Space is a subclass of World. We do not usually need to create objects of world classes—Greenfoot does that for us. When we open a scenario, Greenfoot automatically creates an object of the world subclass. The object is then shown on the main part of the screen. (The big black image of space is an object of the Space class.)

Playing with Asteroids Start Playing by Creating Some Actor Objects (Objects of the Subclass of Actor). Create Objects for Rocket, Bullet, Asteroid, and Explosion

Asteroids Reload Time Activity If you have played this game for a while, you will have noticed that you cannot fire very quickly. Let us tweak our spaceship firing software a bit so that we can shoot a bit quicker. (That should make getting the asteroids a bit easier!) Place a rocket into the world, then invoke its setGunReloadTime method (through the object menu), and set the reload time to 5. Play again (with at least two asteroids) to try it out.

Click on setGunReloadTime(int reloadTime) Right Click on the Object Click on setGunReloadTime(int reloadTime)

Click on setGunReloadTime and Type 5

Right Click on the Object and Select Inspect

These are the parameters for the Rocket object

Right Click on the Object and Select getSpeed ( )

You can set the speed of the rocket by altering the int parameter in the rocket.getSpeed() method

Asteroids have an inherent stability Asteroids have an inherent stability. Each time they get hit by a bullet, their stability decreases. When it reaches zero, they break up. What is their initial stability value after you create them? By how much does the stability decrease from a single hit by a bullet?

Make a very big asteroid Right Click on the Object and Select setSize(int Size) and Set the Size to 256

Source Code Right Click on the Class and Select Open editor

Source Code for Rocket

Change gunReloadTime from 20 to 5

Make a change to the Rocket class source code that will allow the rocket to shoot quickly from the start of the game. Close the editor and compile the classes. Each time you make changes the code will need to be compiled again. Class Changed Class Compiled

Summary We have seen what Greenfoot scenarios can look like and how to interact with them. We have seen how to create objects and how to communicate with these objects by invoking their methods. Some methods are commands to objects, while other methods return information about the object. Parameters are used to provide additional information to methods, while return values pass information back to the caller.

Greenfoot scenarios consist of a set of classes. Many objects can be created from a class. Objects have methods. Invoking these performs an action. The return type of a method specifies what a method call will return. A method with a void return type does not return a value. Methods with void return types represent commands; methods with non-void return types represent questions. A parameter is a mechanism to pass in additional data to a method. Parameters and return values have types. Examples of types are int for numbers, and boolean for true/false values. The specification of a method, which shows its return type, name, and parameters, is called its signature. Objects that can be placed into the world are known as actors. A subclass is a class that represents a specialization of another. In Greenfoot, this is shown with an arrow in the class diagram. Every class is defined by source code. This code defines what objects of this class can do. We can look at the source code by opening the class’s editor. Computers do not understand source code. It needs to be translated to machine code before it can be executed. This is called compilation.