tidy up game implementation
This commit is contained in:
parent
280e7e9cd6
commit
85f6501b2c
15
src/game.rs
15
src/game.rs
|
@ -163,24 +163,14 @@ impl ToString for Game {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TileIds {
|
impl Game {
|
||||||
fn tile_ids(&self) -> Vec<u64>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TileIds for Game {
|
|
||||||
fn tile_ids(&self) -> Vec<u64> {
|
fn tile_ids(&self) -> Vec<u64> {
|
||||||
self.tiles.iter().map(|tile| {tile.id}).collect()
|
self.tiles.iter().map(|tile| {tile.id}).collect()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// first available tile ID.
|
/// first available tile ID.
|
||||||
/// e.g. if current tile IDs are [0, 2, 3] the result will be `1`
|
/// e.g. if current tile IDs are [0, 2, 3] the result will be `1`
|
||||||
/// if current tile IDs are [0, 1, 2] the result will be `3`
|
/// if current tile IDs are [0, 1, 2] the result will be `3`
|
||||||
pub trait NewTileId {
|
|
||||||
fn new_tile_id(&self) -> u64;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NewTileId for Game {
|
|
||||||
fn new_tile_id(&self) -> u64 {
|
fn new_tile_id(&self) -> u64 {
|
||||||
let mut new_id = 0;
|
let mut new_id = 0;
|
||||||
|
|
||||||
|
@ -197,9 +187,6 @@ impl NewTileId for Game {
|
||||||
|
|
||||||
new_id + 1
|
new_id + 1
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl Game {
|
|
||||||
/// adds a tile safely and returns the new tile ID
|
/// adds a tile safely and returns the new tile ID
|
||||||
fn add_tile(&mut self, mut tile: Tile) -> u64 {
|
fn add_tile(&mut self, mut tile: Tile) -> u64 {
|
||||||
let new_id = self.new_tile_id();
|
let new_id = self.new_tile_id();
|
||||||
|
|
Loading…
Reference in New Issue