Skip to content

Instantly share code, notes, and snippets.

@hakunin
Created July 29, 2010 08:35
Show Gist options
  • Save hakunin/497626 to your computer and use it in GitHub Desktop.
Save hakunin/497626 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<link href="//fonts.googleapis.com/css?family=Yanone+Kaffeesatz:200,300,400,700" rel="stylesheet" type="text/css" >
<style>
body {
font-family: 'Yanone Kaffeesatz', serif;
}
h1 {
font-size:4em;
}
input {
font-size:1.5em;
width:100px;
height:100px;
}
.button0 {
border:none;
background:transparent;
color:transparent;
}
body {
width:400px;
margin-left:auto;
margin-right:auto;
text-align:center;
}
#footer {
padding-top:1.667em;
color:gray;
}
.mirah, .appengine {
color:black;
}
</style>
<head>
<meta charset="UTF-8" />
<title><%= @page_title %></title>
<%= stylesheet_link_tag 'source' %>
</head>
<body>
<h1>15-puzzle</h1>
<div id="content">
<%= @page_content %>
</div>
<div id="footer">written in <span class="mirah">Mirah</span>, powered by <span class="appengine">AppEngine</span></div>
</body>
</html>
import com.google.appengine.api.datastore.Text
import com.google.appengine.ext.duby.db.Model
import java.util.HashMap
import java.util.ArrayList
import java.util.Arrays
class FifteenPuzzle < ApplicationController
# GET /shout
def doGet(request, response)
#@shouts = Shout.all.run
@page_title = 'Fifteen puzzle'
tiles = ArrayList.new [
'1','2','3','4',
'5','6','7','8',
'9','10','11','12',
'13','14','15','0'
]
if state =request.getParameter('state')
tiles.removeAll(tiles)
i = 0
state.split(',').each { |t|
i += 1
tiles.add(t)
}
=begin
move = request.getParameter('button')
if tiles.contains(move)
position = Integer.valueOf(tiles.indexOf(move)).intValue()
rightTile = tiles.get(position + 1).toString()
if rightTile.equals("0")
# swap with rightTile
end
end
=end
end
tiles_buttons = ''
i = 0
tiles.each { |tile|
i += 1
tiles_buttons += '<input type="submit" name="button" class="button'+tile.toString()+'" value="'+tile.toString()+'"/>'
if i % 4 == 0
tiles_buttons += "<br>"
end
}
@page_content = '
<form>
<input type="hidden" name="state" value="'+join(tiles, ',')+'">
'+tiles_buttons+'
</form>
'
response.setContentType("text/html; charset=UTF-8")
response.getWriter.write(main_erb)
end
def join(list:java.util.List, glue:string)
glued = ''
last = list.get(list.size-1)
list.each { |item|
glued += item.toString()
if (item != last)
glued += glue
end
}
glued
end
# POST /shout
def doPost(request, response)
shout = Shout.new
shout.title = request.getParameter('title')
shout.body = request.getParameter('body')
shout.save
doGet(request, response)
end
#def_edb(list_erb, 'views/shout/list.html.erb')
def_edb(main_erb, 'views/layouts/application.html.erb')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment