diff --git a/.idea/a2-shortstack.iml b/.idea/a2-shortstack.iml new file mode 100644 index 00000000..e9ef47f8 --- /dev/null +++ b/.idea/a2-shortstack.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..a55e7a17 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 00000000..d1d06d78 --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..8934f6cd --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..8a264877 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/images/BLACK.png b/public/images/BLACK.png new file mode 100644 index 00000000..2625e78f Binary files /dev/null and b/public/images/BLACK.png differ diff --git a/public/images/BLUE.png b/public/images/BLUE.png new file mode 100644 index 00000000..272eb444 Binary files /dev/null and b/public/images/BLUE.png differ diff --git a/public/images/BROWN.png b/public/images/BROWN.png new file mode 100644 index 00000000..6e853323 Binary files /dev/null and b/public/images/BROWN.png differ diff --git a/public/images/CYAN.png b/public/images/CYAN.png new file mode 100644 index 00000000..7bef13a8 Binary files /dev/null and b/public/images/CYAN.png differ diff --git a/public/images/GREEN.png b/public/images/GREEN.png new file mode 100644 index 00000000..a62fd9b7 Binary files /dev/null and b/public/images/GREEN.png differ diff --git a/public/images/LIME.png b/public/images/LIME.png new file mode 100644 index 00000000..3b49bcb5 Binary files /dev/null and b/public/images/LIME.png differ diff --git a/public/images/MIRAHQ_MAP.png b/public/images/MIRAHQ_MAP.png new file mode 100644 index 00000000..c06736cf Binary files /dev/null and b/public/images/MIRAHQ_MAP.png differ diff --git a/public/images/ORANGE.png b/public/images/ORANGE.png new file mode 100644 index 00000000..fc0050b0 Binary files /dev/null and b/public/images/ORANGE.png differ diff --git a/public/images/PINK.png b/public/images/PINK.png new file mode 100644 index 00000000..6942a80b Binary files /dev/null and b/public/images/PINK.png differ diff --git a/public/images/POLUS_MAP.png b/public/images/POLUS_MAP.png new file mode 100644 index 00000000..8d926f00 Binary files /dev/null and b/public/images/POLUS_MAP.png differ diff --git a/public/images/PURPLE.png b/public/images/PURPLE.png new file mode 100644 index 00000000..b03ebfb3 Binary files /dev/null and b/public/images/PURPLE.png differ diff --git a/public/images/RED.png b/public/images/RED.png new file mode 100644 index 00000000..d7722a06 Binary files /dev/null and b/public/images/RED.png differ diff --git a/public/images/SKELD_MAP.jpg b/public/images/SKELD_MAP.jpg new file mode 100644 index 00000000..42e0ef66 Binary files /dev/null and b/public/images/SKELD_MAP.jpg differ diff --git a/public/images/SKELD_MAP.png b/public/images/SKELD_MAP.png new file mode 100644 index 00000000..06562d87 Binary files /dev/null and b/public/images/SKELD_MAP.png differ diff --git a/public/images/TAN.png b/public/images/TAN.png new file mode 100644 index 00000000..94c4755e Binary files /dev/null and b/public/images/TAN.png differ diff --git a/public/images/WHITE.png b/public/images/WHITE.png new file mode 100644 index 00000000..4711c08c Binary files /dev/null and b/public/images/WHITE.png differ diff --git a/public/images/YELLOW.png b/public/images/YELLOW.png new file mode 100644 index 00000000..f3f19d16 Binary files /dev/null and b/public/images/YELLOW.png differ diff --git a/public/index.html b/public/index.html index c56d620e..b1800cef 100755 --- a/public/index.html +++ b/public/index.html @@ -1,41 +1,163 @@ - + + + + CS4241 Assignment 2 - - -
- - -
- - + + +
Among Us Companion
+
+

Select a Map

+
+ + + +
+

Enter Players

+
+ +
+ + + + + + + +
+ +
+ + + + + + +
+
+ +
+ +
+
+ + diff --git a/public/js/game.js b/public/js/game.js new file mode 100644 index 00000000..45740ba8 --- /dev/null +++ b/public/js/game.js @@ -0,0 +1,55 @@ +let notes = []; +$(function () { + $("textarea").on("blur", function () { + console.log($(this).val()); + notes = []; + $("textarea").each(function () { + notes.push($(this).val()) + }) + + fetch('/notes', { + method: 'POST', // or 'PUT' + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(notes), + }) + }) + $('body').on("keydown", function (e) { + if (e.repeat) { + return + } + if ($(e.target).is('textarea')) return; + if (e.keyCode == 32) { + fetch("/gamedata") + .then(response => response.json()) + .then(data => { + $("#overlay").html(` + + + + + + + + ${data.map(function (value) { + return ` + + + + ` + })} + }) +
Game Data
NameColorNotes
${value.name}${value.color}${value.notes}
`) + $("#overlay").show() + }) + } + + }); + $('body').on("keyup", function (e) { + if ($(e.target).is('textarea')) return; + if (e.keyCode == 32) { + $("#overlay").hide() + } + }); +}) \ No newline at end of file diff --git a/public/js/scripts.js b/public/js/scripts.js deleted file mode 100755 index de052eae..00000000 --- a/public/js/scripts.js +++ /dev/null @@ -1,3 +0,0 @@ -// Add some Javascript code here, to run on the front end. - -console.log("Welcome to assignment 2!") \ No newline at end of file diff --git a/server.improved.js b/server.improved.js index 26673fc0..9a6e4a1a 100644 --- a/server.improved.js +++ b/server.improved.js @@ -1,72 +1,146 @@ -const http = require( 'http' ), - fs = require( 'fs' ), - // IMPORTANT: you must run `npm install` in the directory for this assignment - // to install the mime library used in the following line of code - mime = require( 'mime' ), - dir = 'public/', - port = 3000 +const http = require('http'), + {parse} = require('querystring'), + fs = require('fs'), + // IMPORTANT: you must run `npm install` in the directory for this assignment + // to install the mime library used in the following line of code + mime = require('mime'), + dir = 'public/', + port = 3000 + +let playerInfo = []; +let map = ""; const appdata = [ - { 'model': 'toyota', 'year': 1999, 'mpg': 23 }, - { 'model': 'honda', 'year': 2004, 'mpg': 30 }, - { 'model': 'ford', 'year': 1987, 'mpg': 14} + {'model': 'toyota', 'year': 1999, 'mpg': 23}, + {'model': 'honda', 'year': 2004, 'mpg': 30}, + {'model': 'ford', 'year': 1987, 'mpg': 14} ] -const server = http.createServer( function( request,response ) { - if( request.method === 'GET' ) { - handleGet( request, response ) - }else if( request.method === 'POST' ){ - handlePost( request, response ) - } +const server = http.createServer(function (request, response) { + if (request.method === 'GET') { + handleGet(request, response) + } else if (request.method === 'POST') { + handlePost(request, response) + } }) -const handleGet = function( request, response ) { - const filename = dir + request.url.slice( 1 ) - - if( request.url === '/' ) { - sendFile( response, 'public/index.html' ) - }else{ - sendFile( response, filename ) - } +const handleGet = function (request, response) { + const filename = dir + request.url.slice(1) + + if (request.url === '/') { + sendFile(response, 'public/index.html') + playerInfo = [] + } else if (request.url === '/gamedata') { + response.writeHeader(200, {'Content-Type': 'application/json'}) + response.write(JSON.stringify(playerInfo)) + response.end() + } else { + sendFile(response, filename) + } } -const handlePost = function( request, response ) { - let dataString = '' - - request.on( 'data', function( data ) { - dataString += data - }) - - request.on( 'end', function() { - console.log( JSON.parse( dataString ) ) +const handlePost = function (request, response) { + if (request.url == '/notes') { + request.on('data', function (data) { + notes = JSON.parse(data) + notes.forEach(function (n, i) { + playerInfo[i].notes = n; + }) + }) + response.end() + } else if (request.url == '/startgame') { + let dataString = '' + + request.on('data', function (data) { + dataString += data + }) + + request.on('end', function () { + console.log(parse(dataString)) + let data = parse(dataString) + map = Object.keys(data)[0] + data = Object.values(data).slice(1) + console.log(data) + let names = data.slice(0, data.length / 2) + let colors = data.slice(data.length / 2) + names.forEach((key, i) => playerInfo[i] = { + "name": key, + "color": colors[i], + "notes": "" + }); + console.log(playerInfo) + response.write(buildGame()) + response.end() + }) + } +} - // ... do something with the data here!!! +const buildGame = function () { + return ` + + + + + + + + CS4241 Assignment 2 + + +
+ +
Among Us Companion
+
+
+ +
+
+ ${playerInfo.map(value => ` +
+ + + +
`).join("")} +
+
+
+ + + + ${playerInfo.map(value => ``).join("")} + + + ${playerInfo.map(value => ``).join("")} + +
Notes
${value.name}
+
+ + +` - response.writeHead( 200, "OK", {'Content-Type': 'text/plain' }) - response.end() - }) } -const sendFile = function( response, filename ) { - const type = mime.getType( filename ) +const sendFile = function (response, filename) { + const type = mime.getType(filename) - fs.readFile( filename, function( err, content ) { + fs.readFile(filename, function (err, content) { - // if the error = null, then we've loaded the file successfully - if( err === null ) { + // if the error = null, then we've loaded the file successfully + if (err === null) { - // status code: https://httpstatuses.com - response.writeHeader( 200, { 'Content-Type': type }) - response.end( content ) + // status code: https://httpstatuses.com + response.writeHeader(200, {'Content-Type': type}) + response.end(content) - }else{ + } else { - // file not found, error code 404 - response.writeHeader( 404 ) - response.end( '404 Error: File Not Found' ) + // file not found, error code 404 + response.writeHeader(404) + console.log(filename) + response.end('404 Error: File Not Found') - } - }) + } + }) } -server.listen( process.env.PORT || port ) +server.listen(process.env.PORT || port)