Finish take_tiles market implementation
This commit is contained in:
parent
f944f334ba
commit
77b7f10081
17
src/azul.rs
17
src/azul.rs
|
@ -316,7 +316,7 @@ impl GameState {
|
||||||
(c, s, _) if self.get_color(s, c) == 0 => {
|
(c, s, _) if self.get_color(s, c) == 0 => {
|
||||||
return Err(MoveErr::Color("Source does not contain that color"))
|
return Err(MoveErr::Color("Source does not contain that color"))
|
||||||
}
|
}
|
||||||
(_, Source::Factory(f), _) if f >= self.factories.len() => {
|
(_, Source::Factory(f), _) if f > self.factories.len() => {
|
||||||
return Err(MoveErr::Src("Not a valid factory"))
|
return Err(MoveErr::Src("Not a valid factory"))
|
||||||
}
|
}
|
||||||
(_, _, Destination::PatternLine(l))
|
(_, _, Destination::PatternLine(l))
|
||||||
|
@ -400,10 +400,11 @@ impl GameState {
|
||||||
self.market.start -= 1;
|
self.market.start -= 1;
|
||||||
player.floor.start += 1;
|
player.floor.start += 1;
|
||||||
}
|
}
|
||||||
|
let _ = self.market.add_color(color, -(amount as isize));
|
||||||
}
|
}
|
||||||
Source::Factory(f) => {
|
Source::Factory(f) => {
|
||||||
let factory = &mut self.factories[f];
|
let factory = &mut self.factories[f];
|
||||||
factory.add_color(color, -(amount as isize)).unwrap();
|
let _ = factory.add_color(color, -(amount as isize));
|
||||||
self.market += *factory;
|
self.market += *factory;
|
||||||
factory.clear();
|
factory.clear();
|
||||||
}
|
}
|
||||||
|
@ -538,13 +539,17 @@ impl TileSetWithStart {
|
||||||
Color::Blue => self.blue,
|
Color::Blue => self.blue,
|
||||||
Color::Yellow => self.yellow,
|
Color::Yellow => self.yellow,
|
||||||
Color::Red => self.red,
|
Color::Red => self.red,
|
||||||
Color::Black => self.white,
|
Color::Black => self.black,
|
||||||
Color::White => self.black,
|
Color::White => self.white,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_color(&mut self, color: Color, n: isize) -> Result<(), &'static str> {
|
fn add_color(&mut self, color: Color, n: isize) -> Result<(), &'static str> {
|
||||||
match color {
|
match color {
|
||||||
|
Color::Start if n == 1 && self.start == 0 => {
|
||||||
|
self.start = usize::checked_add_signed(self.white, n).ok_or("would overflow")?
|
||||||
|
}
|
||||||
|
Color::Start => return Err("Tried to add more than 1 start tile to TileSet"),
|
||||||
Color::Blue => {
|
Color::Blue => {
|
||||||
self.blue = usize::checked_add_signed(self.blue, n).ok_or("would overflow!")?
|
self.blue = usize::checked_add_signed(self.blue, n).ok_or("would overflow!")?
|
||||||
}
|
}
|
||||||
|
@ -560,10 +565,6 @@ impl TileSetWithStart {
|
||||||
Color::White => {
|
Color::White => {
|
||||||
self.white = usize::checked_add_signed(self.white, n).ok_or("would overflow")?
|
self.white = usize::checked_add_signed(self.white, n).ok_or("would overflow")?
|
||||||
}
|
}
|
||||||
Color::Start if n == 1 && self.start == 0 => {
|
|
||||||
self.start = usize::checked_add_signed(self.white, n).ok_or("would overflow")?
|
|
||||||
}
|
|
||||||
Color::Start => return Err("Tried to add more than 1 start tile to TileSet"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue