Skip to content

Commit

Permalink
basically 1.0 but without notation
Browse files Browse the repository at this point in the history
  • Loading branch information
deanrad committed Aug 11, 2008
1 parent e582891 commit f5e341a
Show file tree
Hide file tree
Showing 293 changed files with 21,368 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tags/0.9/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Chess On Rails is a player-to-player chess game in Rails MVC style, intended for public consumption and open to all.

Dean Radcliffe developed it out of his love of Chess, and growing appreciation of Ruby, Rails and BDD.

Priorities are on 100% Agile best practice compliance, natural mappings of code to world, brevity when possible, and finally most idiomatic and Restful. Of course, that it is fun and educational to play and read the source code of is important to me as well, but for that I require the involvement of individuals like yourselves to get involved and provide feedback.

10 changes: 10 additions & 0 deletions tags/0.9/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require(File.join(File.dirname(__FILE__), 'config', 'boot'))

require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

require 'tasks/rails'
17 changes: 17 additions & 0 deletions tags/0.9/app/controllers/application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
include AuthenticatedSystem

helper :all # include all helpers, all the time

# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you're not using the cookie session store
protect_from_forgery :secret => '9ba9312accbe853c06bf9a8d79d6ecdf'

# See ActionController::Base for details
# Uncomment this to filter the contents of submitted sensitive data parameters
# from your application log (in this case, all fields with names like "password").
# filter_parameter_logging :password
end
16 changes: 16 additions & 0 deletions tags/0.9/app/controllers/matches_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Deals with the creation and updating of matches, such as creation, resignation
class MatchesController < ApplicationController

# GET /matches/N
def show
@match = Match.find( params[:id], :include => :moves )
end

# GET /matches
def index
@matches = current_player.matches if current_player
end

#TODO provide a way to create a new match with someone
#TODO provide a way (in advance of AJAX) to get a refresh of the state of the game
end
28 changes: 28 additions & 0 deletions tags/0.9/app/controllers/moves_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#Allows the posting of moves to a match or the listing of moves for a given match
class MovesController < ApplicationController

before_filter :get_match

#TODO ensure that a player can only move a side if they are playing that side
def create

@move = @match.moves.build( params[:move] )
if @move.valid?
@match.moves << @move
else
flash[:move_in_error] = @move unless @move.valid?
end

redirect_to match_path(@match) and return unless request.xhr?

#respond_to do |format|
# format.html{ }
#end
end

#TODO ensure that a player can only get a match if its theirs, and that players must be authorized
def get_match
@match = Match.find( params[:match_id] )
raise ActiveRecord::RecordNotFound unless @match
end
end
23 changes: 23 additions & 0 deletions tags/0.9/app/controllers/players_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Manages the addition and updating of players and their information
class PlayersController < ApplicationController

# render new.rhtml
def new
end

def create
cookies.delete :auth_token
# protects against session fixation attacks, wreaks havoc with
# request forgery protection.
# uncomment at your own risk
# reset_session
@player = Player.new(params[:player])
@player.save
if @player.errors.empty?
self.current_player = @player
redirect_back_or_default('/')
flash[:notice] = "Thanks for signing up!"
end
end

end
29 changes: 29 additions & 0 deletions tags/0.9/app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This controller handles the login/logout function of the site.
class SessionsController < ApplicationController

# render new.rhtml
def new
end

def create
self.current_player = Player.authenticate(params[:login], params[:password])
if logged_in?
if params[:remember_me] == "1"
current_player.remember_me unless current_player.remember_token?
cookies[:auth_token] = { :value => self.current_player.remember_token , :expires => self.current_player.remember_token_expires_at }
end
redirect_back_or_default('/')
flash[:notice] = "Logged in successfully"
else
render :action => 'new'
end
end

def destroy
self.current_player.forget_me if logged_in?
cookies.delete :auth_token
reset_session
flash[:notice] = "You have been logged out."
redirect_back_or_default('/')
end
end
3 changes: 3 additions & 0 deletions tags/0.9/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
end
40 changes: 40 additions & 0 deletions tags/0.9/app/helpers/matches_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#Contains functions for laying out the chess board
module MatchesHelper

#iterates over the rows and yields columns in the correct order for rendering the board for white or black
def positions_by_row_as( side )


rows_in_order = (side == :white) ? (0..7) : (0..7).to_a.reverse

rows_in_order.each do |row_offset|
from, to = [row_offset*8, row_offset*8 + 7]
row_pieces = Position::POSITIONS[ (from..to) ]
yield side==:white ? row_pieces : row_pieces.reverse
end

end

#an iterator over files that goes in the correct order for the side viewing
def files_as( side )
files = side==:white ? "abcdefgh" : "hgfedcba"
files.each_byte{ |f| yield f.chr }
end

#lets the view query which side the current player is on
#TODO allow the user to turn the board around
def side_of(match, player)
return :white unless match and player
match.player1 == player ? :white : :black
end

#returns the color of a square given a symbol or a string representing a position
def square_color( pos )
pos = pos.to_s
(pos[0] + pos[1]) % 2 == 1 ? :white : :black
end

def image_source_of( piece )
"/images/sets/default/#{piece.role.to_s}_#{piece.side.to_s[0,1]}.gif"
end
end
Loading

0 comments on commit f5e341a

Please sign in to comment.