Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -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
58 changes: 58 additions & 0 deletions app/views/game_templates/rules.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<p>From <a href="https://en.wikipedia.org/wiki/Rock_paper_scissors" target="_blank">Wikipedia</a></p>
<p>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.</p>
<p>These shapes are:</p>
<ul>
<li>"rock" (a closed fist)</li>
<li>"paper" (a flat hand)</li>
<li>"scissors" (a fist with the index and middle fingers extended, forming a V)</li>
</ul>

<p> 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.</p>

<table border = "1">
<tbody>
<tr>
<td rowspan="2" colspan="2">
</td>
<td colspan="3">
and they play...
</td>
</tr>
<tr>
<td>Rock</td>
<td>Paper</td>
<td>Scissors</td>
</tr>
<tr>
<td rowspan="3">If we play...</td>
<td>Rock</td>
<td>We tie</td>
<td>We lose</td>
<td>We win</td>
</tr>
<tr>
<td>Paper</td>
<td>We win</td>
<td>We tie</td>
<td>We lose</td>
</tr>
<tr>
<td>Scissors</td>
<td>We lose</td>
<td>We win</td>
<td>We tie</td>
</tr>
</tbody>
</table>

<p>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".
</p>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/67/Rock-paper-scissors.svg/627px-Rock-paper-scissors.svg.png">
<p>A chart showing how the three game elements interact.</p>

<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/9/9d/Kitsune-ken_%28%E7%8B%90%E6%8B%B3%29%2C_Japanese_rock-paper-scissors_variant%2C_from_the_Genyoku_sui_bento_%281774%29.jpg/640px-Kitsune-ken_%28%E7%8B%90%E6%8B%B3%29%2C_Japanese_rock-paper-scissors_variant%2C_from_the_Genyoku_sui_bento_%281774%29.jpg">\
<p>Kitsune-ken was a popular Japanese rock-paper-scissors variant.</p>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/ae/Mushi-ken_%28%E8%99%AB%E6%8B%B3%29%2C_Japanese_rock-paper-scissors_variant%2C_from_the_Kensarae_sumai_zue_%281809%29.jpg/640px-Mushi-ken_%28%E8%99%AB%E6%8B%B3%29%2C_Japanese_rock-paper-scissors_variant%2C_from_the_Kensarae_sumai_zue_%281809%29.jpg">
<p>Mushi-ken, the earliest Japanese sansukumi-ken game (1809). From left to right: slug (namekuji), frog (kawazu) and snake (hebi).</p>
</body>
</html>
9 changes: 9 additions & 0 deletions app/views/game_templates/user_paper.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h2> We played paper! </h2>

<h2>
They played <%= @comp_move %>!
</h2>

<h2> <%= @outcome %> </h2>

<div> <a href = "/"> Rules </a> </div>
9 changes: 9 additions & 0 deletions app/views/game_templates/user_rock.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h2> We played rock! </h2>

<h2>
They played <%= @comp_move %>!
</h2>

<h2> <%= @outcome %> </h2>

<div> <a href = "/"> Rules </a> </div>
9 changes: 9 additions & 0 deletions app/views/game_templates/user_scissors.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h2> We played scissors! </h2>

<h2>
They played <%= @comp_move %>!
</h2>

<h2> <%= @outcome %> </h2>

<div> <a href = "/"> Rules </a> </div>
12 changes: 12 additions & 0 deletions app/views/layouts/wrapper.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div>
<a href= "/rock">Play Rock </a>
</div>
<div>
<a href= "/paper">Play Paper </a>
</div>
<div>
<a href= "/scissors">Play Scissors </a>
</div>

<%=yield%>

7 changes: 7 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -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
Binary file added db/test.sqlite3
Binary file not shown.