examples/tetris: remove old array hacks
parent
98034e5504
commit
23c9563600
|
@ -179,11 +179,9 @@ fn (mut g Game) init_game() {
|
||||||
row[field_width + 1] = -1
|
row[field_width + 1] = -1
|
||||||
g.field << row
|
g.field << row
|
||||||
}
|
}
|
||||||
mut first_row := g.field[0]
|
|
||||||
mut last_row := g.field[field_height + 1]
|
|
||||||
for j in 0 .. field_width + 2 {
|
for j in 0 .. field_width + 2 {
|
||||||
first_row[j] = -1
|
g.field[0][j] = -1
|
||||||
last_row[j] = -1
|
g.field[field_height + 1][j] = -1
|
||||||
}
|
}
|
||||||
g.score = 0
|
g.score = 0
|
||||||
g.lines = 0
|
g.lines = 0
|
||||||
|
@ -284,8 +282,7 @@ fn (mut g Game) delete_completed_lines() {
|
||||||
|
|
||||||
fn (mut g Game) delete_completed_line(y int) {
|
fn (mut g Game) delete_completed_line(y int) {
|
||||||
for x := 1; x <= field_width; x++ {
|
for x := 1; x <= field_width; x++ {
|
||||||
f := g.field[y]
|
if g.field[y][x] == 0 {
|
||||||
if f[x] == 0 {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -294,9 +291,7 @@ fn (mut g Game) delete_completed_line(y int) {
|
||||||
// Move everything down by 1 position
|
// Move everything down by 1 position
|
||||||
for yy := y - 1; yy >= 1; yy-- {
|
for yy := y - 1; yy >= 1; yy-- {
|
||||||
for x := 1; x <= field_width; x++ {
|
for x := 1; x <= field_width; x++ {
|
||||||
mut a := g.field[yy + 1]
|
g.field[yy + 1][x] = g.field[yy][x]
|
||||||
b := g.field[yy]
|
|
||||||
a[x] = b[x]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -361,9 +356,8 @@ fn (g &Game) draw_block(i int, j int, color_idx int) {
|
||||||
fn (g &Game) draw_field() {
|
fn (g &Game) draw_field() {
|
||||||
for i := 1; i < field_height + 1; i++ {
|
for i := 1; i < field_height + 1; i++ {
|
||||||
for j := 1; j < field_width + 1; j++ {
|
for j := 1; j < field_width + 1; j++ {
|
||||||
f := g.field[i]
|
if g.field[i][j] > 0 {
|
||||||
if f[j] > 0 {
|
g.draw_block(i, j, g.field[i][j])
|
||||||
g.draw_block(i, j, f[j])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue