Struct lib_battleship::Game [] [src]

pub struct Game { /* fields omitted */ }

Struct representing a running game of battleship.

Methods

impl Game
[src]

Creates a new instance. Use of this function is discouraged. You should rather go through the PreGame struct.

Parameters

  • ship_types A non-emptpy vector of ShipTypes.
  • battlefields A Vector of exactly two Battlefields where player 1 owns the battlefield at index 0 and player 2 owns the one at index 1.

This function determines who's turn it is.

Shoot at a player's battlefield.

Parameters

  • target_player The player to be shot at.
  • x The x coordinate.
  • y The y coordinate.

Errors

  • NotThisPlayersTurn if target_player is the same as what's returned by current_player().
  • OutOfBounds if the given coordinates are outside the boundaries of the battlefield.
  • GameOver if the game is already finished

Examples

match game.shoot(P2, 0, 0).unwrap() {
    ShootOk::Hit => println!("hit!"),
    ShootOk::Miss => println!("miss!"),
    ShootOk::Destroyed => println!("ship destroyed!"),
    ShootOk::WinningShot => println!("you won!")
}
// note that you shouldn't just call `unwrap()` after `shoot()`, don't ignore errors.

Gets the status of the cell (x, y) owned by player. Does not display missed shots, i.e. misses are considered Empty (see get_opponent_cell).

Parameters

  • player determines which battlefield to consider, i.e. the owner of the battlefield.
  • x the x coordinate
  • y the y coordinate

Panics

Panics if the x and/or y coordinate is out of bounds.

Gets the status of the opponent cell (x, y) owned by player. Does not display unhit ship cells, i.e. unhit ship cells are considered Empty.

Parameters

  • player determines which battlefield to consider, i.e. the owner of the battlefield.
  • x the x coordinate
  • y the y coordinate

Panics

Panics if the x and/or y coordinate is out of bounds.

Gets the winner of the game, if any.

Trait Implementations

impl PartialEq for Game
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Debug for Game
[src]

Formats the value using the given formatter.

impl Dimensional for Game
[src]

Returns the width of this object.

Returns the height of this object.

impl ShipTypeContainer for Game
[src]

Returns a copy of the list of ship types.