greenfoot - technocamps.com"hello world!");!}!}! objects and classes this is an class: ......

41

Upload: vandung

Post on 11-Mar-2018

226 views

Category:

Documents


5 download

TRANSCRIPT

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 do? •  How? Computer Science: •  What do you already know about Computer

Science? •  What is Computer Science?

Fact: Computers aren’t very smart! In order for the computer to do ANYTHING it has to be told specifically what to do. It needs tasks breaking down into simple steps. This is what programming is!

I am SILLY!

Fact: You can make them very smart! “Computers are incredibly fast, accurate, and stupid. Human beings are incredibly slow, inaccurate, and brilliant. Together they are powerful beyond imagination.”

Leo Cherne 1968.

Why choose Computer Science?

Watch this: https://www.youtube.com/watch?v=1o0oA3fa2ws&feature=related

Modeling in the “Real World” •  Clear, concise instruction giving is important.

•  Solving real problems in addition to making fun games, what kind of problems can you think of that could be solved?

•  What jobs and careers are there? What do you think it is like working in the Computing industry?

•  Is Computing and Computer Science only about programming?

Watch this: http://www.youtube.com/watch?v=yGStqRMShj4&lr=1

What careers are available?

Designer

Engineer Developer

Technician Teacher

Researcher Consultant

Database analyst

What “Developer” jobs are available? “Frontend/UI Developer”

Permanent, London £35k - £46 pa + bonus

“IT Developer” Permanent, Edinburgh

£35k - £50 pa + Package

“Mobile App Developer” Permanent, Birmingham

£30k - £36

“Web Developer Apprentice” Permanent, Edinburgh

£9,600 pa

“Java Software Engineer” Permanent, Cardiff

£30k - £40k pa

“Software Developer” Undergraduate position, Swansea

£17k - £18k

What is “Object Orientated” programming?

Object Orientated means that the programming language is based on “Objects”. These Objects are blocks of code that can be reused after they are written.

What are the benefits of using Object-Orientated programming?

Java is an example of a programming language that is used daily in organisations

throughout the CS industry.

Example of code This is an example of code for a computer in Java. Any ideas what this could mean?

Class MyFirstJavaProg!{ ! public static void main(String [] args)! {! System.out.println("Hello World!");! }!}!

Objects and Classes

This is an class:

This is an object:

Class: Robot

Name RobotNumber GroupName GroupNumber

RoboGirl: Lisa!

Progranimate

Progranimate

Go to the Progranimate website: www.progranimate.com •  Click on “Programming Problems”.

•  Click on “Sequence”.

Try the “McDullard’s problems”

Real Programming •  Year 7s – Year 13s attend a range of Technocamps workshops learning

introductory programming skills using “Drag and Drop” programming environments.

•  You will be experiencing a real programming environment, exposing syntax errors and how to code “properly”.

Greenfoot

Greenfoot Here is an example of what you can

achieve using the “Greenfoot” programming environment:

Watch this: http://www.youtube.com/watch?v=f7qQWvMb64U&feature=relat

ed

Greenfoot Interface

Class!Diagram!

World!

Greenfoot Interface

Subclass!

Constructor!

Instance!of!“Wombat”!class!

How to make Objects “Act” •  Click on “Act” in the execution controls. Each object has a built in “Act” method, so any instructions added here are run when the “Act” button is pressed. In the Wombat example, the leaves are currently not commanded to do anything, however the Wombats are programmed to move forward. •  Place 2 Wombats in the World and press Act, what happens? •  Try placing several leaves on the World. Press Act. •  What happens when the Wombats come across the leaves?

Brackets in Java

() round brackets:

[] square brackets:

{} curly brackets:

Known in the USA as “parentheses”, in the UK these are known as standard brackets. They are used in mathematical expressions, surrounding the parameter lists for method calls.

Known in the USA as “brackets”. In Java these are used for arrays.

These are called “braces” or “squiggly brackets”. In Java, these are used to surround blocks of code such as methods of class content.

Movement

Enter the amount of steps to move within the round brackets inside the “Act” method. This will run each time the “Act” button is pressed after the code is compiled.

Movement

Next, underneath “move(4);” command the actor to also turn to the value of 3. See what happens after compiling and pressing “Act” what do you think “3” stands for?

Task Experiment with the code in this “Act” method:

•  Make the circle the Wombat moves in bigger. •  Make the circle smaller. •  Try adding a different background. •  Try changing the image of the Actor.

Conditional Statements An “If statement” can be used to state the following:

“If a certain condition occurs, execute the following code…Else, if anything other than that condition occurs, execute

this code instead…”

You can use “IF” statements in your code to get your Actor to react to keyboard input, such as the code snippet below:

Obstacles •  Add a new Actor, a rock has been used as an example. This will be your

obstacle. •  You do not want this to move, so the code here does not need to be altered/

added to. •  Place a variety of rocks around the World. To place these at random, click

“WombatWorld” and open up the code. •  Copy the “RandomLeaves” method and paste directly below, edit the name of

“Leaves” to your given obstacle name and re-name the method so you do not have 2 methods with the same names.

Obstacles continued… •  In order to stop the Wombat moving through the obstacle, add the below code

to make a new method in the “Wombat” class: public boolean noRocks(int x, int y) { World myWorld = getWorld(); List rocks = myWorld.getObjectsAt(x, y, Rock.class); if(rocks.isEmpty()) { return true; } else { return false; } }

Remember to change the name of “rock” to whatever you have named your obstacle.

Randomly moving Actors

You can get your Actors to randomly move around the World, this keeps your game exciting and will be different each time you or another user plays the game.

Spinning collectables

To add some visual elements to your Greenfoot game, you can get your collectables (currently the

collectables are leaves on the WombatWorld) to rotate as the Wombat is moving around the screen collecting

them!

Adding Sound

In the Wombat “Act” method you can add a “playSound” command that will play a saved

sound file when the method is run, for example:

Greenfoot.playSound(“file.filetype”);

Score Score is sometimes the most fun

part of a game. It allows other players to compete against one

another without having to play at the same time. It also allows a user

to assess how well they play the game, progressing and improving

their score each time.

Implementing a score as a counter within the WombatWorld will

greatly improve the quality of the game.

Let’s make our own game Lets make our own games and publish them, have a go at the following: •  Change the images (you can upload your own) •  Change the size of the game (in WombatWorld the current size is 8x8) •  Scoring •  Use of obstacles •  Different images for different obstacles •  Adding sounds

Remember, there is a list of other commands on:

www.greenfoot.org/files/javadoc/index-all.html

New game: PONG! You can create a new scenario called “Pong”.

Add the list of classes and subclasses of Actors on

the right hand size to your new world. The aim of the game is to bounce the ball into the oppositions goal, but it is key to protect your own goal as the other player will be trying to do the

same thing and score by knocking the ball into the goal you’re protecting.

Players Controlling multiple players will allow us to play the game against one-another.

The right player will use the standard

arrow keys on a keyboard to control its Actor.

The left player will use the following

keys on a keyboard:

W = up A = left

S = down D = right

New game: Shooting Game! You can create a new scenario called “Shooting”.

Add the list of classes and subclasses of Actors on

the right hand size to your new world.

The aim of the game is to use a laser on a rocket that you can control the movement of, to shoot the

aliens that appear in the created World.

New game: Crab Game! On the Greenfoot website, download the crab scenario and open on Greenfoot.

This may already be downloaded, if not follow the link below:

http://www.greenfoot.org/doc/tut-2

The aim of the game is to control the “Crab” using the left and right keyboard arrow controls to collect and eat the worms as

the crab spins. Alternatively you can make the crab follow your mouse around the World.

Make sure you avoid the lobster!

New game: Marble Drop! You can create a new scenario called

“MarbleWorld”.

Add the list of classes and subclasses of Actors on the right hand size to your new

world.

The aim of this game is to guide a marble left and right using the

mouse to try and fall through the gaps in the floors which move up

the screen.

Let’s make our own game Let’s make our own games and publish them, have a go at the following: •  Change the images (you can upload your own) •  Change the size of the game (in WombatWorld the current size is 8x8) •  Have a method of scoring •  Use of obstacles or several enemies •  Adding sounds

Remember, there is a list of other commands on:

www.greenfoot.org/files/javadoc/index-all.html

Post-day Questionnaires