Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: kidpollo/minesweeper
base: master
...
head fork: kidpollo/minesweeper
compare: james
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 19 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 21, 2011
@kidpollo bal 462f5d9
View
3  app/assets/javascripts/games.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  app/assets/stylesheets/games.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Games controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
56 app/assets/stylesheets/scaffolds.css.scss
@@ -0,0 +1,56 @@
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px; }
+
+a {
+ color: #000;
+ &:visited {
+ color: #666; }
+ &:hover {
+ color: #fff;
+ background-color: #000; } }
+
+div {
+ &.field, &.actions {
+ margin-bottom: 10px; } }
+
+#notice {
+ color: green; }
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table; }
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff; }
+ ul li {
+ font-size: 12px;
+ list-style: square; } }
View
83 app/controllers/games_controller.rb
@@ -0,0 +1,83 @@
+class GamesController < ApplicationController
+ # GET /games
+ # GET /games.json
+ def index
+ @games = Game.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @games }
+ end
+ end
+
+ # GET /games/1
+ # GET /games/1.json
+ def show
+ @game = Game.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @game }
+ end
+ end
+
+ # GET /games/new
+ # GET /games/new.json
+ def new
+ @game = Game.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @game }
+ end
+ end
+
+ # GET /games/1/edit
+ def edit
+ @game = Game.find_by_name(params[:name])
+ end
+
+ # POST /games
+ # POST /games.json
+ def create
+ @game = Game.new(params[:game])
+
+ respond_to do |format|
+ if @game.save
+ format.html { redirect_to named_game_url(@game), notice: 'Game was successfully created.' }
+ format.json { render json: @game, status: :created, location: @game }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @game.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /games/1
+ # PUT /games/1.json
+ def update
+ @game = Game.find(params[:id])
+
+ respond_to do |format|
+ if @game.update_attributes(params[:game])
+ format.html { redirect_to @game, notice: 'Game was successfully updated.' }
+ format.json { head :ok }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @game.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /games/1
+ # DELETE /games/1.json
+ def destroy
+ @game = Game.find(params[:id])
+ @game.destroy
+
+ respond_to do |format|
+ format.html { redirect_to games_url }
+ format.json { head :ok }
+ end
+ end
+end
View
2  app/helpers/games_helper.rb
@@ -0,0 +1,2 @@
+module GamesHelper
+end
View
13 app/models/game.rb
@@ -0,0 +1,13 @@
+class Game < ActiveRecord::Base
+ before_save do |game|
+ game.name.gsub!(' ', '_')
+ end
+
+ def to_param
+ name
+ end
+
+ def set_mine(x, y)
+ end
+
+end
View
2  app/models/square.rb
@@ -0,0 +1,2 @@
+class Square < ActiveRecord::Base
+end
View
33 app/views/games/_form.html.erb
@@ -0,0 +1,33 @@
+<%= form_for(@game) do |f| %>
+ <% if @game.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@game.errors.count, "error") %> prohibited this game from being saved:</h2>
+
+ <ul>
+ <% @game.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :x %><br />
+ <%= f.number_field :x %>
+ </div>
+ <div class="field">
+ <%= f.label :y %><br />
+ <%= f.number_field :y %>
+ </div>
+ <div class="field">
+ <%= f.label :mines %><br />
+ <%= f.number_field :mines %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
6 app/views/games/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Do your first move!</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @game %> |
+<%= link_to 'Back', games_path %>
View
29 app/views/games/index.html.erb
@@ -0,0 +1,29 @@
+<h1>Welcome to Mine Sweeper</h1>
+
+<table>
+ <tr>
+ <th>Name</th>
+ <th>X</th>
+ <th>Y</th>
+ <th>Mines</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @games.each do |game| %>
+ <tr>
+ <td><%= game.name %></td>
+ <td><%= game.x %></td>
+ <td><%= game.y %></td>
+ <td><%= game.mines %></td>
+ <td><%= link_to 'Show', game %></td>
+ <td><%= link_to 'Edit', edit_game_path(game) %></td>
+ <td><%= link_to 'Destroy', game, confirm: 'Are you sure?', method: :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Game', new_game_path %>
View
7 app/views/games/new.html.erb
@@ -0,0 +1,7 @@
+<h1>Welcome to Mine Sweeper</h1>
+
+<h2>New Game:</h2>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', games_path %>
View
25 app/views/games/show.html.erb
@@ -0,0 +1,25 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Name:</b>
+ <%= @game.name %>
+</p>
+
+<p>
+ <b>X:</b>
+ <%= @game.x %>
+</p>
+
+<p>
+ <b>Y:</b>
+ <%= @game.y %>
+</p>
+
+<p>
+ <b>Mines:</b>
+ <%= @game.mines %>
+</p>
+
+
+<%= link_to 'Edit', edit_game_path(@game) %> |
+<%= link_to 'Back', games_path %>
View
2  config.ru
@@ -1,4 +1,4 @@
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
-run Tictactoe::Application
+run MineSweeper::Application
View
6 config/routes.rb
@@ -1,4 +1,10 @@
MineSweeper::Application.routes.draw do
+ resources :games
+
+ root :to => 'games#new'
+
+ match '/:name' => 'games#edit', :as => :named_game
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
12 db/migrate/20111221200957_create_games.rb
@@ -0,0 +1,12 @@
+class CreateGames < ActiveRecord::Migration
+ def change
+ create_table :games do |t|
+ t.string :name
+ t.integer :x
+ t.integer :y
+ t.integer :mines
+
+ t.timestamps
+ end
+ end
+end
View
13 db/migrate/20111221205637_create_squares.rb
@@ -0,0 +1,13 @@
+class CreateSquares < ActiveRecord::Migration
+ def change
+ create_table :squares do |t|
+ t.integer :x
+ t.integer :y
+ t.boolean :covered
+ t.boolean :mined
+ t.references :game
+
+ t.timestamps
+ end
+ end
+end
View
52 db/schema.rb
@@ -0,0 +1,52 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20111221205637) do
+
+ create_table "boards", :force => true do |t|
+ t.string "name"
+ t.integer "x"
+ t.integer "y"
+ t.integer "max_mines"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "games", :force => true do |t|
+ t.string "name"
+ t.integer "x"
+ t.integer "y"
+ t.integer "mines"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "mines", :force => true do |t|
+ t.integer "board_id"
+ t.integer "x"
+ t.integer "y"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "squares", :force => true do |t|
+ t.integer "x"
+ t.integer "y"
+ t.boolean "covered"
+ t.boolean "mined"
+ t.integer "game_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+end
View
241 public/index.html
@@ -1,241 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>Ruby on Rails: Welcome aboard</title>
- <style type="text/css" media="screen">
- body {
- margin: 0;
- margin-bottom: 25px;
- padding: 0;
- background-color: #f0f0f0;
- font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
- font-size: 13px;
- color: #333;
- }
-
- h1 {
- font-size: 28px;
- color: #000;
- }
-
- a {color: #03c}
- a:hover {
- background-color: #03c;
- color: white;
- text-decoration: none;
- }
-
-
- #page {
- background-color: #f0f0f0;
- width: 750px;
- margin: 0;
- margin-left: auto;
- margin-right: auto;
- }
-
- #content {
- float: left;
- background-color: white;
- border: 3px solid #aaa;
- border-top: none;
- padding: 25px;
- width: 500px;
- }
-
- #sidebar {
- float: right;
- width: 175px;
- }
-
- #footer {
- clear: both;
- }
-
- #header, #about, #getting-started {
- padding-left: 75px;
- padding-right: 30px;
- }
-
-
- #header {
- background-image: url("/assets/rails.png");
- background-repeat: no-repeat;
- background-position: top left;
- height: 64px;
- }
- #header h1, #header h2 {margin: 0}
- #header h2 {
- color: #888;
- font-weight: normal;
- font-size: 16px;
- }
-
-
- #about h3 {
- margin: 0;
- margin-bottom: 10px;
- font-size: 14px;
- }
-
- #about-content {
- background-color: #ffd;
- border: 1px solid #fc0;
- margin-left: -55px;
- margin-right: -10px;
- }
- #about-content table {
- margin-top: 10px;
- margin-bottom: 10px;
- font-size: 11px;
- border-collapse: collapse;
- }
- #about-content td {
- padding: 10px;
- padding-top: 3px;
- padding-bottom: 3px;
- }
- #about-content td.name {color: #555}
- #about-content td.value {color: #000}
-
- #about-content ul {
- padding: 0;
- list-style-type: none;
- }
-
- #about-content.failure {
- background-color: #fcc;
- border: 1px solid #f00;
- }
- #about-content.failure p {
- margin: 0;
- padding: 10px;
- }
-
-
- #getting-started {
- border-top: 1px solid #ccc;
- margin-top: 25px;
- padding-top: 15px;
- }
- #getting-started h1 {
- margin: 0;
- font-size: 20px;
- }
- #getting-started h2 {
- margin: 0;
- font-size: 14px;
- font-weight: normal;
- color: #333;
- margin-bottom: 25px;
- }
- #getting-started ol {
- margin-left: 0;
- padding-left: 0;
- }
- #getting-started li {
- font-size: 18px;
- color: #888;
- margin-bottom: 25px;
- }
- #getting-started li h2 {
- margin: 0;
- font-weight: normal;
- font-size: 18px;
- color: #333;
- }
- #getting-started li p {
- color: #555;
- font-size: 13px;
- }
-
-
- #sidebar ul {
- margin-left: 0;
- padding-left: 0;
- }
- #sidebar ul h3 {
- margin-top: 25px;
- font-size: 16px;
- padding-bottom: 10px;
- border-bottom: 1px solid #ccc;
- }
- #sidebar li {
- list-style-type: none;
- }
- #sidebar ul.links li {
- margin-bottom: 5px;
- }
-
- .filename {
- font-style: italic;
- }
- </style>
- <script type="text/javascript">
- function about() {
- info = document.getElementById('about-content');
- if (window.XMLHttpRequest)
- { xhr = new XMLHttpRequest(); }
- else
- { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
- xhr.open("GET","rails/info/properties",false);
- xhr.send("");
- info.innerHTML = xhr.responseText;
- info.style.display = 'block'
- }
- </script>
- </head>
- <body>
- <div id="page">
- <div id="sidebar">
- <ul id="sidebar-items">
- <li>
- <h3>Browse the documentation</h3>
- <ul class="links">
- <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
- <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
- <li><a href="http://www.ruby-doc.org/core/">Ruby core</a></li>
- <li><a href="http://www.ruby-doc.org/stdlib/">Ruby standard library</a></li>
- </ul>
- </li>
- </ul>
- </div>
-
- <div id="content">
- <div id="header">
- <h1>Welcome aboard</h1>
- <h2>You&rsquo;re riding Ruby on Rails!</h2>
- </div>
-
- <div id="about">
- <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
- <div id="about-content" style="display: none"></div>
- </div>
-
- <div id="getting-started">
- <h1>Getting started</h1>
- <h2>Here&rsquo;s how to get rolling:</h2>
-
- <ol>
- <li>
- <h2>Use <code>rails generate</code> to create your models and controllers</h2>
- <p>To see all available options, run it without parameters.</p>
- </li>
-
- <li>
- <h2>Set up a default route and remove <span class="filename">public/index.html</span></h2>
- <p>Routes are set up in <span class="filename">config/routes.rb</span>.</p>
- </li>
-
- <li>
- <h2>Create your database</h2>
- <p>Run <code>rake db:create</code> to create your database. If you're not using SQLite (the default), edit <span class="filename">config/database.yml</span> with your username and password.</p>
- </li>
- </ol>
- </div>
- </div>
-
- <div id="footer">&nbsp;</div>
- </div>
- </body>
-</html>
View
16 spec/requests/mine_sweeper_spec.rb
@@ -17,16 +17,16 @@
scenario "Should be able to create new game" do
page.should have_content('New Game:')
page.should have_field('Name')
- page.should have_field('x')
- page.should have_field('y')
- page.should have_field('mines')
+ page.should have_field('X')
+ page.should have_field('Y')
+ page.should have_field('Mines')
page.should have_button('Create Game')
end
scenario 'Should be able to create new game' do
- fill_in('x', :with => '5')
- fill_in('y', :with => '5')
- fill_in('mines', :with => '5')
+ fill_in('X', :with => '5')
+ fill_in('Y', :with => '5')
+ fill_in('Mines', :with => '5')
fill_in('Name', :with => 'super game')
click_button('Create Game')
current_path.should == '/super_game'
@@ -35,13 +35,13 @@
end
feature "Mine Sweeprer Game", %q{
- In order to have a player loose a lot of productive time
+ In order to have a player lose a lot of productive time
As a player
I want to play the game
} do
background do
- @board = Board.create!({:x => 5, :y => 5, :mines => 5, :sample_game => 'sample_game'})
+ @board = Game.create!({:x => 5, :y => 5, :mines => 5, :name => 'sample_game'})
@board.set_mine(1,1)
visit '/sample_game'
end

No commit comments for this range

Something went wrong with that request. Please try again.