Question

Task 1 of 3 Game Rules Presented here, is an outline of the rules of the...

Task 1 of 3

Game Rules

Presented here, is an outline of the rules of the game around which this assignment is

centred. This is not meant to be a completely exhaustive explanation, as you should defer

to the specics provided in the Task descriptions for more detail, but rather this is to

esh out the design and intention behind the game.

2.1.1 Game Board

The game is played on a square board made of NxN characters where N is a number.

The square board is meant to represent open seas and thus there is no special terrain or

features beyond the ships. The board is numbered of course, with the top leftmost corner

representing the coordinates (0,0). The subsequent rows and columns increase as they

move away from this position.

For example, consider,

01234

0#####

1#####

2#####

3#####

4#####

This is a board made of 5x5 tiles. Each tile represents the open sea and the board

is currently completely empty. The positions of the each tile, in terms of coordinates

it reects is given by the numbers. The top leftmost corner is (0,0) and the bottom

rightmost corner is (4,4)

2.1.2 Ships and Tokens

Unlike Battleships, this game does not use dierently shaped tokens to represent ships

on the board. Instead, a ship is represented by a symbol whose coordinates represent

the location of the ship on the board. All ships are represented this way, indicating that

there are no specialised tokens for ships.

Both players get an equal number of tokens for the match, and they must place them

on the board. Neither player knows, or should know, where their opponent's pieces are

placed and thus, both place their tokens on the board ignoring the positions of the other

player's tokens. In eect, this creates two initially identical boards that then get their

tokens placed on. Tokens belonging to the same player cannot overlap in their placements

on the board; each must be uniquely placed. However, enemy tokens can share.

So Player A cannot have two tokens on position (0,0) but Player A and Player B can

both have one token on (0,0).

2.1.3 Turn Sequences

The game is played in a number of turns. The number of turns is the size of a board

length so a 5x5 board would then have a game consisting of 5 turns. In each turn, both

players will make their guesses for where the enemy ships are on the board. This happens

simultaneously with each player making a number of guesses also equal to the size of the

board length.

So again, a board of 5x5 would have turns where each player makes 5 guesses for where the

enemy ships are. After resolving the guesses, feedback about their positions is provided

as well. This would then be used to inform the next turns' moves.

The game ends when either the turns have elapsed, or one side loses all of their ships. The

winning side is calculated then through a scoring mechanic. As it is possible for the two

sides to destroy each other during a simultaneous turn resolution, there is an additional

scoring mechanic in place that is used to resolve the game.

2.1.4 Example Board

Here is an example 5x5 board with 4 tokens placed.

01234

0*####

1#####

2##*##

3###*#

4#*###

There are no restrictions generally on token placement but it is advisable to try to avoid

a predictable placement such as all of the ships in a straight line.

2.2 Task 1: Ship Class

The basis of the assignment is the Ship class. It is comprised of two les: ship.h and

ship.cpp. You will be required to produce both of these les for yourself. A UML

diagram for the ship class is provided to you below:

ship

-id:string

-value:int

-xCoord:int*

-yCoord:int*

------------------------

+ship()

+ship(newShip:ship*)

+ship(i:string,val:int,x:int,y:int)

+ ship()

+getID():string

+getVal():int

+getX():int

+getY():int

+setID(a:string):void

+setVal(a:int):void

+setX(a:int):void

+setY(a:int):void

The class variables are as follows:

id: A unique string id that identies each of the ships. The ID has the form of a

string with the format of "(X,Y)" where X is the X coordinate of the ship and Y

the y coordinate of the ship. Since each ship must be uniquely assigned, these ids

are all unique to each player.

value: A numerical value in the range [1,5] that assigns additional worth to each

ship.

xCoord: The X coordinate of the ship on the board.

yCoord: The Y coordinate of the ship on the board.

The class methods have the following behaviour:

ship: The default and empty constructor for the ship class.

ship(newShip:ship*): This is a copy constructor for the ship class. It receives an

instantiated ship object and copies the values of that object into a newly constructed

instance.

ship(i:string,val:int,x:int,y:int): This is a value-based constructor for the class. It

takes 4 separate arguments which all correspond to values inside the class.

ship: The class destructor. This deallocates any allocated memory of the class.

It also prints out (on a new line), the following message: "Ship <ID> destroyed"

where <ID> refers to the ID of the ship that is deallocated.

getID: This returns the ID variable.

getVal: This returns the value variable.

getX: This returns the X coordinate variable.

getY: This returns the Y coordinate variable.

setID: This sets the ID variable to the passed in value.

setVal: This sets the value variable to the passed in value.

setX: This sets the x coordinate to the passed in value.

setY: This sets the y coordinate to the passed in value.

You are allowed to make use of the following libraries:

iostream

string

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// ship.h

#ifndef SHIP_H_

#define SHIP_H_

#include <iostream>

using namespace std;

class ship

{

private:

       string id;

       int value;

       int *xCoord;

       int *yCoord;

public:

       ship();

       ship(ship *newShip);

       ship(string i, int val, int x, int y);

       ~ship();

       string getID();

       int getVal();

       int getX();

       int getY();

       void setId(string a);

       void setVal(int val);

       void setX(int a);

       void setY(int a);

};

#endif /* SHIP_H_ */

//end of ship.h

//ship.cpp

#include "ship.h"

ship::ship()

{

       xCoord = new int;

       yCoord = new int;

       id = "";

       value = 0;

}

ship::ship(ship *newShip)

{

       xCoord = new int;

       yCoord = new int;

       id = newShip->id;

       value = newShip->value;

       (*xCoord) = *(newShip->xCoord);

       (*yCoord) = *(newShip->yCoord);

}

ship::ship(string i, int val, int x, int y)

{

       xCoord = new int;

       yCoord = new int;

       *xCoord = x;

       *yCoord = y;

       id = i;

       value = val;

}

ship::~ship()

{

       cout<<"\nShip "<<id<<" destroyed";

       delete(xCoord);

       delete(yCoord);

}

string ship::getID()

{

       return id;

}

int ship::getVal()

{

       return value;

}

int ship::getX()

{

       return *xCoord;

}

int ship::getY()

{

       return *yCoord;

}

void ship::setId(string a)

{

       id = a;

}

void ship::setVal(int val)

{

       value = val;

}

void ship::setX(int a)

{

       *xCoord = a;

}

void ship::setY(int a)

{

       *yCoord = a;

}

//end of ship.cpp

Add a comment
Know the answer?
Add Answer to:
Task 1 of 3 Game Rules Presented here, is an outline of the rules of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment - Battleship In 1967, Hasbro toys introduced a childrens game named “Battleship”. In the next...

    Assignment - Battleship In 1967, Hasbro toys introduced a childrens game named “Battleship”. In the next two assignments you will be creating a one-player version of the game. The game is extremely simple. Each player arranges a fleet of ships in a grid. The grid is hidden from the opponent. Here is an ASCII representation of a 10x10 grid. The ‘X’s represent ships, the ‘~’s represent empty water. There are three ships in the picture: A vertical ship with a...

  • C#: Implement a multiplayer Battleship game with AI The rules are the same as before. The...

    C#: Implement a multiplayer Battleship game with AI The rules are the same as before. The game is played on an NxN grid. Each player will place a specified collection of ships: The ships will vary in length (size) from 2 to 5; There can be any number or any size ship. There may be no ships of a particular size; EXCEPT the battleship – which there will always be 1 and only 1. Player order will be random but...

  • I need assistance with this method. Don't change the method type, decoding UTF8 import java.util.Scanner; /**...

    I need assistance with this method. Don't change the method type, decoding UTF8 import java.util.Scanner; /** * Determines if a sequence of cells of length len in a game board is clear or not. This is used * to determine if a ship will fit on a given game board. The x and y coordinates passed in as * parameters represent the top-left cell of the ship when considering the grid. * * @param board The game board to search....

  • For your Project, you will develop a simple battleship game. Battleship is a guessing game for...

    For your Project, you will develop a simple battleship game. Battleship is a guessing game for two players. It is played on four grids. Two grids (one for each player) are used to mark each players' fleets of ships (including battleships). The locations of the fleet (these first two grids) are concealed from the other player so that they do not know the locations of the opponent’s ships. Players alternate turns by ‘firing torpedoes’ at the other player's ships. The...

  • The game Battleship is played on a grid board. Each opponent has multiple ships that are...

    The game Battleship is played on a grid board. Each opponent has multiple ships that are placed on the grid where the other opponent cannot see them. In order to attack, each player takes turns calling out coordinates on a grid. If the attacker calls out a coordinate that hits their opponent's ship, they must call out, "Hit." You are going to be developing a computer program to mimic this game. Use the Gridlayout that is six columns by six...

  • The game Battleship is played on a grid board. Each opponent has multiple ships that are placed on the grid where the o...

    The game Battleship is played on a grid board. Each opponent has multiple ships that are placed on the grid where the other opponent cannot see them. In order to attack, each player takes turns calling out coordinates on a grid. If the attacker calls out a coordinate that hits their opponent's ship, they must call out, "Hit." You are going to be developing a computer program to mimic this game. Use the Gridlayout that is six columns by six...

  • In C++ please.. I only need the game.cpp. thanks. Game. Create a project titled Lab8_Game. Use...

    In C++ please.. I only need the game.cpp. thanks. Game. Create a project titled Lab8_Game. Use battleship.h, battleship.cpp that mentioned below; add game.cpp that contains main() , invokes the game functions declared in battleship.h and implements the Battleship game as described in the introduction. ——————————————- //battleship.h #pragma once // structure definitions and function prototypes // for the battleship assignment // 3/20/2019 #include #include #ifndef BATTLESHIP_H_ #define BATTLESHIP_H_ // // data structures definitions // const int fleetSize = 6; // number...

  • Connect 4 is a 2 player game where each player has a set of colored tokens...

    Connect 4 is a 2 player game where each player has a set of colored tokens (red or yellow). Players take turns during which they place a single token into one of the columns of an n by m grid (where n is the number of rows and m is the number of columns. They place their token into a slot at the top of the column and it falls into the lowest unoccupied slot in that column. A player...

  • Make sure to include: Ship.java, ShipTester.java, Location.java, LocationTester.java, Grid.java, GridTester.java, Player.java, PlayerTester.java, battleship.java. please do every...

    Make sure to include: Ship.java, ShipTester.java, Location.java, LocationTester.java, Grid.java, GridTester.java, Player.java, PlayerTester.java, battleship.java. please do every part, and include java doc and comments Create a battleship program. Include Javadoc and comments. Grade 12 level coding style using java only. You will need to create a Ship class, Location class, Grid Class, Add a ship to the Grid, Create the Player class, the Battleship class, Add at least one extension. Make sure to include the testers. Starting code/ sample/methods will be...

  • C++ Trek Wars Project: 100% code coverage unit testing is required for this project. once a ship has reached 0 health it...

    C++ Trek Wars Project: 100% code coverage unit testing is required for this project. once a ship has reached 0 health it is considered blown up -throw an exception if the move method is called on it. -repair ships cannot repair ships at 0 health There will be no chaotic corvette ships Trek Wars Purpose: classes, inheritance, class diagrams, virtual, testing Description Universal Merriment Development (UMD) is creating an online space battle game called (Trek Wars) You are tasked with...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT