···11-#ifndef BATTLESHIP_H
22-#define BATTLESHIP_H
33-44-// Author: Keith Shomper
55-// Date: 24 Oct 03
66-// Purpose: Header file for implementing a text-based battleship game
77-// Updated: 14 Nov 08 to align class types with Cedarville standard
88-// Updated: 3 Apr 14 to use struct rather than class for the defined types
99-// Updated: 5 Nov 15 to introduce new functions to replace the ISAxxx macros
1010-// and also the SHIPNUM and DEBUGOUT macros
1111-1212-// include files for implementing battleship
1313-#include <iostream>
1414-#include <cstdlib>
1515-#include <time.h>
1616-#include "kasbs.h"
1717-1818-using namespace std;
1919-2020-// use these constants to indicate if the player is a human or a computer
2121-// battleship board size is 10x10 grid (defined in kasbs.h)
2222-2323-// data structure for position
2424-struct Position {
2525- int startRow; // ship's initial row
2626- int startCol; // ship's initial column
2727- int orient; // indicates whether the ship is running across
2828- // or up and down
2929-};
3030-3131-// data structure for ship
3232-struct Ship {
3333- Position pos; // where the ship is on the board
3434- int size; // number of hits required to sink the ship
3535- int hitsToSink; // number of hits remaining before the ship is sunk
3636- char marker; // the ASCII marker used to denote the ship on the
3737- // board
3838-};
3939-4040-// a game board is made up of a 10x10 playing grid and the ships
4141-struct Board {
4242- char grid[BOARDSIZE][BOARDSIZE];
4343- Ship s[6]; // NOTE: the first (zeroth) position is left empty
4444-};
4545-4646-// use these constants for designating to which player we are referring
4747-const int HUMAN = 0;
4848-const int COMPUTER = 1;
4949-5050-// use these constants for deciding whether or not the user gave a proper move
5151-const int VALID_MOVE = 0;
5252-const int ILLEGAL_FORMAT = 1;
5353-const int REUSED_MOVE = 2;
5454-5555-// functions for screen control and I/O
5656-void welcome(bool debug = false, bool pf = false);
5757-void clearTheLine(int x);
5858-void clearTheScreen(void);
5959-void pauseForEnter(void);
6060-string getResponse(int x, int y, string prompt);
6161-void writeMessage(int x, int y, string message);
6262-void writeResult(int x, int y, int result, int playerType);
6363-void displayBoard(int x, int y, int playerType, const Board &gameBoard);
6464-6565-// functions to control the board situation
6666-void initializeBoard(Board &gameBoard, bool file = false);
6767-int playMove(int row, int col, Board &gameBoard);
6868-6969-// function to tell what happened in the last play_move() command
7070-bool isAMiss(int playMoveResult);
7171-bool isAHit (int playMoveResult);
7272-bool isASunk(int playMoveResult); // formerly named isItSunk()
7373-int isShip (int playMoveResult);
7474-7575-// misc game functions
7676-string randomMove(void);
7777-int checkMove(string move, const Board &gameBoard, int &row, int &col);
7878-void debug(string s, int x = 22, int y = 1);
7979-string numToString(int x);
8080-8181-#ifdef BATTLESHIP_BACKWARD_COMPATIBILITY
8282-8383-// former function signatures
8484-void debug(int x, int y, string s);
8585-bool isItSunk(int playMoveResult);
8686-8787-// a debug macro
8888-#ifdef DEBUG
8989-#define DEBUGOUT(str) debug (22, 1, (str));
9090-#else
9191-#define DEBUGOUT(str)
9292-#endif // DEBUG
9393-9494-#endif // BATTLESHIP_BACKWARD_COMPATABILITY
9595-9696-#endif // BATTLESHIP_H