From 575b74b9455a8b8e11c7f1385fd43e61abbd1d5e Mon Sep 17 00:00:00 2001 From: sebgomez2023 Date: Mon, 23 Jan 2023 20:18:45 +0000 Subject: [PATCH 1/4] Made Rock page --- app/controllers/application_controller.rb | 7 +++++++ app/views/game_templates/user_rock.html.erb | 14 ++++++++++++++ config/routes.rb | 1 + db/test.sqlite3 | 0 4 files changed, 22 insertions(+) create mode 100644 app/views/game_templates/user_rock.html.erb create mode 100644 db/test.sqlite3 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6536063..99323e6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,5 +3,12 @@ class ApplicationController < ActionController::Base # Add your actions below this line # ================================ + def play_rock + # render({:html => "

Howdy, world!

".html_safe}) + # redirect_to("https://wikipedia.org") + + render({:template => "game_templates/user_rock.html.erb"}) + + end end 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..0f9d150 --- /dev/null +++ b/app/views/game_templates/user_rock.html.erb @@ -0,0 +1,14 @@ +

Hello world!

+ +<%comp_move = ["rock", "paper", "scissors"].sample%> +

+ They played <%= comp_move %> +

+ +<%if comp_move == "rock"%> +

tied

+<%elsif comp_move == "paper"%> +

lost

+<%elsif comp_move == "scissors"%> +

won!

+ <%end%> diff --git a/config/routes.rb b/config/routes.rb index b654d52..89b1cab 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + get("/rock", { :controller => "application", :action => "play_rock" }) end diff --git a/db/test.sqlite3 b/db/test.sqlite3 new file mode 100644 index 0000000..e69de29 From 07536196e6ffe4df51286dccb9c85ac0408608f7 Mon Sep 17 00:00:00 2001 From: sebgomez2023 Date: Mon, 23 Jan 2023 20:49:53 +0000 Subject: [PATCH 2/4] Progress on all --- app/controllers/application_controller.rb | 46 +++++++++++++++++-- app/views/game_templates/rules.html.erb | 1 + app/views/game_templates/user_paper.html.erb | 17 +++++++ app/views/game_templates/user_rock.html.erb | 2 +- .../game_templates/user_scissors.html.erb | 0 config/routes.rb | 6 +++ 6 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 app/views/game_templates/rules.html.erb create mode 100644 app/views/game_templates/user_paper.html.erb create mode 100644 app/views/game_templates/user_scissors.html.erb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 99323e6..21ede10 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,12 +3,52 @@ class ApplicationController < ActionController::Base # Add your actions below this line # ================================ - def play_rock - # render({:html => "

Howdy, world!

".html_safe}) + def homepage + render({:template => "game_templates/rules.html.erb"}) + end - # redirect_to("https://wikipedia.org") + def play_rock + @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_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 + + @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_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..36e8994 --- /dev/null +++ b/app/views/game_templates/rules.html.erb @@ -0,0 +1 @@ +

Welcome to RPS!

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..16fb460 --- /dev/null +++ b/app/views/game_templates/user_paper.html.erb @@ -0,0 +1,17 @@ +
+ Play Rock +
+
+ Play Paper +
+
+ Play Scissors +
+ +

We played paper!

+ +

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

+ +

<%= @outcome %>

diff --git a/app/views/game_templates/user_rock.html.erb b/app/views/game_templates/user_rock.html.erb index 0f9d150..8b4927d 100644 --- a/app/views/game_templates/user_rock.html.erb +++ b/app/views/game_templates/user_rock.html.erb @@ -11,4 +11,4 @@

lost

<%elsif comp_move == "scissors"%>

won!

- <%end%> +<%end%> 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..e69de29 diff --git a/config/routes.rb b/config/routes.rb index 89b1cab..8c20161 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,4 +2,10 @@ 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 From 3e899471e1f8f0389840e5acd30678a6f49250de Mon Sep 17 00:00:00 2001 From: sebgomez2023 Date: Mon, 23 Jan 2023 21:07:30 +0000 Subject: [PATCH 3/4] Final Product --- app/controllers/application_controller.rb | 18 +++--- app/views/game_templates/rules.html.erb | 59 +++++++++++++++++- app/views/game_templates/user_paper.html.erb | 12 +--- app/views/game_templates/user_rock.html.erb | 17 ++--- .../game_templates/user_scissors.html.erb | 9 +++ db/test.sqlite3 | Bin 0 -> 20480 bytes 6 files changed, 84 insertions(+), 31 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 21ede10..5945925 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,5 @@ class ApplicationController < ActionController::Base - layout(false) + layout("wrapper.html.erb") # Add your actions below this line # ================================ @@ -11,11 +11,11 @@ def play_rock @comp_move = ["rock", "paper", "scissors"].sample if @comp_move == "rock" - @outcome = "We won!" - elsif @comp_move == "paper" @outcome = "We tied!" - elsif @comp_move == "scissors" + elsif @comp_move == "paper" @outcome = "We lost!" + elsif @comp_move == "scissors" + @outcome = "We won!" end render({:template => "game_templates/user_rock.html.erb"}) @@ -34,17 +34,17 @@ def play_paper render({:template => "game_templates/user_paper.html.erb"}) end - - def play + + def play_scissors @comp_move = ["rock", "paper", "scissors"].sample if @comp_move == "rock" - @outcome = "We won!" + @outcome = "We lost!" elsif @comp_move == "paper" - @outcome = "We tied!" + @outcome = "We won!" elsif @comp_move == "scissors" - @outcome = "We lost!" + @outcome = "We tied!" end render({:template => "game_templates/user_scissors.html.erb"}) diff --git a/app/views/game_templates/rules.html.erb b/app/views/game_templates/rules.html.erb index 36e8994..c48e388 100644 --- a/app/views/game_templates/rules.html.erb +++ b/app/views/game_templates/rules.html.erb @@ -1 +1,58 @@ -

Welcome to RPS!

+

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:

+
    +
  • "rock" (a closed fist)
  • +
  • "paper" (a flat hand)
  • +
  • "scissors" (a fist with the index and middle fingers extended, forming a V)
  • +
+ +

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 index 16fb460..21a54e1 100644 --- a/app/views/game_templates/user_paper.html.erb +++ b/app/views/game_templates/user_paper.html.erb @@ -1,13 +1,3 @@ -
- Play Rock -
-
- Play Paper -
-
- Play Scissors -
-

We played paper!

@@ -15,3 +5,5 @@

<%= @outcome %>

+ +
Rules
diff --git a/app/views/game_templates/user_rock.html.erb b/app/views/game_templates/user_rock.html.erb index 8b4927d..b619d53 100644 --- a/app/views/game_templates/user_rock.html.erb +++ b/app/views/game_templates/user_rock.html.erb @@ -1,14 +1,9 @@ -

Hello world!

+

We played rock!

-<%comp_move = ["rock", "paper", "scissors"].sample%> -

- They played <%= comp_move %> +

+ They played <%= @comp_move %>!

-<%if comp_move == "rock"%> -

tied

-<%elsif comp_move == "paper"%> -

lost

-<%elsif comp_move == "scissors"%> -

won!

-<%end%> +

<%= @outcome %>

+ +
Rules
diff --git a/app/views/game_templates/user_scissors.html.erb b/app/views/game_templates/user_scissors.html.erb index e69de29..911e205 100644 --- a/app/views/game_templates/user_scissors.html.erb +++ 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/db/test.sqlite3 b/db/test.sqlite3 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..bd56f4571722d564ad9072af210537b7450879eb 100644 GIT binary patch literal 20480 zcmeI&O^?z*7zgla3%jn#QZE}0dvF4mC2^OQQpEM3)ezS#u8QnoV@xw`r_xA^wgXv@ z>vz)c;?a+wClfDD2_YD$SL5bCX{W<8Pl4yxUi$LtWj_*}hLbdAf?DJjQ55o!QbI_1 zvC7T7sj@FE#`#8B85a%9P=nW>GpxVx9=WGqEw>?zTJK;+g#Uzp8&D`ghr(K>z{} kfB*y_009U<00Izz00bcLe+uYYU0Jy+p;ol|&dPm*-{2kY*Z=?k literal 0 HcmV?d00001 From d363cd276ea529138ff02189faccf3142474f583 Mon Sep 17 00:00:00 2001 From: sebgomez2023 Date: Mon, 23 Jan 2023 21:09:25 +0000 Subject: [PATCH 4/4] Final Product --- app/views/layouts/wrapper.html.erb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 app/views/layouts/wrapper.html.erb 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 @@ + + + + +<%=yield%> +