代写 algorithm Java shell graph software CPI221 – Assignment – World Building

CPI221 – Assignment – World Building
Topics:
 Review Pillars of OOP
 Create a simple command line application
 Create and use inheritance & polymorphism
 Explore “IS A” and “HAS A”
Description:
We’re going to use Slick2D and a 2D array to generate a simple world out of simple terrain types.
Each terrain type will be a polymorphic class. There will be very low user interaction.
Use the following Guidelines:
 Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc).
 Keep identifiers to a reasonably short length.
 User upper case for constants. Use title case (first letter is upper case)
for classes. Use lower case with uppercase word separators for all other
identifiers (variables, methods, objects).
 Use tabs or spaces to indent code within blocks (code surrounded by braces).
This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent.
 Use white space to make your program more readable.
Important Note:
All submitted assignments must begin with the descriptive comment block. To avoid losing trivial points, make sure this comment header is included in every assignment you submit, and that it is updated accordingly from assignment to assignment.

Specifications:
The software will generate a world using objects from an inheritance/polymorphism hierarchy. You wills store these objects in a 2D array.
User Interface:
When the program starts you will ask the user to input a width and height for the world. This should be between 20 and 50. This will determine how big the world will be and how many objects will be created.
Object Orientation:
The software will consist of several classes:
 Terrain
o Grasslands
o Hills
o Mountains o Desert
o Water
 Main class
Each terrain type will have rules on how it should be shown and what kind of
things can be its neighbors.
Terrain Class
 Abstract base class  Properties
o int width
o int height o Color color
 Methods
o drawSelf(Graphics):void o generateNeighbor:Terrain

Grass
 Should be light green in color
 Should generate a neighbor object with these probabilities:
o 50% Grass
o 25% Hill
o 15% Water
o 10% Desert o 0% Mountain
Hill
 Should be dark green in color
 Should generate a neighbor object with these probabilities:
o 25% Grass
o 50% Hill
o 10% Water
o 0% Desert
o 15% Mountain
Water
 Should be blue in color
 Should generate a neighbor object with these probabilities:
o 30% Grass
o 15% Hill
o 50% Water
o 0% Desert
o 5% Mountain
Desert
 Should be yellow-brown in color
 Should generate a neighbor object with these probabilities:
o 30% Grass
o 0% Hill
o 0% Water
o 65% Desert o 5% Mountain
Mountain
 Should be grey in color
 Should generate a neighbor object with these probabilities:
o 0% Grass
o 25% Hills
o 15% Water
o 5% Desert
o 55% Mountain

Algorithm breakdown:
Setup:
1. Get size of array from user
2. Create Terrain 2D array
3. Divide screen width/height by user inputted size
4. Create first piece of terrain in upper left corner
a. Pick randomly
b. Make sure you pass in the pixel width height to the constructor
First row:
1. Generate the second object by asking the upper left corner object to generate a new Terrain object
2. Store the new Terrain in the second index
3. Continue down the row by asking the object “to the left” to generate the new
object
Subsequent rows:
1. The first item in the row will ask the previous row’s first item to generate the object
2. Each item in the rest of the row will ask the object “up from” the current index and “to the left” of the current index to generate objects
3. Flip a coin and store between the two objects and store the winner in the array
4. Continue
UH WHAT?!
Take your time and think about it. It’s not actually a hard algorithm. You’ll be building a nested for loop to generate your terrain. You’ll iterate the outer loop on the Y and the inner loop on the X
Then you build an if…else if…else chain to make sure you generate the terrain correctly.
C’mon Prof. Selgrad … this sounds daunting … Did you build this?
Yes, I actually built a primitive version with ASCII output to make sure the algorithm works
My ASCII version across all the files is about 300 lines of code

Output
After the terrain is generated … draw it to the screen using slick2D
If you can’t make slick2D work … use ASCII
Here’s a sample of one I generated 20×20:
GGWGHHGWGHHHGGWGGGHH
DHHGGWHWDHHHHHWWDGGH
DGHHHMHWDDHGHWWWGGDG
GGHGHHHGGDWGGGHWWGHD
GGDDGHGDGGGGDDHWWWGM
GHGDHGGGGHGWDDMDWMWW
HHGHHHGDDGHHDDDDDMWW
HHHHHHMDDDMHHMDDDHGW
MGMGHHMMDGDGMMDDDDHH
MHHHHHMMDGHGHWDDDMHG
HGGHHHMDGWWGHHHGDDDD
HHGGGDWGGDDDDMGHWGGG
GHHHGGWWGDDDDWGGMHHH
GGHHHWWHGDDGDGWGGHHG
WWMGMMHMMHHHHGMDGGHH
WWHHMMMMDHWMGWWDDDGM
WHGHHWGDDGWWGWWDGDGM
GHWMGDGDDDWWDDGDDGGH
HGWGGGHHDDDHDGHGGGGG
HGWWHHHMMHDMDHGGWGGG
What to turn in:
Create a zip file to submit:
__hw1.java  Terrain.java
 Grass.java
 Hill.java
 Water.java
 Desert.java
 Mountain.java
Name your zip file __hw1.zip
Submit to the course shell.
Grading of Programming Assignment
The grader will grade your program following these steps:
(1) Compile the code. If it does not compile you will receive a U on the Specifications in the Rubric
(2) The grader will read your program and give points based on the points allocated to each component, the readability of your code (organization of the code and comments), logic, inclusion of the required functions, and correctness of the implementations of each function.