© A+ Computer Science - www.apluscompsci.com GridWorld © A+ Computer Science - www.apluscompsci.com.

Slides:



Advertisements
Similar presentations
GridWorld Case Study The Classes A Summary by Jim Mims.
Advertisements

GridWorld Case Study Part 1 Experiments to Observe Attributes and Behavior of Actors A Summary by Jim Mims.
GridWorld Case Study Part 3 GridWorld Classes and Interfaces A Summary by Jim Mims.
GridWorld Case Study Part 2 Bug Variations A Summary by Jim Mims.
GridWorld Case Study Part 4 Classes that Extend the Critter Interface A Summary by Jim Mims.
GridWorld Case Study Part 5 Grid Data Structures Not Tested on A Exam A Summary by Jim Mims.
© A+ Computer Science - GridWorld © A+ Computer Science -
Critters A Study in Design Patterns. Design Patterns  Not specific algorithms or data structures  A general reusable solution to a common problem.
Location Class Gridworld. Location Class Encapsulates the coordinates for an actor’s position in a grid – Row and Column number Rows increase going down.
Using a different image than normal Multiple images for a class Controlling the mouse click Controlling the keys pressed Launching an input dialog box.
Syntax & terminology review While the following slides are not exactly what we did on the board (object diagrams are not shown here) they cover most of.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Inheritance Inheritance is the process of using features (both attributes and methods) from an existing class. The existing class is called the superclass.
GridWorld Case Study1 Barbara Ericson Georgia Tech Jan 2008.
1 Phase Testing. \ 2 Overview of Implementation phase Create Class Skeletons Define Implementation Plan (+ determine subphases) Define Coding Standards.
© A+ Computer Science - Row = 0 Column = 0.
Java is an object oriented programming language In this model of programming all entities are objects that have methods and fields Methods perform tasks.
How to do well on the AP CS Free Response Questions
Inheritance Inheritance is the process of using features (both attributes and methods) from an existing class. The existing class is called the superclass.
© A+ Computer Science - Chicken yeller = new Chicken();
© A+ Computer Science - A queue is a group of same-type values. Values are added to the back of a queue and removed from the front.
GridWorld Case Study Barbara Ericson March 24, 2007.
Game Maker Terminology
© A+ Computer Science - Grid is an interface that details the behaviors expected of a grid. All its methods are abstract methods.
The GridWorld Case Study Program Section 1 - Overview of the Class Hierarchies Section 2 - The Actor Class Section 3 - The Rock and Flower Classes Section.
© A+ Computer Science - In Java, any variable that refers to an Object is a reference variable. The variable stores the memory.
GridWorld Case Study The case study is a program that simulates actions and interactions of objects in a two- dimensional grid. During a single step of.
Chomp. How is the game played Human player goes first choose a square, all to the right and down are “eaten” computer takes a turn whoever is forced to.
Object Orientated Programming in Perl Simulated Models of Termites.
JAVA CLASSES, METHODS AND VARIABLES.  Defined Noun: A set or category of things having some property or attribute in common and differentiated from others.
© A+ Computer Science - In Java, any variable that refers to an Object is a reference variable. The variable stores the memory.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
GridWorld.
© A+ Computer Science -
Java Programming: Guided Learning with Early Objects
Lecture 27 Creating Custom GUIs
GridWorld Part 4 Meet the Critters.
Agenda About Quiz ChameleonCritter class CrabCritter class homework.
Barbara Ericson Georgia Tech Jan 2008
Creating Games with Greenfoot
Multiple Choice -answer the easiest question 1st
Board: Objects, Arrays and Pedagogy
Section 8.7 The Consequences of Scope.
A+ Computer Science INPUT.
© A+ Computer Science - GridWorld © A+ Computer Science -
© A+ Computer Science - GridWorld © A+ Computer Science -
© A+ Computer Science - Arrays and Lists © A+ Computer Science -
Using PARAMETERS In Java.
Teaching Java using Turtles part 2
A+ Computer Science METHODS.
The Matrix A b a d e a a a a a a a A b a d e a a a a a a a
© A+ Computer Science - Classes And Objects © A+ Computer Science -
© A+ Computer Science - OOP Pieces © A+ Computer Science -
GridWorld Part 4 Meet the Critters.
A+ Computer Science INPUT.
A+ Computer Science METHODS.
See requirements for practice program on next slide.
© A+ Computer Science - GridWorld The GridWorld case study provides a graphical environment where visual objects inhabit and interact.
© A+ Computer Science - GridWorld © A+ Computer Science -
GridWorld Case Study.
Building Java Programs
Agenda Dancing bug class Class vs object Comparable interface
A+ Computer Science PARAMETERS
© A+ Computer Science - GridWorld © A+ Computer Science -
Teaching Java using Turtles part 2
Presentation transcript:

© A+ Computer Science - www.apluscompsci.com GridWorld © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com What is GridWorld? Row = 0 Column = 0 A grid is a structure that has rows and columns. A spreadsheet is a grid. A checker board is a grid. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com What is GridWorld? cols rows A grid is a structure that has rows and columns. A grid is a structure that has rows and columns. A spreadsheet is a grid. A checker board is a grid. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com What is GridWorld? Row = 2 Column = 1 A grid is a structure that has rows and columns. A spreadsheet is a grid. A checker board is a grid. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com What is GridWorld? © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com GridWorld Classes © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com ActorWorld © A+ Computer Science - www.apluscompsci.com

frequently used methods © A+ Computer Science - www.apluscompsci.com ActorWorld frequently used methods Name Use ActorWorld() creates a new world using 10X10 grid ActorWorld(grid) creates a new world using grid add(loc, thang) add thang at spot loc show() makes the world visible import info.gridworld.actor.World; © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com ActorWorld ActorWorld earth = new ActorWorld(); earth.show(); ActorWorld is used to graphically display a grid of Actors. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com ActorWorld A reference variable stores the memory address of an object. ActorWorld earth = new ActorWorld(); A reference variable is used to store the location of an Object. In most situations, a reference stores the actual memory address of an Object. earth stores the location / memory address of a new ActorWorld object. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com ActorWorld ActorWorld earth = new ActorWorld(); earth 0xF5 0xF5 ActorWorld Object A reference variable is used to store the location of an Object. In most situations, a reference stores the actual memory address of an Object. earth stores the location / memory address of a new ActorWorld. earth stores the address of an ActorWorld © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com ActorWorld reference command / method earth.show(); earth is a reference to an ActorWorld. earth.show() calls the ActorWorld show method to show the grid of actors graphically. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Location © A+ Computer Science - www.apluscompsci.com

frequently used methods © A+ Computer Science - www.apluscompsci.com Location frequently used methods Name Use Location(row, col) creates a new row,col Location getCol() gets the column value for this location getRow() gets the row value for this location Location is a class that stores row and column information. Location spot = new Location(4,5); spot has a row value of 4 and a column value of 5. import info.gridworld.grid.Location; © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Location Location locTwo = new Location(3,5); System.out.println(locTwo); Location locThree = new Location(2,9); System.out.println(locThree); OUTPUT (3, 5) (2, 9) Location is a class that stores row and column information. Location spot = new Location(4,5); spot has a row value of 4 and a column value of 5. The Location class stores row and column information. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Location reference variable Location theLoc = new Location(3,4); Location is a class which must be instantiated before it can be used. In other words, you must make a new Location if you want to use a Location. A reference must be used to store the location in memory of the Location object created. A row value and a column value must be passed as parameters to the Location constructor. theLoc is a reference that will store the location/memory address of newly created Location object. object instantiation © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Actor © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Actor Actor is the basic object from which all other GridWorld actors will be built. Each of the new actors created will extend the original actor class. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Actor ActorWorld world = new ActorWorld(); Actor dude = new Actor(); Location loc = new Location(0,0); world.add(loc, dude); world.show(); The add method of class World receives a Location parameter and an Actor reference. The Actor reference is stored in the grid at the specified Location. The default color of an Actor is BLUE. ActorWorld world = new ActorWorld(); Actor dude = new Actor(); Location loc = new Location(0,0); world.add(loc, dude); world.show(); What happens if you click on the actor? © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Methods reference command / method world.add(loc, dude); World is the reference to an world. Add is a method that adds a reference at a particular location. The add method is called to tell world to add dude at location loc. Methods are used to tell an object what to do. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Bug © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Bug Bug differs from actor in that a bug actually moves from cell to cell. A bug moves to the cell immediately in front if possible. If a move is not possible, the bug turns in 45 degree increments until it finds a spot to which it can move. Bug is a suped up Actor. Bug extends Actor. Bug has two constructors, one of which takes a Color parameter. Bug will move when its act method is called. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Bug ActorWorld world = new ActorWorld(); Bug dude = new Bug(); world.add(new Location(3,3), dude); world.show(); In this example, a default Bug is created. A default bug is red and facing NORTH. The bug moves NORTH until it reaches the top of the grid. The bug them turns in 45 degree increments until it finds an empty location to which to move. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Critter © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Critter Critter differs from actor in that a critter moves around the grid and eats specific types of other actors. Critter randomly picks one of its valid adjacent empty locations and moves to that location. Critter is a suped up actor that moves around the grid and eats other actors. Critter will eat all neighbors that are not critters and not rocks. Critter randomly selects one of its valid empty adjacent locations. Critter moves to the new location. © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com Critter ActorWorld world = new ActorWorld(); Critter thang = new Critter(); Location loc = new Location(1,1); world.add(loc, thang); world.show(); //shortcut version of the code above ActorWorld world = new ActorWorld(); world.add(new Location(1,1), new Critter()); world.show(); © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com imports © A+ Computer Science - www.apluscompsci.com

© A+ Computer Science - www.apluscompsci.com imports Imports are used to tell Java where to find a class. import info.gridworld.grid.Location; import info.gridworld.actor.Rock; import info.gridworld.actor.Flower; import java.awt.Color; © A+ Computer Science - www.apluscompsci.com