Fixed a bug that three tiles will merge into one
This commit is contained in:
parent
c46b19e8c3
commit
71f75c87d7
1 changed files with 16 additions and 2 deletions
18
src/board.rs
18
src/board.rs
|
|
@ -136,7 +136,9 @@ impl Board {
|
|||
match self.get_tile(col, row) {
|
||||
Some(ref d_tile) => {
|
||||
match self.get_next_tile(col, row, 0, y_step) {
|
||||
Some(ref s_tile) if d_tile.score == s_tile.score => {
|
||||
Some(ref s_tile)
|
||||
if d_tile.score == s_tile.score
|
||||
&& self.get_tile_count(d_tile.tile_x, d_tile.tile_y) == 1 => {
|
||||
found = true;
|
||||
dx = d_tile.tile_x;
|
||||
dy = d_tile.tile_y;
|
||||
|
|
@ -216,7 +218,9 @@ impl Board {
|
|||
match self.get_tile(col, row) {
|
||||
Some(ref d_tile) => {
|
||||
match self.get_next_tile(col, row, x_step, 0) {
|
||||
Some(ref s_tile) if d_tile.score == s_tile.score => {
|
||||
Some(ref s_tile)
|
||||
if d_tile.score == s_tile.score
|
||||
&& self.get_tile_count(d_tile.tile_x, d_tile.tile_y) == 1 => {
|
||||
found = true;
|
||||
dx = d_tile.tile_x;
|
||||
dy = d_tile.tile_y;
|
||||
|
|
@ -335,6 +339,16 @@ impl Board {
|
|||
None
|
||||
}
|
||||
|
||||
fn get_tile_count(&self, x: int, y: int) -> int {
|
||||
let mut count = 0;
|
||||
for tile in self.tiles.iter() {
|
||||
if tile.tile_x == x && tile.tile_y == y {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
count
|
||||
}
|
||||
|
||||
fn render_board(&self, c: &Context, gl: &mut Gl) {
|
||||
let width = settings::TILE_SIZE * settings::TILE_WIDTH as f64 + settings::TILE_PADDING * (settings::TILE_WIDTH + 1) as f64;
|
||||
let height = settings::TILE_SIZE * settings::TILE_HEIGHT as f64 + settings::TILE_PADDING * (settings::TILE_HEIGHT + 1) as f64;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue