Sergidev commited on
Commit
0d5c428
·
verified ·
1 Parent(s): 94bfcb7

Update static/js/game.js

Browse files
Files changed (1) hide show
  1. static/js/game.js +35 -3
static/js/game.js CHANGED
@@ -22,7 +22,7 @@ function startGame() {
22
  document.getElementById('sessionInfo').style.display = 'block';
23
  document.getElementById('playButton').style.display = 'none';
24
  if (data.status === 'ready') {
25
- startGamePlay();
26
  } else {
27
  checkGameStatus();
28
  }
@@ -34,18 +34,50 @@ function checkGameStatus() {
34
  .then(response => response.json())
35
  .then(data => {
36
  if (data.status === 'ready') {
37
- startGamePlay();
38
  } else {
39
  setTimeout(checkGameStatus, 2000); // Check again in 2 seconds
40
  }
41
  });
42
  }
43
 
44
- function startGamePlay() {
45
  document.getElementById('waitingMessage').style.display = 'none';
46
  document.getElementById('wordInput').style.display = 'block';
47
  }
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  function submitWord() {
50
  const word = document.getElementById('wordInputField').value;
51
  if (word.length !== 7) {
 
22
  document.getElementById('sessionInfo').style.display = 'block';
23
  document.getElementById('playButton').style.display = 'none';
24
  if (data.status === 'ready') {
25
+ startWordInput();
26
  } else {
27
  checkGameStatus();
28
  }
 
34
  .then(response => response.json())
35
  .then(data => {
36
  if (data.status === 'ready') {
37
+ startWordInput();
38
  } else {
39
  setTimeout(checkGameStatus, 2000); // Check again in 2 seconds
40
  }
41
  });
42
  }
43
 
44
+ function startWordInput() {
45
  document.getElementById('waitingMessage').style.display = 'none';
46
  document.getElementById('wordInput').style.display = 'block';
47
  }
48
 
49
+ function submitWord() {
50
+ const word = document.getElementById('wordInputField').value;
51
+ if (word.length !== 7) {
52
+ alert('Word must be 7 letters long');
53
+ return;
54
+ }
55
+ fetch('/submit_word', {
56
+ method: 'POST',
57
+ headers: {
58
+ 'Content-Type': 'application/json',
59
+ },
60
+ body: JSON.stringify({ session_id: sessionId, player_id: playerId, word: word }),
61
+ })
62
+ .then(response => response.json())
63
+ .then(data => {
64
+ if (data.status === 'waiting_for_opponent') {
65
+ document.getElementById('wordInput').style.display = 'none';
66
+ document.getElementById('waitingMessage').style.display = 'block';
67
+ document.getElementById('waitingMessage').textContent = 'Waiting for opponent to submit their word...';
68
+ } else if (data.status === 'game_started') {
69
+ startGamePlay();
70
+ }
71
+ });
72
+ }
73
+
74
+ function startGamePlay() {
75
+ document.getElementById('waitingMessage').style.display = 'none';
76
+ document.getElementById('wordInput').style.display = 'none';
77
+ document.getElementById('gameArea').style.display = 'block';
78
+ updateGameState();
79
+ }
80
+
81
  function submitWord() {
82
  const word = document.getElementById('wordInputField').value;
83
  if (word.length !== 7) {