Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

sass, json2.js, show stack in game

  • Loading branch information...
commit da43476ec3635ec80c88ce8ef8695bb92b6f3c3f 1 parent b367979
James MacAulay authored
4 app/controllers/games_controller.rb
@@ -2,6 +2,10 @@ class GamesController < ApplicationController
2 2 before_filter :load_game
3 3
4 4 def show
  5 + respond_to do |format|
  6 + format.html
  7 + format.js { render :json => @game}
  8 + end
5 9 end
6 10
7 11 protected
5 app/models/game.rb
@@ -32,6 +32,11 @@ def to_xml(options={})
32 32 super(options)
33 33 end
34 34
  35 + def to_json(options={})
  36 + options[:include] ||= [:players]
  37 + super(options)
  38 + end
  39 +
35 40 def starting_stack
36 41 read_attribute(:starting_stack) || write_attribute(:starting_stack, [])
37 42 end
3  app/views/games/show.haml
... ... @@ -1 +1,2 @@
1   -%pre=h @game.to_xml
  1 +%ol#stack
  2 +=javascript_tag "$(document).ready(function() { Game.init(#{@game.id}); });"
9 app/views/matchmaker/index.haml
... ... @@ -1,5 +1,6 @@
1   -#loading
2   - =image_tag '/images/loading-48x48.gif'
3   - %p#message waiting for another mind
4   - =periodically_call_remote(:url => "/matchmaker/poller/#{@game_player.id}", :frequency => 3, :success => "Matchmaker.handleSuccessfulPoll(request)")
  1 +#central
  2 + #loading
  3 + =image_tag '/images/loading-48x48.gif'
  4 + %p#message waiting for another mind
  5 + =periodically_call_remote(:url => "/matchmaker/poller/#{@game_player.id}", :frequency => 3, :success => "Matchmaker.handleSuccessfulPoll(request)")
5 6
5 app/views/welcome/index.haml
... ... @@ -1,2 +1,3 @@
1   -#start
2   - %h1=link_to 'start chromaclimbing', '/matchmaker'
  1 +#central
  2 + #start
  3 + %h1=link_to 'climb', '/matchmaker'
11 public/javascripts/application.js
@@ -5,4 +5,15 @@ var Matchmaker = {
5 5 window.location.href = '/games/' + request;
6 6 },500);
7 7 }
  8 +}
  9 +
  10 +var Game = {
  11 + init: function(game_id) {
  12 + $.getJSON("/games/" + game_id + ".js", function(data){
  13 + Game.stack = data['game']['starting_stack'];
  14 + $.each(Game.stack, function(){
  15 + $('ol#stack').append("<li class='" + this + "' />");
  16 + });
  17 + });
  18 + }
8 19 }
29 public/javascripts/json2.js
... ... @@ -0,0 +1,29 @@
  1 +
  2 +if(!this.JSON){JSON={};}
  3 +(function(){function f(n){return n<10?'0'+n:n;}
  4 +if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return this.getUTCFullYear()+'-'+
  5 +f(this.getUTCMonth()+1)+'-'+
  6 +f(this.getUTCDate())+'T'+
  7 +f(this.getUTCHours())+':'+
  8 +f(this.getUTCMinutes())+':'+
  9 +f(this.getUTCSeconds())+'Z';};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};}
  10 +var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';}
  11 +function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);}
  12 +if(typeof rep==='function'){value=rep.call(holder,key,value);}
  13 +switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';}
  14 +gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';}
  15 +v=partial.length===0?'[]':gap?'[\n'+gap+
  16 +partial.join(',\n'+gap)+'\n'+
  17 +mind+']':'['+partial.join(',')+']';gap=mind;return v;}
  18 +if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==='string'){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}
  19 +v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+
  20 +mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}}
  21 +if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;}
  22 +rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}
  23 +return str('',{'':value});};}
  24 +if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}}
  25 +return reviver.call(holder,key,value);}
  26 +cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+
  27 +('0000'+a.charCodeAt(0).toString(16)).slice(-4);});}
  28 +if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;}
  29 +throw new SyntaxError('JSON.parse');};}}());
69 public/stylesheets/main.css
@@ -2,28 +2,47 @@ body {
2 2 margin: 0;
3 3 padding: 0;
4 4 text-align: center;
5   - font-family: Helvetica, Arial, sans-serif;
6   - font-size: 14px;
7   -}
8   -
9   -h1 {
10   - font-size: 6em;
11   -}
12   -
13   -a {
14   - color: red;
15   - text-decoration: none;
16   -}
17   -
18   -a:hover {
19   - color: orange;
20   -}
21   -
22   -pre {
23   - font-family: "DejaVu Sans Mono", "Panic Sans", "Monaco", "Courier New";
24   - text-align: left;
25   -}
26   -
27   -#content {
28   - margin: 200px 50px 0;
29   -}
  5 + font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  6 + font-size: 14px; }
  7 + body h1 {
  8 + font-size: 6em; }
  9 + body a {
  10 + color: red;
  11 + text-decoration: none; }
  12 + body a:hover {
  13 + color: orange; }
  14 + body pre {
  15 + font-family: "DejaVu Sans Mono", "Panic Sans", "Monaco", "Courier New";
  16 + text-align: left; }
  17 + body #central {
  18 + margin: 200px 50px 0; }
  19 + body ol#stack {
  20 + margin: 0;
  21 + padding: 0;
  22 + list-style-type: none; }
  23 + body ol#stack li {
  24 + height: 6px;
  25 + width: 29.12461182px;
  26 + border-width: 2px 3px;
  27 + border-style: solid; }
  28 + body ol#stack li.red {
  29 + background-color: #ff0000;
  30 + border-color: #ff6600; }
  31 + body ol#stack li.yellow {
  32 + background-color: #ffff00;
  33 + border-color: #ffdd00; }
  34 + body ol#stack li.green {
  35 + background-color: #008000;
  36 + border-color: #00aa00; }
  37 + body ol#stack li.blue {
  38 + background-color: #0000ff;
  39 + border-color: #4444ff; }
  40 + body ol#stack li.purple {
  41 + background-color: #800080;
  42 + border-color: #aa00aa; }
  43 + body ol#stack li.black {
  44 + background-color: #000000;
  45 + border-color: #333333; }
  46 + body ol#stack li.white {
  47 + background-color: #ffffff;
  48 + border-color: #eeeeee; }
82 public/stylesheets/sass/main.sass
... ... @@ -0,0 +1,82 @@
  1 +!red = red
  2 +!yellow = yellow
  3 +!green = green
  4 +!blue = blue
  5 +!purple = purple
  6 +!black = black
  7 +!white = white
  8 +
  9 +!red_border = #f60
  10 +!yellow_border = #fd0
  11 +!green_border = #0a0
  12 +!blue_border = #44f
  13 +!purple_border = #a0a
  14 +!black_border = #333
  15 +!white_border = #eee
  16 +
  17 +!golden_ratio = 1.61803399
  18 +
  19 +!stack_space_height = 6px
  20 +
  21 +body
  22 + :margin 0
  23 + :padding 0
  24 + :text-align center
  25 + :font-family "Helvetica Neue", Helvetica, Arial, sans-serif
  26 + :font-size 14px
  27 +
  28 + h1
  29 + :font-size 6em
  30 +
  31 + a
  32 + :color red
  33 + :text-decoration none
  34 + &:hover
  35 + :color orange
  36 +
  37 + pre
  38 + :font-family "DejaVu Sans Mono", "Panic Sans", "Monaco", "Courier New"
  39 + :text-align left
  40 +
  41 + #central
  42 + :margin 200px 50px 0
  43 +
  44 + ol#stack
  45 + :margin 0
  46 + :padding 0
  47 + :list-style-type none
  48 +
  49 + li
  50 + :height = !stack_space_height
  51 + :width = !golden_ratio * !stack_space_height * 3
  52 + :border
  53 + :width 2px 3px
  54 + :style solid
  55 +
  56 + &.red
  57 + :background-color = !red
  58 + :border-color = !red_border
  59 +
  60 + &.yellow
  61 + :background-color = !yellow
  62 + :border-color = !yellow_border
  63 +
  64 + &.green
  65 + :background-color = !green
  66 + :border-color = !green_border
  67 +
  68 + &.blue
  69 + :background-color = !blue
  70 + :border-color = !blue_border
  71 +
  72 + &.purple
  73 + :background-color = !purple
  74 + :border-color = !purple_border
  75 +
  76 + &.black
  77 + :background-color = !black
  78 + :border-color = !black_border
  79 +
  80 + &.white
  81 + :background-color = !white
  82 + :border-color = !white_border
4 test/unit/game_test.rb
@@ -8,10 +8,12 @@ class GameTest < ActiveSupport::TestCase
8 8 end
9 9
10 10 test "generates a randomized stack" do
11   - srand
12 11 assert_equal [], @game.starting_stack
13 12 @game.save!
14 13 assert_equal 60, @game.starting_stack.length
  14 + first_stack = @game.starting_stack
  15 + @game.save!
  16 + assert_equal first_stack, @game.starting_stack
15 17 end
16 18 end
17 19

0 comments on commit da43476

Please sign in to comment.
Something went wrong with that request. Please try again.