CSCI 2312-002: Object Oriented Prgramming Final Prject Assigned: Octber 17, 2017 Design Due: Octber 24, 2017 IN CLASS (Graded as ne hmewrk grade) Final prject Due: Nvember 16, 2017 at 11:59 PM Fr many f us ld schl gamers, we started ut playing gd ld-fashined bard games. Many f us learned strategy frm games like Risk and Battleship. Fr yur final prject, yu will be develping a simple battleship type game t test yur knwledge f the cncepts we have learned in Object Oriented Prgramming class. Figure 1: A Battleship game by Pg The purpse f this final prject is t have yu design a fairly cmplicated prject using cncepts we have learned and then implement the slutin using sme f the cde that we wrte in the previus assignments alng with new cde, and then test yur game. Yu need t first start with the design f the prject. If yur design is carefully thught thrugh, the cding f the game shuld be relatively straightfrward since many f the classes and cncepts 1
clsely match previus assignments. Yu will need t first read these requirements and make a design dcument (ensuring that all the requirements are met in the design). A sample design dcument is psted in Canvas and shuld be used as yur design TEMPLATE (example). Create a design dcument cmplete with the bjects and flw f data, as well as any decisins yu made n the best use f classes, inheritance, plymrphism, and exceptin handling. After yu have cmpleted yur design, then yu will be ready t implement the game and test. I cannt stress enugh that a gd design dcument and understanding f the requirements will make the actual cding f the game much faster and mre simple. Please dn't leave things until the last tw weeks. Get started nw, and please ask yur instructr fr help BEFORE yu get t lst. Get the big picture dne first. Wrry abut the structure and implementatin f the majr functinality. Then if yu have time, wrk n the little details, and minr errr checking. S nw nt the requirements. Yu sunk my battleship!. Battleship is a guessing game fr tw players. It is played n fur grids. Tw grids (ne fr each player) are used t mark each players' fleets f ships (including battleships). The lcatins f the fleet (these first tw grids) are cncealed frm the ther player s that they d nt knw the lcatins f the ppnent s ships. Players alternate turns by firing trpedes at ther player's ships. The bjective f the game is t destry the ppsing player's entire fleet. In ur game, firing a trped will be allwing the player t take a guess at where n the grid their ppnent may have placed a ship. In the requirements, we will set frth ther simplifying rules t limit the scpe f this prject. Requirements Given the requirements as a rugh specificatin, yu are t design the classes and implement the game. In ur imaginary game cmpany, the requirements belw were develped by the Prduct Develpment Team and yur instructr is the Prduct Owner. Yu are in full cntrl f the chice f classes (please use classes apprpriately r pints will be deducted), data structures, algrithms, internal file frmat, detailed user interface scheme, r any ther pertinent design decisins yu need t make. As the Prduct wner, I care that it cmpiles and runs like it is suppsed t, meets all the functinality and requirements I have set frth, and is easy t play and understand. The Battleship game yu are designing and implementing is a simplified versin f the electrnic Battleship game played in ne player mde. The game is played n fur grids, tw fr each player. The grids are typically square and in ur case will be 10 by 10. The individual squares in the grid are identified by the rw number (indicated by a letter) fllwed by the clumn number (indicated by a number). The fllwing is an example f a 10 by 10 grid with an X in the psitin C2. 2
1 2 3 4 5 6 7 8 9 10 A B C X D E F G H I J Each player uses tw grids. Each player uses ne f their grids t arrange their ships and recrd the trpedes fired by the ppnent. On the ther grid, the player recrds their wn shts and whether they hit r missed. Befre play begins, each player secretly arranges their ships n their primary grid. Each ship ccupies a certain number f cnsecutive squares n the grid (sizes f ships are in the fllwing table), arranged either hrizntally r vertically. The number f squares fr each ship is determined by the type f the ship. The ships cannt verlap s nly ne ship can ccupy any given square in the grid. The types and numbers f ships allwed are the same fr each player. Ship Type Number f Grid Squares Carrier 5 Battleship 4 Destryer 3 Submarine 3 PT Bat 2 Cruiser 1 The game is played in runds. In each rund, each player takes a turn t fire a trped at a target square in the ppnent's grid. The ppnent then indicates whether the sht was a hit (a ship ccupied the square) r a miss (there was nt ship in the square). If the sht is a miss", the player marks their primary grid with a white peg (X in ur game); if a "hit" they mark this n their wn 3
primary grid with a red peg (O in ur game). The attacking player then indicates the hit r miss n their wn "tracking" grid with the apprpriate clr peg (red (0) fr "hit", white (X) fr "miss") s that they can understand where the ppnent s ship might be. When all f the crdinates f a ship have been hit, the ship is sunk, and the ship's wner annunces, Yu sunk my battleship! (Or whatever the particular ship that was destryed). When all f ne player s ships are sunk, the ther player wins the game. Fr yur game, yu will create a ne-persn versin f the game where the cmputer will play fr the secnd player. At the beginning f the game, yu will read a file called ship_placement.csv which cntains the type f ship, the first grid square fr the ship placement, and whether the ship is placed vertically r hrizntally (V r H in the field). The file will be in csv frmat (cmma separated values). This is a cmmn frmat and is cmma separated (instead f being n separate lines). There will be cmmas between the values. Blank values will just have a cmma nting t g t the next field (the game input shuld nt have blank fields s yu shuld handle the case where a field is blank). If yu want t view the file, ften this will be pened by a spreadsheet unless yu specifically pen it with a text editr. D nt pen it with Micrsft Wrd, as this may change the frmat. The first line f a CSV file ntes the data descriptins as fllws: TypeOfShip,Lcatin,HrizOrVert I have prvided several sample files which cntain gd scenaris and scenaris with placement issues that yu will need t handle using exceptin handling. Yur game shuld run with any f these files, but shuld als be able t run with any valid file in the crrect frmat. Yu will need t check whether all ships were included in the input file (and apprpriate actin t take if nt), whether all ships have been placed, whether they fit n the bard in the cnfiguratin given, and whether mre than ne ship ccupies a space (which is nt allwed) when yu read the input file frm the user and hw t recver if an errr ccurs. Yu will then need t randmly psitin the cmputer s ships n the grid taking int cnsideratin the same factrs as yu did fr the player s input. Yu will need t prmpt fr and allw fr the user t input their next guess in the frm f a letter (A thrugh J) and a number (1 10) indicating where they are targeting fr their trped and yu shuld errr check the input. In ur simplified game, yu will determine if the trped sht was a hit r a miss. Yu shuld display a hit r miss, whether the ship was sunk and which ne, and display their tracking grid s they knw what they have guessed and where they have made hits. After the user takes their turn, yu must have the cmputer randmly select a sht that they have nt previusly taken. Then yu must display t the user what the cmputer guessed, whether it hit any f the player s ships, whether a ship was sunk, and then display the player s placement grid shwing where ships are lcated and what has been hit. Yu shuld cntinue this until smene wins r quits the game meaning yu shuld allw the player t gracefully quit at any turn. 4
At the end f the game, yu shuld indicate the game is ver and wh the winner was. Yu shuld als allw the user t quit the game by entering a Q when prmpted fr their next guess. If a player decides t quit the game, the grid with all f their guesses and the lcatins f the cmputer s ships shuld be displayed. Overall System Design 1. Yu must have tw different classes in yur design. 2. Yu must use inheritance in ne f the classes. 3. When reading frm a data file, yur prgram shuld test the input file t ensure that data is f valid frmat (basic errr detectin) using Exceptin Handling. 4. Yu shuld cnsider using the Grids frm Assignment 2 t make this easier. Yu d nt need t have 4 grids fr this but if yu decide t use nly tw grids, yu need t make sure yu d nt shw the player the cmputer s ship lcatin when yu display the grid after each turn. 5. Each cmpnent f the verall prgram shuld be mdular. 6. Prgram shuld be fairly fault tlerant f user input and the apprpriate user prmpts and n-screen directins shuld be displayed 7. Split the prgram int multiple files based n the rughly categrized functinality r classes. Submissin Guideline Yu need t submit fllwing items (all zipped tgether): 1. Surce cde with reasnable cmments 2. Makefile that wrks (and is tested) n the csegrid. 3. A single final reprt that includes: Summary f prvided functins. This shuld be matched with the requirements Design that shws the verall prgram structures, and the explanatin f key algrithms. A descriptin f user interface scheme is required t explain the menu items at tp level and items in sub menus and hw t navigate thrugh menus. A detailed instructin and sample skeletn is available frm Design Dcument. Accurate status f the prgram, what's dne, and what's nt cmpletely implemented. Accurate status f testing n the csegrid. The final reprt shuld be in MS Wrd, r PDF frmat. 5
Grading Criteria A. This is an individual prject. All yur cdes will be checked fr plagiarism by the use f a sftware called Mss (https://thery.stanfrd.edu/~aiken/mss/). Any instances f cheating will result in either a zer fr the assignment, a grade f zer in the curse, r sanctins determined by the cllege (including suspensin and expulsin). B. Submitting a wrking prgram that prvides all f the required features will result in a maximum 80 pints (nt including the pssible extra credit pints). C. Dcumentatin explained abve will result in 20 pints. D. Any r all f the fllwing will result in pint deductins f up t 5% fr each infractin. 1. Pr and/r incnsistent prgramming style. This includes the fllwing: a. Imprper use f indentatin. b. Overuse f glbal variables. c. Failure t keep functins mdular and reusable (pssibly applicable t ther prgrams). d. Insufficient cmments. e. Failure t use classes and inheritance. f. Failure t use exceptin handling. 2. Insufficient menu prmpts 3. Prgram is nt reasnably (nt abslutely) fault tlerant. a. Test t ensure that yur prgram cannt be crashed r sent int an infinite lp by a user wh is nt fllwing directins. b. Include a reasnable input file integrity check. Rejecting any nncnfrming file is fine. E. Partial credit may be awarded. 1. Yu may get partial credit fr nn-wrking mdules (functins) by explaining (in the separate dcument) where yu think the prblem lies. 2. Up t 10% culd be lst fr each required feature that is nt prvided. F. Submitting a prgram that des nt cmpile n csegrid.ucdenver.pvt may result in a deductin f at least 20%. Additinal pints will be lst fr each required feature that is nt adequately addressed. Extra Challenge / Extra Credit Sme f yu may want an extra challenge t bst yur abilities and have sme interesting resume material. Hw abut make it a custmizable 3 player game: meaning each player can be chsen t be the cmputer r human. And make sure nbdy is ging t see thers fleet-plan until smene wins after the game begins. Make the cmputer s trped selectin smart s that a stretch f hits can lead t a prper sinking f a ship f the ppnent. If yu d the extra credit, please nte this in yur dcumentatin and make it clear in the running f the prgram, s we can give yu up t 20% extra credit. (meaning yu culd get 120% n the prject). Nte: Since this is extra credit, it needs t meet a higher standard fr full extra credit). 6
FAQ Q: Shuld the final reprt be ne dcument r a series f dcuments? A: One MS wrd r pdf dcument. Q: D we need t give ur users an ability t surrender (give up n the game)? A: Yes, the user shuld be able t exit the game gracefully if they are dne playing but the game is nt ver. Q: Is extra-challenge/extra-credit required? A: N. 7