aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/site/game.js
blob: 4a5eff9a70a0916e8ca1ae4d075e01be08f5930d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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);
}