Copyright 2010 by Pearson Education 1 Assignment 11: Critters.

Slides:



Advertisements
Similar presentations
 Variables  What are they?  Declaring and initializing variables  Common uses for variables  Variables you get “for free” in Processing ▪ Aka: Built-in.
Advertisements

Fields, Constructors, Methods
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington UML for design: Class Diagrams.
CS 112 Introduction to Programming
Animation Mrs. C. Furman. Animation  We can animate our crab by switching the image between two pictures.  crab.png and crab2.png.
CSCI 1100/1202 April 3, Testing A program should be executed multiple times with various input in an attempt to find errors Debugging is the process.
Asteroids Games and Simulations O-O Programming in Java The Walker School The Walker School – Games and Simulations
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Lecture 9-2: Static Data; More Inheritance reading:
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Critters; Subtype Polymorphism Reading: HW9 Handout, Chapter 9.2.
Copyright 2010 by Pearson Education 1 Assignment 11: Critters reading: HW11 assignment spec.
ACSE th Conference The Iconic Programmer Stephen Chen.
Programming – Touch Sensors Intro to Robotics. The Limit Switch When designing robotic arms there is always the chance the arm will move too far up or.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
Games and Simulations O-O Programming in Java The Walker School
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Lecture 9-x: Critters reading: HW9 Spec.
Fundamentals of Python: From First Programs Through Data Structures
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
AP ® Marine Biology Simulation Case Study Alyce Brady Kalamazoo College.
MrsBillinghurst. net A2 Computing A2 Computing Projects Game Animation in Pascal.
Microsoft® Small Basic
AP ® Marine Biology Simulation Case Study Alyce Brady Kalamazoo College.
Fundamentals of Python: First Programs
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Programming & Scratch. Programming Learning to program is ultimately about learning to think logically and to approach problems methodically. The building.
Visual Basic .NET BASICS
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-4: Static Methods and Fields.
Game Maker Terminology
1 ball, 2 ball, red ball, blue ball By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Copyright 2010 by Pearson Education Homework 9: Critters (cont.) reading: HW9 spec.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Lecture 9-2: Interacting with the Superclass ( super ) reading:
Building Java Programs Chapter 8 Lecture 8-3: Object state; Homework 8 (Critters) reading:
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Lecture 9-2: Interacting with the Superclass ( super ); Discussion of Homework 9:
Copyright 2010 by Pearson Education Building Java Programs Homework 8: Critters reading: Critters Assignment Spec.
Copyright 2010 by Pearson Education Homework 8: Critters reading: HW8 spec.
Copyright 2008 by Pearson Education Building Java Programs Chapter 9 Lecture 9-2: Interacting with the Superclass ( super ); Discussion of Homework 9:
Copyright 2010 by Pearson Education Homework 9: Critters (cont.) reading: HW9 spec.
Object Orientated Programming in Perl Simulated Models of Termites.
Copyright 2009 by Pearson Education Building Java Programs Chapter 8: Classes Lecture 8-3: More Critters, static.
Copyright 2009 by Pearson Education Building Java Programs Chapter 9: Inheritance and Interfaces Lecture 9-1.
CS 112 Introduction to Programming Method Overriding; Object Hierarchy; Event-Driven Programming Yang (Richard) Yang Computer Science Department Yale University.
Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
Building Java Programs
Weds, Nov. 26th Reading: Section Handout
Homework 8: Critters reading: HW8 spec.
The software crisis software engineering: The practice of developing, designing, documenting, testing large computer programs. Large-scale projects face.
Building Java Programs
Chapter 4: Writing Classes
HW11 Assignment Specification
Lecture 8-3: Encapsulation, this
Critter exercise: Snake
Organizing Memory in Java
Homework 8: Critters (cont.)
CSE 142 Critters (IPL) behavior: Ant Bird Hippo Vulture
Adapted from slides by Marty Stepp and Stuart Reges
The software crisis software engineering: The practice of developing, designing, documenting, testing large computer programs. Large-scale projects face.
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Homework 8: Critters (cont.)
Building Java Programs
Building Java Programs
Homework 9: Critters (cont.)
Building Java Programs
Building Java Programs
Presentation transcript:

Copyright 2010 by Pearson Education 1 Assignment 11: Critters

Copyright 2010 by Pearson Education 2 Overview of Critters Critters is a 2-D rectangular simulation world with moving animals that interact with other animals. Different kinds of animals are implemented in the simulation (or game) that move around in the world and fight with the other animals. Fighting happens when two animals move into the same space, and it results in the death of one of the two. Each animal is described by a Class that represents its unique rules of moving and fighting. You will write four Classes – one for each of 4 animals. The simulation engine will be the client of (i.e. will use) your 4 classes. The engine is provided to you. Running the simulation will show you (graphically) the behavior of the animals in their world.

Copyright 2010 by Pearson Education 3 Overview of Critters Contd The simulation engine works like Conway’s Game of Life engine. 1. Start off with a pattern of animals in a 2-D grid. 2. Draw the grid. 3. After ‘time tick’, the animals move to new positions according to their individual rules. If more than one animal wants to move to the same place, the order in which they move is random. 4. If they encounter another animal, there is a fight to the death. 5. When all fights are over, go back to 1. The simulation also summarizes the number of each animal remaining.

Copyright 2010 by Pearson Education 4 Critters A simulation world with animal objects with behavior: fight animal fighting getColor color to display getMove movement toString letter to display You must implement: Lion Tiger Bear Wolf (Creative) Animal counts Buttons 2-D World

Copyright 2010 by Pearson Education 5 Movie of simulation

Copyright 2010 by Pearson Education 6 A Critter class public class name implements Critter {... } implements Critter tells the simulator your class is a critter an example of interfaces Must implement all of the methods specified by the interface interface is like a "to do list"

Copyright 2010 by Pearson Education 7 Critter Interface

Copyright 2010 by Pearson Education 8 Interface Declares methods that classes of that type must implement classes that implement the interface must have the method, but how the method works can be very different A way of ensuring certain behaviors / methods of classes

Copyright 2010 by Pearson Education 9 Examples of behavior of Fox Move in a 5 steps x 5 steps square: N, E, S, W, N … Each time tick, the fox takes one step in the appropriate direction. Fight – all fights are rock-paper-scissors Fox alternates between Rock and Paper, regardless of opponent.

Copyright 2010 by Pearson Education 10 How the simulator works When you press "Go", the simulator enters a loop: move each animal once ( getMove ), in random order if the animal has moved onto an occupied square, fight ! Key concept: The simulator is in control, NOT your animal. Example: getMove can return only one move at a time. getMove can't use loops to return a sequence of moves. It wouldn't be fair to let one animal make many moves in one turn! Your animal must keep state (as fields, instance variables) so that it can make a single move, and know what moves to make later.

Copyright 2010 by Pearson Education 11 Critter exercise: Stone Write a critter class Stone (the dumbest of all critters): MethodBehavior constructor public Stone() fight Always ROCK getColor Always Color.GRAY getMove CENTER toString"S"

Copyright 2010 by Pearson Education 12 Ideas for state You must not only have the right state, but update that state properly when relevant actions occur. Counting is helpful: How many total moves has this animal made? How many times has it fought? Remembering recent actions in fields is helpful: Which direction did the animal move last? How many times has it moved that way?

Copyright 2010 by Pearson Education 13 Keeping state How can a critter move west until it fights? public Direction getMove() { while (animal has not fought) { return Direction.EAST; } while (animal has not fought a second time) { return Direction.EAST; } } private int moves; // total moves made by this Critter public int getMove() { moves++; if (moves % 4 == 1 || moves % 4 == 2) { return WEST; } else { return EAST; } }

Copyright 2010 by Pearson Education 14 Testing critters Focus on one specific critter of one specific type Only spawn 1 of each animal, for debugging Make sure your fields update properly Use println statements to see field values Look at the behavior one step at a time Use "Tick" rather than "Go"

Copyright 2010 by Pearson Education 15 Critter exercise: Snake MethodBehavior constructor public Snake() fight SCISSORS getColor black getMove 1 E, 1 S; 2 W, 1 S; 3 E, 1 S; 4 W, 1 S; 5 E,... toString"K"

Copyright 2010 by Pearson Education 16 Determining necessary fields Information required to decide what move to make? Direction to go in Length of current cycle Number of moves made in current cycle Remembering things you've done in the past: an int counter? a boolean flag?