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

Sinatra Scrabble #3

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6d6b264
Baseline ready
Apr 6, 2016
5f0257d
Primary requiremets All Pages:
Apr 6, 2016
fded2db
Once user input is retrieved, your app will score the input and then …
Apr 7, 2016
daa2b13
Score many words page. Accessible from /score-many. Allow the user to…
Apr 7, 2016
2e011ef
include a letter-by-letter breakdown showing the point value for each…
Apr 7, 2016
437f8ce
included a letter-by-letter breakdown in any view that shows a scored…
Apr 7, 2016
17e2fd4
Created the letter-by-letter breakdown method for multiple words, ve…
Apr 7, 2016
227bc9b
finale got the letter-by-letter breakdown method for multiple words…
Apr 8, 2016
89d09d3
Got out of the CSS holegit add .
Apr 8, 2016
e2bb5cc
Created a library points.rb that contains the code for each tale poin…
Apr 9, 2016
16f9617
Added the radious buttons, did some refactoring, improved desing
Apr 9, 2016
c4ce0db
made the radius botton part requied. made the vierw :ponits linked wi…
Apr 9, 2016
008b18b
whataver
Apr 25, 2016
083b015
created the file confi.gu
Apr 30, 2016
f1a09e8
edited conf.gu file
Apr 30, 2016
1fbfee3
edited conf.gu file
Apr 30, 2016
a6c2c11
tryed chanching the CSS path in Layout file
Apr 30, 2016
2ceabb9
tryed chanching the CSS path in Layout file
Apr 30, 2016
4aaddac
trying more things
May 1, 2016
3329bf0
trying more things
May 1, 2016
328cc7e
trying more things
May 1, 2016
690fe0f
trying more things
May 1, 2016
2e289bd
trying more things
May 1, 2016
159643c
bundle
May 1, 2016
960879e
deketed run
May 1, 2016
5adbe73
Tried other ton of things
May 1, 2016
5462896
Tried other ton of things
May 1, 2016
f15de5d
m
May 1, 2016
3610877
m
May 1, 2016
117f06a
mj
May 1, 2016
3c78038
v
May 1, 2016
537f1d5
v
May 1, 2016
26dfbea
v
May 1, 2016
ace88a6
v
May 1, 2016
bee3c86
v
May 1, 2016
661dc07
d
May 1, 2016
e55040a
added some css
May 1, 2016
f906d9e
bundle
May 1, 2016
dfd917a
better CSS
May 1, 2016
d908192
finished!!
May 1, 2016
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
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source 'https://rubygems.org'

gem 'sinatra', '~>1.4.7'
# gem 'sinatra-contrib', '~>1.4.6'
gem 'rerun', '~>0.11.0'
gem 'colorize', '0.7.7'
gem 'thin', '~>1.6.4'
# faster than rebrick
39 changes: 39 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
GEM
remote: https://rubygems.org/
specs:
colorize (0.7.7)
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
colorize (= 0.7.7)
rerun (~> 0.11.0)
sinatra (~> 1.4.7)
thin (~> 1.6.4)

BUNDLED WITH
1.11.2
2 changes: 2 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require './scrabble_sin'
run Sinatra::Application
6 changes: 6 additions & 0 deletions libs/points.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BONUS = 50
SCORES = {
A: 1, E: 1, I: 1, O: 1, U: 1, L: 1, N: 1, R: 1, S: 1, T: 1, D: 2, G: 2,
B: 3, C: 3, M: 3, P: 3, F: 4, H: 4, V: 4, W: 4, Y: 4, K: 5, J: 8, X: 8,
Q: 10, Z: 10
}
39 changes: 39 additions & 0 deletions libs/scorecode.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class Scoring

def self.letter_by_letter(word)
if word.length > 7
raise ArgumentError.new
end

word = word.upcase.split(//) # change letters of word to uppercase to match keys
score = word.map { |letter| SCORES[letter.to_sym] }
word.zip score
end

def self.letter_by_letter_many(array_of_words)
final = {}
points = array_of_words.map do |one_word|
final[one_word] = self.letter_by_letter(one_word)
end
return final

end

def self.score(word)
if word.length > 7
raise ArgumentError.new
end

word = word.upcase.split(//)
points = 0
word.each { |letter| points += SCORES[letter.to_sym] }

return points
end

def self.score_many(array_of_words)
all_scores = array_of_words.map { |one_word| self.score(one_word) }
all_scores.zip(array_of_words)
end

end
Binary file added public/.DS_Store
Binary file not shown.
Binary file added public/images/tile.jpg
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/tile.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/tile2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
251 changes: 251 additions & 0 deletions public/stylesheets/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
/************LAYOUT*****************/

* {
box-sizing: border-box;
}

html{
/*background-color: #D4FFEB;*/
}

body {
font-size: 16px;
font-family: helvetica;
background-image: repeating-linear-gradient( 45deg, #85D5E6 0px, #85D5E6 30px, #71C1D2 30px, #71C1D2 60px );
padding: 0;
margin: 0;
text-decoration-style: none;
}

header {
width: 100%;
padding: 0;
margin: 0;
overflow: auto;
position: relative;
float: none;
clear: both;
background-color: #2DA8AB;
height: 8vh;
}

nav ul {
list-style: none;
text-align: right;
padding: 0;
margin: 0;
overflow: auto;
padding-left: 10%;
padding-right: 10%;
}

nav li {
font-family: 'Oswald', sans-serif;
font-size: 1.2em;
display: inline-block;
width: 220px;
text-align: center;
height: 8vh;
padding-top: 1rem;
}

.logo {
font-family: 'Shadows Into Light', cursive;
font-size: 2rem;
color: #FFF;
float: left;
margin: 0;
height: 8vh;
}

nav a {
text-decoration: none;
color: #fff;
}

nav li:hover {
background-color: #2768B8;
}

nav a.active {
background-color: #fff;
color: #444;
cursor: default;
}

.score, .equal, h1, h3 {
font-family: 'Shadows Into Light', cursive;
text-align: center;
}

h1{
font-size: 2.5rem;
}

h3{
font-size: 1.5rem;
line-height: 1.3rem;
}

.mainmain {
width: 100%;
padding: 0;
padding-top: 2.5rem;
position: relative;
height: 86.5vh;
float: right;
overflow: auto;
}
/*********************END****************/

/*********************PAGE****************/
form {
text-align: center;
overflow: auto;
margin-bottom: 1.6rem;
line-height: 5rem;
}

label {
font-size: 36px;
font-family: 'Fjalla One', sans-serif;
}

input {
font-size: 36px;
}

.radio {
font-size: 1.5rem;
font-family: Arial;
background-color: #2768B8;
padding: 1rem;
border-radius: 5%;
margin-right: .5rem;
box-shadow: 4px 4px 4px gray;
color: white;
}

ul.mess {
margin-left: 10%;
padding-right: auto;
}

.cont {
text-align: center;
}

.mess > li {
display: inline-block;
overflow: auto;
width: 350px;
height: 583px;
position: relative;
background-color: white;
text-align: center;
box-shadow: 10px 10px 7px gray;
}

.line {
text-align: center;
display: inline-block;
margin: 0;
padding: 0;
width: 180px;
list-style: none;
border: gray;
}

.tile, .equal, .score {
float: left;
position: relative;
width: 58px;
height: 58px;
}

.tile {
padding: 1rem;
background-image: url("/images/tile.jpg");
border-radius: 25%;
background-repeat: no-repeat;
background-size: 100%;
font-size: 1.6rem;

}

.score, .equal {
font-size: 2rem;
}

input[type=submit] {
background-color: #B84393;
border-radius: 5px;
color:white;
cursor:pointer;
font-family: 'Oswald', sans-serif;
font-size: 16px;
margin-top: 5px;
margin-left: 10px;
padding:15px 25px 15px 25px;
}

.one-word {
background-color: white;
padding: 20px;
margin-left: 4%;
margin-right: 4%;
display: inline-block;
overflow: auto;
width: 350px;
height: 523px;
position: relative;
text-align: center;
box-shadow: 10px 10px 7px gray;
padding: 2rem;
}

.main-button {
display: inline-block;
margin-top: 12%;
margin-left: 9%;
width: 36%;
background-color: #B84393;
box-shadow: 5px 5px 5px gray;
}

.short {
color: white;
padding: 5%;
padding-right: 24%;
padding-left: 24%;

}

.long {
color: white;
padding: 5%;
padding-right: 18%;
padding-left: 18%;
}
/*********************END****************/


footer {
background-color: #2DA8AB;
width: 100%;
/*margin-bottom: 0;*/
/*bottom: 0;*/
height: 5.5vh;
position: relative;
float: right;
/*overflow: auto;*/
/*clear: both;*/
}

small {
height: 5.5vh;
color: white;
float: right;
padding-top: 1.5vh;
margin-right: 10%;
}
38 changes: 38 additions & 0 deletions scrabble_sin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'sinatra'
require_relative 'libs/scorecode'
require_relative 'libs/points'

class Scrabble < Sinatra::Base

get '/' do
erb :index
end

get '/score' do
erb :score
end

post '/score' do
if params["word"][/\d+/] == nil
@points = Scoring.score(params["word"])
@by_letter = Scoring.letter_by_letter(params["word"])
else
"nothing hapend"
end
erb :score
end

get '/score_many' do
erb :score_many
end

post '/score_many' do
@multiple_scores = Scoring.score_many(params["words"].split)
@score_weight = params["scoreweight"]
@by_letter_many = Scoring.letter_by_letter_many(params["words"].split)
erb :score_many
end

run!

end
Loading