GameBoard

class GameBoard(width: Int, height: Int, boozeCount: Int) extends Grid[Glass]

Each instance of the class GameBoard represents a board for a game of Viinaharava. A game board is a Grid whose elements are Glass objects.

A GameBoard is first initialized with water glasses (by initialElements). However, a number of the glasses are then immediately poured full of booze while the rest keep their default content of water.

Once created, a GameBoard does not replace any of its Glass objects with another. However, the state of each individual Glass may change.

Value parameters:
boozeCount

the number of booze glasses on the game board. When a GameBoard object is created, it randomly chooses this many different locations on the board and pours booze in them.

height

the number of rows of glasses in the game board

width

the number of glasses in each row of the game board

trait Grid[Glass]
class Object
trait Matchable
class Any

Value members

Concrete methods

Returns a collection of all the booze glasses currently on the board.

Returns a collection of all the booze glasses currently on the board.

def drink(target: Glass): Unit

Virtually drinks the contents of the given glass.

Virtually drinks the contents of the given glass.

For a glass of water, “drinking” it just means that the glass is emptied. (If the water glass was already empty, this method does nothing.)

For a glass of booze, “drinking” it empties not just that glass but also all the other glasses of booze on the game board. (This will have the carry-on effect that the all the locations of booze glasses are revealed and the game ends. All this method does is empty the glasses, though.)

Value parameters:
target

a glass on this board

Generates the elements that initially occupy the grid. In the case of a GameBoard grid, this means generating a new Glass object for each location on the board. This method is automatically invoked by the superclass Grid to initialize the contents of the grid.

Generates the elements that initially occupy the grid. In the case of a GameBoard grid, this means generating a new Glass object for each location on the board. This method is automatically invoked by the superclass Grid to initialize the contents of the grid.

Determines whether all the water on the board has been drunk already. This is the case if and only if each of the glasses either contains booze or is empty.

Determines whether all the water on the board has been drunk already. This is the case if and only if each of the glasses either contains booze or is empty.

Inherited methods

def allElements: Vector[Element]

Returns a collection of all the elements currently in the grid.

Returns a collection of all the elements currently in the grid.

Inherited from:
Grid

Returns a collection of all the locations on the grid.

Returns a collection of all the locations on the grid.

Inherited from:
Grid
def apply(location: GridPos): Element

Returns the element at the given pair of coordinates. (This does the same as elementAt.)

Returns the element at the given pair of coordinates. (This does the same as elementAt.)

Value parameters:
location

a location on the grid (which must be within range or this method will fail with an error)

Inherited from:
Grid
def contains(location: GridPos): Boolean

Determines whether the grid contains the given pair of coordinates. For instance, a grid with a width and height of 5 will contain (0, 0) and (4, 4) but not (-1, -1), (4, 5) or (5, 4).

Determines whether the grid contains the given pair of coordinates. For instance, a grid with a width and height of 5 will contain (0, 0) and (4, 4) but not (-1, -1), (4, 5) or (5, 4).

Inherited from:
Grid
def elementAt(location: GridPos): Element

Returns the element at the given pair of coordinates. (This does the same as apply.)

Returns the element at the given pair of coordinates. (This does the same as apply.)

Value parameters:
location

a location on the grid (which must be within range or this method will fail with an error)

Inherited from:
Grid
def neighbors(middleLoc: GridPos, includeDiagonals: Boolean): Vector[Element]

Returns a vector of all the neighboring elements of the element indicated by the first parameter. Depending on the second parameter, either only the four neighbors in cardinal compass directions (north, east, south, west) are considered, or the four diagonals as well.

Returns a vector of all the neighboring elements of the element indicated by the first parameter. Depending on the second parameter, either only the four neighbors in cardinal compass directions (north, east, south, west) are considered, or the four diagonals as well.

Note that an element at the grid’s edge has fewer neighbors than one in the middle. For instance, the element at (0, 0) of a 5-by-5 grid has only three neighbors, diagonals included.

Value parameters:
includeDiagonals

true if diagonal neighbors also count (resulting in up to eight neighbors), false if only cardinal directions count (resulting in up to four)

middleLoc

the location between the neighbors

Inherited from:
Grid
def swap(location1: GridPos, location2: GridPos): Unit

Swaps the elements at two given locations on the grid. The given locations must be within range or this method will fail with an error.

Swaps the elements at two given locations on the grid. The given locations must be within range or this method will fail with an error.

Inherited from:
Grid
def update(location: GridPos, newElement: Glass): Unit

Modifies the grid by replacing the existing element at the given location with the new element.

Modifies the grid by replacing the existing element at the given location with the new element.

Value parameters:
location

a location on the grid (which must be within range or this method will fail with an error)

newElement

the new element that replaces the old one at location

Inherited from:
Grid

Inherited fields

val size: Int

the number of elements in this grid, in total. (Equals width times height.)

the number of elements in this grid, in total. (Equals width times height.)

Inherited from:
Grid