10000 initial commit · Sanoobk/github-actions-for-ci@14de496 · GitHub
[go: up one dir, main page]

Skip to content

Commit 14de496

Browse files
committed
initial commit
0 parents  commit 14de496

File tree

10 files changed

+245
-0
lines changed

10 files changed

+245
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
package-lock.json
3+
public/*.js

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 The GitHub Training Team
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Tic Tac Toe Game
2+
3+
Learn GitHub Actions through a fun little game.

babel.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
targets: {
7+
node: 'current'
8+
}
9+
}
10+
]
11+
]
12+
}

index.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title>TicTacToe</title>
8+
9+
<link href="public/index.css" type="text/css" rel="stylesheet" />
10+
<script src="public/game.js"></script>
11+
</head>
12+
<body>
13+
<div id="app">
14+
<div>
15+
<h2 id="turn">It's <span id="player"></span>'s turn!</h2>
16+
</div>
17+
<table>
18+
<tr"0">
19+
<td class="0 0"></td>
20+
<td class="0 1"></td>
21+
<td class="0 2"></td>
22+
</tr>
23+
<tr>
24+
<td class="1 0"></td>
25+
<td class="1 1"></td>
26+
<td class="1 2"></td>
27+
</tr>
28+
<tr>
29+
<td class="2 0"></td>
30+
<td class="2 1"></td>
31+
<td class="2 2"></td>
32+
</tr>
33+
</table>
34+
</div>
35+
</body>
36+
</html>

package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "actions-template",
3+
"version": "1.0.0",
4+
"description": "Learn how to use GitHub Actions!",
5+
"main": "index.js",
6+
"directories": {
7+
"test": "__test__",
8+
"src": "src"
9+
},
10+
"scripts": {
11+
"build": "npx webpack --config ./src/webpack.config.js --mode production",
12+
"dev": "npx webpack --config ./src/webpack.config.js --mode development --watch",
13+
"test": "npx standard && npx jest"
14+
},
15+
"author": "githubtraining",
16+
"license": "MIT",
17+
"standard": {
18+
"env": [
19+
"jest",
20+
"browser"
21+
]
22+
},
23+
"devDependencies": {
24+
"@babel/core": "^7.2.2",
25+
"@babel/preset-env": "^7.2.3",
26+
"@babel/register": "^7.0.0",
27+
"babel-jest": "^24.9.0",
28+
"babel-loader": "^8.0.5",
29+
"html-webpack-plugin": "^3.2.0",
30+
"script-ext-html-webpack-plugin": "^2.1.3",
31+
"standard": "^14.3.1",
32+
"webpack": "^4.28.4",
33+
"webpack-cli": "^3.2.1",
34+
"webpack-dev-server": "^3.1.14"
35+
},
36+
"dependencies": {}
37+
}

public/index.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
table {
2+
border-collapse: collapse;
3+
}
4+
5+
table td {
6+
min-height: 100px;
7+
min-width: 100px;
8+
height: 100px;
9+
width: 100px;
10+
text-align: center;
11+
12+
font-size: 4em;
13+
border: thin solid black;
14+
}
15+
16+
table td:hover {
17+
background: #CCCCCC;
18+
}
19+
20+
table tr {
21+
width: 300px;
22+
height: 100px;
23+
}
24+
25+
#app {
26+
margin: auto;
27+
width: 60%;
28+
}

src/game.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
export default class Game {
2+
constructor (p1, p2) {
3+
this.p1 = p1
4+
this.p2 = p2
5+
this.board = [[null, null, null], [null, null, null], [null, null, null]]
6+
this.player = Math.random() < 0.5 ? this.p1 : this.p2
7+
this.sym = 'X'
8+
}
9+
10+
turn (row, col) {
11+
col = col || row
12+
this.board[row][col] = this.sym
13+
}
14+
15+
nextPlayer () {
16+
this.player = this.player === this.p1 ? this.p2 : this.p1
17+
this.sym = this.sym === 'X' ? 'O' : 'X'
18+
}
19+
20+
hasWinner () {
21+
return this.rowWin() || this.colWin() || this.diagWin()
22+
}
23+
24+
rowWin () {
25+
let win = false
26+
for (let r = 0; r < 3; r++) {
27+
const row = this.board[r]
28+
if (row[0] === null) { continue }
29+
win = win || (row[0] === row[1] && row[0] === row[2])
30+
}
31+
32+
return win
33+
}
34+
35+
colWin () {
36+
let win = false
37+
for (let c = 0; c < 3; c++) {
38+
const col = this.board
39+
if (col[0][c] === null) { continue }
40+
win = win || (col[0][c] === col[1][c] && col[0][c] === col[2][c])
41+
}
42+
43+
return win
44+
}
45+
46+
diagWin () {
47+
const b = this.board
48+
return ((b[0][0] !== null && b[0][0] === b[1][1] && b[0][0] === b[2][2]) ||
49+
(b[0][2] !== null && b[0][2] === b[1][1] && b[0][2] === b[2][0]))
50+
}
51+
}

src/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Game from './game.js'
2+
3+
let p1, p2
4+
while (!p1) {
5+
p1 = window.prompt('Enter player 1 name:')
6+
}
7+
8+
while (!p2 && p1 !== p2) {
9+
p2 = window.prompt(p1 === p2
10+
? `Please enter a different name than ${p1}.`
11+
: 'Enter player 2 name:')
12+
}
13+
14+
window.onload = () => {
15+
const game = new Game(p1, p2)
16+
const turn = document.getElementById('turn')
17+
const player = document.getElementById('player')
18+
player.innerText = game.player
19+
20+
document.querySelectorAll('td').forEach((el) => {
21+
el.onclick = (evt) => {
22+
el.onclick = undefined
23+
evt.target.innerText = game.sym
24+
evt.target.onclick = undefined
25+
26+
const [row, col] = evt.target.classList
27+
game.turn(row, col)
28+
29+
if (game.hasWinner()) {
30+
turn.innerText = `${game.player} wins!`
31+
document.querySelectorAll('td').forEach(el => {
32+
el.onclick = undefined
33+
})
34+
} else {
35+
game.nextPlayer()
36+
player.innerText = game.player
37+
}
38+
}
39+
})
40+
}

src/webpack.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const path = require('path')
2+
3+
module.exports = {
4+
entry: {
5+
'main.js': [
6+
path.resolve(__dirname, 'index.js'),
7+
path.resolve(__dirname, 'game.js')
8+
]
9+
},
10+
output: {
11+
filename: 'main.js',
12+
path: path.resolve(__dirname, '../public')
13+
}
14+
}

0 commit comments

Comments
 (0)
0