Objectives

Students will be able to:

  • define a class file storing properties
  • define a constructor method
  • create an instance of an object(s) in a computer program

Warning!

If you submit work that is obviously very similar to any of your classmates' work, your work and your classmates' will be graded fairly for each document you submit.

However, you and your classmates' final grade will be calculated as the lower number of the previous band for each document.

The following table demonstrates the difference:

Document Grade Final Grade
Design_Doc 4 1
Development_Doc 7 5
Screencast 3 1

Getting started

This video will introduce how to create a Java frame with a single panel on which to play the game.

The Game Thread

We will construct a Thread and play the game on it. This will allow us to control when to start, stop, pause... the game.

To use a thread, we need to implement the Runnable class, which demands that we code the run() method.

The Game Loop

Let's create a game loop where mario and luigi will both jump until one of them reaches a health value of 0.

The thread will stop when this happens.

Repaint

After updating the game data, we need to repaint the panel - this is how most computer games work.

In Java we will call the repaint() method - this is built in. This method automatically calls the paintComponent method... very confusing!

We also need a strategy for slowing the game down. We will sleep the thread to do this!

Restart Button

Let's add a restart button (introduction to action listeners)

Object Oriented Programming

Jumping Mario

 

This activity is based on the exercise regarding a Jumping Mario character.

Mario and Luigi jump! They start with a health rating of 10.

If they jump off the game board, their health decreases by 1.

The jumper who reaches a health rating of 0 first is the loser.

Let's code this game using Java's AWT and SWING libraries.

There are 5 short videos in the series. Click a green button to access the content and the orange button for a fresh copy of the Mario class.

Personal Adaptation

Adapt the code such that different game behaviour occurs.

You are free to implement any idea for example:

  • instead of colored squares, can we incorporate character images? How about sound?
  • each time Mario and Luigi collide, something happens.
  • Each character can choose a Weapon secretly at the start of the game. If they collide, the character with the weakest weapon loses health.
  • incorporate the idea of aggregation - Mario and/or Luigi HAS-A AppleBomb(s). When the AppleBomb is dropped on the game grid, if the other character jumps on it something happens.
  • can you find ways to incorporate method overloading in your class designs?

The only limit here is your personal creativity and ingenuity, and the project time limit!

Personal Project Submission

You will submit 3 documents and a video file stored in a folder.

  1. Design_Doc: this document will include all UML diagrams and at least 1 flowchart representing code that you used in your program
  2. Development_Doc: you will include screenshots and commentary of sample blocks of code that you used in your program. The blocks eg methods/algorithms should represent innovative techniques that you used to make your game what it is. The commentary should be a detailed description of the purpose of the code.
  3. Appendix_A: All of your source code
  4. Screencast: A short screencast of your program in action. After you show your program working, you should describe how you would further develop the program if you had more time.
  5. Figure out how to save your finished file as a JAR file (optional). Store this file in the Product folder.

Create and complete each document listed above in a Google Drive folder.

Save your screencast in a common video format ie .wmv, .mp4 or .avi in your Google Drive folder. It should be between 2 and 7 minutes long. It must not be more that 500MB in size.

When everything is finished (before the deadline), submit a link to your Google Drive folder in Google Classroom.

Note: if you managed to create a JAR file you can include it in your folder, too.

SUBMISSION

Submit a link to your Google Drive folder in Google Classroom.

Glossary

object

property

method

create an object/instance of a class

instantiate an object

encapsulate

access

mutate

abstraction

Tags

idesyntax file class instantiate constructor type propertymethod