-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
89 lines (78 loc) · 2.36 KB
/
main.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { build, develop, endTurn, ready, unready, join, setColor } from "./modules/actions.js"
import { showBuild, showTrade, showChat } from "./modules/sidebar.js";
// Expose functions to the global scope
window.setColor = setColor;
window.build = build;
window.develop = develop;
window.endTurn = endTurn;
window.ready = ready;
window.unready = unready;
window.join = join;
window.showBuild = showBuild;
window.showTrade = showTrade;
window.showChat = showChat;
/**
* Represents the game state.
* @typedef {Object} Game
* @property {string} currentType - The current type of building being built.
* @property {null|Map} map - The game map.
* @property {boolean} roadBuilding - Indicates if the road building action is being performed.
* @property {number} roadsBuilt - The number of roads built during road building.
* @property {boolean} knightPlayed - Indicates if a knight card is being played.
* @property {Array} chat - The chat messages.
* @property {Array} players - The players in the game.
*/
/**
* The game object representing the state of the game.
* @type {Game}
*/
export const game = {
currentType: "settlement",
map: null,
roadBuilding: false,
roadsBuilt: 0,
knightPlayed: false,
chat: [],
players: [],
turn: 0,
}
export function getRound() {
return Math.floor(game.turn / game.players.length);
}
export function getTurnPlayer() {
return game.players[getRound() == 1 ? game.players.length - game.turn % game.players.length - 1 : game.turn % game.players.length];
}
/**
* Represents a player in the game.
* @typedef {Object} Player
* @property {string} name - The name of the player.
* @property {string} color - The color assigned to the player.
*/
/**
* The player object representing the current player.
* @type {Player}
*/
export const myPlayer = {
name: "",
color: ""
}
/**
* Represents the user interface.
* @namespace ui
* @property {HTMLElement} notifications - The notifications element.
*/
export const ui = {
notifications: document.getElementById('notifications')
}
/**
* The server object representing the WebSocket connection to the server.
* @type {WebSocket|null}
*/
export let server = null;
/**
* Connects to the server using the specified address.
* @param {string} address - The address of the server.
*/
export function connect(address) {
server = new WebSocket("ws://" + address);
}