Skip to content

Commit ff37fad

Browse files
authored
Merge pull request #5 from Cyrus-Kiprop/feature/testing
Feature/testing
2 parents acc281c + cec3b07 commit ff37fad

14 files changed

+18942
-2426
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
jest.config.js

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules/
2+
yarn-error.log

README.md

Lines changed: 74 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,74 @@ In this project,we are building a Tic Tac Toe game made on Javascript.The tic-ta
3131

3232
## Built With
3333

34+
```sh
35+
Front-End(client)
36+
```
37+
3438
- HTML + CSS
3539
- JavaScript
3640
- Bootstrap
3741

42+
```sh
43+
Testing Frameworks
44+
```
45+
46+
- Jest
47+
3848
## Getting Started
3949

40-
To get started with the app, cd to the directory where you would like the repo to live by typing on your terminal:
50+
To get a local copy up and running follow these simple example steps.
51+
52+
### Prerequisites
53+
54+
- Node
55+
56+
- Basic knowledge of npm/yarn
57+
58+
### Installation
4159

42-
Clone the repo typing:
60+
1. Clone the repo
4361

62+
```sh
63+
git clone https://github.com/Cyrus-Kiprop/Javascript-Tic-Tac-Toe.git
4464
```
45-
$git clone https://github.com/Cyrus-Kiprop/Javascript-Tic-Tac-Toe.git
65+
66+
2. CD into the project root directory
67+
68+
```sh
69+
cd ./Javascript-Tic-Tac-Toe.git
70+
```
71+
72+
3. Install Dependencies and packages
73+
74+
```sh
75+
npm install
4676
```
4777

78+
4. Build the files
79+
80+
```sh
81+
npm run build
82+
```
83+
84+
<!-- USAGE EXAMPLES -->
85+
86+
## Usage
87+
88+
Open the index.html file using live servers.
89+
90+
```sh
91+
right click on index.html file and open it with the browser or with live server.
92+
```
93+
94+
### Navigate to your browser and open port 8080 (use your live server port):
95+
96+
```JS
97+
http//localhost:8080
98+
```
99+
100+
### Enjoy the game
101+
48102
# Rules
49103

50104
1. The game is played on a grid that's 3 squares by 3 squares.
@@ -81,6 +135,22 @@ The match is over if the winnning critera is met, or else the match will be a dr
81135
Reset - The data of Players will be not saved and the user need to provide the entire data once more at the beggining.
82136
Restart- The player is taken back to thr board, and the players can replay the game.
83137

138+
## Roadmap
139+
140+
See the [open issues](https://github.com/Cyrus-Kiprop/Javascript-Tic-Tac-Toe/issues) for a list of proposed features (and known issues).
141+
142+
<!-- CONTRIBUTING -->
143+
144+
## Contributing
145+
146+
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.
147+
148+
1. Fork the Project
149+
2. Create your Feature Branch (`git checkout -b feature/NewAwesomeFeature`)
150+
3. Commit your Changes (`git commit -m 'Add some NewAmazingFeature'`)
151+
4. Push to the Branch (`git push origin feature/NewAmazingFeature`)
152+
5. Open a Pull Request
153+
84154
## Authors
85155

86156
👤 **Cyrus Kiprop**
@@ -94,12 +164,6 @@ Restart- The player is taken back to thr board, and the players can replay the g
94164
- Github: [@ShubhamRaj](https://github.com/shubham14p3)
95165
- Linkedin: [Shubham14p3](https://www.linkedin.com/in/shubham14p3/)
96166

97-
## 🤝 Contributing
98-
99-
Contributions, issues and feature requests are welcome!
100-
101-
Feel free to check the [issues page](https://github.com/Cyrus-Kiprop/Javascript-Tic-Tac-Toe/issues/).
102-
103167
## Show your support
104168

105169
Give a ⭐️ if you like this project!
@@ -108,7 +172,7 @@ Give a ⭐️ if you like this project!
108172

109173
- Project requested by [Microverse Program](https://www.microverse.org/).
110174

111-
## Future Enhancement
175+
## Future Enhancement
112176

113177
- Adding Validation.
114178
- Adding AI Logic.

assets/js/index.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// using the object oriented way
1+
import '../styles/reset.css';
2+
import '../styles/main.css';
23

34
const boardUtils = (function boardUtils() {
45
const WINNING_COMBINATIONS = [
@@ -17,15 +18,14 @@ const boardUtils = (function boardUtils() {
1718
}());
1819

1920
const gameUtils = (function gameUtils() {
20-
const container = document.getElementById('container');
21-
2221
const winningMessage = (player) => winDrawUI(`Congratulation ${player} is the winner!!`);
2322

2423
const drawMessage = () => winDrawUI("It's a draw ");
2524

2625
const handleGameReset = () => window.location.reload();
2726

2827
const winDrawUI = (message) => {
28+
const container = document.getElementById('container');
2929
const div = document.createElement('div');
3030
div.setAttribute('class', 'bg-dark');
3131
const hide = document.getElementById('hide');
@@ -68,16 +68,19 @@ const gameUtils = (function gameUtils() {
6868
}());
6969

7070
const form = document.getElementById('welcome-form');
71-
form.addEventListener('submit', (event) => {
72-
const player1 = document.getElementById('player-one-name').value || 'player1';
73-
const player2 = document.getElementById('player-two-name').value || 'player2';
74-
const board = document.getElementById('play-area');
75-
event.preventDefault();
76-
form.classList.toggle('none');
77-
board.classList.toggle('none');
78-
79-
const game = new TicTacToe(player1, player2);
80-
game.start();
71+
72+
document.addEventListener('DOMContentLoaded', () => {
73+
form.addEventListener('submit', (event) => {
74+
const player1 = document.getElementById('player-one-name').value || 'player1';
75+
const player2 = document.getElementById('player-two-name').value || 'player2';
76+
const board = document.getElementById('play-area');
77+
event.preventDefault();
78+
form.classList.toggle('none');
79+
board.classList.toggle('none');
80+
81+
const game = new TicTacToe(player1, player2);
82+
game.start();
83+
});
8184
});
8285

8386
function TicTacToe(player1, player2) {
@@ -142,6 +145,7 @@ function Player(name, board, signature) {
142145

143146
this.myTurn = function myTurn() {
144147
board.cells.forEach((cell) => {
148+
cell.setAttribute('data-clickable', 'true');
145149
if (cell.innerHTML === '') {
146150
cell.addEventListener('click', makeMove);
147151
}
@@ -151,9 +155,11 @@ function Player(name, board, signature) {
151155
const { target } = event;
152156
target.innerText = this.signature;
153157
board.cells.forEach((element) => {
158+
element.setAttribute('data-clickable', 'true');
154159
element.removeEventListener('click', makeMove, { useCapture: true });
155160
});
156161
};
162+
this.playerMove = makeMove;
157163
}
158164

159165
function Board() {
@@ -167,7 +173,7 @@ function Board() {
167173
boardUtils.WINNING_COMBINATIONS.forEach((combination) => {
168174
const firstCell = positions[combination[0]].innerText;
169175
const secondCell = positions[combination[1]].innerText;
170-
const thirdCell = positions[combination[2]].innerText;
176+
const thirdCell = positions[combination[2]].innerText || '';
171177

172178
const confirmWin = firstCell !== ''
173179
&& secondCell === firstCell
@@ -191,3 +197,12 @@ function Board() {
191197
});
192198
};
193199
}
200+
201+
const game = {
202+
Board,
203+
Player,
204+
gameUtils,
205+
boardUtils,
206+
};
207+
208+
export default game;

babel.config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/preset-env"]
3+
}

dist/app.bundle.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html renamed to dist/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ <h2 class="mb-4 mt-5">Tic-Tac-Toe Game</h2>
5555
</div>
5656
</div>
5757
</div>
58-
<script src="./assets/js/index.js"></script>
58+
<script src="app.bundle.js"></script>
5959
</body>
6060
</html>

0 commit comments

Comments
 (0)