aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/site/game.js
diff options
context:
space:
mode:
Diffstat (limited to 'site/game.js')
-rw-r--r--site/game.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/site/game.js b/site/game.js
new file mode 100644
index 0000000..4a5eff9
--- /dev/null
+++ b/site/game.js
@@ -0,0 +1,56 @@
+const order = document.getElementById("graphOrder");
+//TODO: read in player's name
+
+
+function foo(){
+ console.log(order.valueAsNumber);
+}
+
+function getNimber(length){
+ //TODO: copy from fast_p_sage
+ //TODO: put in seperate file
+}
+
+function createGame(length){
+ const game = {
+ board: Array(length).fill(1),
+ turn: getNimber(length) > 0 ? "computer" : "human",
+ finished: false,
+ result: "In Progress...",
+ //FIXME: turn shouldn't be an argument,
+ //FIXME: human and computer Play needs the game as an argument
+ nextTurn: (turn) => {
+ if(turn === "computer")
+ computerPlay()
+ else
+ humanPlay()
+ }
+ }
+ //TODO: create game in DOM
+ return game;
+}
+
+function computerPlay(game){
+
+}
+
+function humanPlay(game){
+
+}
+
+function renderGame(game){
+ //TODO: update game in DOM
+}
+
+function displayMessage(text){
+
+}
+
+function playGame(){
+ const length = order.valueAsNumber;
+ const game = createGame(length);
+ while(!game.finished){
+ game.nextTurn(game.turn);
+ }
+ displayMessage(game.result);
+}