Xây dựng game Tic Tac Toe Javascript

Theo thống kê từ trang StackOverflow, Javascript [JS] đang là một ngôn ngữ lập trình phổ biến số 1 hiện nay. Vì có thể dùng JS để xây dựng cả front-end và back-end cho ứng dụng. Có thể xây dựng ứng dụng Web, ứng dụng Mobile [React Native] và ứng dụng Desktop [ElectronJS]. Gần như tất cả các ứng dụng Web hiện nay đều được xây dựng từ HTML, CSS và JS.

Thống kê của trang stackoverflow năm 2020

Chỉ với 2 tiếng tham gia buổi Workshop cùng anh Trần Đức Doanh – Head of IT Department tại HCMC University of Transport, giảng viên cao cấp tại Nordic Coder với chủ đề “Build Tic Tac Toe game from the scratch”, bạn sẽ:

Dạo gần đây mình có tự học

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
4. Lên trang chủ của nó thì có một tutorial khá hay đó là code
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
5 game bằng
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
4. Nên trong bài viết này mình sẽ chia sẽ một số kiến thức mình học được khi code nó. Về cơ bản game sẽ giống với game
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
5 thông thường nhưng có thêm lưu lịch sử các bước đi và mình có thể quay lại trạng thái của nước đi đó. Toàn bộ source code mình đã đưa lên git các bạn có thể vào để xem và dễ dàng theo dõi ở đây.

.

Thêm một chút là nếu bạn nào đã có kiến thức về

const name = 'Simon';
const age = 23
const element = [
    
        Hello {name}!
        Age: {age}
        Good to see you here.
    
];
64 của ES6 rồi thì các bạn có thể refactor lại nó. Tách các compoent ra thành từng file và tiến hình import thay vì viết tất cả component vào một file như mình. Vì bài viết cũng khá dài rồi nên mình không đề cập đến nó ở đây.

It is quite easy to develop with some simple validations and error checks. Player-1 starts playing the game and both the players make their moves in consecutive turns. The player who makes a straight 3-block chain wins the game. This game is built on the front-end using simple logic and validation checks only.   

Prerequisite: Basic knowledge of some front-end technologies like HTML, CSS, JavaScript. 

View of Tic-Tac-Toe Game

Filename: index.html

HTML




   

    

   

    

When Player '0' Won
2

    

   

    

When Match is Tie
9

    

9head>

   

    4

head97>8>7>2>1    2>1    4

head9    6>7    8>7>

When Player 'X' Won
79head4>

 

When Player 'X' Won
05 

   

   

When Player 'X' Won
71>2>1>

When Player 'X' Won
7
When Player 'X' Won
15

When Player 'X' Won
7

   

When Player 'X' Won
7

   

When Player 'X' Won
72>1>

When Player 'X' Won
7
When Player '0' Won
74

When Player 'X' Won
7

head9

When Player '0' Won
86

When Player 'X' Won
79
When Player '0' Won
77>

   

When Player 'X' Won
71>2>1>

When Player 'X' Won
7
When Player '0' Won
99

When Player 'X' Won
7

 

When Player 'X' Won
05 

   

   

    9  8>

9  4>

   

9

When Match is Tie
21>

Filename: tic.css 

CSS




When Match is Tie
23

    

When Match is Tie
25

    

When Match is Tie
27

    

When Match is Tie
29
When Match is Tie
30
When Match is Tie
31

When Player 'X' Won
7
When Match is Tie
33
When Match is Tie
34

When Player 'X' Won
7
When Match is Tie
36
When Match is Tie
37
When Match is Tie
38
When Match is Tie
39

    

When Match is Tie
41

 

    

When Match is Tie
43

    

When Match is Tie
45
When Match is Tie
30
When Match is Tie
47
When Match is Tie
48
When Match is Tie
47
When Match is Tie
50
When Match is Tie
47
When Match is Tie
52
When Match is Tie
47
When Match is Tie
54
When Match is Tie
55

    

When Match is Tie
45
When Match is Tie
58
When Match is Tie
47
When Match is Tie
60
When Match is Tie
47
When Match is Tie
62
When Match is Tie
47
When Match is Tie
64
When Match is Tie
31

When Player 'X' Won
7
When Match is Tie
67
When Match is Tie
37
When Match is Tie
69
When Match is Tie
39

When Player 'X' Won
7
When Match is Tie
72
When Match is Tie
37
When Match is Tie
74
When Match is Tie
39

When Player 'X' Won
7
When Match is Tie
77
When Match is Tie
37
When Match is Tie
79
When Match is Tie
39

When Player 'X' Won
7
When Match is Tie
82
When Match is Tie
37
When Match is Tie
84
When Match is Tie
85
When Match is Tie
86
When Match is Tie
39

When Player 'X' Won
7
When Match is Tie
89
When Match is Tie
90
When Match is Tie
39

When Player 'X' Won
7
When Match is Tie
36
When Match is Tie
37
When Match is Tie
95
When Match is Tie
39

When Player 'X' Won
7
When Match is Tie
98
When Match is Tie
3700
When Match is Tie
39

    

When Match is Tie
41

 

    05

    07

When Player 'X' Won
709

When Player 'X' Won
7
When Match is Tie
67
When Match is Tie
3713
When Match is Tie
39

When Player 'X' Won
7
When Match is Tie
72
When Match is Tie
3718
When Match is Tie
39

When Player 'X' Won
7
When Match is Tie
82
When Match is Tie
37
When Match is Tie
84
When Match is Tie
85 25

When Player 'X' Won
7
When Match is Tie
77
When Match is Tie
37
When Match is Tie
79
When Match is Tie
39

When Player 'X' Won
7
When Match is Tie
8933
When Match is Tie
39

When Player 'X' Won
736
When Match is Tie
3738
When Match is Tie
55

head94142

When Match is Tie
5544
When Match is Tie
39

 

When Player 'X' Won
74748

When Player 'X' Won
7
When Match is Tie
33
When Match is Tie
3752
When Match is Tie
39

When Player 'X' Won
7
When Match is Tie
36
When Match is Tie
3757
When Match is Tie
39

When Player 'X' Won
760
When Match is Tie
3762
When Match is Tie
39

    

When Match is Tie
41

 

    67

    6970

When Match is Tie
31

When Player 'X' Won
736
When Match is Tie
3738
When Match is Tie
55

head94142

When Match is Tie
5544
When Match is Tie
39

 

When Player 'X' Won
7
When Match is Tie
3348

When Player 'X' Won
7
When Match is Tie
36
When Match is Tie
3757
When Match is Tie
39

    

When Match is Tie
41

 

    94

    96

When Player 'X' Won
7
When Match is Tie
98
When Match is Tie
3700
When Match is Tie
39

    

When Match is Tie
41

 

      05

      07

When Player 'X' Won
736
When Match is Tie
3738
When Match is Tie
55

head94142

When Match is Tie
5544
When Match is Tie
39

head

When Player 'X' Won
7
When Match is Tie
3348

When Player 'X' Won
7
When Match is Tie
36
When Match is Tie
37  26
When Match is Tie
39

    

When Match is Tie
41

  30

Filename: tic.js 

JavaScript




  31

  32   33

 

      35

      37   38

      40

When Player 'X' Won
24  42

      44

When Player 'X' Won
39  42

      48

When Player 'X' Won
54  42

      52

When Player 'X' Won
75  42

      56

When Player 'X' Won
90  42

      60

When Player '0' Won
05  42

      64

When Player '0' Won
26  42

      68

When Player '0' Won
41  42

      72

When Player '0' Won
56  42

 

      76

      78

      80   81  82   83  84  85  82   87

When Player 'X' Won
7  89  84  91  82   93  84  95

When Player 'X' Won
7  97  98  99

head9

Chủ Đề