Skip to content

Commit

Permalink
play a game without logging in
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofumaker committed Feb 2, 2017
1 parent 8a3ebdd commit d7bbcbb
Show file tree
Hide file tree
Showing 5 changed files with 488 additions and 268 deletions.
10 changes: 7 additions & 3 deletions app/controllers/games_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class GamesController < ApplicationController
def index
@game = Game.new unless @game
# @board = GamesHelper.process_board(@game.game_board)
end

def show
Expand All @@ -11,8 +10,14 @@ def show

def create
@game = Game.new
@game.user = current_user
@game.difficulty = params[:difficulty]
if current_user
@game.user = current_user
else
temp_user = User.new
temp_user.username = "Human Player"
@game.user = temp_user
end
@game.save
redirect_to @game
end
Expand All @@ -23,7 +28,6 @@ def edit
if request.xhr?
@game.game_board = GamesHelper.plot(params[:player_move], @game.game_board)
if check_board('x', @game.game_board)
p "player wins!!!!"
@game.game_status = "Player Won!"
end

Expand Down
13 changes: 4 additions & 9 deletions app/views/games/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
<section class="container">
<% if session[:user_id] %>
<%= form_for @game do |f| %>
<div class="input-field col s12">
<div class="input-field col s12">
<%= select_tag(:difficulty, options_for_select([['Easy', 'easy'],['Medium', 'medium'],['Hard', 'hard'],['Impossible', 'impossible']]))%>
</div>
<%= f.submit "Play a Game!", :class => 'waves-effect waves-light btn-large ' %>
<%= button_tag(type: "Play a Game!", class: "waves-effect waves-light btn-large") do %>
Play a Game!<i class="material-icons right">dashboard</i>
<% end %>
<% end %>
<%else%>
<div class="input-field col s12">
<%= select_tag(:difficulty, options_for_select([['Easy', 'easy'],['Medium', 'medium'],['Hard', 'hard'],['Impossible', 'impossible']]))%>
</div>
<a class="waves-effect waves-light btn-large" href="http://tofumaker.github.io?=<%=:difficulty%>"><i class="material-icons right">dashboard</i>Play a Game!</a>
<% end %>
</section>
Loading

0 comments on commit d7bbcbb

Please sign in to comment.