Friday, January 30, 2015

Cat Simulator 2015

I worked together with my friend Tim to make a 'cat simulator' of sorts in Java. After naming your virtual cat, you can use text commands to pet it, give it things to play with / eat, or watch it interact with things you've given it. Here's an example run of the program:

You got a new pet cat! What do you want to name him?
Tom
You named him Tom.
What do you want to do?
(pet, give, watch, exit)
give
What item is it?
paper ball
Is it edible?
no
Tom plays idly with the paper ball.
(pet, give, watch, exit)
give
What item is it?
catnip
Is it edible?
yes
Tom stares at the catnip.
(pet, give, watch, exit)
watch
Tom eats the catnip. Viciously.
(pet, give, watch, exit)
watch
Tom meows.
(pet, give, watch, exit)
pet
You pet Tom and he purrs softly.
(pet, give, watch, exit)
pet
You pet Tom the wrong way, and he scratches you!
(pet, give, watch, exit)

The program is split into three .java files and three separate classes; a main class, a cat class, and an Object class. The main class handles command inputs and stores objects, the cat class decides what it wants to do with with the objects it's given, and the Object class stores information about each object.

The project code can be viewed in this Eclipse project.

No comments:

Post a Comment