From 61d4127a35de824da6a5d36aabd536e52fbd0700 Mon Sep 17 00:00:00 2001 From: Roel Cabrera Date: Fri, 21 Apr 2017 09:10:28 -0700 Subject: [PATCH] Add files via upload --- LICENSE.txt | 2 +- bossgle.js | 306 +++++++++++++++++++++++++-------------------------- index.html | 179 +++++++++++++++--------------- index.js | 9 ++ main.css | 137 +++++++++-------------- package.json | 19 ++++ 6 files changed, 315 insertions(+), 337 deletions(-) create mode 100644 index.js create mode 100644 package.json diff --git a/LICENSE.txt b/LICENSE.txt index ce5c81d..b22ea5e 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 JW +Copyright (c) 2017 Roel Cabrera Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/bossgle.js b/bossgle.js index b33bf48..124f75e 100644 --- a/bossgle.js +++ b/bossgle.js @@ -1,171 +1,161 @@ - -$(document).ready(function () { - - var lettersHTML = ''; - var totalScore = 0; - var totalWords = 0; - var wordHash = {}; - - // Set initial random letters. - randomLetters(); - - if (timer() === 0) { - console.log('Game Ended'); +var score = 0; +var letterContainer = []; +var letters = []; +var active_letters = []; +var word_list = []; +var word_count = []; +var count = 60; + +//random letter generator +function randomLetters() { + var num = Math.floor(Math.random() * 26); + var letter = String.fromCharCode(num + 65); + return letter; +} +//displays letters +function display_letters() { + $('#letter-container').html(active_letters.join('')); +} +// score updates +function update_score(add_me) { + var $score = $('#totalScore'); + $score.html(parseInt($score.html()) + add_me); +} +//correct word counter +function update_word_count() { + var $count = $('#wordCount'); + word_count.push($count); + $count.html(word_count.length); +} +// Reset Board +//function reset_game() { +// active_letters.length = 0; +// display_letters(); +// $('.flex-item.box').removeClass('box-disabled'); +//} +$(function () { + $('.flex-item.box').on('click', function (e) { + if ($(this).hasClass('box-disabled')) return; + //If the jquery wrapped object that this element + active_letters.push(this.innerHTML); + console.log(active_letters); + display_letters(); + $(this).addClass('box-disabled'); + }).each(function (i, item) { + var $this = $(item), + letter = randomLetters(); + //this function handles the initial setup. + while (letters.indexOf(letter) != -1) { + letter = randomLetters(); } - - // The 16 boxes are in the list section. - $('.aligner-item').click(function () { - - var idElement = document.getElementById(this.id); - - if (!idElement.disabled) { - var content = idElement.innerHTML; - - idElement.style.backgroundColor = 'red'; - - lettersHTML += content; - $('#letters').html(lettersHTML); - - // Disable clicked button. - idElement.disabled = true; - } - - }); - - // Clear the letter field. - $('#clear').on('click', function () { - resetBoxes(); - $('#letters').html('Selected Letters'); - lettersHTML = ''; - }); - - // Submit the letter field and add to word list. - $('#submit').on('click', function () { - if (lettersHTML.length > 0) { - if (!(lettersHTML in wordHash)) { - // document.getElementById('chosen-words').innerHTML += lettersHTML + '
'; - - // Check if word has at least three letters. - // If so update word score and total score. - var oneWordScore = 0; - if (lettersHTML.length > 2) { - oneWordScore = checkWord(lettersHTML); - totalScore += oneWordScore; - } - - document.getElementById('score-tally').innerHTML = totalScore; - - // Add key/value to word hash. - wordHash[lettersHTML] = oneWordScore; - - // Convert hash to 2 arrays. One for keys and the other for values. - var keys = Object.keys(wordHash); - var values = keys.map(function (v) { return wordHash[v]; }); - - // Clear words and scores before reversing them. - document.getElementById('chosen-words').innerHTML = ''; - document.getElementById('word-score').innerHTML = ''; - - // Reverse words and scores. - for (var i = keys.length - 1; i >= 0; i--) { - document.getElementById('chosen-words').innerHTML += keys[i] + '
'; - document.getElementById('word-score').innerHTML += values[i] + '
'; - } - - $('#letters').html('
'); - lettersHTML = ''; - - // Reset the box colors. - resetBoxes(); - } - } - - // Clear the log html string. Always at the end! - lettersHTML = ''; - }); - - // Reset board. - $('#reset').on('click', function () { - $('#word-score').html(''); - $('#chosen-words').html(''); - $('#letters').html('Selected Letters'); - $('#score-tally').html(''); - lettersHTML = ''; - totalScore = 0; - resetBoxes(); - randomLetters(); - wordHash = {}; - }); - + letters.push(letter); + $this.html(letter); }); +}); -function checkWord(word) { - - var wordScore = 0; - var wordCase; - - // The 1000 word dictionary is in lowere case except 'I'. - // Cover this condition. - if (word !== 'I') { - wordCase = word.toLowerCase(); - } else { - wordCase = word; - } - - if (isBasicWord(wordCase)) { - wordScore = 9 * (word.length); - } - - return wordScore; +for (var i = 0; i < $('.flex-item').length; i++) { + item = $('.flex-item')[i]; } -function randomLetters() { - - var num; - var char; - - for (var i = 1; i < 17; i++) { - // Random letter ascii code between 65 and 90 (A-Z). - // Max (excluded) = 91, Min (included) = 65. - num = Math.floor(Math.random() * (91 - 65)) + 65; +//clear and un disable the previously chosen letters +$(function () { + $('.btn-danger').on('click', function () { + active_letters.length = 0; + display_letters(); + console.log(active_letters); + $('.flex-item.box').removeClass('box-disabled'); + }); +}); + + +//the submit button does a whole lot of stuff. +//first it un disables all the disabled letter boxes +$(function () { + $('.btn-primary').on('click', function (e) { + var word = active_letters.join('').toLowerCase(); + console.log(word, isBasicWord(word)); + var wordUp = word.toUpperCase(); + var checkDouble = word_list.indexOf(wordUp) + $('.flex-item.box').removeClass('box-disabled'); + // then it checks if there is a word submitted + if (word <= 0) { + active_letters.length = []; + display_letters(); + //checks to see if the submitted word is listed already and if listed will receive no points + } else if (checkDouble >= 0) { + active_letters.length = []; + display_letters(); + word_list.unshift(wordUp); + var score = 0; + var new_items = $('
' + wordUp + '
' + score + '
'); + $('#current-words').prepend(new_items); + update_score(score); + // checks if the word is "I" because "I" is in the dictionary provided but not "i" + } else if (wordUp == "I") { + active_letters.length = []; + display_letters(); + word_list.unshift(wordUp); + var score = 9; + var new_items = $('
' + wordUp + '
' + score + '
'); + $('#current-words').prepend(new_items); + update_score(score); + update_word_count(); + // checks against extremely limited dictionary + } else if (isBasicWord(word)) { + active_letters.length = []; + display_letters(); + word_list.unshift(wordUp); + var score = 9 * word.length; + var new_items = $('
' + wordUp + '
' + score + '
'); + $('#current-words').prepend(new_items); + update_score(score); + update_word_count(); + // if it doesnt pass anything before this it isnt a word and needs to get out of my face + } else { + active_letters.length = []; + display_letters(); + word_list.unshift(wordUp); + var score = 0; + var new_items = $('
' + wordUp + '
' + score + '
'); + $('#current-words').prepend(new_items); + update_score(score); + } + }); +}); - // Convert ascii number to character. - char = String.fromCharCode(num); - // Change box to new character. - var boxID = 'box' + i; - document.getElementById(boxID).innerHTML = char; - var idElement = document.getElementById(boxID); - } +//update count down display +$("#counter").text(count); -} -// Reset the 16 boxes to original color. -// Enable the boxes. -function resetBoxes() { - for (var i = 1; i < 17; i++) { - var boxID = 'box' + i; - var idElement = document.getElementById(boxID); +timer = setTimeout(update, 1000); - // TODO: Color to global variable? - idElement.style.backgroundColor = '#69b390'; - idElement.disabled = false; +//timer function to disable all buttons except the reset game button +function update() { + if (count > 0) { + $("#counter").text(--count); + timer = setTimeout(update, 1000); + } else { + alert("Game Over Meow"); + active_letters.length = 0; + display_letters(); + $('.flex-item.box').addClass('box-disabled'); + $('#Button').prop('disabled', true); + $('#button').prop('disabled', true); } } -function timer() { - var timeInterval = 9; - setInterval(function () { - document.getElementById('timer').innerHTML = timeInterval; - if (timeInterval === 0) { - // alert('Time Ran Out!'); - return timeInterval; - } - - timeInterval--; - }, 1000); -} - -function logWords() { - -} +//function to reset game +$('.btn-warning').on('click', function () { + $('#Button').prop('disabled', false); + $('#button').prop('disabled', false); + score = 0; + letterContainer = []; + letters = []; + word_list = []; + word_count = []; + count = 60; + active_letters.length = 0; + display_letters(); + $('.flex-item.box').removeClass('box-disabled'); +}); diff --git a/index.html b/index.html index d32f68e..69819cc 100644 --- a/index.html +++ b/index.html @@ -1,115 +1,114 @@ + - Bossggle Word Game - - + + + - - - - - - - + + -
-
-
- - -
- -

Bossggle

-

Make words by clicking the letters!

-
    -
  • Only dictionary words count.
  • -
  • Each word must be a minimum of 3 letters.
  • -
  • You have 60 seconds.
  • -
- - -
- -
Score0
-
-
- -
Words
-
-
-
-
-
-
-
-
+
+
+
+
+

BOSSGLE!

+
+
Make words by clicking on the letters.
+
+
+

Words: 0

+
+
+

Score: 0

-
+
- -
- -
-

Selected Letters

- - -
-
- +
+
+
+ +

LETTERS

+
-
- - -
-
B1
-
B2
-
B3
-
B4
+
+
+
    +
  • m
  • +
  • e
  • +
  • o
  • +
  • w
  • +
+
+
+
    +
  • m
  • +
  • e
  • +
  • o
  • +
  • w
  • +
+
+
+
    +
  • m
  • +
  • e
  • +
  • o
  • +
  • w
  • +
+
+
+
    +
  • m
  • +
  • e
  • +
  • o
  • +
  • w
  • +
+
- - -
-
B1
-
B2
-
B3
-
B4
+
+

Time Left:

+
meow
+
+
+
+
+ - -
-
B1
-
B2
-
B3
-
B4
-
- -
-
B1
-
B2
-
B3
-
B4
-
- -
-

Time Left : 60

-
-
+ + + + + diff --git a/index.js b/index.js new file mode 100644 index 0000000..7de6c84 --- /dev/null +++ b/index.js @@ -0,0 +1,9 @@ +var http = require('http'); + +http.createServer(function(request, response){ + response.writeHead(200, {'Content-Type':'text/html'}); + response.end('

DICKS

'); + +}).listen(8081); + +console.log('Node server running'); diff --git a/main.css b/main.css index b1ff815..fc47684 100644 --- a/main.css +++ b/main.css @@ -1,115 +1,76 @@ -/*body { - background-color: #cdc5cc; - background-color: #eee4e5; -}*/ - -.score { - /*margin-left: 30%;*/ - width: 100%; - margin-top: 15%; - margin-bottom: 2%; - /*height: 650px;*/ - /*background: #eee4e5;*/ +html, +body { + height: 100%; } -hr { - display: block; - border: 0; - border-top: 1px solid black; - /*margin-right: 5%;*/ - padding: 0; +.main { + flex: 1 1 80%; + height: 100%; } -.aligner { +.flex-container { + object-position: center; + list-style: none; + width: 100%; display: flex; - align-items: center; - justify-content: center; + flex-flow: row nowrap; } -.aligner-item { - text-align: center; - padding-bottom: 3%; - padding-top: 3%; - width: 10%; +.flex-item { + background: grey; + padding: 5px; + width: 75px; + height: 75px; border-color: orange; - /*background-color:orange;*/ - background: #69b390; - border-width: 2px; + border-width: 3px; border-style: solid; - /*max-width: 20vh;*/ - margin-right: 2%; - margin-bottom: 2%; + margin: 10px; + line-height: 60px; + color: white; font-weight: bold; - font-size: 1.5em; -} - -.aligner-item--top { - align-self: flex-start; -} - -.aligner-item--bottom { - align-self: flex-end; -} - -.row { - height: 100%; - display: table-row; + font-size: 2em; + text-align: center; } -.row .no-float { - display: table-cell; - float: none; +.flex-center { + justify-content: center; } .button { display: inline-block; - color: white; - background-color: #302e2c; - border-radius: 0px; - border: 1px solid #e2855a; - padding: 10px 10px; + padding: 15px 25px; + font-size: 24px; + cursor: pointer; text-align: center; text-decoration: none; - font-size: 13px; - width: 8%; -} - -.btn-start { - color: white; - background-color: #532b6f; - text-align: right; + outline: none; + color: #fff; + border: none; + border-radius: 15px; + box-shadow: 0 9px #999; } -.btn-start:hover { - background-color: #2bb19e; +.button:active { + box-shadow: 0 5px #666; + transform: translateY(4px); } -.button:hover { - background-color: #f7bfa5; -} -.box:hover { - background-color: #f7bfa5; -} -.box::selection { - background-color: blue; } - .box:active { - background-color: yellow; -} - -.box:visited { - color: green; -} - -.score-right { - color: #b05c04; - float: right; + background-color: orange; + color: white; } - -.score-bg { - color: #b05c04; - /*background-color: #b05c04;*/ - text-align: center; +.box-disabled { + background-color: orange; + color: white; + border-style: solid; + border-width: 3px; + border-color: grey; + cursor: not-allowed; +} +.btn-disabled { + background-color: grey; + cursor: not-allowed; + color: black; } diff --git a/package.json b/package.json new file mode 100644 index 0000000..9bd7ac1 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "web-dev", + "version": "1.0.0", + "description": "something", + "main": "index.js", + "scripts": { + "test": "test" + }, + "keywords": [ + "test", + "bootcamp", + "go", + "go", + "power", + "rangers" + ], + "author": "roel cabrera", + "license": "MIT" +}