1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/examples/game_of_life/life.v

26 lines
409 B
V
Raw Normal View History

module main
2019-06-24 15:58:47 +03:00
import time
import automaton
2019-06-24 15:58:47 +03:00
fn print_automaton(a &automaton.Automaton) {
for y := 1; y < a.field.maxy; y++ {
2019-06-24 15:58:47 +03:00
mut s := ' '
for x := 1; x < a.field.maxx; x++ {
cell := a.field.get(x, y)
s += if cell == 1 { '@' } else { '.' }
2019-06-24 15:58:47 +03:00
}
println(s)
}
println('')
}
fn main() {
mut a := automaton.gun()
2019-06-24 15:58:47 +03:00
for {
a.update()
print_automaton(a)
2021-02-27 20:41:06 +03:00
time.sleep(100 * time.millisecond)
2019-06-24 15:58:47 +03:00
}
}