Session 8 Finishing Touches to the Air Raid Game

Similar documents
Session 4 Starting the Air Raid Game

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

Creating Java Programs with Greenfoot

ISY00245 Principles of Programming. Module 7

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

CSE 113 A. Announcements - Lab

Today in CS161. Lecture #12 Arrays. Learning about arrays. Examples. Graphical. Being able to store more than one item using a variable

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

Creating Java Programs with Greenfoot

CS103 Handout 29 Winter 2018 February 9, 2018 Inductive Proofwriting Checklist

PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 00. WELCOME TO OBJECTVILLE. Speaking the Language of OO

Improving the crab: more sophisticated programming

CS201 - Assignment 3, Part 2 Due: Wednesday March 5, at the beginning of class

Pong in Unity a basic Intro

1.7 Limit of a Function

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

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

What did we talk about last time? Examples switch statements

CMSC 104 -Lecture 2 John Y. Park, adapted by C Grasso

MICROSOFT WINDOWS SIG OCTOBER 24, 2016 HOW TO CREATE A MICROSOFT ACCOUNT AND FREE OFFICE PROGRAMS USING ONE DRIVE

Digital Workflow 10 Tech Rules to Guide You

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM

So computers can't think in the same way that people do. But what they do, they do excellently well and very, very fast.

CIT 590 Homework 10 Battleship

Introduction to Game Programming

Introduction to Programming

Memory Addressing, Binary, and Hexadecimal Review

What goes inside when you declare a variable?

Assignment 6: Dodo keeps getting smarter

Making a PowerPoint Accessible

CPSC 217 Assignment 3

[ the academy_of_code] Senior Beginners

Elements of Computers and Programming Dr. William C. Bulko. What is a Computer?

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

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

Computer Basics PC-100

Assignment #4 Hangman Due: 3:15pm on Monday, November 3rd Your Early Assignment Help (YEAH) hours: 4:15pm-5:15pm, Friday, October 24th in Hewlett 200

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

Week 3. This is CS50. Harvard University. Fall Cheng Gong

Admin. ! Assignment 3. ! due Monday at 11:59pm! one small error in 5b (fast division) that s been fixed. ! Midterm next Thursday in-class (10/1)

Code Ninjas: Introduction to Computer Science. Macomb Science Olympiad Presented by Swati Dharia Shane Storks

Expressions and Casting

CS 170 Java Programming 1. Week 15: Interfaces and Exceptions

Computer Basics. Electronic computers have changed dramatically over their 50 history, but a few basic principles characterize all computers

Programming assignment A

Parts are adapted from Windows 98 by Mark Twain Media, Inc. A Computer System has Hardware and Software

Improving the Crab more sophisticated programming

b A bit is the basic unit for storing electronic data, for example an MP3 file. The term bit is a

Processing Assignment Write- Ups

SPRITES Moving Two At the Same Using Game State

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

Unit 9 Tech savvy? Tech support. 1 I have no idea why... Lesson A. A Unscramble the questions. Do you know which battery I should buy?

Fractions and their Equivalent Forms

Unit 4: Multiplication

Electricity: Voltage. Gate: A signal enters the gate at a certain voltage. The gate performs operations on it, and sends it out was a new signal.

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Google Docs Tipsheet. ABEL Summer Institute 2009

Lecture 14: Exceptions 10:00 AM, Feb 26, 2018

CISC 110 Day 1. Hardware, Algorithms, and Programming

Lecture 5: Implementing Lists, Version 1

CS61B Lecture #32. Last modified: Sun Nov 5 19:32: CS61B: Lecture #32 1

The first program: Little Crab

4. Java Project Design, Input Methods

More on Classes. The job of this method is to return a String representation of the object. Here is the tostring method from the Time class:

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

4.7 Approximate Integration

Understanding Recursion

Divisibility Rules and Their Explanations

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

Using sticks to count was a great idea for its time. And using symbols instead of real sticks was much better.

BOOKL LET GRADE NAME CLASS. School vision:

Beyond Blocks: Python Session #1

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

Flying Start AS Computer Science. September 2015

Chapter 1 Introduction

LCC 6310 The Computer as an Expressive Medium. Lecture 1

Hello, and welcome to another episode of. Getting the Most Out of IBM U2. This is Kenny Brunel, and

HPC VT Machine-dependent Optimization

CSE 373: Data Structures and Algorithms. Memory and Locality. Autumn Shrirang (Shri) Mare

#30: Graph theory May 25, 2009

Unit 2 Digital Information. Chapter 1 Study Guide

Recursion. Fundamentals of Computer Science

Why Hash? Glen Becker, USAA

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

Introduction to Programming with JES

CSE 143X. Accelerated Computer Programming I/II

Part 2: The Material PART 2

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych

Assignment 4 Hangman

Fractions and their Equivalent Forms

Discussion. Why do we use Base 10?

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

Lecture 24. GUI Applications

CSE351 Winter 2016, Final Examination March 16, 2016

Civil Engineering Computation

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2014 Lecture 14

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

XP: Backup Your Important Files for Safety

Android Programming Family Fun Day using AppInventor

Transcription:

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 Attribution-NonCommercial-ShareAlike 3.0 Unported License. See http://creativecommons.org/licenses/by-nc-sa/3.0/ for details.

Growth in Computing Power If you think about how fast computers have evolved over the last few decades it is truly amazing. To demonstrate how much computers have changed I have a challenge for you. Most people have a smart phone of some sort today so I want you to find out the processor speed and memory available either in your phone or a phone you would like to have! Done that? Well compare that to the Apollo 11 (the spacecraft that landed on the moon) computers which ran at 2.048 MHz (not GHz) and about 2KB (not MB or GB) of memory. There is a table below to help you compare these values. All I can say is wow it does make me wonder if you could do all that with such simple machines why do people always complain about their computers running too slow? Do you have any ideas? Unit Conversion 1 KiloByte 1024 Bytes 1 MegaByte 1024 KiloBytes (1,048,576 Bytes) 1 GigaByte 1045 MegaBytes (1,073,741,824 Bytes) Replacing the Plane and Making it Harder One of the biggest issues with the game at the moment is that if you shoot the plane it isn t replaced and so there is nothing left for you to do. At the same time the game never really gets harder and it would seem to be a good idea if we add more and more planes the higher the score gets. As both these problems relate to adding planes to the world we are going to try and deal with both of them at the same time. To start with we are going to add two more methods to our AirRaidWorld class. The first method will be called addplane and will be used to add a new plane to the world. The second will be called getnumberofplanes and will tell you how many planes are currently in the world. You should already know how to write the method to add a new plane to the world as you have already done it in the constructor. So write the method and copy the code into the new method. It should look like the code below once you are finished. Note that once you have written this method you could replace the line where you add the plane in the constructor with addplane; public void addplane () addobject(new Plane(), 100, 30); The second method is a little more tricky but we know that we want to return the number of planes in the game so the method definition is going to look something like this.

public int getnumberofplanes () // Code to count the number of planes goes here. return 0; We can get a list of all the planes in the game by calling the getobjects method and passing it the Plane class as a parameter. Luckily for us the List returned by this has a size method which will tell us how many planes are in the list. This means that the final code will be as shown. public int getnumberofplanes () List planelist = getobjects(plane.class); return planelist.size(); There is one final complication that means that this code won t compile at the moment. The problem is that unless you tell it Java won t know where to find the List class we are using in this code. To sort this out we need to go to the top of the file and import the List class. At the very top of the file you will see a line importing the Greenfoot classes and right underneath it simply write the following to import the list class. import java.util.list; Now that we have both a way of checking how many planes are left and creating a new one we need to go back to our Rocket class and find the code where we remove a plane that is hit by the a rocket. After the code that removes the plane we need to check if there are any planes that are left (using an if statement) and if there isn t add a new one. Once you have added these new lines of code test your program and make sure it works. if (airworld.getnumberofplanes() == 0) airworld.addpane(); The final thing to do is consider when we need to add more planes to the game to make it harder. For example we could add a new plane to the game every time a player scores 5 points but where would we put that code? You may have guessed that the increasescore method might be a good place to do this and that is what we are going to do. We are going to check if the score is evenly divisible by 5 and if it is then we will add a new plane. The easiest way to find if a number is evenly divisible by 5 is to use the modulo operator (written as %). This will give you the remainder of a division so, for example, 11 % 5 would give you 1 as an answer because when you divide 11 by 5 you get a remainder of 1. The code you need to add to the increasescore method is shown below. Make sure you add it AFTER you increase the score otherwise it won t work properly! Once you have added the code try the

if (score % 5 == 0) addplane(); Game Over Screen The easiest way to make a game over screen is to open up a graphics program (paint/fireworks/etc) and draw one! I would suggest that you make your image 300 by 200 pixels to ensure it fits properly on the screen. Once you have made you image create a new subclass of Actor called GameOver and choose your picture for it to use. Add the following code to the lostlife method just before it stops the program to display your game over actor in the middle of the screen. addobject (new GameOver(), 300, 200); Other Refinements At this stage it is over to you! You need to decide what if any improvements that can be made. One thing that you might want to consider is changing the graphics used in the game. You can change the picture used by any of the objects simply by right clicking on the class and choosing the Set Image option. Get someone else in the group to play your game and give you feedback on what they think. It s your game so customise it! Publishing Your Game Want to get others feedback on the game? Then why not publish it to the Greenfoot site. You can do this by clicking the Share button on the right hand side of the window. Publishing a game like this can be a great way to get feedback and you can always use the Greenfoot forums to ask for more help if you need it!