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));
height: calc(min(90vw, 90vh));
}
#game-over, #stats, #copy-stats, #play-again {
#game-over, #stats, #copy-stats, #play-again, #win-count {
display: none;
margin-left: auto;
margin-right: auto;
}
#game-over {
#game-over, #win-count {
text-align: center;
width: 100%;
}
@ -157,4 +157,6 @@
<a href="https://pl.pyrope.net/terezi">me</a>
</footer>
</body>
<div id="win-count"></div>
</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";
function with_move(board, move) {
let new_board = new Chess(board.fen());
@ -621,8 +620,13 @@ function find_specified_in_hash() {
}
// bad
// 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)];
console.log(`SPOILER: today's player is ${todays_player.name}`);
function get_todays_player() {
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;
var board = document.getElementById("board");
var game = new Chess();
@ -639,6 +643,7 @@ function show_game_over() {
console.log("GAME OVER");
}
function show_win() {
wins++;
let game_over = document.getElementById("game-over");
game_over.style.display = "block";
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);
}
}
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: !
// INELEGANT
// "HACK"!
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();
board.fen = game.fen();
board.turn = "white";
@ -712,7 +730,6 @@ function reset() {
stats.innerHTML = "";
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";
}
window.addEventListener("DOMContentLoaded", () => {

36
main.ts
View file

@ -744,11 +744,18 @@ function find_specified_in_hash(): null | {
// bad
// const todays_player = players[days_since_epoch() % players.length];
const todays_player =
find_specified_in_hash() ??
players[Math.floor(Math.random() * players.length)];
function get_todays_player() {
let player =
find_specified_in_hash() ??
players[Math.floor(Math.random() * players.length)];
console.log(`SPOILER: "today"'s player is ${player.name}`);
return player;
}
var todays_player = get_todays_player();
console.log(`SPOILER: today's player is ${todays_player.name}`);
// const todays_player = min_oppt_move;
var board: any = document.getElementById("board");
@ -771,6 +778,8 @@ function show_game_over() {
}
function show_win() {
wins++;
let game_over = document.getElementById("game-over");
game_over.style.display = "block";
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: !
// INELEGANT
// "HACK"!
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();
board.fen = game.fen();
board.turn = "white";
@ -864,7 +891,6 @@ function reset() {
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";
}