Presentation is loading. Please wait.

Presentation is loading. Please wait.

Code reading skills LEVEL GAME.  Skeleton has error messages.  Notice the red lines on right slider. Click… you’ll go to an error.  pieces = levels.getPieces();

Similar presentations


Presentation on theme: "Code reading skills LEVEL GAME.  Skeleton has error messages.  Notice the red lines on right slider. Click… you’ll go to an error.  pieces = levels.getPieces();"— Presentation transcript:

1 Code reading skills LEVEL GAME

2  Skeleton has error messages.  Notice the red lines on right slider. Click… you’ll go to an error.  pieces = levels.getPieces(); // a statement with an error  Double click on pieces  Select Search->Declarations->project. Eclipse will take you to where this is defined.  From the declaration, try Search->References->Project. This will help you figure out how/where this data is used. ECLIPSE CAN HELP

3  Your first task … is to read the code in the provided skeleton.  How many of you went on to read the assignment details?  From employers: code reading is critical skill that most students have not yet acquired fully. HOW DOES GAME ENGINE WORK?

4  How about main?  Creates a Game Engine  Calls playGame  playGame includes:  Code to determine if game is over  Calls setupLevel to get ready for next level  Calls doOneLevel  After the while loop, some final messages and exit WHERE TO BEGIN?

5  Checks if level over  Displays the board  Gets the player’s option  Moves the player  If player moved, interact with other pieces and let other pieces move  Pseudo code: informal, high-level description  Productive strategy when writing code: write pseudocode as comments, fill in the details DO ONE LEVEL

6  Prints the player (oh, symbol is P)  Displays space if nothing at that location  Tells object to draw itself  How can we be sure pieces know how to draw themselves? private Drawable [] pieces;  Pieces is an array of Drawable!  But wait, what does that mean? How can that be?  It means that EVERY object in the array must IMPLEMENT Drawable  Drawable is an interface. It has exactly one method: draw() DISPLAY BOARD

7  Anything that implements Drawable must have a draw method  We don’t care what type of thing it is, as long as it can draw itself.  BumbleBee? Sure!  DoorMat? Sure!  Kangalo? Sure! else pieces[i].draw();  Can I add new types? Yes!!  Do I need lots of if/else statements? No!! THE POWER OF THE INTERFACE

8 public interface Moveable extends Drawable{ public void move(Drawable[] pieces, int playerLocation); } public interface InteractingPiece extends Drawable { public InteractionResult interact( Drawable [] pieces, int playerLocation); } SO WHAT IS THIS EXTENDS?

9  Start slow  You can figure out you need a LevelEngine  LevelEngine needs some data structures (lists of pieces, moveable pieces, interacting pieces).  Set these to null  Create ONE game piece  Make it as simple as possible (like my DoorMat)  Can you get it to display?? Woo hoo! FEELING UNSURE?* * Of course you are. It’s like working with legacy code… lots to figure out before you can even begin to code.


Download ppt "Code reading skills LEVEL GAME.  Skeleton has error messages.  Notice the red lines on right slider. Click… you’ll go to an error.  pieces = levels.getPieces();"

Similar presentations


Ads by Google