Basic game of battleship

Assignment Help C/C++ Programming
Reference no: EM13545182

Programming Assignment: Basic Game of Battleship

I. Learner Objectives:

At the conclusion of this programming assignment, participants should be able to:

Apply and implement pointers 2-dimenional arrays

Define and apply structs in C

II. Prerequisites:

Before starting this programming assignment, participants should be able to:

Apply and implement pointers in C

Pass output parameters to functions

Analyze a basic set of requirements and apply top-down design principles for a problem

Apply repetition structures within an algorithm

Construct while (), for (), or do-while () loops in C

Compose C programs consisting of sequential, conditional, and iterative statements

Eliminate redundancy within a program by applying loops and functions

Create structure charts for a given problem

Open and close files

Read, write to, and update files

Manipulate file handles

Apply standard library functions: fopen (), fclose (), fscanf (), and fprintf ()

Compose decision statements ("if" conditional statements)

Create and utilize compound conditions

Summarize topics from Hanly&Koffman Chapter 8 including:

What is an array?

Distinguishing between single dimensional and 2-dimentional arrays

What is an index?

III. Overview & Requirements:

Write a program that simulates the game of Battleship. The game will be completely text-based (see Sample Execution). Battleship is a two player Navy game. The objective of the game is to sink all ships in your enemy's fleet. The Player to sink his/her enemy's fleet first wins. Both players' fleets consist of 5 ships that are hidden from the enemy. Each ship may be differentiated by its "size" (besides the Cruiser and Submarine) or number of cells it expands on the game board. The Carrier has 5 cells, Battleship has 4 cells, Cruiser has 3 cells, Submarine has 3 cells, and the Destroyer has 2 cells.

The program should be built such that the user is Player1 and the computer is Player2. Two boards exist within the game. Hint: each board should be implemented as a 2-dimensional array. Each 2-dimensional array should be 10 X 10. One represents Player1's board and one represents Player2's board. At the beginning of the game each Players' game board should be initialized to all '-' indicating that no ships have been placed on either board. Before the game starts, Player1 should have the option to either manually place each of the 5 ships in his/her fleet or to have them randomly placed on the board. If Player1 decides to place the ships manually, then he/she should be prompted to place the Carrier first, Battleship second, Cruiser third, Submarine fourth, and the Destroyer last. Note that ships cannot be placed diagonally on the board, they can only be placed vertically or horizontally. You program must check to see if the user tries to place a ship outside the boundaries of the board or on top of a ship that has already been placed. Each cell on the board that contains part of the ship must be indicated by 'c' for Carrier, 'b' for Battleship, 'r' for Cruiser, 's' for Submarine, or 'd' for Destroyer. For example, if the Carrier was placed then the board should contain 5 'c' s for each cell on the board that has a piece of the Carrier, etc. Once Player1's ships have been placed, Player2's ships must be randomly placed. Note that the placement of Player2's ships must be unknown. Thus, Player2's board will only display '-' in each cell after the placement of each ship. The program should randomly select Player1 or Player2 to go first.

Once it has been decided on which player goes first, the game starts. Whenever it's Player1's turn, a prompt should be displayed asking for a position to target (specifying where to "shoot") on the enemy's (Player2's) board (2-dimensional array). The position should be specified in terms of a row and a column on the board. The row and column should always be displayed along with the board. If the position specified happens to hit a ship, then a '*' should replace the '-' on Player2's board. If the positioned specified misses any one of the ships in the fleet, then a 'm' should replace the '-' on Player2's board. Note that from turn-to-turn each player should NOT be allowed to enter the same position. Also, between turns clear the screen (system("cls")). In one turn, a player can only take one shot at the enemy's (other player's) fleet. When Player2 takes a shot at Player1's board, each hit should be specified with a '*' and each miss with a 'm' on Player1's board. The game is over win Player1 or Player2 has sunk all of the ships in the fleet of the enemy.

For each move made by Player1 and Player2, the results should be echoed to a file called "battleship.log". In this file, you should log the targeted position by each player on each move and whether it was a hit on one of the ships in the fleet. Also, if one of the ships happens to sink, then note this in the log file. For more information about the rules of Battleship visit: Rules of Battleship.

At the end of the game, Player1's and Player2's statistics should be written to "battleship.log". The stats include total number of hits, total number of misses, total number of shots, hits to misses ratio (as a percentage), and won or lost the game. Note that the statistics should be placed into a structure called Stats. You need two variables of type Stats, one for Player1 and one for Player2. Once the game has ended you should write the contents of each struct variable to the "battleship.log" file.

Reference no: EM13545182

Questions Cloud

Assessment of the risks associated with collection : Identify and provide an assessment of the risks associated with collection, processing, and storage of confidential client information (loss of confidentiality).
Evaluate the ph of a buffer containing hc2h3o2 : Calculate the pH of a buffer containing 0.030 M HC2H3O2 and 0.050 M NaC2H3O2. The Ka of HC2H3O2 is 1.75 x 10^-5
Define what are the equilibrium concentrations : In the reaction 2A ? X + Y, the initial concentrations are all 0.600 M. If the equilibrium constant is 1.20 x 10^6, what are the equilibrium concentrations
Evaluate the activation energy of a reaction : Calculate the activation energy of a reaction whose rate constant is 4.22 x 10?4 s?¹ at 25°C and 4.54 x 10?4s?¹ at 45°C.
Basic game of battleship : Basic Game of Battleship - Analyze a basic set of requirements and apply top-down design principles for a problem and eliminate redundancy within a program by applying loops and functions
Find the angle through which the wheel rotates between t : A wheel rotates with a constant angular acceleration of 3.10 rad/s2. Assume the angular speed of the wheel is 1.55 rad/s at ti = 0. a) Find the angle through which the wheel rotates between t = 2.00 s and t = 3.10 s. _____rad (b) Find the angular spe..
Find out the free energy change in the reaction : A certain reaction has a ?H of -213 KJ/mol and a ?S of -27.0 J/mol.K at 625°C. Determine the free energy change in the reaction and whether the reaction is spontaneous under these conditions.
Find out the molality of a solution : Determine the molality of a solution that is 7.25 M NaNO3(aq) and has a density of 1.37 g?mL
Explain the neutron-induced fission reactions of u-235 : In one of the neutron-induced fission reactions of U-235(atomic mass = 235.043922 ), the products are Ba -140 and Kr-93 (a radioactive gas). What volume of Kr-93(at and 1.0 ) is produced when 1.80 g of U-235 undergoes this fission reaction

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Loops and if conditions

Write a program that requests a password

  Businesspartner class that contains a first name

Create a BusinessPartner class that contains a first name, company name, and a telephone number. Create a Contacts class that contains a dynamically allocated array of BusinessPartners as well as the owner's name and cell phone number.

  Derive the expression for variance of the continuous uniform

Derive the expression for variance of the continuous uniform probability distribution (we derived the expression for mean in class). Show your work.

  Write program using c language to find page fault

Write program using c language to find page fault for individual processes, group of processes and system as whole using following system call int sys_pgfltstats(pid_t pid,int flag,pf_info_struct *info).

  Write a function named smallest that receives three integer

Write a function named smallest that receives three integer arguments and returns the smallest of the three values.

  That takes the time as six integer arguments

Write a C function seconds_since_jan1() that takes the time as six integer arguments (year, month, day, hour, minute, and second) and returns the number of seconds since the beginning of the year.

  A run is a sequence of adjacent repeated val

A   run   is   a   sequence   of   adjacent   repeated   values.   Using   an   array,   write   a   program   that   generates   a   sequence   of

  Ansi-c program complete assignment as per written in the

complete assignment as per written in the

  The program should support a ''new'' feature

Write a GUI program that represents a simple Notepad clone. The program should support a 'new' feature that clears the text buffer, a save feature that writes to a file using a PrintStream

  Design customized mailing lists for marketing department

Marketing department requires to be able to design customized mailing lists, to send different messages to different types of donors. What system will best meet these requirements?

  An integer on this system is 4 bytes long

Assume the following for the program below. An integer on this system is 4 bytes long. The memory address where the array "a[]" was created begins at location 8000. a. #include

  Calculate that implements a simple arithmetic calculator

Write a  C program  calc.c that implements a simple arithmetic calculator. Input to the calculator consists of lines composed of integer constants separated by the five arithmetic operators used in C: +, -, *, /, and %. For each line of input,

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd