diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6536063..5945925 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,54 @@ class ApplicationController < ActionController::Base - layout(false) + layout("wrapper.html.erb") # Add your actions below this line # ================================ + def homepage + render({:template => "game_templates/rules.html.erb"}) + end + + def play_rock + @comp_move = ["rock", "paper", "scissors"].sample + + if @comp_move == "rock" + @outcome = "We tied!" + elsif @comp_move == "paper" + @outcome = "We lost!" + elsif @comp_move == "scissors" + @outcome = "We won!" + end + + render({:template => "game_templates/user_rock.html.erb"}) + end + + def play_paper + @comp_move = ["rock", "paper", "scissors"].sample + + if @comp_move == "rock" + @outcome = "We won!" + elsif @comp_move == "paper" + @outcome = "We tied!" + elsif @comp_move == "scissors" + @outcome = "We lost!" + end + + render({:template => "game_templates/user_paper.html.erb"}) + end + + def play_scissors + + @comp_move = ["rock", "paper", "scissors"].sample + + if @comp_move == "rock" + @outcome = "We lost!" + elsif @comp_move == "paper" + @outcome = "We won!" + elsif @comp_move == "scissors" + @outcome = "We tied!" + end + + render({:template => "game_templates/user_scissors.html.erb"}) + end + end diff --git a/app/views/game_templates/rules.html.erb b/app/views/game_templates/rules.html.erb new file mode 100644 index 0000000..c48e388 --- /dev/null +++ b/app/views/game_templates/rules.html.erb @@ -0,0 +1,58 @@ +

From Wikipedia

+

Rock-paper-scissors (also known as paper, scissors, stone or other variants) is a hand game usually played between two people, in which each player simultaneously forms one of three shapes with an outstretched hand.

+

These shapes are:

+ + +

A player who decides to play rock will beat another player who has chosen scissors ("rock crushes scissors" or sometimes "blunts scissors"), but will lose to one who has played paper ("paper covers rock"); a play of paper will lose to a play of scissors ("scissors cut[s] paper"). If both players choose the same shape, the game is tied and is usually immediately replayed to break the tie.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + and they play... +
RockPaperScissors
If we play...RockWe tieWe loseWe win
PaperWe winWe tieWe lose
ScissorsWe loseWe winWe tie
+ +

Originating from China and Japan, other names for the game in the English-speaking world include roshambo and other orderings of the three items, with "rock" sometimes being called "stone". +

+ +

A chart showing how the three game elements interact.

+ + \ +

Kitsune-ken was a popular Japanese rock-paper-scissors variant.

+ +

Mushi-ken, the earliest Japanese sansukumi-ken game (1809). From left to right: slug (namekuji), frog (kawazu) and snake (hebi).

+ + diff --git a/app/views/game_templates/user_paper.html.erb b/app/views/game_templates/user_paper.html.erb new file mode 100644 index 0000000..21a54e1 --- /dev/null +++ b/app/views/game_templates/user_paper.html.erb @@ -0,0 +1,9 @@ +

We played paper!

+ +

+ They played <%= @comp_move %>! +

+ +

<%= @outcome %>

+ +
Rules
diff --git a/app/views/game_templates/user_rock.html.erb b/app/views/game_templates/user_rock.html.erb new file mode 100644 index 0000000..b619d53 --- /dev/null +++ b/app/views/game_templates/user_rock.html.erb @@ -0,0 +1,9 @@ +

We played rock!

+ +

+ They played <%= @comp_move %>! +

+ +

<%= @outcome %>

+ +
Rules
diff --git a/app/views/game_templates/user_scissors.html.erb b/app/views/game_templates/user_scissors.html.erb new file mode 100644 index 0000000..911e205 --- /dev/null +++ b/app/views/game_templates/user_scissors.html.erb @@ -0,0 +1,9 @@ +

We played scissors!

+ +

+ They played <%= @comp_move %>! +

+ +

<%= @outcome %>

+ +
Rules
diff --git a/app/views/layouts/wrapper.html.erb b/app/views/layouts/wrapper.html.erb new file mode 100644 index 0000000..9f6a03d --- /dev/null +++ b/app/views/layouts/wrapper.html.erb @@ -0,0 +1,12 @@ +
+ Play Rock +
+
+ Play Paper +
+
+ Play Scissors +
+ +<%=yield%> + diff --git a/config/routes.rb b/config/routes.rb index b654d52..8c20161 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,11 @@ Rails.application.routes.draw do + get("/rock", { :controller => "application", :action => "play_rock" }) + get("/", {:controller =>"application", :action =>"homepage"}) + + get("/paper", {:controller =>"application", :action => "play_paper"}) + + get("/scissors", {:controller =>"application", :action => "play_scissors"}) + end diff --git a/db/test.sqlite3 b/db/test.sqlite3 new file mode 100644 index 0000000..bd56f45 Binary files /dev/null and b/db/test.sqlite3 differ