cse 142: more critters!
DESCRIPTION
CSE 142: More Critters!. Weds, Nov. 26 th Reading: Section Handout. Today’s Agenda. Review ideas behind Critter assignment, answer questions Practice writing Critters Critters will also be on the final!. Role of CritterMain. Think of CritterMain as Game Master - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: CSE 142: More Critters!](https://reader033.vdocuments.us/reader033/viewer/2022061601/56812d1a550346895d920d3c/html5/thumbnails/1.jpg)
CSE 142: More Critters!
Weds, Nov. 26th
Reading: Section Handout
![Page 2: CSE 142: More Critters!](https://reader033.vdocuments.us/reader033/viewer/2022061601/56812d1a550346895d920d3c/html5/thumbnails/2.jpg)
Today’s Agenda• Review ideas behind Critter assignment,
answer questions• Practice writing Critters• Critters will also be on the final!
![Page 3: CSE 142: More Critters!](https://reader033.vdocuments.us/reader033/viewer/2022061601/56812d1a550346895d920d3c/html5/thumbnails/3.jpg)
• Think of CritterMain as Game Master• Does the behind the scenes
work to administer the game• Constructs your Critters,
places them in the world for you
• What the Game Master does you do NOT have to implement!!• You create the Critter classes,
which are like players in the game
Role of CritterMain
CritterMain the Game Master
![Page 4: CSE 142: More Critters!](https://reader033.vdocuments.us/reader033/viewer/2022061601/56812d1a550346895d920d3c/html5/thumbnails/4.jpg)
Review of CritterMain
CritterMain
![Page 5: CSE 142: More Critters!](https://reader033.vdocuments.us/reader033/viewer/2022061601/56812d1a550346895d920d3c/html5/thumbnails/5.jpg)
• Game Master also runs each “move” of the game• Every Critter’s “move” is executed during a tick • Game = Sequence of ticks
• Moves the critters, runs battles, figures out who’s napping/mating/eating, etc
• Must prompt each Critter:• Tell me what you look like (toString(), getColor()),
Tell me where you want to go to next (getMove())
• If on a food, calls eat()• If in a fight, calls fight()
Role of CritterMain, 2
![Page 6: CSE 142: More Critters!](https://reader033.vdocuments.us/reader033/viewer/2022061601/56812d1a550346895d920d3c/html5/thumbnails/6.jpg)
LLWhat’s your next move?
![Page 7: CSE 142: More Critters!](https://reader033.vdocuments.us/reader033/viewer/2022061601/56812d1a550346895d920d3c/html5/thumbnails/7.jpg)
![Page 8: CSE 142: More Critters!](https://reader033.vdocuments.us/reader033/viewer/2022061601/56812d1a550346895d920d3c/html5/thumbnails/8.jpg)
• Our job is to program Critters: we decide how a Critter behaves when CritterMain calls its methods• How it moves, how it eats, etc.
• Behavior often dependent on things the Critter has to “remember” so we also give Critters state
Programming a Critter
![Page 9: CSE 142: More Critters!](https://reader033.vdocuments.us/reader033/viewer/2022061601/56812d1a550346895d920d3c/html5/thumbnails/9.jpg)
A Simple Critter: RabbitMethod Behavior
Constructor public Rabbit()
Color dark gray (Color.DARK_GRAY)
Eatingalternates between true and false(true, false, true, ...)
Fighting if opponent is a Lion, then scratch; otherwise, roar
Movement 2 N, 2 S, 2 E, repeat
toString "V"
![Page 10: CSE 142: More Critters!](https://reader033.vdocuments.us/reader033/viewer/2022061601/56812d1a550346895d920d3c/html5/thumbnails/10.jpg)
Rabbit movement
![Page 11: CSE 142: More Critters!](https://reader033.vdocuments.us/reader033/viewer/2022061601/56812d1a550346895d920d3c/html5/thumbnails/11.jpg)
Rabbit movement
1
2
4
3
5 6
![Page 12: CSE 142: More Critters!](https://reader033.vdocuments.us/reader033/viewer/2022061601/56812d1a550346895d920d3c/html5/thumbnails/12.jpg)
A complex Critter: SnakeMethod Behavior
Constructor public Snake()
Color (red=20, green=50, blue=128)
Eating Never eats
Fighting Randomly choose to roar or pounce
Movement 1 E, 1 S; 2 W, 1 S; 3 E, 1 S; 4 W, 1 S; 5 E, ...
toString Always returns "S"