A bit confused on how to begin.

So we are doing a program at school and I am a bit confused on what to do.

For this program I have to make a game that sort of looks like this:

XXXXXXXXXXTREASURE ISLANDXXXXXXXXXX

0123456789

+ - + - + - + - + - + - + - + - + - + - +

0 ||| S | S | S | S |||||

+ - + - + - + - + - + - + - + - + - + - +

1 |||| S || F | S ||||

+ - + - + - + - + - + - + - + - + - + - +

2 |||| S || F |||||

+ - + - + - + - + - + - + - + - + - + - +

3 |||||| C |||||

+ - + - + - + - + - + - + - + - + - + - +

4 |||||||||||

+ - + - + - + - + - + - + - + - + - + - +

5 |||||||||||

+ - + - + - + - + - + - + - + - + - + - +

6 |||||||||||

+ - + - + - + - + - + - + - + - + - + - +

7 |||||||||||

+ - + - + - + - + - + - + - + - + - + - +

8 |||||||||||

+ - + - + - + - + - + - + - + - + - + - +

9 |||||||||||

+ - + - + - + - + - + - + - + - + - + - +

S - seaF - forest C - cave V - cliffs

M - mountains O - oak tree X - treasure

Move (NEWS)? N

You have fallen into the ocean

You are drowning. Triangular fins are moving closer!

You made it to shore.

My teacher says that: The grid is filled in semi-randomly with forest representing 20 connected squares; mountains 10 connected squares; caves in three individual squares; cliffs in three groups of three; oak tree one square and ocean - ALL outside squares plus 10 connected squares

My question is: How on earth do I fill in these squares with the proper letters.

[1601 byte] By [AlanG4lyfea] at [2007-11-27 7:44:37]
# 1
> My question is: How on earth do I fill in these squares with the proper letters.Has your teacher dropped you in the ocean, metaphorically speaking, or was some more help given?
Hippolytea at 2007-7-12 19:25:13 > top of Java-index,Java Essentials,New To Java...
# 2

Well I'll post you the whole thing if you would like:

1.Treasure Island:This project involves the creation of a simulation game. In this case, the player is marooned on the island. There will be a 10 X 10 grid of squares which will be randomly filled with mountains, caves, cliffs, forest, an oak tree and treasure. (See the sample screen below) The objective is to explore the island to find the treasure without falling into the sea and drowning or being eaten by sharks.

The player can move north, south, east or west one square at a time with a 75% chance of moving into the direction and a 25% chance of moving to a square one side or the other of the location (to simulate using a bad compass). After each move, a description of the location will be printed and a grid location will be filled in. A fall into the ocean represents a 30% chance of drowning and a 10% chance of being eaten by sharks.

The treasure is located one square to the south of the oak tree. The grid is filled in semi-randomly with forest representing 20 connected squares; mountains 10 connected squares; caves in three individual squares; cliffs in three groups of three; oak tree one square and ocean - ALL outside squares plus 10 connected squares. The oak tree must be placed far enough north to allow a cave to be placed south of it. The treasure is located in this cave. When the player finds this cave the game ends.

The game begins with the player randomly placed in the grid either on land or in the sea and the rest of the map remains blank. As the player moves, the squares are filled in with symbols representing the terrain traversed. With each move, a random number between 1 and 100 is chosen. If the value is between 1 and 74 the player moves to the square, 75 and 87 the player moves to one side of the location and 88 and 100 the player goes to the other side. Descriptions are printed with IF commands as the player moves through different squares of the grid (慪ou are in deep forest.? 慪ou fall into the ocean.? 慚ountains surround you? When the player falls into the ocean another random number between 1 and 100 is chosen. If the value is between 1 and 29 the player drowns. If it is between 30 and 39, the player is eaten by sharks. Otherwise the player swims to shore and continues.

AlanG4lyfea at 2007-7-12 19:25:13 > top of Java-index,Java Essentials,New To Java...
# 3
> My question is: How on earth do I fill in these squares with the proper letters.Okay, try to solve one thing at a time. 1. What have you done so far?2. What is the hardest part for you? It's a good idea to attach the hardest part first.
Hippolytea at 2007-7-12 19:25:13 > top of Java-index,Java Essentials,New To Java...
# 4
Do you know how to create a 2d array of chars?
hunter9000a at 2007-7-12 19:25:13 > top of Java-index,Java Essentials,New To Java...
# 5
> Do you know how to create a 2d array of chars?Yes, but perhaps an object-oriented solution with a grid of Terrain objects would be better.
Hippolytea at 2007-7-12 19:25:13 > top of Java-index,Java Essentials,New To Java...
# 6
> > Do you know how to create a 2d array of chars?> > Yes, but perhaps an object-oriented solution with a> grid of Terrain objects would be better.Baby steps ;P
hunter9000a at 2007-7-12 19:25:13 > top of Java-index,Java Essentials,New To Java...
# 7

> Okay, try to solve one thing at a time.

>

> 1. What have you done so far?

> 2. What is the hardest part for you? It's a good idea

> to attach the hardest part first.

So far I have: made the grid, been able to generate the numbers to determine if the person dies/ doesn't die, I have also been able to set the cursor at each place on the grid depending on what direction the user wants to move.

The hardest part for me is: Determining which item (ocean,tree etc) will be in each square. I'm thinking I'm gonna need an array but I'm not sure how I'll use it for this scenario

AlanG4lyfea at 2007-7-12 19:25:13 > top of Java-index,Java Essentials,New To Java...
# 8
> I have also been able to set the cursor at each place on the grid depending on what direction the user wants to move.What sort of UI will there be? Console, Swing, ...?
Hippolytea at 2007-7-12 19:25:13 > top of Java-index,Java Essentials,New To Java...
# 9
I'm pretty sure you mean the :import hsa.Console;So I hope that answers your question (sorry if it doesn't)
AlanG4lyfea at 2007-7-12 19:25:13 > top of Java-index,Java Essentials,New To Java...
# 10
I don't know what hsa.Console is, so I'll not pursue that.Anyway you need to be able to create a 10x10 grid of squares (char or whatever,but Hunter is right, take small steps.) You must have worked with arraysbefore. Have you ever made a 2D array (an array of
Hippolytea at 2007-7-12 19:25:13 > top of Java-index,Java Essentials,New To Java...
# 11
No I have not worked with them before but I just did a quick Google search and found http://www.willamette.edu/~gorr/classes/cs231/lectures/chapter9/arrays2d.htmI'll read that right now. Looks like it will help a lot.If you havemore info about them that would be great. :)
AlanG4lyfea at 2007-7-12 19:25:13 > top of Java-index,Java Essentials,New To Java...
# 12

String sea = "S";

String forest = "F";

String cave = "C";

String clifss = "V";

String mountains = "M";

String oak = "O";

String board [] [] = new String [10] [10]; // create 100 integers

board [0] [0] = sea;

board [0] [1] = sea;

board [0] [2] = sea;

Should I do something like that for each square on the board? (I know I can use a loop for some of it though)

AlanG4lyfea at 2007-7-12 19:25:13 > top of Java-index,Java Essentials,New To Java...
# 13
I suppose you could start with the board all SEA, and then you sprinkle in the forest etc... or you could start with the board all nulls, and you make the remaining null cells SEA after filling in the forest and mountains, etc...
Hippolytea at 2007-7-12 19:25:13 > top of Java-index,Java Essentials,New To Java...
# 14

> I suppose you could start with the board all SEA, and

> then you sprinkle in the forest etc... or you could

> start with the board all nulls, and you make the

> remaining null cells SEA after filling in the forest

> and mountains, etc...

So would you think I'd be best to do all of those individually? And is there a command to fill all the nulls?

AlanG4lyfea at 2007-7-12 19:25:13 > top of Java-index,Java Essentials,New To Java...
# 15

> So would you think I'd be best to do all of those individually?

I didn't say either approach is best. I'd say it's six or one, half-dozen of the other.

> And is there a command to fill all the nulls?

When you create an array of objects, it is initialized to all nulls. The following code leaves you with100 nulls

String[][] board = new String [10] [10];

If you want to fill that with 100 SEAs, you will need to code the loops. It's not hard.

Hippolytea at 2007-7-21 22:20:14 > top of Java-index,Java Essentials,New To Java...