From 2c02c02f6c2ec218d92835a9dbc0c0f24031d129 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Appel Date: Mon, 23 Oct 2023 03:18:54 -0400 Subject: test posting from js --- site/game.js | 51 +++++++++++++++++++++++---------------------------- site/index.html | 6 +++--- site/style.css | 0 3 files changed, 26 insertions(+), 31 deletions(-) create mode 100644 site/style.css diff --git a/site/game.js b/site/game.js index 4a5eff9..e0015be 100644 --- a/site/game.js +++ b/site/game.js @@ -2,38 +2,20 @@ 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", + size: length, 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() - } + board: Array(length).fill(true), + turn: 0, + version: "0.0.0", + human_turn: false, + winner: "" } //TODO: create game in DOM return game; } -function computerPlay(game){ - -} - function humanPlay(game){ } @@ -46,11 +28,24 @@ function displayMessage(text){ } +async function sendGame(game){ + let response = await fetch("https://jpappel.xyz/toggle/query", { + method: "POST", + body: JSON.stringify(game), + headers: { + "Accept": "application/json", + "Content-Type": "application/json; charset=UTF-8" + } + }) + return JSON.parse(response.json()) +} + function playGame(){ const length = order.valueAsNumber; const game = createGame(length); - while(!game.finished){ - game.nextTurn(game.turn); - } - displayMessage(game.result); + console.log(sendGame(game)) + //while(!game.finished){ + // game.nextTurn(game.turn); + //} + // displayMessage(game.result); } diff --git a/site/index.html b/site/index.html index 24d50d2..5497e9a 100644 --- a/site/index.html +++ b/site/index.html @@ -9,12 +9,12 @@

Toggle Online

Try to beat the computer :) - +

Options

- - + +

Game

diff --git a/site/style.css b/site/style.css new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3