Skip to content

Commit 47db0fc

Browse files
Start refactoring JS
1 parent 6598898 commit 47db0fc

File tree

7 files changed

+428
-375
lines changed

7 files changed

+428
-375
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# hexchess
1+
# Hexchess
22

33
A web app for hexagonal chess (chexss)
44

5-
It's [live](https://hexchess.dev)!
5+
It's live: [https://hexchess.dev](https://hexchess.dev)!
66

77
Read more about it on my [blog post](https://anderserver.ddns.net/blog/2023/8)
88

index.html

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,45 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<meta name="color-scheme" content="dark" />
7+
<meta name="theme-color" content="#994DE6" />
8+
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
9+
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
10+
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
11+
<link rel="manifest" href="/site.webmanifest" />
12+
<meta property="og:type" content="website" />
13+
<meta property="og:url" content="https://theonlytechnohead.github.io/Hexchess" />
14+
<meta property="og:title" content="Hexchess" />
15+
<meta property="og:description" content="♟ Hexagonal chess in a browser!" />
16+
<meta name="description" content="♟ Hexagonal chess in a browser!" />
17+
<title>Hexchess</title>
18+
<link rel="stylesheet" href="index.css" />
19+
<link rel="stylesheet" href="css/hex.css" />
20+
<link rel="stylesheet" href="css/print.css" media="print" />
21+
<script type="module" src="js/play.js"></script>
22+
</head>
323

4-
<head>
5-
<meta charset="UTF-8">
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<meta name="color-scheme" content="dark">
8-
<meta name="theme-color" content="#994DE6">
9-
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
10-
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
11-
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
12-
<link rel="manifest" href="/site.webmanifest">
13-
<meta property="og:type" content="website">
14-
<meta property="og:url" content="https://theonlytechnohead.github.io/Hexchess">
15-
<meta property="og:title" content="Hexchess">
16-
<meta property="og:description" content="♟ Hexagonal chess in a browser!">
17-
<meta name="description" content="♟ Hexagonal chess in a browser!">
18-
<title>Hexchess</title>
19-
<link rel="stylesheet" href="index.css">
20-
<link rel="stylesheet" href="hex.css">
21-
<link rel="stylesheet" href="print.css" media="print">
22-
<script src="play.js"></script>
23-
</head>
24-
25-
<body>
26-
<header>
27-
<h1><span></span> Hexchess</h1>
28-
<p>Inspired by <a href="https://www.youtube.com/watch?v=bgR3yESAEVE">CGP Grey</a>.</p>
29-
</header>
30-
<main>
31-
<button id="play" onclick="play();">Play!</button>
32-
</main>
33-
<footer>
34-
<p>© Craig Anderson (<a href="https://discord.gg/zaRuA8n4tm">Discord</a>)</p>
35-
<p>v1.2 (<a href="https://github.com/theonlytechnohead/Hexchess">source</a>) (<a href="https://anderserver.ddns.net/blog/2023/8">story</a>)</p>
36-
</footer>
37-
</body>
38-
39-
</html>
24+
<body>
25+
<header>
26+
<h1><span></span> Hexchess</h1>
27+
<p>
28+
Inspired by
29+
<a href="https://www.youtube.com/watch?v=bgR3yESAEVE">CGP Grey</a>
30+
</p>
31+
</header>
32+
<main>
33+
<button id="play" onclick="play();">Play!</button>
34+
</main>
35+
<footer>
36+
<p>© Craig Anderson</p>
37+
<p>
38+
v1.2.1 (<a href="https://github.com/theonlytechnohead/Hexchess">source</a>) (<a
39+
href="https://anderserver.ddns.net/blog/2023/8"
40+
>story</a
41+
>) (<a href="https://discord.gg/zaRuA8n4tm">discord</a>)
42+
</p>
43+
</footer>
44+
</body>
45+
</html>

js/black.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export const blackKing = "♚";
2+
export const blackQueen = "♛";
3+
export const blackRook = "♜";
4+
export const blackBishop = "♝";
5+
export const blackKnight = "♞";
6+
export const blackPawn = "♟︎";
7+
8+
export const blackEnds = [
9+
[0, 2],
10+
[1, 2],
11+
[1, 3],
12+
[2, 1],
13+
[2, 3],
14+
[3, 1],
15+
[3, 4],
16+
[5, 1],
17+
[5, 4],
18+
[5, 0],
19+
[5, 5],
20+
];
21+
22+
export const blackPawns = [
23+
[4, 0],
24+
[4, 4],
25+
[5, 1],
26+
[5, 4],
27+
[6, 1],
28+
[6, 3],
29+
[7, 2],
30+
[7, 3],
31+
[8, 2],
32+
];
33+
34+
export const blackPieces = [blackKing, blackQueen, blackRook, blackBishop, blackKnight, blackPawn];

js/board.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import {
2+
whiteKing,
3+
whiteQueen,
4+
whiteRook,
5+
whiteKnight,
6+
whiteBishop,
7+
whitePawn,
8+
whitePieces,
9+
} from "./white.js";
10+
11+
import {
12+
blackKing,
13+
blackQueen,
14+
blackRook,
15+
blackKnight,
16+
blackBishop,
17+
blackPawn,
18+
blackPieces,
19+
} from "./black.js";
20+
21+
export function getBoard() {
22+
return document.getElementsByTagName("board")[0];
23+
}
24+
25+
function setPieceRaw(row, column, piece) {
26+
let board = getBoard();
27+
let r = board.children[row];
28+
let h = r.children[column];
29+
let p = h.children[0];
30+
p.textContent = piece;
31+
if (blackPieces.includes(piece)) p.classList.add("black");
32+
else if (whitePieces.includes(piece)) p.classList.add("white");
33+
}
34+
35+
export function setNormalBoard() {
36+
setPieceRaw(0, 2, blackBishop);
37+
setPieceRaw(1, 2, blackQueen);
38+
setPieceRaw(1, 3, blackKing);
39+
setPieceRaw(2, 1, blackKnight);
40+
setPieceRaw(2, 2, blackBishop);
41+
setPieceRaw(2, 3, blackKnight);
42+
setPieceRaw(3, 1, blackRook);
43+
setPieceRaw(3, 4, blackRook);
44+
setPieceRaw(4, 2, blackBishop);
45+
setPieceRaw(4, 0, blackPawn);
46+
setPieceRaw(4, 4, blackPawn);
47+
setPieceRaw(5, 1, blackPawn);
48+
setPieceRaw(5, 4, blackPawn);
49+
setPieceRaw(6, 1, blackPawn);
50+
setPieceRaw(6, 3, blackPawn);
51+
setPieceRaw(7, 2, blackPawn);
52+
setPieceRaw(7, 3, blackPawn);
53+
setPieceRaw(8, 2, blackPawn);
54+
55+
setPieceRaw(20, 2, whiteBishop);
56+
setPieceRaw(19, 2, whiteQueen);
57+
setPieceRaw(19, 3, whiteKing);
58+
setPieceRaw(18, 1, whiteKnight);
59+
setPieceRaw(18, 2, whiteBishop);
60+
setPieceRaw(18, 3, whiteKnight);
61+
setPieceRaw(17, 1, whiteRook);
62+
setPieceRaw(17, 4, whiteRook);
63+
setPieceRaw(16, 2, whiteBishop);
64+
setPieceRaw(16, 0, whitePawn);
65+
setPieceRaw(16, 4, whitePawn);
66+
setPieceRaw(15, 1, whitePawn);
67+
setPieceRaw(15, 4, whitePawn);
68+
setPieceRaw(14, 1, whitePawn);
69+
setPieceRaw(14, 3, whitePawn);
70+
setPieceRaw(13, 2, whitePawn);
71+
setPieceRaw(13, 3, whitePawn);
72+
setPieceRaw(12, 2, whitePawn);
73+
}
74+
75+
export function setKingsTest() {
76+
setPieceRaw(19, 2, whiteQueen);
77+
setPieceRaw(1, 3, blackKing);
78+
}

js/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const NONE = -1;
2+
export const WHITE = 0;
3+
export const BLACK = 1;

0 commit comments

Comments
 (0)