-
Notifications
You must be signed in to change notification settings - Fork 0
/
support.cpp
executable file
·101 lines (94 loc) · 2.37 KB
/
support.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* Triad Development Group
* Battleship console game
*
* Support.cpp - Support/Reference Module (Supports modules 1 and 2)
*
*/
#include<iostream>
#include<ctime>
#include<climits>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#include <sstream> // for ostringstream
#include <cctype>
#include <iomanip>
#include <fstream>
#include <cstdlib>
const int NUMBER_OF_SHIPS = 5;
const int MIN_COL_LABEL = 'A';
const int MAX_COL_LABEL = 'J';
const int MIN_ROW_LABEL = 1;
const int MAX_ROW_LABEL = 10;
typedef char grid[MAX_ROW_LABEL][MAX_ROW_LABEL];
using namespace std;
/* createGrid:
*
* This function creates a grid (2-D array) that contains a '.' in every location in the grid.
* This function is called at multiple places throughout module 1 and 2.
*
* Pre-Condition: The function is correctly handed an empty 2-D array
*
* Post-Condition: The grid is correctly filled in with each coordinate containing a '.' for every
* value.
*
*/
void createGrid(grid grid) {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
grid[i][j] = '.';
}
}
}
/*printGrid:
*
* This function contains a loop that will print out the grid. First printing out the axis labels. Then
* printing out what is contained in each coordinate.
*
* Pre-Condition:The function is correctly handed a loaded 2-D array to print out, meaning that
* grid[i][j] contains some value.
*
* Post-Condition:The function correctly prints the grid to the screen.
*
*/
void printGrid(grid grid) {
cout << " A B C D E F G H I J" << endl;
int x = 1;
for (int i = 0; i < 10; i++) {
if (x < 10) {
cout << " ";
}
cout << x;
x++;
for (int j = 0; j < 10; j++) {
cout << " " << grid[i][j];
}
cout << endl;
}
}
/*quitGame:
*
* This function clears the screen, prints out the Battleship header, then thanks the user for playing
* the game, than exits the program.
*
* Pre-Condiition: This function accepts no parameters.
*
* Post-Condition: The program has been exited.
*
*/
void quitGame() {
//system("clear");
cout
<< "*******************************************************************"
<< endl;
cout
<< " BATTLESHIP "
<< endl;
cout
<< "*******************************************************************"
<< endl;
cout << endl << endl;
cout << "Thanks for playing Battleship!" << endl;
exit(0);
}