Download presentation
1
Warship C++: An entity of Battleship
Created and Presented by: Quinn Morgan and Raymond Sastraputera
2
Goal of Warship Warship is a game similar to battleship in which one player and one computer (simulated) compete on two square grids, one for each player. The grides are identified by rows and columns . On one grid the player arranges his own ships and records shots taken by the opponent. On the other grid the opposite way the player records his own shots taken towards his opponent. The player places the ships manually into the grid and the computer automatically assigns the ships positions. Each turn the player attempts to destroy the opponents ship by plotting their attack on the opponents grid. The first player to destroy all his opponents ships wins.
3
Code Technique Implemented
The Warship game was set into a basic header (.h) and two source files for the class and the driver (.cpp). Instead of using an array the warship board is simply entered into columns and rows with the getblock function initializing a x and y variable. This board is finally printed out with the print grid function specified under the warship.h header file displaying the game board. There are also horizontal and vertical direction set to show the navigation of the warships. These coordianates will be manually entered by the selected player also with a flag set to remind the player if the position has been acquired already. Auto shoot and Auto ship placement commands have also been implemented within the game for the computer to predict its movements instead of an onslaught player vs. player game.
4
More Code techniques….. Several cases are included into the code for x and y grid ship placements and shot predictions by players and computers. These different cases allow the program to identify a direct hit with the grid placement of ships on the board. If the case is true then the program breaks off and displays (cout) a message stating that there has been a direct hit on target. The position of the ships are important to each player to avoid a direct coordinate of enemy fire. Once the game is played and either player or computer has won a message of victory is displayed using the game statues command and get ship functions. This leads to the prompting of the program to display the message of entering another game similar to: “would you like to play another game”? This prompt can either be answered with a y or n for yes or no. If yes is selected another game is prompted if no is selected the program reads this answer as play =false and exits the game.
5
Code Example Header: Warship\warship.cpp Driver: Warship\game.cpp
Warship\warship.h Warship\warship.cpp Driver: Warship\game.cpp
6
Improvements??? Networking Warship
Multiple players instead of computer vs. player mode 3D mode warship Implement save/load game function Add different types of vessels such as submarines, cruisers, destroyers. Add sounds to the program into the MS-Dos prompt.
7
QUESTIONS??
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.