I am having problems with another exercise from a website to learn Java.
I am supposed to create classes for a game called cat and mouse.
Basically, there is a grid 5x5 (representing the island) surrounded by water and has 6 bridges off the grid. The cat is hungry and wants the mouse, but the mouse can escape if he finds a bridge or dies if he goes into the water. The cat and mice are placed randomly on the grid at the beginning of the game. Bridges are evenly-spaced, 2 on each side.
There are a lot of parts for this exercise, but I'll just start with the first one right now. I want to create an Animal abstract class with a protected attribute of type Point (the location on the map) and a private String attribute (the animal name). A few more attributes would be: String getName(), Point getLocation(), void setStartLocation(). It will also have one constructor that takes a String (the animal's name) and a Random object. It'll store these values as instance variables (attributes).
Animal( String name, Random rng )
It'll also declare an abstract method:
void move()
I understand what it wants me to do, but it doesn't ask me to create the grid so am I not supposed to? I am not sure how to start this. There are also other classes to be created. Any help and guidance would be appreciated.
The grid is context, but you should make a 2d arrray or collection of classes that rep the squares and the ref and nature of 4 (assuming no diagonal movement) adjacent squares (die, square, bridge).
The grid is context, but you should make a 2d arrray or collection of classes that rep the squares and the ref and nature of 4 (assuming no diagonal movement) adjacent squares (die, square, bridge).
2 per side is 8 bridges.
Of course, displaying it all is a second puzzle.
Okay, I'll just create the classes. What does it mean by: create an Animal abstract class with a protected attribute of type Point (the location on the map) and a private String attribute (the animal name)? Can you give me a layout on how to do this in general?
The Animal needs to be a child/friend of the Grid object, so movement can be determined from the nature of the current 4 walls.
Of course, there are other ways to encode the grid, but the more compact, the more work to figure out what happens with a direction choice.
Hello friends,
could you please advice me of how to traslate this program written in C to java?
#include <cstdio>
main( ){
char c;
c = getchar( );
while (c != EOF) {
putchar(c);
c = getchar( );
}
}
I am supposed to test the difference in time between compiling the C... (2 Replies)
Hello,
So I sorted my file as I was supposed to:
sort -n -r -k 2 -k 1 file1 | uniq > file2
and when I wrote
> cat file2
in the command line, I got what I was expecting, but in the script itself
...
sort -n -r -k 2 -k 1 averages | uniq > temp
cat file2
It wrote a whole... (21 Replies)
Hi, I'm using rxvt in Cygwin and I'm wondering how to change my mouse bindings from the middle button for pasting to the right button. The main reason why I want to do this is because my laptop doesn't have a middle mouse button. Thanks for any help! (2 Replies)
Hello all,
I'm hoping to get a little insight from some of the wily veterans amongst you.
I've written a script to check for new outgoing files to our vendors located on our ssl server. It seems to be working ok, but the final question here, will be one of logic, and/or a better way to... (4 Replies)