From b7f7c266196d61aedc024b076589c2703fb5cef3 Mon Sep 17 00:00:00 2001 From: h0vscat Date: Tue, 19 May 2020 12:52:05 -0400 Subject: [PATCH 01/21] Revert "Merge branch 'dev' of https://github.com/hatchways/team-goose into dev" This reverts commit efe12a7f0fab004bf89e978e84ae4c8ceafa041d, reversing changes made to e57edcc6cf521ee4db6df1711c9208f89d56190d. --- server/.env | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/.env b/server/.env index 6c32912..a41c9d3 100644 --- a/server/.env +++ b/server/.env @@ -1,4 +1,3 @@ -TEAM_MEMBERS="Aecio, Bonnie, Renyi, Manpreet" - -MONGOLAB_URI="mongodb+srv://username:@cluster0-ttytd.mongodb.net/test?retryWrites=true&w=majority" +TEAM_MEMBERS="Aecio, Bonnie, Renyi" +MONGOLAB_URI="mongodb+srv://username:@cluster0-ttytd.mongodb.net/test?retryWrites=true&w=majority" \ No newline at end of file From c076da84016c8fa2049233face03e6ed92dd123a Mon Sep 17 00:00:00 2001 From: h0vscat Date: Tue, 19 May 2020 12:55:39 -0400 Subject: [PATCH 02/21] Revert "Revert "Merge branch 'dev' of https://github.com/hatchways/team-goose into dev"" This reverts commit b7f7c266196d61aedc024b076589c2703fb5cef3. --- server/.env | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/.env b/server/.env index a41c9d3..6c32912 100644 --- a/server/.env +++ b/server/.env @@ -1,3 +1,4 @@ -TEAM_MEMBERS="Aecio, Bonnie, Renyi" +TEAM_MEMBERS="Aecio, Bonnie, Renyi, Manpreet" + +MONGOLAB_URI="mongodb+srv://username:@cluster0-ttytd.mongodb.net/test?retryWrites=true&w=majority" -MONGOLAB_URI="mongodb+srv://username:@cluster0-ttytd.mongodb.net/test?retryWrites=true&w=majority" \ No newline at end of file From f451fb34a140d022c46aea1bc91de8a972db09c7 Mon Sep 17 00:00:00 2001 From: h0vscat Date: Tue, 19 May 2020 12:55:47 -0400 Subject: [PATCH 03/21] Revert "Merge branch 'dev' of https://github.com/hatchways/team-goose into dev" This reverts commit efe12a7f0fab004bf89e978e84ae4c8ceafa041d, reversing changes made to e57edcc6cf521ee4db6df1711c9208f89d56190d. --- server/.env | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/.env b/server/.env index 6c32912..a41c9d3 100644 --- a/server/.env +++ b/server/.env @@ -1,4 +1,3 @@ -TEAM_MEMBERS="Aecio, Bonnie, Renyi, Manpreet" - -MONGOLAB_URI="mongodb+srv://username:@cluster0-ttytd.mongodb.net/test?retryWrites=true&w=majority" +TEAM_MEMBERS="Aecio, Bonnie, Renyi" +MONGOLAB_URI="mongodb+srv://username:@cluster0-ttytd.mongodb.net/test?retryWrites=true&w=majority" \ No newline at end of file From a230751aaa99337da5b654041667dd3d0641aabd Mon Sep 17 00:00:00 2001 From: h0vscat Date: Tue, 19 May 2020 13:23:48 -0400 Subject: [PATCH 04/21] Revert "set up database" This reverts commit e57edcc6cf521ee4db6df1711c9208f89d56190d. --- server/.env | 2 - server/app.js | 2 - server/db/mongoose.js | 5 - server/package-lock.json | 193 +++------------------------------------ server/package.json | 1 - 5 files changed, 11 insertions(+), 192 deletions(-) delete mode 100644 server/db/mongoose.js diff --git a/server/.env b/server/.env index a41c9d3..b0f0d24 100644 --- a/server/.env +++ b/server/.env @@ -1,3 +1 @@ TEAM_MEMBERS="Aecio, Bonnie, Renyi" - -MONGOLAB_URI="mongodb+srv://username:@cluster0-ttytd.mongodb.net/test?retryWrites=true&w=majority" \ No newline at end of file diff --git a/server/app.js b/server/app.js index e54fa48..a8dcc25 100644 --- a/server/app.js +++ b/server/app.js @@ -7,8 +7,6 @@ const logger = require("morgan"); const indexRouter = require("./routes/index"); const pingRouter = require("./routes/ping"); -const { mongoose } = require("./db/mongoose"); - const { json, urlencoded } = express; var app = express(); diff --git a/server/db/mongoose.js b/server/db/mongoose.js deleted file mode 100644 index c889b5d..0000000 --- a/server/db/mongoose.js +++ /dev/null @@ -1,5 +0,0 @@ - -const mongoose = require('mongoose'); -const url = process.env.MONGOLAB_URI; -mongoose.connect(url, { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true}); -module.exports = { mongoose } \ No newline at end of file diff --git a/server/package-lock.json b/server/package-lock.json index 98b44ac..a7e12a8 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -221,20 +221,6 @@ "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.13.1.tgz", "integrity": "sha512-Un7MIEDdUC5gNpcGDV97op1Ywk748MpHcFTHoYs6qnj1Z3j7I53VG3nwZhKzoBZmbdRNnb6WRdFlwl7tSDuZGw==" }, - "bl": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/bl/-/bl-2.2.0.tgz", - "integrity": "sha512-wbgvOpqopSr7uq6fJrLH8EsvYMJf9gzfo2jCsL2eTy75qXPukA4pCgHamOQkZtY5vmfVtjB+P3LNlMHW5CEZXA==", - "requires": { - "readable-stream": "^2.3.5", - "safe-buffer": "^5.1.1" - } - }, - "bluebird": { - "version": "3.5.1", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz", - "integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==" - }, "body-parser": { "version": "1.18.3", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz", @@ -308,11 +294,6 @@ "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", "dev": true }, - "bson": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.4.tgz", - "integrity": "sha512-S/yKGU1syOMzO86+dGpg2qGoDL0zvzcb262G+gqEy6TgP6rt6z6qxSFX/8X6vLC91P7G7C3nLs0+bvDzmvBA3Q==" - }, "bytes": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", @@ -663,11 +644,6 @@ "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", "dev": true }, - "denque": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/denque/-/denque-1.4.1.tgz", - "integrity": "sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ==" - }, "depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", @@ -1064,8 +1040,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -1083,13 +1058,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -1102,18 +1075,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -1216,8 +1186,7 @@ }, "inherits": { "version": "2.0.3", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -1227,7 +1196,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -1240,20 +1208,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.3.5", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -1270,7 +1235,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -1343,8 +1307,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -1354,7 +1317,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -1430,8 +1392,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -1461,7 +1422,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -1479,7 +1439,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -1518,13 +1477,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.0.3", - "bundled": true, - "optional": true + "bundled": true } } }, @@ -1986,11 +1943,6 @@ "esprima": "^4.0.0" } }, - "kareem": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.3.1.tgz", - "integrity": "sha512-l3hLhffs9zqoDe8zjmb/mAN4B8VT3L56EUvKNqLFVs9YlFA+zx7ke1DO8STAdDyYNkeSo1nKmjuvQeI12So8Xw==" - }, "kind-of": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", @@ -2098,12 +2050,6 @@ "p-is-promise": "^2.0.0" } }, - "memory-pager": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", - "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", - "optional": true - }, "merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", @@ -2264,49 +2210,6 @@ } } }, - "mongodb": { - "version": "3.5.7", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.5.7.tgz", - "integrity": "sha512-lMtleRT+vIgY/JhhTn1nyGwnSMmJkJELp+4ZbrjctrnBxuLbj6rmLuJFz8W2xUzUqWmqoyVxJLYuC58ZKpcTYQ==", - "requires": { - "bl": "^2.2.0", - "bson": "^1.1.4", - "denque": "^1.4.1", - "require_optional": "^1.0.1", - "safe-buffer": "^5.1.2", - "saslprep": "^1.0.0" - } - }, - "mongoose": { - "version": "5.9.14", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.9.14.tgz", - "integrity": "sha512-LScxCruQv0YpU/9DasKdThd+3r3PFQbCgesmfa6g0pTDOIiD1A9N9OQsGYrDf+dyUksfLCxJYYF9qpBHLvS1tg==", - "requires": { - "bson": "^1.1.4", - "kareem": "2.3.1", - "mongodb": "3.5.7", - "mongoose-legacy-pluralize": "1.0.2", - "mpath": "0.7.0", - "mquery": "3.2.2", - "ms": "2.1.2", - "regexp-clone": "1.0.0", - "safe-buffer": "5.1.2", - "sift": "7.0.1", - "sliced": "1.0.1" - }, - "dependencies": { - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" - } - } - }, - "mongoose-legacy-pluralize": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz", - "integrity": "sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ==" - }, "morgan": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz", @@ -2319,33 +2222,6 @@ "on-headers": "~1.0.1" } }, - "mpath": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.7.0.tgz", - "integrity": "sha512-Aiq04hILxhz1L+f7sjGyn7IxYzWm1zLNNXcfhDtx04kZ2Gk7uvFdgZ8ts1cWa/6d0TQmag2yR8zSGZUmp0tFNg==" - }, - "mquery": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/mquery/-/mquery-3.2.2.tgz", - "integrity": "sha512-XB52992COp0KP230I3qloVUbkLUxJIu328HBP2t2EsxSFtf4W1HPSOBWOXf1bqxK4Xbb66lfMJ+Bpfd9/yZE1Q==", - "requires": { - "bluebird": "3.5.1", - "debug": "3.1.0", - "regexp-clone": "^1.0.0", - "safe-buffer": "5.1.2", - "sliced": "1.0.1" - }, - "dependencies": { - "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "requires": { - "ms": "2.0.0" - } - } - } - }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -2812,11 +2688,6 @@ "safe-regex": "^1.1.0" } }, - "regexp-clone": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-1.0.0.tgz", - "integrity": "sha512-TuAasHQNamyyJ2hb97IuBEif4qBHGjPHBS64sZwytpLEqtBQ1gPJTnOaQ6qmpET16cK14kkjbazl6+p0RRv0yw==" - }, "registry-auth-token": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-3.4.0.tgz", @@ -2861,20 +2732,6 @@ "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", "dev": true }, - "require_optional": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/require_optional/-/require_optional-1.0.1.tgz", - "integrity": "sha512-qhM/y57enGWHAe3v/NcwML6a3/vfESLe/sGM2dII+gEO0BpKRUkWZow/tyloNqJyN6kXSl3RyyM8Ll5D/sJP8g==", - "requires": { - "resolve-from": "^2.0.0", - "semver": "^5.1.0" - } - }, - "resolve-from": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-2.0.0.tgz", - "integrity": "sha1-lICrIOlP+h2egKgEx+oUdhGWa1c=" - }, "resolve-url": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz", @@ -2903,15 +2760,6 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, - "saslprep": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz", - "integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==", - "optional": true, - "requires": { - "sparse-bitfield": "^3.0.3" - } - }, "semver": { "version": "5.7.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", @@ -3001,21 +2849,11 @@ "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-1.0.0.tgz", "integrity": "sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=" }, - "sift": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/sift/-/sift-7.0.1.tgz", - "integrity": "sha512-oqD7PMJ+uO6jV9EQCl0LrRw1OwsiPsiFQR5AR30heR+4Dl7jBBbDLnNvWiak20tzZlSE1H7RB30SX/1j/YYT7g==" - }, "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=" }, - "sliced": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz", - "integrity": "sha1-CzpmK10Ewxd7GSa+qCsD+Dei70E=" - }, "snapdragon": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz", @@ -3135,15 +2973,6 @@ "resolved": "https://registry.npmjs.org/source-map-url/-/source-map-url-0.4.0.tgz", "integrity": "sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM=" }, - "sparse-bitfield": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", - "integrity": "sha1-/0rm5oZWBWuks+eSqzM004JzyhE=", - "optional": true, - "requires": { - "memory-pager": "^1.0.2" - } - }, "split-string": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/split-string/-/split-string-3.1.0.tgz", diff --git a/server/package.json b/server/package.json index 8242af0..aa1220f 100644 --- a/server/package.json +++ b/server/package.json @@ -13,7 +13,6 @@ "dotenv": "^8.0.0", "express": "~4.16.1", "http-errors": "~1.6.3", - "mongoose": "^5.9.14", "morgan": "~1.9.1", "nodemon": "^1.19.1" }, From 7bab89977814bc33c31537d2bff912667b872718 Mon Sep 17 00:00:00 2001 From: h0vscat Date: Tue, 19 May 2020 21:16:24 -0400 Subject: [PATCH 05/21] correctly set up prettier --- server/db/mongoose.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/db/mongoose.js b/server/db/mongoose.js index 31d1e5c..45b15b6 100644 --- a/server/db/mongoose.js +++ b/server/db/mongoose.js @@ -1,5 +1,9 @@ -const mongoose = require('mongoose'); +const mongoose = require("mongoose"); const url = process.env.MONGOLAB_URI; -mongoose.connect(url, { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true}); -module.exports = { mongoose }; \ No newline at end of file +mongoose.connect(url, { + useNewUrlParser: true, + useCreateIndex: true, + useUnifiedTopology: true, +}); +module.exports = { mongoose }; From 58a2c563563989d4d09e6624204284e5ee6038cb Mon Sep 17 00:00:00 2001 From: h0vscat Date: Wed, 20 May 2020 10:31:01 -0400 Subject: [PATCH 06/21] create new board --- server/engine/Board.js | 51 ++ server/engine/Card.js | 13 + server/engine/MapCard.js | 19 + server/engine/WordRoles.js | 8 + server/engine/Words.js | 927 +++++++++++++++++++++++++++++++++++++ 5 files changed, 1018 insertions(+) create mode 100644 server/engine/Board.js create mode 100644 server/engine/Card.js create mode 100644 server/engine/MapCard.js create mode 100644 server/engine/WordRoles.js create mode 100644 server/engine/Words.js diff --git a/server/engine/Board.js b/server/engine/Board.js new file mode 100644 index 0000000..18b0f17 --- /dev/null +++ b/server/engine/Board.js @@ -0,0 +1,51 @@ +const Words = require("./Words"); +const Card = require("./Card"); +const MapCard = require("./MapCard"); + +class Board { + constructor() { + //new deck of words + this.deck = [...Words]; + this.shuffle(this.deck); + this.deckLength = this.deck.length; + this.mapCard = new MapCard(); + //drawed cards + this.cards = []; + } + + generateNewRound() { + let selectedWords = []; + if (this.deckLength > 25) { + selectedWords = this.deck.splice(0, 25); + this.updateDeckLength(); + } else { + this.deck = [...Words]; + this.shuffle(this.deck); + } + this.shuffle(this.mapCard); + this.cards = selectedWords.map( + (word, index) => new Card(word, this.mapCard.roles[index]) + ); + } + + updateDeckLength() { + this.deckLength = this.deck.length; + } + + getCards() { + return this.cards; + } + + shuffle(array) { + for (let i = array.length - 1; i > 0; i--) { + let j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]]; + } + } +} + +const newBoard = new Board(); +newBoard.generateNewRound(); +console.log(newBoard.deckLength); +console.log(newBoard.mapCard); +console.log(newBoard.cards); diff --git a/server/engine/Card.js b/server/engine/Card.js new file mode 100644 index 0000000..4be10a5 --- /dev/null +++ b/server/engine/Card.js @@ -0,0 +1,13 @@ +class Card { + constructor(word, role) { + this.word = word; + this.role = role; + this.selected = false; + } + + select() { + this.selected = true; + } +} + +module.exports = Card; diff --git a/server/engine/MapCard.js b/server/engine/MapCard.js new file mode 100644 index 0000000..19d8e45 --- /dev/null +++ b/server/engine/MapCard.js @@ -0,0 +1,19 @@ +const WordRoles = require("./WordRoles"); + +const blueAgents = new Array(9).fill(WordRoles.BLUE); +const redAgents = new Array(8).fill(WordRoles.RED); +const innocentBystanders = new Array(7).fill(WordRoles.WHITE); +const assassins = new Array(WordRoles.BLACK); + +class MapCard { + constructor() { + this.roles = new Array().concat( + blueAgents, + redAgents, + innocentBystanders, + assassins + ); + } +} + +module.exports = MapCard; diff --git a/server/engine/WordRoles.js b/server/engine/WordRoles.js new file mode 100644 index 0000000..c8e8def --- /dev/null +++ b/server/engine/WordRoles.js @@ -0,0 +1,8 @@ +const WordRoles = { + BLUE: "Blue Agent", + RED: "Red Agent", + WHITE: "Innocent Bystander", + BLACK: "Assassin", +}; + +module.exports = WordRoles; diff --git a/server/engine/Words.js b/server/engine/Words.js new file mode 100644 index 0000000..ff37d90 --- /dev/null +++ b/server/engine/Words.js @@ -0,0 +1,927 @@ +const Words = [ + "account", + "achiever", + "acoustics", + "act", + "action", + "activity", + "actor", + "addition", + "adjustment", + "advertisement", + "advice", + "aftermath", + "afternoon", + "afterthought", + "agreement", + "air", + "airplane", + "airport", + "alarm", + "amount", + "amusement", + "anger", + "angle", + "animal", + "answer", + "ant", + "apparatus", + "apparel", + "apple", + "appliance", + "approval", + "arch", + "argument", + "arithmetic", + "arm", + "army", + "art", + "attack", + "attempt", + "attention", + "attraction", + "aunt", + "authority", + "babies", + "baby", + "back", + "badge", + "bag", + "bait", + "balance", + "ball", + "balloon", + "banana", + "band", + "base", + "baseball", + "basin", + "basket", + "basketball", + "bat", + "bath", + "battle", + "bead", + "beam", + "bean", + "bear", + "bears", + "beast", + "bed", + "bedroom", + "bee", + "beef", + "beetle", + "beggar", + "beginner", + "behavior", + "belief", + "bell", + "berry", + "bike", + "bird", + "birth", + "birthday", + "bit", + "bite", + "blade", + "blood", + "blow", + "board", + "boat", + "boats", + "body", + "bomb", + "bone", + "book", + "boot", + "border", + "bottle", + "boundary", + "box", + "boy", + "brain", + "brake", + "branch", + "brass", + "bread", + "breakfast", + "breath", + "brick", + "bridge", + "brother", + "brush", + "bubble", + "bucket", + "building", + "bulb", + "bun", + "burn", + "burst", + "bushes", + "business", + "butter", + "button", + "cabbage", + "cable", + "cactus", + "cake", + "calculator", + "calendar", + "camera", + "camp", + "can", + "cannon", + "canvas", + "cap", + "caption", + "car", + "card", + "care", + "carpenter", + "carriage", + "cart", + "cast", + "cat", + "cattle", + "cause", + "cave", + "celery", + "cellar", + "cemetery", + "cent", + "chain", + "chair", + "chalk", + "chance", + "change", + "channel", + "cheese", + "cherry", + "chess", + "chicken", + "children", + "chin", + "church", + "circle", + "clam", + "class", + "clock", + "cloth", + "cloud", + "clover", + "club", + "coach", + "coal", + "coast", + "coat", + "cobweb", + "coil", + "collar", + "color", + "comb", + "comfort", + "committee", + "company", + "comparison", + "competition", + "condition", + "connection", + "control", + "cook", + "copper", + "copy", + "cord", + "cork", + "corn", + "cough", + "country", + "cover", + "cow", + "crack", + "cracker", + "crate", + "crayon", + "cream", + "creator", + "creature", + "credit", + "crib", + "crime", + "crook", + "crow", + "crowd", + "crown", + "crush", + "cry", + "cub", + "cup", + "current", + "curtain", + "curve", + "cushion", + "dad", + "daughter", + "day", + "death", + "debt", + "decision", + "deer", + "degree", + "design", + "desire", + "desk", + "destruction", + "detail", + "development", + "digestion", + "dime", + "dinner", + "dinosaurs", + "direction", + "dirt", + "discovery", + "discussion", + "disease", + "disgust", + "distance", + "distribution", + "division", + "dock", + "doctor", + "dog", + "doll", + "donkey", + "door", + "downtown", + "drain", + "drawer", + "dress", + "drink", + "driving", + "drop", + "drug", + "drum", + "duck", + "dust", + "ear", + "earth", + "earthquake", + "edge", + "education", + "effect", + "egg", + "eggnog", + "elbow", + "end", + "engine", + "error", + "event", + "example", + "exchange", + "existence", + "expansion", + "experience", + "expert", + "eye", + "face", + "fact", + "fairies", + "fall", + "family", + "fan", + "fang", + "farm", + "farmer", + "father", + "faucet", + "fear", + "feast", + "feather", + "feeling", + "feet", + "fiction", + "field", + "fifth", + "fight", + "finger", + "fire", + "fireman", + "fish", + "flag", + "flame", + "flavor", + "flesh", + "flight", + "flock", + "floor", + "flower", + "fly", + "fog", + "fold", + "food", + "foot", + "force", + "fork", + "form", + "fowl", + "frame", + "friction", + "friend", + "frog", + "front", + "fruit", + "fuel", + "furniture", + "alley", + "game", + "garden", + "gate", + "geese", + "ghost", + "giants", + "giraffe", + "girl", + "glass", + "glove", + "glue", + "goat", + "gold", + "goldfish", + "good-bye", + "goose", + "government", + "governor", + "grade", + "grain", + "grandfather", + "grandmother", + "grape", + "grass", + "grip", + "ground", + "group", + "growth", + "guide", + "guitar", + "gun", + "hair", + "haircut", + "hall", + "hammer", + "hand", + "harbor", + "harmony", + "hat", + "hate", + "head", + "health", + "hearing", + "heart", + "heat", + "help", + "hen", + "hill", + "history", + "hobbies", + "hole", + "holiday", + "home", + "honey", + "hook", + "hope", + "horn", + "horse", + "hose", + "hospital", + "hot", + "hour", + "house", + "humor", + "hydrant", + "ice", + "icicle", + "idea", + "impulse", + "income", + "increase", + "industry", + "ink", + "insect", + "instrument", + "insurance", + "interest", + "invention", + "iron", + "island", + "jail", + "jam", + "jar", + "jeans", + "jelly", + "jellyfish", + "jewel", + "join", + "joke", + "journey", + "judge", + "juice", + "jump", + "kettle", + "key", + "kick", + "kiss", + "kite", + "kitten", + "knee", + "knife", + "knot", + "knowledge", + "laborer", + "lace", + "ladybug", + "lake", + "lamp", + "land", + "language", + "laugh", + "lawyer", + "lead", + "leaf", + "learning", + "leather", + "leg", + "letter", + "lettuce", + "level", + "library", + "lift", + "light", + "limit", + "line", + "linen", + "lip", + "liquid", + "list", + "lizard", + "loaf", + "lock", + "locket", + "look", + "loss", + "love", + "low", + "lumber", + "lunch", + "lunchroom", + "machine", + "magic", + "maid", + "mailbox", + "man", + "manager", + "map", + "marble", + "mark", + "market", + "mask", + "mass", + "match", + "meal", + "measure", + "meat", + "meeting", + "memory", + "men", + "metal", + "mice", + "middle", + "milk", + "mind", + "mine", + "minister", + "mint", + "minute", + "mist", + "mitten", + "mom", + "money", + "monkey", + "month", + "moon", + "morning", + "mother", + "motion", + "mountain", + "mouth", + "move", + "muscle", + "music", + "nail", + "name", + "nation", + "neck", + "need", + "needle", + "nerve", + "nest", + "net", + "news", + "night", + "noise", + "north", + "nose", + "note", + "notebook", + "number", + "nut", + "oatmeal", + "observation", + "ocean", + "offer", + "office", + "oil", + "operation", + "opinion", + "orange", + "order", + "organization", + "ornament", + "oven", + "owl", + "owner", + "page", + "pail", + "pain", + "paint", + "pan", + "pancake", + "paper", + "parcel", + "parent", + "park", + "part", + "partner", + "party", + "passenger", + "paste", + "patch", + "payment", + "peace", + "pear", + "pen", + "pencil", + "person", + "pest", + "pet", + "pickle", + "picture", + "pie", + "pig", + "pin", + "pipe", + "pizzas", + "place", + "plane", + "plant", + "plantation", + "plastic", + "plate", + "play", + "playground", + "pleasure", + "plot", + "plough", + "pocket", + "point", + "poison", + "police", + "polish", + "pollution", + "popcorn", + "porter", + "position", + "pot", + "potato", + "powder", + "power", + "price", + "print", + "prison", + "process", + "produce", + "profit", + "property", + "prose", + "protest", + "pull", + "pump", + "punishment", + "purpose", + "push", + "quarter", + "quartz", + "queen", + "question", + "quicksand", + "quiet", + "quill", + "quilt", + "quince", + "quiver", + "rabbit", + "rail", + "railway", + "rain", + "rainstorm", + "rake", + "range", + "rat", + "rate", + "ray", + "reaction", + "reading", + "reason", + "receipt", + "recess", + "record", + "regret", + "relation", + "religion", + "representative", + "request", + "respect", + "rest", + "reward", + "rhythm", + "rice", + "riddle", + "rifle", + "ring", + "river", + "road", + "robin", + "rock", + "rod", + "roll", + "roof", + "room", + "root", + "rose", + "route", + "rub", + "rule", + "run", + "sack", + "sail", + "salt", + "sand", + "scale", + "scarecrow", + "scarf", + "scene", + "scent", + "school", + "science", + "scissors", + "screw", + "sea", + "seashore", + "seat", + "secretary", + "seed", + "selection", + "self", + "sense", + "servant", + "shade", + "shake", + "shame", + "shape", + "sheep", + "sheet", + "shelf", + "ship", + "shirt", + "shock", + "shoe", + "shop", + "show", + "side", + "sidewalk", + "sign", + "silk", + "silver", + "sink", + "sister", + "size", + "skate", + "skin", + "skirt", + "sky", + "slave", + "sleep", + "sleet", + "slip", + "slope", + "smash", + "smell", + "smile", + "smoke", + "snail", + "snake", + "sneeze", + "snow", + "soap", + "society", + "sock", + "soda", + "sofa", + "son", + "song", + "sort", + "sound", + "soup", + "space", + "spade", + "spark", + "spiders", + "sponge", + "spoon", + "spot", + "spring", + "spy", + "square", + "squirrel", + "stage", + "stamp", + "star", + "start", + "statement", + "station", + "steam", + "steel", + "stem", + "step", + "stew", + "stick", + "stitch", + "stocking", + "stomach", + "stone", + "stop", + "store", + "story", + "stove", + "stranger", + "straw", + "stream", + "street", + "stretch", + "string", + "structure", + "substance", + "sugar", + "suggestion", + "suit", + "summer", + "sun", + "support", + "surprise", + "sweater", + "swim", + "swing", + "system", + "table", + "tail", + "talk", + "tank", + "taste", + "tax", + "teaching", + "team", + "teeth", + "temper", + "tendency", + "tent", + "territory", + "test", + "texture", + "theory", + "thing", + "thought", + "thread", + "thrill", + "throat", + "throne", + "thumb", + "thunder", + "ticket", + "tiger", + "time", + "tin", + "title", + "toad", + "toe", + "tomatoes", + "tongue", + "tooth", + "toothbrush", + "toothpaste", + "top", + "touch", + "town", + "toy", + "toys", + "trade", + "trail", + "train", + "trains", + "tramp", + "transport", + "tray", + "treatment", + "tree", + "trick", + "trip", + "trouble", + "trousers", + "truck", + "tub", + "turkey", + "turn", + "twig", + "twist", + "umbrella", + "uncle", + "underwear", + "unit", + "use", + "vacation", + "value", + "van", + "vase", + "vegetable", + "veil", + "vein", + "verse", + "vessel", + "vest", + "view", + "visitor", + "voice", + "volcano", + "volleyball", + "voyage", + "walk", + "wall", + "war", + "wash", + "waste", + "watch", + "water", + "wave", + "wax", + "way", + "wealth", + "weather", + "week", + "weight", + "wheel", + "whip", + "whistle", + "wilderness", + "wind", + "window", + "wine", + "wing", + "winter", + "wire", + "wish", + "woman", + "women", + "wood", + "wool", + "word", + "work", + "worm", + "wound", + "wren", + "wrench", + "wrist", + "writer", + "writing", + "yak", + "yam", + "yard", + "yarn", + "year", + "yoke", + "zebra", + "zephyr", + "zinc", + "zipper", + "zoo", +]; + +module.exports = Words; \ No newline at end of file From c13bbb81a624a107418f6bde6bc8c6ecd405f638 Mon Sep 17 00:00:00 2001 From: h0vscat Date: Wed, 20 May 2020 10:36:58 -0400 Subject: [PATCH 07/21] add select functionality to card --- server/engine/Card.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/engine/Card.js b/server/engine/Card.js index 4be10a5..039f895 100644 --- a/server/engine/Card.js +++ b/server/engine/Card.js @@ -6,7 +6,11 @@ class Card { } select() { - this.selected = true; + if (this.selected) { + return false; + } else { + this.selected = true; + } } } From 4e42c6e6d8a1afde78b8678b4799cd0f422ac25f Mon Sep 17 00:00:00 2001 From: h0vscat Date: Wed, 20 May 2020 10:44:19 -0400 Subject: [PATCH 08/21] remove test code for pull request --- server/engine/Board.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/server/engine/Board.js b/server/engine/Board.js index 18b0f17..e677e12 100644 --- a/server/engine/Board.js +++ b/server/engine/Board.js @@ -43,9 +43,3 @@ class Board { } } } - -const newBoard = new Board(); -newBoard.generateNewRound(); -console.log(newBoard.deckLength); -console.log(newBoard.mapCard); -console.log(newBoard.cards); From 23451cd515cc0ffc4612e7e97966b72889aacbd4 Mon Sep 17 00:00:00 2001 From: Tony Chen Date: Thu, 21 May 2020 00:42:28 -0700 Subject: [PATCH 09/21] Rough draft of Game Lobby UI for assign roles to players. Added Material icons module. --- client/package-lock.json | 8 ++ client/package.json | 1 + client/src/App.js | 2 + client/src/pages/common/common.css | 8 ++ client/src/pages/game_lobby/GameLobby.css | 0 client/src/pages/game_lobby/GameLobby.js | 58 +++++++++++++++ client/src/pages/game_lobby/TeamSelect.css | 11 +++ client/src/pages/game_lobby/TeamSelect.js | 86 ++++++++++++++++++++++ 8 files changed, 174 insertions(+) create mode 100644 client/src/pages/game_lobby/GameLobby.css create mode 100644 client/src/pages/game_lobby/GameLobby.js create mode 100644 client/src/pages/game_lobby/TeamSelect.css create mode 100644 client/src/pages/game_lobby/TeamSelect.js diff --git a/client/package-lock.json b/client/package-lock.json index 3a30b62..9df58ff 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -1221,6 +1221,14 @@ } } }, + "@material-ui/icons": { + "version": "4.9.1", + "resolved": "https://registry.npmjs.org/@material-ui/icons/-/icons-4.9.1.tgz", + "integrity": "sha512-GBitL3oBWO0hzBhvA9KxqcowRUsA0qzwKkURyC8nppnC3fw54KPKZ+d4V1Eeg/UnDRSzDaI9nGCdel/eh9AQMg==", + "requires": { + "@babel/runtime": "^7.4.4" + } + }, "@material-ui/styles": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/@material-ui/styles/-/styles-4.1.2.tgz", diff --git a/client/package.json b/client/package.json index 45c0f2c..a700a17 100644 --- a/client/package.json +++ b/client/package.json @@ -4,6 +4,7 @@ "private": true, "dependencies": { "@material-ui/core": "^4.1.3", + "@material-ui/icons": "^4.9.1", "react": "^16.8.6", "react-dom": "^16.8.6", "react-router-dom": "^5.0.1", diff --git a/client/src/App.js b/client/src/App.js index 9afb2a6..ad25c68 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -5,6 +5,7 @@ import { BrowserRouter, Route } from "react-router-dom"; import { theme } from "./themes/theme"; import LandingPage from "./pages/Landing"; import CreateGame from "./pages/create_game/CreateGame"; +import GameLobby from "./pages/game_lobby/GameLobby"; import "./App.css"; @@ -14,6 +15,7 @@ function App() { + ); diff --git a/client/src/pages/common/common.css b/client/src/pages/common/common.css index a5f4f67..bd52d21 100644 --- a/client/src/pages/common/common.css +++ b/client/src/pages/common/common.css @@ -11,3 +11,11 @@ width: 75px; background-color: limegreen; } + +.grid-content { + padding: 25px; +} + +.label { + padding-right: 8px; +} diff --git a/client/src/pages/game_lobby/GameLobby.css b/client/src/pages/game_lobby/GameLobby.css new file mode 100644 index 0000000..e69de29 diff --git a/client/src/pages/game_lobby/GameLobby.js b/client/src/pages/game_lobby/GameLobby.js new file mode 100644 index 0000000..28f80c8 --- /dev/null +++ b/client/src/pages/game_lobby/GameLobby.js @@ -0,0 +1,58 @@ +import React from "react"; +import Button from "@material-ui/core/Button"; +import Container from "@material-ui/core/Container"; +import Grid from "@material-ui/core/Grid"; +import Typography from "@material-ui/core/Typography"; + +import Header from "../common/Header"; +import TeamSelect from "./TeamSelect"; +import "../common/common.css"; +import "./GameLobby.css"; + +function GameLobby() { + return ( + + + +
+ + + + + + + + + + + + + Share Game ID: + + + + + + + + + + + ); +} + +export default GameLobby; diff --git a/client/src/pages/game_lobby/TeamSelect.css b/client/src/pages/game_lobby/TeamSelect.css new file mode 100644 index 0000000..1094221 --- /dev/null +++ b/client/src/pages/game_lobby/TeamSelect.css @@ -0,0 +1,11 @@ +.team { + padding: 25px; +} + +#red-team { + color: red; +} + +#blue-team { + color: blue; +} diff --git a/client/src/pages/game_lobby/TeamSelect.js b/client/src/pages/game_lobby/TeamSelect.js new file mode 100644 index 0000000..ef3e23c --- /dev/null +++ b/client/src/pages/game_lobby/TeamSelect.js @@ -0,0 +1,86 @@ +import React from "react"; +import AddCircle from "@material-ui/icons/AddCircle"; +import Grid from "@material-ui/core/Grid"; +import IconButton from "@material-ui/core/IconButton"; +import List from "@material-ui/core/List"; +import ListItem from "@material-ui/core/ListItem"; +import ListItemText from "@material-ui/core/ListItemText"; +import ListItemSecondaryAction from "@material-ui/core/ListItemSecondaryAction"; +import RemoveCircle from "@material-ui/icons/RemoveCircle"; +import Typography from "@material-ui/core/Typography"; + +import "./TeamSelect.css"; + +function TeamSelect() { + return ( + + + + + + Red Team + + + + + + Bonnie + + + Renyi + + + Manpreet + + + Tony (You) + + + + + + + + + + + + + + + Blue Team + + + + + + Sina + + + Jaclyn + + + (Empty) + + + + + + + + (Empty) + + + + + + + + + + + + ); +} + +export default TeamSelect; From c69646859cd362f19358f6c399dbb34a62465679 Mon Sep 17 00:00:00 2001 From: h0vscat Date: Thu, 21 May 2020 09:25:28 -0400 Subject: [PATCH 10/21] fix random assign number of agents --- server/engine/Board.js | 48 ++++++++++++++++++++++++++++--------- server/engine/Game.js | 0 server/engine/MapCard.js | 19 --------------- server/engine/getMapCard.js | 31 ++++++++++++++++++++++++ server/engine/shuffle.js | 8 +++++++ 5 files changed, 76 insertions(+), 30 deletions(-) create mode 100644 server/engine/Game.js delete mode 100644 server/engine/MapCard.js create mode 100644 server/engine/getMapCard.js create mode 100644 server/engine/shuffle.js diff --git a/server/engine/Board.js b/server/engine/Board.js index e677e12..eb04178 100644 --- a/server/engine/Board.js +++ b/server/engine/Board.js @@ -1,30 +1,37 @@ const Words = require("./Words"); const Card = require("./Card"); -const MapCard = require("./MapCard"); +const getMapCard = require("./getMapCard"); +const shuffle = require("./shuffle"); class Board { constructor() { //new deck of words this.deck = [...Words]; - this.shuffle(this.deck); + shuffle(this.deck); this.deckLength = this.deck.length; - this.mapCard = new MapCard(); + this.mapCard = []; //drawed cards this.cards = []; + + this.redAgentNum = 0; + this.blueAgentNum = 0; + + this.decideAgentNum(); + this.generateNewRound(); } generateNewRound() { let selectedWords = []; - if (this.deckLength > 25) { + const numRemainCards = 25; + if (this.deckLength > numRemainCards) { selectedWords = this.deck.splice(0, 25); this.updateDeckLength(); } else { this.deck = [...Words]; - this.shuffle(this.deck); + shuffle(this.deck); } - this.shuffle(this.mapCard); this.cards = selectedWords.map( - (word, index) => new Card(word, this.mapCard.roles[index]) + (word, index) => new Card(word, this.mapCard[index]) ); } @@ -36,10 +43,29 @@ class Board { return this.cards; } - shuffle(array) { - for (let i = array.length - 1; i > 0; i--) { - let j = Math.floor(Math.random() * (i + 1)); - [array[i], array[j]] = [array[j], array[i]]; + decideAgentNum() { + const decision = Math.round(Math.random()); + if (decision === 0) { + this.blueAgentNum = 9; + this.redAgentNum = 8; + } else { + this.blueAgentNum = 8; + this.redAgentNum = 9; } + this.mapCard = getMapCard(decision); } } + + +const newBoard = new Board(); +console.log(newBoard.deckLength, "deck"); +console.log(newBoard.mapCard); +console.log(newBoard.cards); +console.log(newBoard.redAgentNum); +console.log(newBoard.blueAgentNum); +newBoard.generateNewRound(); +console.log(newBoard.deckLength, "deck"); +console.log(newBoard.mapCard); +console.log(newBoard.cards); +console.log(newBoard.redAgentNum); +console.log(newBoard.blueAgentNum); \ No newline at end of file diff --git a/server/engine/Game.js b/server/engine/Game.js new file mode 100644 index 0000000..e69de29 diff --git a/server/engine/MapCard.js b/server/engine/MapCard.js deleted file mode 100644 index 19d8e45..0000000 --- a/server/engine/MapCard.js +++ /dev/null @@ -1,19 +0,0 @@ -const WordRoles = require("./WordRoles"); - -const blueAgents = new Array(9).fill(WordRoles.BLUE); -const redAgents = new Array(8).fill(WordRoles.RED); -const innocentBystanders = new Array(7).fill(WordRoles.WHITE); -const assassins = new Array(WordRoles.BLACK); - -class MapCard { - constructor() { - this.roles = new Array().concat( - blueAgents, - redAgents, - innocentBystanders, - assassins - ); - } -} - -module.exports = MapCard; diff --git a/server/engine/getMapCard.js b/server/engine/getMapCard.js new file mode 100644 index 0000000..23309f0 --- /dev/null +++ b/server/engine/getMapCard.js @@ -0,0 +1,31 @@ +const WordRoles = require("./WordRoles"); +const shuffle = require("./shuffle"); + +const blueAgents0 = new Array(9).fill(WordRoles.BLUE); +const redAgents0 = new Array(8).fill(WordRoles.RED); +const blueAgents1 = new Array(8).fill(WordRoles.BLUE); +const redAgents1 = new Array(9).fill(WordRoles.RED); +const innocentBystanders = new Array(7).fill(WordRoles.WHITE); +const assassins = new Array(WordRoles.BLACK); +const deck0 = new Array().concat( + blueAgents0, + redAgents0, + innocentBystanders, + assassins +); +const deck1 = new Array().concat( + blueAgents1, + redAgents1, + innocentBystanders, + assassins +); + +const getMapCard = (binaryNum) => { + if (binaryNum === 0) { + return shuffle(deck0); + } else { + return shuffle(deck1); + } +}; + +module.exports = getMapCard; diff --git a/server/engine/shuffle.js b/server/engine/shuffle.js new file mode 100644 index 0000000..e01c081 --- /dev/null +++ b/server/engine/shuffle.js @@ -0,0 +1,8 @@ +const shuffle = (array) => { + for (let i = array.length - 1; i > 0; i--) { + let j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]]; + } + return array; +} +module.exports = shuffle; From 5456b2e8546101f762cf50a48ba7a69b8ffa3583 Mon Sep 17 00:00:00 2001 From: Tony Chen Date: Thu, 21 May 2020 09:51:29 -0700 Subject: [PATCH 11/21] Revised text for player name with no players assigned to a role on a team in lobby. --- client/src/pages/game_lobby/TeamSelect.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client/src/pages/game_lobby/TeamSelect.js b/client/src/pages/game_lobby/TeamSelect.js index ef3e23c..144f521 100644 --- a/client/src/pages/game_lobby/TeamSelect.js +++ b/client/src/pages/game_lobby/TeamSelect.js @@ -60,7 +60,9 @@ function TeamSelect() { Jaclyn - (Empty) + + (Empty slot) + @@ -68,7 +70,9 @@ function TeamSelect() { - (Empty) + + (Empty slot) + From 24a0820b18e8c699c6025a6014569e362c7db244 Mon Sep 17 00:00:00 2001 From: Tony Chen Date: Thu, 21 May 2020 10:06:09 -0700 Subject: [PATCH 12/21] Merged latest changes to create-ui-new-game_tony_13 branch --- client/src/pages/common/common.css | 4 -- client/src/pages/create_game/CreateGame.js | 80 +++++++++++----------- 2 files changed, 39 insertions(+), 45 deletions(-) diff --git a/client/src/pages/common/common.css b/client/src/pages/common/common.css index bd52d21..6a6e25c 100644 --- a/client/src/pages/common/common.css +++ b/client/src/pages/common/common.css @@ -1,7 +1,3 @@ -.header { - justify-content: center; -} - .header .title { padding: 15px; } diff --git a/client/src/pages/create_game/CreateGame.js b/client/src/pages/create_game/CreateGame.js index 7856ef7..496098b 100644 --- a/client/src/pages/create_game/CreateGame.js +++ b/client/src/pages/create_game/CreateGame.js @@ -10,51 +10,49 @@ import "./CreateGame.css"; function CreateGame() { return ( - <> - - - -
- - - - - - - - - - Join a Game: - - - - - - - - - - + + + +
+ + + + + + + + + + Join a Game: + + + + + + + + + - - - - - - - New Game: - - - - - + + + + + + + + New Game: + + + + @@ -62,8 +60,8 @@ function CreateGame() { - - + + ); } From 66ad39930305aaee2788a19c439e757da337afdf Mon Sep 17 00:00:00 2001 From: Tony Chen Date: Thu, 21 May 2020 22:56:25 -0700 Subject: [PATCH 13/21] Implemented client logic for handling the selecting of a player's team in a game lobby and sharing game ID. Some dummy data are currently present as placeholders until full integration with backend. --- client/src/pages/game_lobby/GameLobby.js | 56 ++++++++- client/src/pages/game_lobby/TeamPresets.js | 11 ++ client/src/pages/game_lobby/TeamSelect.js | 136 +++++++++++++-------- 3 files changed, 150 insertions(+), 53 deletions(-) create mode 100644 client/src/pages/game_lobby/TeamPresets.js diff --git a/client/src/pages/game_lobby/GameLobby.js b/client/src/pages/game_lobby/GameLobby.js index 28f80c8..e6660c4 100644 --- a/client/src/pages/game_lobby/GameLobby.js +++ b/client/src/pages/game_lobby/GameLobby.js @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState } from "react"; import Button from "@material-ui/core/Button"; import Container from "@material-ui/core/Container"; import Grid from "@material-ui/core/Grid"; @@ -10,6 +10,43 @@ import "../common/common.css"; import "./GameLobby.css"; function GameLobby() { + const currentUser = { sessionID: 1, firstName: "Tony" }; // dummy data of current user. sessionID will be generated from web socket in backend + const [gameID] = useState("ABCD"); // dummy game ID + const [canStartGame, setCanStartGame] = useState(false); + + const isTeamReady = (team) => { + const SPYERMASTER_INDEX = 0; + const FIELD_AGENT_INDEX = 1; + const spymaser = team[SPYERMASTER_INDEX]; + const fieldAgents = team.slice(FIELD_AGENT_INDEX); + + return spymaser.player && fieldAgents.some((agent) => agent.player); + }; + + const copyGameIDToClipboard = () => { + // source: https://stackoverflow.com/questions/33855641/copy-output-of-a-javascript-variable-to-the-clipboard + let dummy = document.createElement("textarea"); + document.body.appendChild(dummy); + dummy.value = gameID; + dummy.select(); + document.execCommand("copy"); + document.body.removeChild(dummy); + }; + + const onTeamSelect = (redTeam, blueTeam) => { + const isRedTeamReady = isTeamReady(redTeam); + const isBlueTeamReady = isTeamReady(blueTeam); + + setCanStartGame(isRedTeamReady && isBlueTeamReady); + }; + + const startGame = () => { + if (canStartGame) { + // send list of players of each team to server and transition to game board + console.log("Game is starting..."); + } + }; + return ( @@ -24,10 +61,15 @@ function GameLobby() { alignItems="center" > - + - @@ -42,7 +84,13 @@ function GameLobby() { Share Game ID: - diff --git a/client/src/pages/game_lobby/TeamPresets.js b/client/src/pages/game_lobby/TeamPresets.js new file mode 100644 index 0000000..fdb44f9 --- /dev/null +++ b/client/src/pages/game_lobby/TeamPresets.js @@ -0,0 +1,11 @@ +export const TEAM_CODE = { + RED: "RED", + BLUE: "BLUE", +}; + +export const DEFAULT_TEAM_STATE = [ + { role: "Spymaster", player: null }, + { role: "Field Agent", player: null }, + { role: "Field Agent", player: null }, + { role: "Field Agent", player: null }, +]; diff --git a/client/src/pages/game_lobby/TeamSelect.js b/client/src/pages/game_lobby/TeamSelect.js index 144f521..3663f04 100644 --- a/client/src/pages/game_lobby/TeamSelect.js +++ b/client/src/pages/game_lobby/TeamSelect.js @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState, useEffect } from "react"; import AddCircle from "@material-ui/icons/AddCircle"; import Grid from "@material-ui/core/Grid"; import IconButton from "@material-ui/core/IconButton"; @@ -9,9 +9,92 @@ import ListItemSecondaryAction from "@material-ui/core/ListItemSecondaryAction"; import RemoveCircle from "@material-ui/icons/RemoveCircle"; import Typography from "@material-ui/core/Typography"; +import { TEAM_CODE, DEFAULT_TEAM_STATE } from "./TeamPresets"; import "./TeamSelect.css"; -function TeamSelect() { +const DEFAULT_RED_TEAM_STATE = JSON.parse(JSON.stringify(DEFAULT_TEAM_STATE)); +const DEFAULT_BLUE_TEAM_STATE = JSON.parse(JSON.stringify(DEFAULT_TEAM_STATE)); + +const UNOCCUPIED_SPOT_NAME = "--"; + +function TeamSelect(props) { + const [redTeam, setRedTeam] = useState(DEFAULT_RED_TEAM_STATE); + const [blueTeam, setBlueTeam] = useState(DEFAULT_BLUE_TEAM_STATE); + const [isRoleAssigned, setIsRoleAssigned] = useState(false); + + useEffect(() => { + props.onChange(redTeam, blueTeam); + }); + + const changeRole = (teamCode, index) => { + const getNewTeam = (team) => { + const spot = team[index]; + const player = props.currentUser; + let result = [...team]; + + // join a role only if spot is unoccupied by another player + if (!spot.player) { + result[index].player = player; + } else { + result[index].player = null; + } + setIsRoleAssigned(!isRoleAssigned); + + return result; + }; + + if (teamCode === TEAM_CODE.RED) { + const newRedTeam = getNewTeam(redTeam, index); + setRedTeam(newRedTeam); + } else { + const newBlueTeam = getNewTeam(blueTeam, index); + setBlueTeam(newBlueTeam); + } + }; + + const generateListItem = (teamCode) => { + const team = teamCode === TEAM_CODE.RED ? redTeam : blueTeam; + const generateActions = (spot, index) => { + return !spot.player ? ( + !isRoleAssigned ? ( + { + changeRole(teamCode, index); + }} + edge="end" + > + + + ) : null + ) : // show "Leave Role" action only if current user's session ID matches their own + props.currentUser.sessionID === spot.player.sessionID && + isRoleAssigned ? ( + { + changeRole(teamCode, index); + }} + edge="end" + > + + + ) : null; + }; + + return team.map((spot, index) => { + const uniquekey = teamCode + "-" + index; + return ( + + + {spot.player ? spot.player.firstName : UNOCCUPIED_SPOT_NAME} + + + {generateActions(spot, index)} + + + ); + }); + }; + return ( @@ -22,25 +105,7 @@ function TeamSelect() { - - - Bonnie - - - Renyi - - - Manpreet - - - Tony (You) - - - - - - - + {generateListItem(TEAM_CODE.RED)} @@ -52,34 +117,7 @@ function TeamSelect() { - - - Sina - - - Jaclyn - - - - (Empty slot) - - - - - - - - - - (Empty slot) - - - - - - - - + {generateListItem(TEAM_CODE.BLUE)} From 086d50796c7f4ccd6d6fad3d20652e72a65b5526 Mon Sep 17 00:00:00 2001 From: Tony Chen Date: Thu, 21 May 2020 23:53:56 -0700 Subject: [PATCH 14/21] Minor change to button sizes in Game lobby UI. --- client/src/pages/game_lobby/GameLobby.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/src/pages/game_lobby/GameLobby.js b/client/src/pages/game_lobby/GameLobby.js index e6660c4..ca61478 100644 --- a/client/src/pages/game_lobby/GameLobby.js +++ b/client/src/pages/game_lobby/GameLobby.js @@ -69,6 +69,7 @@ function GameLobby() { disabled={!canStartGame} variant="contained" color="primary" + size="large" > Start Game @@ -90,6 +91,7 @@ function GameLobby() { }} variant="outlined" color="default" + size="small" > Copy From 8015b4e856f7b4648abe1d3ad07e84ab73993a5a Mon Sep 17 00:00:00 2001 From: h0vscat Date: Fri, 22 May 2020 09:54:49 -0400 Subject: [PATCH 15/21] able to change in different game turns --- server/engine/Board.js | 47 ++++---- server/engine/Game.js | 202 +++++++++++++++++++++++++++++++++++ server/engine/GameTurns.js | 9 ++ server/engine/Operative.js | 12 +++ server/engine/PlayerRoles.js | 8 ++ server/engine/SpyMaster.js | 23 ++++ server/engine/Team.js | 33 ++++++ 7 files changed, 316 insertions(+), 18 deletions(-) create mode 100644 server/engine/GameTurns.js create mode 100644 server/engine/Operative.js create mode 100644 server/engine/PlayerRoles.js create mode 100644 server/engine/SpyMaster.js create mode 100644 server/engine/Team.js diff --git a/server/engine/Board.js b/server/engine/Board.js index eb04178..3f187b6 100644 --- a/server/engine/Board.js +++ b/server/engine/Board.js @@ -22,14 +22,15 @@ class Board { generateNewRound() { let selectedWords = []; - const numRemainCards = 25; - if (this.deckLength > numRemainCards) { - selectedWords = this.deck.splice(0, 25); - this.updateDeckLength(); - } else { + const remainCardsNum = 25; + + if (this.deckLength < remainCardsNum) { this.deck = [...Words]; shuffle(this.deck); } + selectedWords = this.deck.splice(0, 25); + this.updateDeckLength(); + this.cards = selectedWords.map( (word, index) => new Card(word, this.mapCard[index]) ); @@ -43,6 +44,16 @@ class Board { return this.cards; } + setCard(selectedCard) { + //assume it pass the card + this.cards.forEach(card => { + if (card === selectedCard) { + card.select(); + return card.role; + } + }) + } + decideAgentNum() { const decision = Math.round(Math.random()); if (decision === 0) { @@ -56,16 +67,16 @@ class Board { } } - -const newBoard = new Board(); -console.log(newBoard.deckLength, "deck"); -console.log(newBoard.mapCard); -console.log(newBoard.cards); -console.log(newBoard.redAgentNum); -console.log(newBoard.blueAgentNum); -newBoard.generateNewRound(); -console.log(newBoard.deckLength, "deck"); -console.log(newBoard.mapCard); -console.log(newBoard.cards); -console.log(newBoard.redAgentNum); -console.log(newBoard.blueAgentNum); \ No newline at end of file +module.exports = Board; +// const newBoard = new Board(); +// console.log(newBoard.deckLength, "deck"); +// console.log(newBoard.mapCard); +// console.log(newBoard.cards); +// console.log(newBoard.redAgentNum); +// console.log(newBoard.blueAgentNum); +// newBoard.generateNewRound(); +// console.log(newBoard.deckLength, "deck"); +// console.log(newBoard.mapCard); +// console.log(newBoard.cards); +// console.log(newBoard.redAgentNum); +// console.log(newBoard.blueAgentNum); \ No newline at end of file diff --git a/server/engine/Game.js b/server/engine/Game.js index e69de29..b661584 100644 --- a/server/engine/Game.js +++ b/server/engine/Game.js @@ -0,0 +1,202 @@ +const Board = require("./Board"); +const Team = require("./Team"); +const Operative = require("./Operative"); +const SpyMaster = require("./SpyMaster"); +const GameTurns = require("./GameTurns"); +const PlayerRoles = require("./PlayerRoles"); +const WordRoles = require("./WordRoles"); + +class Game { + constructor(machId) { + this.machId = machId; + + this.gameTurn = [GameTurns.BLUE_SPY_TURN, GameTurns.RED_SPY_TURN][ + Math.round(Math.random()) + ]; + + this.redTeam = new Team(); + this.blueTeam = new Team(); + this.redPoints = 0; + this.bluePoints = 0; + this.numGuessLeft = 0; + + this.gameBoard = new Board(); + } + + //adders + addRedPoint() { + this.redPoints += 1; + } + addBluePoint() { + this.bluePoints += 1; + } + + //reducers + reduceNumGuessLeft() { + this.numGuessLeft -= 1; + } + + //getters + getMatchId() { + return this.machId; + } + getGameTurn() { + return this.gameTurn; + } + getRedTeam() { + return this.redTeam; + } + getBlueTeam() { + return this.blueTeam; + } + getRedPoints() { + return this.redPoints; + } + getBluePoints() { + return this.bluePoints; + } + getNumGuessLeft() { + return this.numGuessLeft; + } + getBoard() { + return this.gameBoard; + } + getGameState() { + return { + gameTurn: this.gameTurn, + redPoints: this.redPoints, + bluePoints: this.bluePoints, + // gameBoard: this.gameBoard, + numGuessLeft: this.numGuessLeft + }; + } + + //setters + setGameTurn(turn) { + this.gameTurn = turn; + } + setNumGuessLeft(num) { + this.numGuessLeft = num; + } + + setGamePoints(guess) { + switch(guess.role) { + case WordRoles.BLUE: + this.addBluePoint(); + guess.select(); + break; + case WordRoles.RED: + this.addRedPoint(); + guess.select(); + break; + case WordRoles.WHITE: + guess.select(); + break; + case WordRoles.BLACK: + guess.select(); + this.setGameTurn(GameTurns.End); + break; + } + } + + setRoles(players) { + players.forEach((player) => { + switch (player.role) { + case PlayerRoles.RED_OP: + const newRedOperative = new Operative(player, "Red"); + this.redTeam.addPlayer(newRedOperative); + this.redTeam.addOperative(newRedOperative); + break; + case PlayerRoles.BLUE_OP: + const newBlueOperative = new Operative(player, "Blue"); + this.redTeam.addPlayer(newBLueOperative); + this.redTeam.addOperative(newBlueOperative); + break; + case PlayerRoles.RED_SPY: + const newRedSpyMaster = new SpyMaster(player, "Red"); + this.redSpyMaster = newRedSpyMaster; + this.redTeam.addPlayer(newRedSpyMaster); + this.redTeam.setSpymaster(newRedSpyMaster); + break; + case PlayerRoles.BLUE_SPY: + const newBlueSpyMaster = new SpyMaster(player, "Blue"); + this.blueSpyMaster = newBlueSpyMaster; + this.blueTeam.addPlayer(newBlueSpyMaster); + this.blueTeam.setSpymaster(newBlueSpyMaster); + break; + } + }); + } + + nextGameTurn(info) { + switch (this.gameTurn) { + + case GameTurns.RED_SPY_TURN: + this.setNumGuessLeft(info.numGuess); + // this.redTeam.spymaster.setClue(info); + this.setGameTurn(GameTurns.RED_AGENT_TURN); + break; + case GameTurns.BLUE_SPY_TURN: + this.setNumGuessLeft(info.numGuess); + // this.blueTeam.spymaster.setClue(info); + this.setGameTurn(GameTurns.BLUE_AGENT_TURN); + break; + case GameTurns.RED_AGENT_TURN: + this.gameBoard.setCard(info.guess); + this.reduceNumGuessLeft(); + this.setGamePoints(info.guess); + if (this.getNumGuessLeft() === 0) { + this.setGameTurn(GameTurns.BLUE_SPY_TURN); + } + break; + case GameTurns.BLUE_AGENT_TURN: + this.gameBoard.setCard(info.guess); + this.reduceNumGuessLeft(); + this.setGamePoints(info.guess); + if (this.getNumGuessLeft() === 0) { + this.setGameTurn(GameTurns.RED_SPY_TURN); + } + break; + case GameTurns.End: + break; + } + } + + isGameOver() { + } + +} + + +const newGame = new Game("123"); +newGame.setRoles([{"user1":"user1", role:"Blue agent"}, {"user2":"user2", role:"Blue spymaster"}]); +//spymaster +console.log("============Spymaster==========="); +newGame.nextGameTurn({clue:"afkj", numGuess:4}); +console.log(newGame.getGameState()); +//agents +console.log("=========Agents========") +newGame.nextGameTurn({guess:newGame.gameBoard.cards[0]}); +console.log(newGame.gameBoard.cards[0]); +console.log(newGame.getGameState()); +newGame.nextGameTurn({guess:newGame.gameBoard.cards[1]}); +console.log(newGame.gameBoard.cards[1]); +console.log(newGame.getGameState()); +newGame.nextGameTurn({guess:newGame.gameBoard.cards[2]}); +console.log(newGame.gameBoard.cards[2]); +console.log(newGame.getGameState()); +newGame.nextGameTurn({guess:newGame.gameBoard.cards[3]}); +console.log(newGame.gameBoard.cards[3]); +console.log(newGame.getGameState()); +//spymaster +console.log("========Spymaster======="); +newGame.nextGameTurn({clue:"asga", numGuess:2}); +console.log(newGame.getGameState()); +//agents +console.log("=======Agents=======") +newGame.nextGameTurn({guess:newGame.gameBoard.cards[4]}); +console.log(newGame.gameBoard.cards[4]); +console.log(newGame.getGameState()); +newGame.nextGameTurn({guess:newGame.gameBoard.cards[5]}); +console.log(newGame.gameBoard.cards[5]); +console.log(newGame.getGameState()); \ No newline at end of file diff --git a/server/engine/GameTurns.js b/server/engine/GameTurns.js new file mode 100644 index 0000000..b80f7de --- /dev/null +++ b/server/engine/GameTurns.js @@ -0,0 +1,9 @@ +const GameTurns = { + RED_AGENT_TURN: "Red agent's turn", + BLUE_AGENT_TURN:"Blue agent's turn", + RED_SPY_TURN: "Red spymaster's turn", + BLUE_SPY_TURN: "Blue spymaster's turn", + END: "End" +} + +module.exports = GameTurns; \ No newline at end of file diff --git a/server/engine/Operative.js b/server/engine/Operative.js new file mode 100644 index 0000000..e4c06bc --- /dev/null +++ b/server/engine/Operative.js @@ -0,0 +1,12 @@ +class Operative { + constructor(user, team) { + this.user = user; + this.team = team; + } + + selectCard(card, board) { + return board.chooseCard(card); + } +} + +module.exports = Operative; \ No newline at end of file diff --git a/server/engine/PlayerRoles.js b/server/engine/PlayerRoles.js new file mode 100644 index 0000000..b0b1a06 --- /dev/null +++ b/server/engine/PlayerRoles.js @@ -0,0 +1,8 @@ +const PlayerRoles = { + RED_OP: "Red operative", + BLUE_OP: "Blue operative", + RED_SPY: "Red spymaster", + BLUE_SPY: "Blue spymaster", +} + +module.exports = PlayerRoles; \ No newline at end of file diff --git a/server/engine/SpyMaster.js b/server/engine/SpyMaster.js new file mode 100644 index 0000000..2c517fb --- /dev/null +++ b/server/engine/SpyMaster.js @@ -0,0 +1,23 @@ +class SpyMaster { + constructor(user, team) { + this.user = user; + this.team = team; + this.clue = {}; + } + + setClue(clue) { + //todo + //return moves? + this.clue = clue; + } + + getClue() { + return this.clue; + } + + deleteClue() { + this.clue = {}; + } +} + +module.exports = SpyMaster; \ No newline at end of file diff --git a/server/engine/Team.js b/server/engine/Team.js new file mode 100644 index 0000000..789cbe8 --- /dev/null +++ b/server/engine/Team.js @@ -0,0 +1,33 @@ +class Team { + constructor() { + this.players = []; + this.operatives = []; + this.spymaster = null; + } + + addPlayer(player) { + this.players.push(player); + } + + addOperative(operative) { + this.operatives.push(operative); + } + + getOperatives() { + return this.operatives; + } + + getPlayers() { + return this.players; + } + + setSpymaster(player) { + this.spymaster = player; + } + + getSpymaster() { + return this.spymaster; + } +} + +module.exports = Team; From 706c57be3ce0414b8b0f5d5140b5e3ddd88230f6 Mon Sep 17 00:00:00 2001 From: h0vscat Date: Fri, 22 May 2020 21:51:56 -0400 Subject: [PATCH 16/21] can check for winner and resetGame --- server/engine/Board.js | 7 +++ server/engine/Game.js | 130 +++++++++++++++++++++++++++++------------ server/engine/Team.js | 17 ++++-- 3 files changed, 112 insertions(+), 42 deletions(-) diff --git a/server/engine/Board.js b/server/engine/Board.js index 3f187b6..04c4c2f 100644 --- a/server/engine/Board.js +++ b/server/engine/Board.js @@ -40,9 +40,16 @@ class Board { this.deckLength = this.deck.length; } + //getters getCards() { return this.cards; } + getRedAgentNum() { + return this.redAgentNum; + } + getBlueAgentNum() { + return this.blueAgentNum; + } setCard(selectedCard) { //assume it pass the card diff --git a/server/engine/Game.js b/server/engine/Game.js index b661584..09ed0a3 100644 --- a/server/engine/Game.js +++ b/server/engine/Game.js @@ -1,5 +1,5 @@ const Board = require("./Board"); -const Team = require("./Team"); +const { Team, TeamColor } = require("./Team"); const Operative = require("./Operative"); const SpyMaster = require("./SpyMaster"); const GameTurns = require("./GameTurns"); @@ -14,11 +14,12 @@ class Game { Math.round(Math.random()) ]; - this.redTeam = new Team(); - this.blueTeam = new Team(); + this.redTeam = new Team(TeamColor.RED); + this.blueTeam = new Team(TeamColor.BLUE); this.redPoints = 0; this.bluePoints = 0; this.numGuessLeft = 0; + this.winner = null; this.gameBoard = new Board(); } @@ -33,12 +34,12 @@ class Game { //reducers reduceNumGuessLeft() { - this.numGuessLeft -= 1; + this.numGuessLeft -= 1; } //getters getMatchId() { - return this.machId; + return this.machId; } getGameTurn() { return this.gameTurn; @@ -56,7 +57,10 @@ class Game { return this.bluePoints; } getNumGuessLeft() { - return this.numGuessLeft; + return this.numGuessLeft; + } + getWinner() { + return this.winner; } getBoard() { return this.gameBoard; @@ -66,8 +70,8 @@ class Game { gameTurn: this.gameTurn, redPoints: this.redPoints, bluePoints: this.bluePoints, - // gameBoard: this.gameBoard, - numGuessLeft: this.numGuessLeft + // gameBoard: this.gameBoard, + numGuessLeft: this.numGuessLeft, }; } @@ -76,26 +80,28 @@ class Game { this.gameTurn = turn; } setNumGuessLeft(num) { - this.numGuessLeft = num; + this.numGuessLeft = num; + } + setWinner(team) { + this.winner = team; } - setGamePoints(guess) { - switch(guess.role) { - case WordRoles.BLUE: - this.addBluePoint(); - guess.select(); - break; - case WordRoles.RED: - this.addRedPoint(); - guess.select(); - break; - case WordRoles.WHITE: - guess.select(); - break; - case WordRoles.BLACK: - guess.select(); - this.setGameTurn(GameTurns.End); - break; + switch (guess.role) { + case WordRoles.BLUE: + this.addBluePoint(); + guess.select(); + break; + case WordRoles.RED: + this.addRedPoint(); + guess.select(); + break; + case WordRoles.WHITE: + guess.select(); + break; + case WordRoles.BLACK: + // guess.select(); + this.setGameTurn(GameTurns.End); + break; } } @@ -103,23 +109,23 @@ class Game { players.forEach((player) => { switch (player.role) { case PlayerRoles.RED_OP: - const newRedOperative = new Operative(player, "Red"); + const newRedOperative = new Operative(player, TeamColor.RED); this.redTeam.addPlayer(newRedOperative); this.redTeam.addOperative(newRedOperative); break; case PlayerRoles.BLUE_OP: - const newBlueOperative = new Operative(player, "Blue"); + const newBlueOperative = new Operative(player, TeamColor.BLUE); this.redTeam.addPlayer(newBLueOperative); this.redTeam.addOperative(newBlueOperative); break; case PlayerRoles.RED_SPY: - const newRedSpyMaster = new SpyMaster(player, "Red"); + const newRedSpyMaster = new SpyMaster(player, TeamColor.RED); this.redSpyMaster = newRedSpyMaster; this.redTeam.addPlayer(newRedSpyMaster); this.redTeam.setSpymaster(newRedSpyMaster); break; case PlayerRoles.BLUE_SPY: - const newBlueSpyMaster = new SpyMaster(player, "Blue"); + const newBlueSpyMaster = new SpyMaster(player, TeamColor.BLUE); this.blueSpyMaster = newBlueSpyMaster; this.blueTeam.addPlayer(newBlueSpyMaster); this.blueTeam.setSpymaster(newBlueSpyMaster); @@ -129,8 +135,13 @@ class Game { } nextGameTurn(info) { + const winner = this.checkIfWinning(info.guess); + console.log(info) + if (winner) { + console.log(winner, "if"); + this.setGameTurn(GameTurns.End); + } switch (this.gameTurn) { - case GameTurns.RED_SPY_TURN: this.setNumGuessLeft(info.numGuess); // this.redTeam.spymaster.setClue(info); @@ -145,35 +156,78 @@ class Game { this.gameBoard.setCard(info.guess); this.reduceNumGuessLeft(); this.setGamePoints(info.guess); + if (this.getNumGuessLeft() === 0) { - this.setGameTurn(GameTurns.BLUE_SPY_TURN); + this.setGameTurn(GameTurns.BLUE_SPY_TURN); } break; case GameTurns.BLUE_AGENT_TURN: this.gameBoard.setCard(info.guess); this.reduceNumGuessLeft(); this.setGamePoints(info.guess); + if (this.getNumGuessLeft() === 0) { - this.setGameTurn(GameTurns.RED_SPY_TURN); + this.setGameTurn(GameTurns.RED_SPY_TURN); } break; case GameTurns.End: + console.log("I'm in the end") break; - } + } } - isGameOver() { + checkIfWinning(info) { + if ( + this.getGameTurn() === GameTurns.BLUE_AGENT_TURN || + this.getGameTurn() === GameTurns.RED_AGENT_TURN + ) { + console.log("in") + if ( + info.role === WordRoles.BLACK && + this.getGameTurn() === GameTurns.BLUE_AGENT_TURN + ) { + this.setWinner(this.getRedTeam()); + return true; + } + if ( + info.role === WordRoles.BLACK && + this.getGameTurn() === GameTurns.RED_AGENT_TURN + ) { + this.setWinner(this.getBlueTeam()); + return true; + } + if (this.getRedPoints() === this.gameBoard.getRedAgentNum()) { + this.setWinner(this.getRedTeam()); + return true; + } + if (this.getBluePoints() === this.gameBoard.getBlueAgentNum()) { + this.setWinner(this.getBlueTeam()); + return true; + } + } + return false; } + resetGame() { + this.bluePoints = 0; + this.redPoints = 0; + this.numGuessLeft = 0; + this.gameBoard.generateNewRound(); + this.gameTurn = [GameTurns.BLUE_SPY_TURN, GameTurns.RED_SPY_TURN][ + Math.round(Math.random()) + ]; + this.winner=null; + } } const newGame = new Game("123"); newGame.setRoles([{"user1":"user1", role:"Blue agent"}, {"user2":"user2", role:"Blue spymaster"}]); +// console.log(newGame.getBlueTeam()); //spymaster console.log("============Spymaster==========="); newGame.nextGameTurn({clue:"afkj", numGuess:4}); -console.log(newGame.getGameState()); +// console.log(newGame.getGameState()); //agents console.log("=========Agents========") newGame.nextGameTurn({guess:newGame.gameBoard.cards[0]}); @@ -199,4 +253,8 @@ console.log(newGame.gameBoard.cards[4]); console.log(newGame.getGameState()); newGame.nextGameTurn({guess:newGame.gameBoard.cards[5]}); console.log(newGame.gameBoard.cards[5]); +console.log(newGame.getGameState()); + +console.log(newGame.getWinner()); +newGame.resetGame() console.log(newGame.getGameState()); \ No newline at end of file diff --git a/server/engine/Team.js b/server/engine/Team.js index 789cbe8..d8d9478 100644 --- a/server/engine/Team.js +++ b/server/engine/Team.js @@ -1,5 +1,6 @@ class Team { - constructor() { + constructor(color) { + this.teamColor = color; this.players = []; this.operatives = []; this.spymaster = null; @@ -21,13 +22,17 @@ class Team { return this.players; } - setSpymaster(player) { - this.spymaster = player; - } - getSpymaster() { return this.spymaster; } + + setSpymaster(player) { + this.spymaster = player; + } } -module.exports = Team; +const TeamColor = { + RED: "RED", + BLUE: "BLUE", +}; +module.exports = { Team, TeamColor }; From 682fee8f2d2140e56190a6947889afa2d8ccf1ba Mon Sep 17 00:00:00 2001 From: h0vscat Date: Fri, 22 May 2020 22:05:45 -0400 Subject: [PATCH 17/21] can stop guess early --- server/engine/Board.js | 16 +------- server/engine/Game.js | 72 +++++++++++------------------------- server/engine/Operative.js | 16 ++++---- server/engine/PlayerRoles.js | 12 +++--- server/engine/SpyMaster.js | 34 ++++++++--------- server/engine/shuffle.js | 2 +- 6 files changed, 55 insertions(+), 97 deletions(-) diff --git a/server/engine/Board.js b/server/engine/Board.js index 04c4c2f..51c7774 100644 --- a/server/engine/Board.js +++ b/server/engine/Board.js @@ -53,12 +53,12 @@ class Board { setCard(selectedCard) { //assume it pass the card - this.cards.forEach(card => { + this.cards.forEach((card) => { if (card === selectedCard) { card.select(); return card.role; } - }) + }); } decideAgentNum() { @@ -75,15 +75,3 @@ class Board { } module.exports = Board; -// const newBoard = new Board(); -// console.log(newBoard.deckLength, "deck"); -// console.log(newBoard.mapCard); -// console.log(newBoard.cards); -// console.log(newBoard.redAgentNum); -// console.log(newBoard.blueAgentNum); -// newBoard.generateNewRound(); -// console.log(newBoard.deckLength, "deck"); -// console.log(newBoard.mapCard); -// console.log(newBoard.cards); -// console.log(newBoard.redAgentNum); -// console.log(newBoard.blueAgentNum); \ No newline at end of file diff --git a/server/engine/Game.js b/server/engine/Game.js index 09ed0a3..d066463 100644 --- a/server/engine/Game.js +++ b/server/engine/Game.js @@ -136,9 +136,7 @@ class Game { nextGameTurn(info) { const winner = this.checkIfWinning(info.guess); - console.log(info) if (winner) { - console.log(winner, "if"); this.setGameTurn(GameTurns.End); } switch (this.gameTurn) { @@ -171,7 +169,7 @@ class Game { } break; case GameTurns.End: - console.log("I'm in the end") + console.log("I'm in the end"); break; } } @@ -181,7 +179,6 @@ class Game { this.getGameTurn() === GameTurns.BLUE_AGENT_TURN || this.getGameTurn() === GameTurns.RED_AGENT_TURN ) { - console.log("in") if ( info.role === WordRoles.BLACK && this.getGameTurn() === GameTurns.BLUE_AGENT_TURN @@ -208,53 +205,26 @@ class Game { return false; } + stopGuess() { + switch (this.gameTurn) { + case GameTurns.BLUE_AGENT_TURN: + this.setNumGuessLeft = 0; + this.setGameTurn(GameTurns.RED_SPY_TURN); + break; + case GameTurns.RED_AGENT_TURN: + this.setNumGuessLeft = 0; + this.setGameTurn(GameTurns.BLUE_SPY_TURN); + break; + } + } resetGame() { - this.bluePoints = 0; - this.redPoints = 0; - this.numGuessLeft = 0; - this.gameBoard.generateNewRound(); - this.gameTurn = [GameTurns.BLUE_SPY_TURN, GameTurns.RED_SPY_TURN][ - Math.round(Math.random()) - ]; - this.winner=null; + this.bluePoints = 0; + this.redPoints = 0; + this.numGuessLeft = 0; + this.gameBoard.generateNewRound(); + this.gameTurn = [GameTurns.BLUE_SPY_TURN, GameTurns.RED_SPY_TURN][ + Math.round(Math.random()) + ]; + this.winner = null; } } - - -const newGame = new Game("123"); -newGame.setRoles([{"user1":"user1", role:"Blue agent"}, {"user2":"user2", role:"Blue spymaster"}]); -// console.log(newGame.getBlueTeam()); -//spymaster -console.log("============Spymaster==========="); -newGame.nextGameTurn({clue:"afkj", numGuess:4}); -// console.log(newGame.getGameState()); -//agents -console.log("=========Agents========") -newGame.nextGameTurn({guess:newGame.gameBoard.cards[0]}); -console.log(newGame.gameBoard.cards[0]); -console.log(newGame.getGameState()); -newGame.nextGameTurn({guess:newGame.gameBoard.cards[1]}); -console.log(newGame.gameBoard.cards[1]); -console.log(newGame.getGameState()); -newGame.nextGameTurn({guess:newGame.gameBoard.cards[2]}); -console.log(newGame.gameBoard.cards[2]); -console.log(newGame.getGameState()); -newGame.nextGameTurn({guess:newGame.gameBoard.cards[3]}); -console.log(newGame.gameBoard.cards[3]); -console.log(newGame.getGameState()); -//spymaster -console.log("========Spymaster======="); -newGame.nextGameTurn({clue:"asga", numGuess:2}); -console.log(newGame.getGameState()); -//agents -console.log("=======Agents=======") -newGame.nextGameTurn({guess:newGame.gameBoard.cards[4]}); -console.log(newGame.gameBoard.cards[4]); -console.log(newGame.getGameState()); -newGame.nextGameTurn({guess:newGame.gameBoard.cards[5]}); -console.log(newGame.gameBoard.cards[5]); -console.log(newGame.getGameState()); - -console.log(newGame.getWinner()); -newGame.resetGame() -console.log(newGame.getGameState()); \ No newline at end of file diff --git a/server/engine/Operative.js b/server/engine/Operative.js index e4c06bc..739d0c0 100644 --- a/server/engine/Operative.js +++ b/server/engine/Operative.js @@ -1,12 +1,12 @@ class Operative { - constructor(user, team) { - this.user = user; - this.team = team; - } + constructor(user, team) { + this.user = user; + this.team = team; + } - selectCard(card, board) { - return board.chooseCard(card); - } + selectCard(card, board) { + return board.chooseCard(card); + } } -module.exports = Operative; \ No newline at end of file +module.exports = Operative; diff --git a/server/engine/PlayerRoles.js b/server/engine/PlayerRoles.js index b0b1a06..3fce16b 100644 --- a/server/engine/PlayerRoles.js +++ b/server/engine/PlayerRoles.js @@ -1,8 +1,8 @@ const PlayerRoles = { - RED_OP: "Red operative", - BLUE_OP: "Blue operative", - RED_SPY: "Red spymaster", - BLUE_SPY: "Blue spymaster", -} + RED_OP: "Red operative", + BLUE_OP: "Blue operative", + RED_SPY: "Red spymaster", + BLUE_SPY: "Blue spymaster", +}; -module.exports = PlayerRoles; \ No newline at end of file +module.exports = PlayerRoles; diff --git a/server/engine/SpyMaster.js b/server/engine/SpyMaster.js index 2c517fb..3d61ae8 100644 --- a/server/engine/SpyMaster.js +++ b/server/engine/SpyMaster.js @@ -1,23 +1,23 @@ class SpyMaster { - constructor(user, team) { - this.user = user; - this.team = team; - this.clue = {}; - } + constructor(user, team) { + this.user = user; + this.team = team; + this.clue = {}; + } - setClue(clue) { - //todo - //return moves? - this.clue = clue; - } + setClue(clue) { + //todo + //return moves? + this.clue = clue; + } - getClue() { - return this.clue; - } + getClue() { + return this.clue; + } - deleteClue() { - this.clue = {}; - } + deleteClue() { + this.clue = {}; + } } -module.exports = SpyMaster; \ No newline at end of file +module.exports = SpyMaster; diff --git a/server/engine/shuffle.js b/server/engine/shuffle.js index e01c081..5455e4d 100644 --- a/server/engine/shuffle.js +++ b/server/engine/shuffle.js @@ -4,5 +4,5 @@ const shuffle = (array) => { [array[i], array[j]] = [array[j], array[i]]; } return array; -} +}; module.exports = shuffle; From 3588a41c6298d039adc5ca0d94803c013f183760 Mon Sep 17 00:00:00 2001 From: Tony Chen Date: Sun, 24 May 2020 13:19:26 -0700 Subject: [PATCH 18/21] Created utils.js for useful helper functions. Renamed references of Game ID to Match ID. --- client/src/pages/create_game/CreateGame.js | 2 +- client/src/pages/game_lobby/GameLobby.js | 17 ++++------------- client/src/utils/utils.js | 9 +++++++++ 3 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 client/src/utils/utils.js diff --git a/client/src/pages/create_game/CreateGame.js b/client/src/pages/create_game/CreateGame.js index 496098b..5f3cc8f 100644 --- a/client/src/pages/create_game/CreateGame.js +++ b/client/src/pages/create_game/CreateGame.js @@ -29,7 +29,7 @@ function CreateGame() { - +