Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SuzHarrison-ScrabbleSinatra #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
Binary file added .DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'https://rubygems.org'

gem 'sinatra', '~>1.4.7'
gem 'rerun', '~>0.11.0'
gem 'thin', '~>1.6.4'
37 changes: 37 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
GEM
remote: https://rubygems.org/
specs:
daemons (1.2.3)
eventmachine (1.2.0.1)
ffi (1.9.10)
listen (3.0.6)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9.7)
rack (1.6.4)
rack-protection (1.5.3)
rack
rb-fsevent (0.9.7)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
rerun (0.11.0)
listen (~> 3.0)
sinatra (1.4.7)
rack (~> 1.5)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
thin (1.6.4)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (~> 1.0)
tilt (2.0.2)

PLATFORMS
ruby

DEPENDENCIES
rerun (~> 0.11.0)
sinatra (~> 1.4.7)
thin (~> 1.6.4)

BUNDLED WITH
1.11.2
76 changes: 76 additions & 0 deletions lib/scoring.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
class Scoring
#some sort of data structure to store the individual letter scores
SCORE_CHART = {
"A"=>1, "B"=>3, "C"=>3, "D"=>2,
"E"=>1, "F"=>4, "G"=>2, "H"=>4,
"I"=>1, "J"=>8, "K"=>5, "L"=>1,
"M"=>3, "N"=>1, "O"=>1, "P"=>3,
"Q"=>10, "R"=>1, "S"=>1, "T"=>1,
"U"=>1, "V"=>4, "W"=>4, "X"=>8,
"Y"=>4, "Z"=>10
}

def self.score(word)
if word.match /[^a-zA-Z]/
puts "You have entered invalid information. Please try again."
else
word_array = word.upcase.split("")

word_score = 0
#validity of entry

# if word.length <= 7
word_array.each do |letter|
word_score += SCORE_CHART[letter]
#returns score value for given word. word input as string.
end
#seven letter word get 50point bonus
word.length >= 7 ? word_score += 50 : word_score
# end
return word_score
end
end

def self.score_many(words)
#words = "melissa suz"

words = words.split(" ")
# words = ["melissa", "suz"]
words_hash ={}
words.each do |word|
words_hash[word] = self.score(word)
end
return words_hash
# @word_score = Scoring.score(words["word"])
# @word = words["word"]
end

def self.letter_by_letter(word)
letters = word.upcase.chars
letters.map do |letter|
{letter => SCORE_CHART[letter]}
end
end

def self.highest_score_from(array_of_words)
win_score = 0
win_word = array_of_words[0]


array_of_words.each do |word|
score_inst = self.score(word)
#checks if current winning score is less than or equal
#to the current word's score, then uses the tiebreaker
#conditions to determine winning word and score
if score_inst > win_score
win_score = score_inst
win_word = word
elsif score_inst == win_score && word.length < win_word.length
win_word = word
win_score = score_inst
end
end
return win_word

end
end
Binary file added public/images/Scrabble_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/scrabble_tiles.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 109 additions & 0 deletions public/stylesheets/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
html {
font-size: 16px;
}

.header_image {
align-self: center;
}

header ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}

header li {
float: left;
}

header li a {
display: block;
color: white;
font-family: "Arial";
font-size: 16px;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}

header li a:hover:not(.active) {
background-color: #111;
}

header.active {
background-color: #4CAF50;
}

h1 {
color: black;
font-family: 'Tangerine', serif;
font-size: 36px;
text-shadow: 4px 4px 4px #aaa;
text-align: center;
}


body {
background: url(../images/scrabble_tiles.jpg) no-repeat center center fixed;
background-size: cover;
color: white;
font-size: 1.5rem;
height: 100%;
}

input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}

input[type=submit]:hover {
background-color: #45a049;
}

section.transbox {
margin: 30px;
background-color: #ffffff;
color: black;
border: 1px solid black;
opacity: 0.6;
filter: alpha(opacity=60);
}

.transbox ul {
/*width: 17em;*/
margin-left: 34%;
margin-right: 34%;
}

/*section.gradient button {
color: #fff;
text-shadow: -2px 2px #346392;
background-color: #ff9664;
background-image: linear-gradient(top, #6496c8, #346392);
box-shadow: inset 0 0 0 1px #27496d;
border: none;
border-radius: 15px;
}

section.gradient button:hover,
section.gradient button.hover {
box-shadow: inset 0 0 0 1px #27496d,0 5px 15px #193047;
}

section.gradient button:active,
section.gradient button.active {
box-shadow: inset 0 0 0 1px #27496d,inset 0 5px 30px #193047;
}*/
/*section.transbox {
margin: 5%;
font-weight: bold;
color: #000000;
}*/
36 changes: 36 additions & 0 deletions scrabble.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'sinatra'
require_relative 'lib/scoring.rb'

class ScrabbleSinatra < Sinatra::Base

get '/' do
erb :index
end

get '/index' do
erb :index
end

get '/score' do
erb :score
end

post '/score' do
@word_score = Scoring.score(params["word"])
@word = params["word"]
@letter_scores = Scoring.letter_by_letter(params["word"])
erb :score
end

get '/score-many' do
erb :score_many
end

post '/score-many' do
@words_scores = Scoring.score_many(params["word"])
@word = params["word"]
erb :score_many
end

run!
end
Binary file added views/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions views/index.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1> Click <a href="/score">to visit Score page</a></h1>
24 changes: 24 additions & 0 deletions views/layout.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>scrabble sinatra</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="css" href="stylesheets/styles.css">
</head>
<header>
<img class="header_image" src="images/Scrabble_logo.png" alt="scrabble_logo">
<nav>
<ul>
<li><a href="/index">Home</a></li>
<li><a href="/score">Score-a-Word!</a></li>
<li><a href="/score-many">Score-Many-Words!</a></li>
</ul>
</nav>
</header>

<body>
<main>
<%= yield %>
</main>
</body>
</html>
33 changes: 33 additions & 0 deletions views/score.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<section class="transbox">
<% if @word_score %>
<h1>
<%= @word.upcase %> has a score of <%= @word_score %> points!
</h1>
<ul>
<% @letter_scores.each do |letter_hash|
letter_hash.each do |letter, score|%>
<li><%= letter %> has a score of <%= score %></li>
<% end
end%>
</ul>

<% end %>
</section>

<div class="params">
<% params %>
</div>

<form action="" method="post" accept-charset="utf-8">
<label for="word">Enter your single Scrabble Word!</label>
<input type="text" name="word" value="" id="word">


<input type="submit" value="Score It!">
</form>
<!--
<section class="gradient">
<button>Button</button>
<button class="hover">:hover</button>
<button class="active">:active</button>
</section> -->
20 changes: 20 additions & 0 deletions views/score_many.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<section class="transbox">
<% if @words_scores %>
<% @words_scores.each do |word, score| %>
<h1>
<span><%= word.upcase %></span> has a score of <span><%= score %></span> points!
</h1>
<% end %>
<% end %>
</section>

<div class="params">
<% params %>
</div>

<form action="" method="post" accept-charset="utf-8">
<label for="word">Enter your Scrabble words separated by a space</label>
<input type="text" name="word" value="" id="word">

<input type="submit" value="Score It!">
</form>