-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModelGameBoard.java
More file actions
77 lines (68 loc) · 1.8 KB
/
ModelGameBoard.java
File metadata and controls
77 lines (68 loc) · 1.8 KB
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
package edu.sdccd.cisc191;
// Adapted from GoneFishing by Tasha Frankie and Allan Schougaard
import java.util.Random;
/**
* Contains all the data required for the game play
*/
public class ModelGameBoard
{
public static int DIMENSION = 6;
public static int GUESSES = 30;
public static int TOTAL_FISH = 10;
private boolean[][] gameBoard;
private int guessesRemaining;
private int fishRemaining;
/**
* Initializes the game board with fish
*/
public ModelGameBoard()
{
gameBoard = new boolean[DIMENSION][DIMENSION]; // defaults to false
guessesRemaining = GUESSES;
fishRemaining = TOTAL_FISH;
Random randomNumberGenerator = new Random();
for (int fishCounter = 0; fishCounter < TOTAL_FISH; fishCounter++)
{
int x, y;
// finds an empty gameBoard slot
do
{
x = randomNumberGenerator.nextInt(DIMENSION);
y = randomNumberGenerator.nextInt(DIMENSION);
} while (gameBoard[x][y]);
gameBoard[x][y] = true;
}
}
/**
* @param row
* @param col
* @return Returns true if fish is found at row,col
*/
public boolean fishAt(int row, int col)
{
return gameBoard[row][col];
}
/**
* @param row
* @param col
* @return Returns true if fish is found at row,col and updates counters
*/
public boolean makeGuess(int row, int col)
{
boolean foundFish = fishAt(row, col);
guessesRemaining--;
if (foundFish)
{
fishRemaining--;
}
return foundFish;
}
public int getGuessesRemaining()
{
return guessesRemaining;
}
public int getFishRemaining()
{
return fishRemaining;
}
}