Pawe艂 艁aba commited on
Commit
745e516
1 Parent(s): b0be829

zmiana w uruchamianiu proagramu

Browse files
Files changed (2) hide show
  1. public/index.html +1 -1
  2. public/script.js +10 -3
public/index.html CHANGED
@@ -11,7 +11,7 @@
11
  <h1>K贸艂ko i Krzy偶yk</h1>
12
  <div class="board"></div>
13
  <div class="message"></div>
14
- <button class="restart" onclick="restart()">Restart</button>
15
  </div>
16
 
17
 
 
11
  <h1>K贸艂ko i Krzy偶yk</h1>
12
  <div class="board"></div>
13
  <div class="message"></div>
14
+ <button class="restart">Restart</button>
15
  </div>
16
 
17
 
public/script.js CHANGED
@@ -1,3 +1,4 @@
 
1
  const board = Array(9).fill(0);
2
  const step = [];
3
  let fitstMove = true;
@@ -7,6 +8,8 @@ const winPatterns = [
7
  [0, 4, 8], [2, 4, 6] // przek膮tne
8
  ];
9
 
 
 
10
  function restart(){
11
  board = Array(9).fill(0);
12
  step = [];
@@ -25,7 +28,7 @@ function checkWin(board) {
25
  }
26
 
27
  function initializeBoard() {
28
- const boardElement = document.querySelector('.board');
29
  boardElement.innerHTML = '';
30
 
31
  for(let i = 0; i < 9; i++) {
@@ -43,7 +46,7 @@ function initializeBoard() {
43
 
44
  function updateBoardDisplay() {
45
  board.forEach((value, index) => {
46
- const cell = document.getElementById('cell-' + index);
47
  cell.className = 'cell';
48
  if (value === 1) {
49
  cell.classList.add('o');
@@ -53,7 +56,7 @@ function updateBoardDisplay() {
53
  });
54
 
55
  const winner = checkWin(board);
56
- const messageElement = document.querySelector('.message');
57
  if (winner === 1) {
58
  messageElement.textContent = 'Komputer wygra艂!';
59
  } else if (winner === -1) {
@@ -130,4 +133,8 @@ async function initGame() {
130
  initializeBoard();
131
  }
132
 
 
 
 
 
133
  initGame();
 
1
+ const $ = e =>document.querySelector(e);
2
  const board = Array(9).fill(0);
3
  const step = [];
4
  let fitstMove = true;
 
8
  [0, 4, 8], [2, 4, 6] // przek膮tne
9
  ];
10
 
11
+
12
+
13
  function restart(){
14
  board = Array(9).fill(0);
15
  step = [];
 
28
  }
29
 
30
  function initializeBoard() {
31
+ const boardElement =$('.board');
32
  boardElement.innerHTML = '';
33
 
34
  for(let i = 0; i < 9; i++) {
 
46
 
47
  function updateBoardDisplay() {
48
  board.forEach((value, index) => {
49
+ const cell = $('#cell-' + index);
50
  cell.className = 'cell';
51
  if (value === 1) {
52
  cell.classList.add('o');
 
56
  });
57
 
58
  const winner = checkWin(board);
59
+ const messageElement =$('.message');
60
  if (winner === 1) {
61
  messageElement.textContent = 'Komputer wygra艂!';
62
  } else if (winner === -1) {
 
133
  initializeBoard();
134
  }
135
 
136
+ $('.restart').addEventListener('click', ()=>{
137
+ restart();
138
+ });
139
+
140
  initGame();