forked from deanrad/chess_on_rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
293 changed files
with
21,368 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.