actually reset player, show win count

This commit is contained in:
mehbark 2023-03-29 19:20:55 -04:00
parent 30f147095d
commit beb4183088
3 changed files with 56 additions and 11 deletions

View file

@ -28,13 +28,13 @@
width: calc(min(90vw, 90vh)); width: calc(min(90vw, 90vh));
height: calc(min(90vw, 90vh)); height: calc(min(90vw, 90vh));
} }
#game-over, #stats, #copy-stats, #play-again { #game-over, #stats, #copy-stats, #play-again, #win-count {
display: none; display: none;
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
} }
#game-over { #game-over, #win-count {
text-align: center; text-align: center;
width: 100%; width: 100%;
} }
@ -157,4 +157,6 @@
<a href="https://pl.pyrope.net/terezi">me</a> <a href="https://pl.pyrope.net/terezi">me</a>
</footer> </footer>
</body> </body>
<div id="win-count"></div>
</html> </html>

25
main.js
View file

@ -1,4 +1,3 @@
var _a;
import { Chess, Ox88, DEFAULT_POSITION, SQUARES, rank, file, WHITE, BLACK, KING, } from "./chess.js"; import { Chess, Ox88, DEFAULT_POSITION, SQUARES, rank, file, WHITE, BLACK, KING, } from "./chess.js";
function with_move(board, move) { function with_move(board, move) {
let new_board = new Chess(board.fen()); let new_board = new Chess(board.fen());
@ -621,8 +620,13 @@ function find_specified_in_hash() {
} }
// bad // bad
// const todays_player = players[days_since_epoch() % players.length]; // const todays_player = players[days_since_epoch() % players.length];
const todays_player = (_a = find_specified_in_hash()) !== null && _a !== void 0 ? _a : players[Math.floor(Math.random() * players.length)]; function get_todays_player() {
console.log(`SPOILER: today's player is ${todays_player.name}`); var _a;
let player = (_a = find_specified_in_hash()) !== null && _a !== void 0 ? _a : players[Math.floor(Math.random() * players.length)];
console.log(`SPOILER: "today"'s player is ${player.name}`);
return player;
}
var todays_player = get_todays_player();
// const todays_player = min_oppt_move; // const todays_player = min_oppt_move;
var board = document.getElementById("board"); var board = document.getElementById("board");
var game = new Chess(); var game = new Chess();
@ -639,6 +643,7 @@ function show_game_over() {
console.log("GAME OVER"); console.log("GAME OVER");
} }
function show_win() { function show_win() {
wins++;
let game_over = document.getElementById("game-over"); let game_over = document.getElementById("game-over");
game_over.style.display = "block"; game_over.style.display = "block";
game_over.innerText = "YOU WIN YOU WIN YOU WIN YOU WIN HOLY CRAP"; game_over.innerText = "YOU WIN YOU WIN YOU WIN YOU WIN HOLY CRAP";
@ -693,10 +698,23 @@ function append_players_to(n) {
n.appendChild(child); n.appendChild(child);
} }
} }
var wins = 0;
// extraordinarily necessary
function wins_exclamation_marks() {
let wins_divided_by_ten = Math.floor(wins / 10);
return wins_divided_by_ten > 0 ? "!".repeat(wins_divided_by_ten) : ".";
}
// ERROR: ! // ERROR: !
// INELEGANT // INELEGANT
// "HACK"! // "HACK"!
function reset() { function reset() {
let play_again = document.getElementById("play-again");
play_again.style.display = "none";
play_again.onclick = _ => console.log("you can't play again again sorry :]");
let win_count = document.getElementById("win-count");
win_count.style.display = "block";
win_count.innerText = `You have won ${wins} time${wins > 1 ? "s" : ""}${wins_exclamation_marks()}`;
todays_player = get_todays_player();
game = new Chess(); game = new Chess();
board.fen = game.fen(); board.fen = game.fen();
board.turn = "white"; board.turn = "white";
@ -712,7 +730,6 @@ function reset() {
stats.innerHTML = ""; stats.innerHTML = "";
stats.style.display = "none"; stats.style.display = "none";
document.getElementById("copy-stats").style.display = "none"; document.getElementById("copy-stats").style.display = "none";
document.getElementById("play-again").style.display = "none";
document.getElementById("game-over").style.display = "none"; document.getElementById("game-over").style.display = "none";
} }
window.addEventListener("DOMContentLoaded", () => { window.addEventListener("DOMContentLoaded", () => {

32
main.ts
View file

@ -744,11 +744,18 @@ function find_specified_in_hash(): null | {
// bad // bad
// const todays_player = players[days_since_epoch() % players.length]; // const todays_player = players[days_since_epoch() % players.length];
const todays_player = function get_todays_player() {
let player =
find_specified_in_hash() ?? find_specified_in_hash() ??
players[Math.floor(Math.random() * players.length)]; players[Math.floor(Math.random() * players.length)];
console.log(`SPOILER: today's player is ${todays_player.name}`); console.log(`SPOILER: "today"'s player is ${player.name}`);
return player;
}
var todays_player = get_todays_player();
// const todays_player = min_oppt_move; // const todays_player = min_oppt_move;
var board: any = document.getElementById("board"); var board: any = document.getElementById("board");
@ -771,6 +778,8 @@ function show_game_over() {
} }
function show_win() { function show_win() {
wins++;
let game_over = document.getElementById("game-over"); let game_over = document.getElementById("game-over");
game_over.style.display = "block"; game_over.style.display = "block";
game_over.innerText = "YOU WIN YOU WIN YOU WIN YOU WIN HOLY CRAP"; game_over.innerText = "YOU WIN YOU WIN YOU WIN YOU WIN HOLY CRAP";
@ -840,10 +849,28 @@ function append_players_to(n: Node) {
} }
} }
var wins = 0;
// extraordinarily necessary
function wins_exclamation_marks() {
let wins_divided_by_ten = Math.floor(wins / 10);
return wins_divided_by_ten > 0 ? "!".repeat(wins_divided_by_ten) : ".";
}
// ERROR: ! // ERROR: !
// INELEGANT // INELEGANT
// "HACK"! // "HACK"!
function reset() { function reset() {
let play_again = document.getElementById("play-again");
play_again.style.display = "none";
play_again.onclick = _ =>
console.log("you can't play again again sorry :]");
let win_count = document.getElementById("win-count");
win_count.style.display = "block";
win_count.innerText = `You have won ${wins} time${
wins > 1 ? "s" : ""
}${wins_exclamation_marks()}`;
todays_player = get_todays_player();
game = new Chess(); game = new Chess();
board.fen = game.fen(); board.fen = game.fen();
board.turn = "white"; board.turn = "white";
@ -864,7 +891,6 @@ function reset() {
stats.style.display = "none"; stats.style.display = "none";
document.getElementById("copy-stats").style.display = "none"; document.getElementById("copy-stats").style.display = "none";
document.getElementById("play-again").style.display = "none";
document.getElementById("game-over").style.display = "none"; document.getElementById("game-over").style.display = "none";
} }