Permalink
Browse files

sass, json2.js, show stack in game

  • Loading branch information...
1 parent b367979 commit da43476ec3635ec80c88ce8ef8695bb92b6f3c3f @jamesmacaulay committed May 4, 2009
@@ -2,6 +2,10 @@ class GamesController < ApplicationController
before_filter :load_game
def show
+ respond_to do |format|
+ format.html
+ format.js { render :json => @game}
+ end
end
protected
View
@@ -32,6 +32,11 @@ def to_xml(options={})
super(options)
end
+ def to_json(options={})
+ options[:include] ||= [:players]
+ super(options)
+ end
+
def starting_stack
read_attribute(:starting_stack) || write_attribute(:starting_stack, [])
end
@@ -1 +1,2 @@
-%pre=h @game.to_xml
+%ol#stack
+=javascript_tag "$(document).ready(function() { Game.init(#{@game.id}); });"
@@ -1,5 +1,6 @@
-#loading
- =image_tag '/images/loading-48x48.gif'
- %p#message waiting for another mind
- =periodically_call_remote(:url => "/matchmaker/poller/#{@game_player.id}", :frequency => 3, :success => "Matchmaker.handleSuccessfulPoll(request)")
+#central
+ #loading
+ =image_tag '/images/loading-48x48.gif'
+ %p#message waiting for another mind
+ =periodically_call_remote(:url => "/matchmaker/poller/#{@game_player.id}", :frequency => 3, :success => "Matchmaker.handleSuccessfulPoll(request)")
@@ -1,2 +1,3 @@
-#start
- %h1=link_to 'start chromaclimbing', '/matchmaker'
+#central
+ #start
+ %h1=link_to 'climb', '/matchmaker'
@@ -5,4 +5,15 @@ var Matchmaker = {
window.location.href = '/games/' + request;
},500);
}
+}
+
+var Game = {
+ init: function(game_id) {
+ $.getJSON("/games/" + game_id + ".js", function(data){
+ Game.stack = data['game']['starting_stack'];
+ $.each(Game.stack, function(){
+ $('ol#stack').append("<li class='" + this + "' />");
+ });
+ });
+ }
}
Oops, something went wrong.
@@ -2,28 +2,47 @@ body {
margin: 0;
padding: 0;
text-align: center;
- font-family: Helvetica, Arial, sans-serif;
- font-size: 14px;
-}
-
-h1 {
- font-size: 6em;
-}
-
-a {
- color: red;
- text-decoration: none;
-}
-
-a:hover {
- color: orange;
-}
-
-pre {
- font-family: "DejaVu Sans Mono", "Panic Sans", "Monaco", "Courier New";
- text-align: left;
-}
-
-#content {
- margin: 200px 50px 0;
-}
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
+ font-size: 14px; }
+ body h1 {
+ font-size: 6em; }
+ body a {
+ color: red;
+ text-decoration: none; }
+ body a:hover {
+ color: orange; }
+ body pre {
+ font-family: "DejaVu Sans Mono", "Panic Sans", "Monaco", "Courier New";
+ text-align: left; }
+ body #central {
+ margin: 200px 50px 0; }
+ body ol#stack {
+ margin: 0;
+ padding: 0;
+ list-style-type: none; }
+ body ol#stack li {
+ height: 6px;
+ width: 29.12461182px;
+ border-width: 2px 3px;
+ border-style: solid; }
+ body ol#stack li.red {
+ background-color: #ff0000;
+ border-color: #ff6600; }
+ body ol#stack li.yellow {
+ background-color: #ffff00;
+ border-color: #ffdd00; }
+ body ol#stack li.green {
+ background-color: #008000;
+ border-color: #00aa00; }
+ body ol#stack li.blue {
+ background-color: #0000ff;
+ border-color: #4444ff; }
+ body ol#stack li.purple {
+ background-color: #800080;
+ border-color: #aa00aa; }
+ body ol#stack li.black {
+ background-color: #000000;
+ border-color: #333333; }
+ body ol#stack li.white {
+ background-color: #ffffff;
+ border-color: #eeeeee; }
@@ -0,0 +1,82 @@
+!red = red
+!yellow = yellow
+!green = green
+!blue = blue
+!purple = purple
+!black = black
+!white = white
+
+!red_border = #f60
+!yellow_border = #fd0
+!green_border = #0a0
+!blue_border = #44f
+!purple_border = #a0a
+!black_border = #333
+!white_border = #eee
+
+!golden_ratio = 1.61803399
+
+!stack_space_height = 6px
+
+body
+ :margin 0
+ :padding 0
+ :text-align center
+ :font-family "Helvetica Neue", Helvetica, Arial, sans-serif
+ :font-size 14px
+
+ h1
+ :font-size 6em
+
+ a
+ :color red
+ :text-decoration none
+ &:hover
+ :color orange
+
+ pre
+ :font-family "DejaVu Sans Mono", "Panic Sans", "Monaco", "Courier New"
+ :text-align left
+
+ #central
+ :margin 200px 50px 0
+
+ ol#stack
+ :margin 0
+ :padding 0
+ :list-style-type none
+
+ li
+ :height = !stack_space_height
+ :width = !golden_ratio * !stack_space_height * 3
+ :border
+ :width 2px 3px
+ :style solid
+
+ &.red
+ :background-color = !red
+ :border-color = !red_border
+
+ &.yellow
+ :background-color = !yellow
+ :border-color = !yellow_border
+
+ &.green
+ :background-color = !green
+ :border-color = !green_border
+
+ &.blue
+ :background-color = !blue
+ :border-color = !blue_border
+
+ &.purple
+ :background-color = !purple
+ :border-color = !purple_border
+
+ &.black
+ :background-color = !black
+ :border-color = !black_border
+
+ &.white
+ :background-color = !white
+ :border-color = !white_border
@@ -8,10 +8,12 @@ class GameTest < ActiveSupport::TestCase
end
test "generates a randomized stack" do
- srand
assert_equal [], @game.starting_stack
@game.save!
assert_equal 60, @game.starting_stack.length
+ first_stack = @game.starting_stack
+ @game.save!
+ assert_equal first_stack, @game.starting_stack
end
end

0 comments on commit da43476

Please sign in to comment.