-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
54 lines (47 loc) · 1.28 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# web application
require 'rubygems'
require 'sinatra'
require 'lib/game_life'
INIT_GENERATION = \
" \n" +
" \n" +
" * \n" +
" *** * \n" +
" * * * * *** * * \n" +
" *** * * * * * * \n" +
" * * * * * * * * \n" +
" * * ** *** *** \n" +
" * \n" +
" *** \n" +
" \n"
get '/' do
game = GameLife.new :empty_cell=>' ', :life_cell=>'*', :map=>INIT_GENERATION
@screen = game.screen
erb :index
end
post '/' do
game = GameLife.new :empty_cell=>' ', :life_cell=>'*', :map=>params[:g]
game.do_step
@screen = game.screen
erb :index
end
__END__
@@ layout
<html>
<head>
<title>John Horton Conway - Game of Life</title>
</head>
<body>
<%= yield %>
<br>
<a href="http://ruby-game-life.cloudfoundry.com">index</a> |
<a href="https://github.com/nemilya/ruby-game-life">github</a> |
<a href="http://en.wikipedia.org/wiki/Conway's_Game_of_Life">wikipedia</a>
</body>
</html>
@@ index
<form action="/" method="post">
<pre><%= @screen %></pre>
<input type="hidden" name="g" value="<%= @screen %>">
<input type="submit" value="Step">
</form>