首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

一个标题没思路。求各位指点下

2013-09-28 
一个题目没思路。。。求各位指点下Problem Description and BackgroundThe planet Pern, in a faraway star s

一个题目没思路。。。求各位指点下
Problem Description and Background
The planet Pern, in a faraway star system, has been settled by humans. Every 200 years or so, Pern is plagued by Thread. Thread comes from outer space and falls through the atmosphere. If Thread reaches the ground then it destroys plants and animals (including humans). The people of Pern have fire breathing dragons, ridden by humans. When Thread falls the dragons and riders rise up into the air and attempt to destroy the Thread before it reaches the ground. If a dragon is close enough to a patch of Thread then its flame completely destroys the Thread.

Dragons come in different sizes, this is based on the colour of the dragon. Bigger dragons have a bigger wingspan which means that they can go up and down faster than smaller dragons. However bigger dragons don't go left or right as well as smaller dragons.

Bigger dragons also have a stronger flame which means they can be further away from Thread when they attempt to destroy it, than smaller dragons, and still succeed.

This is known as the flame distance.

When Thread starts to fall the Dragons (and riders) know that Thread has started to fall, but they don't know exactly where. So the dragon starts at a certain location in the sky. When the dragon and rider see the position of the Thread then they have to try and fly to the position of the Thread.

The position of Thread is recorded using two co-ordinates, x1 and y1, for example. The x1 (horizontal) coordinate is the distance (plus or minus) from some arbitrary point on the ground. The y1 (vertical) coordinate is the height above the ground.

The position of the dragon is also recorded using two coordinates, x2 and y2, for example. The x2 (horizontal) coordinate is the distance (plus or minus) from the same arbitrary point on the ground as is used for Thread. The y2 (vertical) coordinate is the height of the dragon above the ground.
 
In the action against Thread the flight is divided up into time slices. In one time slice, Thread falls 100 units or is blown horizontally 100 units left or right. When a dragon carries out a menu choice, this also lasts for the whole time slice.

± means plus or minus

All dragons go left or right using this formula newX = oldX ± ((100 / wingspan) * 50 )
to go left makes newX less than oldX so subtract to go right makes newX greater than oldX so add

NOTE: x can be negative

All dragons go up or down using this formula newY = oldY ± (wingspan * 5 )
Dragons never crash into the ground, they land, so if newY is negative make it zero
The formula for working out the distance between 2 points is distance = √ (x2 - x1)2 + (y2 - y1)2

Thread can go down, left or right.

This is determined randomly which is explained below.

Working out the next position of Thread.

Generate a random number between 0 and 16 (exclusive)

If the random number is 0, 3 or 11
then the new x1 (horizontal) position of Thread is 100 units to the right. the y1 (vertical) position stays the same.

If the random number is 5, 9 or 14
then the new x1 (horizontal) position of Thread is 100 units to the left. the y1 (vertical) position stays the same.



any other number except the ones above means that
the y1 (vertical) position of the Thread is 100 units down the x1 (horizontal) position stays the same.
 
Program Requirements

You are required to write a program, in Java, to simulate a dragon and rider trying to destroy Thread.

The program starts by reading in values from a text file. The format of the text file is given on page 6. You may assume that the text file is always correct and in the correct format. Your program must not hard code the name of the input file. That is, your program must work with any text file in the correct format.

The values in the text file are stored in local variables, one for each line of the file input, see page 6 for the full explanation.

Then the initial position of Thread is generated.

The x1 (horizontal) position is generated by a random number between 0 and 4000 (exclusive)

The y1 (vertical) position is generated by a random number between 1000 and 2000 (exclusive)

After the text file is read in, and the initial position of Thread is generated, the user is presented with a menu. The user then enters commands until the dragon either successfully destroys Thread, Thread reaches the ground or the user enters the "quit" command

Commands must be case insensitive. That means that the commands lefT and LEft
must have the same result.

Shown below is an example of the menu (note, you can customize the menu, but the commands that are entered must be text, and must be able to handle a command of more than one word)

Menu

left - Go left right - Go right up - Go up
down - Go down
flame on - breathe fire between - go between quit
Enter choice >>
 
Commands that can be entered and an explanation of each command

left

If the user enters this command, then the new x2 (horizontal) position of the dragon is worked out using the formula on page 3. The y2 (vertical) position of the dragon remains the same. Note that the new x2 position will be less than the old x2 position.

right

If the user enters this command, then the new x2 (horizontal) position of the dragon is worked out using the formula on page 3. The y2 (vertical) position of the dragon remains the same. Note that the new x2 position will be greater than the old x2 position.

up

If the user enters this command, then the new y2 (vertical) position of the dragon
is worked out using the formula on page 3. The x2 (horizontal) position of the dragon remains the same. Note that the new y2 position will be greater than the old y2 position.

down

If the user enters this command, then the new y2 (vertical) position of the dragon
is worked out using the formula on page 3. The x2 (horizontal) position of the dragon remains the same. Note that the new y2 position will be less than the old y2  position.

flame on

If the user enters this command, then the distance between the dragon and Thread is worked out using the formula for the distance between 2 points on page 3.
If this distance is less than or equal to the flame distance of the dragon, then the Thread is destroyed, an appropriate message (which includes the name and colour of the dragon) is output to the screen and the program closes.



If the distance is greater than the flame distance then an appropriate message is output to the screen advising the user that the Thread was not destroyed. The program continues.

This menu choice does NOT change the position of the dragon. If Thread is not destroyed then the new position of Thread is calculated, but the dragon
stays in the same position.
 
between

If the user enters this command then the dragon "goes between" for this time slice. This means that the position of the dragon does not change. The new position of Thread is, however, calculated.

Hint: this command is useful if a dragon is in the right position (horizontally) but Thread is above the dragon, but out of flame distance range. The dragon can "go between", come back in exactly the same position and Thread will
have dropped down closer to the dragon. Of course, Thread may be blown left or right instead of going down while the dragon was between.

quit

If the user enters this command, the program ends, without displaying a message about whether or not Thread was destroyed.

NOTE: System.exit( ) is NOT allowed and any use will result in a major loss of marks.

The program continues to loop around until: Thread is destroyed, Thread reaches the ground, in both these 2 cases an appropriate message
(which includes the name and colour of the dragon) is output to the screen, or the user enters the "quit" command.


Each time through the loop is considered to be one time slice.

Each time through the loop, the positions of both Thread and the dragon should be displayed to the screen.

Format of the input text file

File lineExplanation
Mnementhdragon name
39wingspan (int)
Bendenweyr (can be more than one word)
bronzecolour of the dragon
1000initial y2 (height) position of the dragon
2000initial x2 (horizontal) position of the dragon
200flame distance of the dragon

挺多不知道该怎么写的- - Bigger dragons一个标题没思路。求各位指点下
老外的题目这么碉堡
[解决办法]
我把这文章当阅读理解看了一遍,不错,挺有意思,
再看看时间,没时间回答了。。。

热点排行