You are so recognized now as a premiere programmer that you

You are so recognized now as a premiere programmer that you were hired by pirates to guide their ship out of harbor and onto the open sea. You will have to avoid numerous perils along the way.

Overview

The area between the harbor and the hole in the reef can be represented by a 15-by-30 grid where each point representing a square nautical mile. Contained in this grid are:

One British battleship on patrol.

Very hungry great white sharks that fancy pirates (they taste like chicken marinated in Guinness).

Random icebergs. In addition, the entire perimeter of the oceanic area described is made up of icebergs that formed overnight.

A single exit point from the wall of surrounding icebergs that will release your ship into the open sea for escape.

Your program will repeatedly ask you which direction you want to move in. Each time you move, you must try to avoid hitting, or being hit/eaten by an iceberg or a shark (remember, they’re very big and like to eat pirates), or being blasted by the Brits. You are within range of the Brits if you are in an adjacent square to their war vessel, including diagonal squares. It’s almost certain that your ship will be obliterated by cannon fire.

Function Decomposition

You are being provided with the functions that you will need below. You simply need to add these to your program and complete the code and commit your program as below (see submission). The function prototypes and purposes are as follows:

void briefing();

Give the user playing instructions.

void readMap(char ocean[ROWS][COLUMNS], int, int, int, int);

Read in the initial map from a file (this is the map.txt file). Parameters include the map, your current position and the coordinates of the hole in the wall. The file contains exactly 15 lines of 30 integers per line, coded as follows:

0 = open sea

1 = iceberg

2 = shark

3 = British battleship

4 = the escape position

5 = your pirate ship

When you create the actual map you are to insert/convert to the actual characters to be displayed into the array.

Your ship and mates are represented by the character ‘’. (Arrgh!)

The battle ship is represented by an asterisk ‘*’.

Sharks are represented by the Latin symbol ‘œ’ (which sort of looks like a fish with its mouth open).

Icebergs are represented by a solid dot ‘’.

Open sea is represented by a blank ‘ ’.

The escape position is represented by an ‘X’.

You read in the map as a 2-dimensional array of integers for the sole purpose of file reading sanity. However, this is not how it will appear when you display it on the screen. You may not use the integer array to represent your ocean. As you read numbers, populate a 2-dimensional character array appropriately and proceed when finished reading the file.

void printMap(const char ocean[ROWS][COLUMNS]);

Print the current ocean grid map. The ocean map should be displayed on the screen after each time you move and after the battleship and all of the sharks have moved.

bool pirateMove(char ocean[ROWS][COLUMNS], int myX, int myY, const int escX, const int escY);

Get a move from the player. Remember, each time you move all the sharks and the battleship move one space toward you. Parameters are the same as for readMap(). Keyboard commands from the numeric keypad will move your ship as follows:

move one row above

your current position

move one column to the left

of your current position

move one column to the right

of your current position

move one row below

your current position

Any other keyboard entry will keep your ship in the same position. (Optionally you can implement diagonal moves for the ship if you choose.) After moving the ship, check to see if your voyage is to continue (see endVoyage() below). If so return true, otherwise false.

void endVoyage(int outcome);

Check to see if you have reached the escape point. There are four possibilities:

You’ve found the hole in the wall and escaped.

You’ve run into an iceberg.

You’ve been eaten by the sharks.

You’ve been destroyed by the British patrols.

Accept as an argument one of these options and print an appropriate message explaining what happened.

bool sharkMoves(char ocean[ROWS][COLUMNS], int myX, int myY);

Move the sharks. Each time you move your ship, the battleship and sharks move toward you (see below). Unlike your ship sharks can move diagonally (northeast, northwest, southeast and southwest). Sharks cannot travel through icebergs and therefore avoid them. The shark must still move toward you but it may not be optimal. Two sharks may not hit each other. If two sharks collide one is left.

bool battleshipMove(char ocean[ROWS][COLUMNS], int myX, int myY);

Move the battleship. The battleship can also navigate diagonally (northeast, northwest, southeast and southwest) and destroys anything in its path – icebergs, sharks, and, unfortunately, you. That means if a battleship moves to a position where an iceberg was, when it moves away, that map position becomes open sea.

The game continues until you reach the exit point; or until the sharks or the Brits have eliminated you; or you carelessly navigate into an iceberg. Once the scenario has reached a conclusion, print out what happened.

Further Coding Details

Make sure you use call by value and call by reference properly. Don’t automatically assume that the function examples given have headers and prototypes that are correct.

Use a two-dimensional character array to represent the oceanic grid map.

At a minimum you need functions previously described

Give the user playing instructions.

Read in the initial map.

Print the current ocean grid map.

Get a move from the pirate (that’s you by the way) and move to that position.

Move the sharks and battleship.

Check to see if you have reached the escape point, been blown up or eaten.

Functions must have header comments that include the purpose of the function. They also must include the pre-condition and post-condition documentation as well.

Refer to the Programming Rubric for details located on Springboard: Table of Contents -> main() -> { Course Orientation ->RubricProgrammingforAssigments

Use a header comment with your name and the description of the program.

Use pre and post condition comments for each function.

Use prototypes for the functions (pre & post comments go with them).

Include all your functions at the end of the program.

Use appropriate code comments.

Use appropriate variable names.

Use constants where appropriate.

Use good coding practices (i.e., spacing, indentation, etc.).

MAP::

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 1
1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 1
1 1 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 2 0 1
1 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 2 1 0 1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

move one row above

your current position

move one column to the left

of your current position

move one column to the right

of your current position

move one row below

your current position

Solution

import java.awt.*; import java.util.*; import java.applet.*; /* */ //The basic applet class.The applet shows 4 cars crossing each other at a square. public class Animation extends Applet implements Runnable { Thread t; //4 variables used to vary the car\'s positions. int x1=0,x2=380,y1=50,y2=250; public void start() { if(t==null) { t=new Thread(this,\"New Thread\");//New side Thread created on start of applet. t.start(); } } public void stop() { if(t!=null) { t=null;//On stop of applet the created thread is destroyed. } } //Implementation of method run() of Runnable interface. public void run() { Thread t1=Thread.currentThread(); while(t==t1) { repaint(); try { Thread.sleep(100); } catch(Exception e) { } } } public void paint(Graphics g) { setBackground(Color.cyan); g.setColor(Color.BLACK); x1=(x1+16)%400; x2=x2-16; y1=(y1+12)%300; y2=y2-12; if(y2<0) y2=288; if(x2<0) x2=384; //Draw the roads using 2 filled rectangles using black color. g.fillRect(0,130,400,40); g.fillRect(180,0,40,305); //Draw the white colored lines. g.setColor(Color.white); for(int i=0;i<20;i++) { if(i!=9 && i!=10) g.drawLine(i*20,150,i*20+10,150); } for(int j=0;j<15;j++) { if(j!=7 && j!=8) g.drawLine(200,j*20,200,j*20+10); } //Draw 4 colored cars using filled round rectangles. g.setColor(Color.red); g.fillRoundRect(x2,152,20,8,2,2); g.fillRoundRect(x1,140,20,8,2,2); g.fillRoundRect(190,y1,8,20,2,2); g.fillRoundRect(202,y2,8,20,2,2); } }
You are so recognized now as a premiere programmer that you were hired by pirates to guide their ship out of harbor and onto the open sea. You will have to avoi
You are so recognized now as a premiere programmer that you were hired by pirates to guide their ship out of harbor and onto the open sea. You will have to avoi
You are so recognized now as a premiere programmer that you were hired by pirates to guide their ship out of harbor and onto the open sea. You will have to avoi
You are so recognized now as a premiere programmer that you were hired by pirates to guide their ship out of harbor and onto the open sea. You will have to avoi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site