SC CODE: Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "index.html")
31 STORE("descrHdr", "tic_tac_toe index.html")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "tic_tac_toe.doc")
34 STORE("docType", "TELA-HTML-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "2e05dcd4992615cf3b956a5f0affe20ef5a25825da16be6ad3cb9914ce846d8f")
37 STORE("fileCheckS", "35bb19036dff0253c9bfddb233d5a17dc19f7422bf12851ba53ce3fd1e8a39c")
100 RETURN 0
End Function
Function init() Uint64
10 IF EXISTS("owner") == 0 THEN GOTO 30
20 RETURN 1
30 STORE("owner", address())
50 STORE("docVersion", "1.0.0")
60 STORE("hash", HEX(TXID()))
70 STORE("likes", 0)
80 STORE("dislikes", 0)
100 RETURN 0
End Function
Function address() String
10 DIM s as String
20 LET s = SIGNER()
30 IF IS_ADDRESS_VALID(s) THEN GOTO 50
40 RETURN "anon"
50 RETURN ADDRESS_STRING(s)
End Function
Function Rate(r Uint64) Uint64
10 DIM addr as String
15 LET addr = address()
16 IF r < 100 && EXISTS(addr) == 0 && addr != "anon" THEN GOTO 30
20 RETURN 1
30 STORE(addr, ""+r+"_"+BLOCK_HEIGHT())
40 IF r < 50 THEN GOTO 70
50 STORE("likes", LOAD("likes")+1)
60 RETURN 0
70 STORE("dislikes", LOAD("dislikes")+1)
100 RETURN 0
End Function
/*
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="/tic_tac_toe.svg" type="image/svg">
<title>Tic-Tac-Toe</title>
<style>
body {
text-align: center;
font-family: Arial, sans-serif;
}
.board {
display: grid;
grid-template-columns: repeat(3, 100px);
grid-gap: 5px;
width: 310px;
margin: 20px auto;
}
.cell {
width: 100px;
height: 100px;
display: flex;
align-items: center;
justify-content: center;
font-size: 2em;
background: #eee;
cursor: pointer;
border: 2px solid #333;
}
.cell.taken {
cursor: not-allowed;
}
#status {
font-size: 1.5em;
margin: 10px;
}
button {
margin-top: 10px;
padding: 10px;
font-size: 1em;
cursor: pointer;
}
select {
font-size: 1em;
padding: 5px;
margin-top: 20px;
}
</style>
</head>
<body>
<h1>Tic-Tac-Toe</h1>
<img src="/tic_tac_toe.svg" alt="Tic Tac Toe" width="200">
<div>
<label for="gameMode">Choose Game Mode:</label>
<select id="gameMode">
<option value="human">Player vs Player</option>
<option value="bot">Player vs Bot</option>
</select>
</div>
<div id="status">Player X's turn</div>
<div class="board" id="board"></div>
<button onclick="resetGame()">Restart</button>
<script>
const board = document.getElementById("board");
const status = document.getElementById("status");
const gameModeSelect = document.getElementById("gameMode");
let currentPlayer = "X";
let gameBoard = Array(9).fill(null);
let gameMode = "human";
gameModeSelect.addEventListener("change", () => {
gameMode = gameModeSelect.value;
resetGame();
});
function checkWinner() {
const winningCombos = [
[0, 1, 2], [3, 4, 5], [6, 7, 8],
[0, 3, 6], [1, 4, 7], [2, 5, 8],
[0, 4, 8], [2, 4, 6]
];
for (const [a, b, c] of winningCombos) {
if (gameBoard[a] && gameBoard[a] === gameBoard[b] && gameBoard[a] === gameBoard[c]) {
status.innerText = "Player " + gameBoard[a] + " Wins!";
document.querySelectorAll(".cell").forEach(cell => cell.classList.add("taken"));
return true;
}
}
if (!gameBoard.includes(null)) {
status.innerText = "It's a draw!";
return true;
}
return false;
}
function botMove() {
if (checkWinner()) return;
let availableSpots = gameBoard.map((val, idx) => val === null ? idx : null).filter(val => val !== null);
if (availableSpots.length === 0) return;
let botChoice = availableSpots[Math.floor(Math.random() * availableSpots.length)];
gameBoard[botChoice] = "O";
let botCell = document.querySelector("[data-index='" + botChoice + "']");
botCell.innerText = "O";
botCell.classList.add("taken");
if (!checkWinner()) {
currentPlayer = "X";
status.innerText = "Player X's turn";
}
}
function handleClick(event) {
const index = event.target.dataset.index;
if (gameBoard[index] || event.target.classList.contains("taken") || (gameMode === "bot" && currentPlayer === "O")) return;
gameBoard[index] = currentPlayer;
event.target.innerText = currentPlayer;
event.target.classList.add("taken");
if (!checkWinner()) {
if (currentPlayer === "X") {
currentPlayer = "O";
status.innerText = gameMode === "bot" ? "Bot's turn" : "Player O's turn";
if (gameMode === "bot") {
setTimeout(botMove, 500);
}
} else {
currentPlayer = "X";
status.innerText = "Player X's turn";
}
}
}
function resetGame() {
gameBoard.fill(null);
currentPlayer = "X";
status.innerText = "Player X's turn";
board.innerHTML = "";
for (let i = 0; i < 9; i++) {
const cell = document.createElement("div");
cell.classList.add("cell");
cell.dataset.index = i;
cell.addEventListener("click", handleClick);
board.appendChild(cell);
}
if (gameMode === "bot" && currentPlayer === "O") {
setTimeout(botMove, 500);
}
}
resetGame();
</script>
</body>
<footer style="display: flex; justify-content: center; align-items: center; padding: 10px;">
<p style="font-size: 14px; margin: 0;">
Donate:
<span style="font-family: monospace; background-color: #e9ecef; padding: 3px 6px; border-radius: 4px;">
dero1qyqmgwqq8v3mc7guyp2ha0rcven9k8p7h655y33k5vgkg8sv5ka2zqqkxfr40
</span>
</p>
</footer>
</html>
*/ |
SC Arguments: [Name:SC_ACTION Type:uint64 Value:'1' Name:SC_CODE Type:string Value:'Function InitializePrivate() Uint64
10 IF init() == 0 THEN GOTO 30
20 RETURN 1
30 STORE("nameHdr", "index.html")
31 STORE("descrHdr", "tic_tac_toe index.html")
32 STORE("iconURLHdr", "")
33 STORE("dURL", "tic_tac_toe.doc")
34 STORE("docType", "TELA-HTML-1")
35 STORE("subDir", "")
36 STORE("fileCheckC", "2e05dcd4992615cf3b956a5f0affe20ef5a25825da16be6ad3cb9914ce846d8f")
37 STORE("fileCheckS", "35bb19036dff0253c9bfddb233d5a17dc19f7422bf12851ba53ce3fd1e8a39c")
100 RETURN 0
End Function
Function init() Uint64
10 IF EXISTS("owner") == 0 THEN GOTO 30
20 RETURN 1
30 STORE("owner", address())
50 STORE("docVersion", "1.0.0")
60 STORE("hash", HEX(TXID()))
70 STORE("likes", 0)
80 STORE("dislikes", 0)
100 RETURN 0
End Function
Function address() String
10 DIM s as String
20 LET s = SIGNER()
30 IF IS_ADDRESS_VALID(s) THEN GOTO 50
40 RETURN "anon"
50 RETURN ADDRESS_STRING(s)
End Function
Function Rate(r Uint64) Uint64
10 DIM addr as String
15 LET addr = address()
16 IF r < 100 && EXISTS(addr) == 0 && addr != "anon" THEN GOTO 30
20 RETURN 1
30 STORE(addr, ""+r+"_"+BLOCK_HEIGHT())
40 IF r < 50 THEN GOTO 70
50 STORE("likes", LOAD("likes")+1)
60 RETURN 0
70 STORE("dislikes", LOAD("dislikes")+1)
100 RETURN 0
End Function
/*
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="/tic_tac_toe.svg" type="image/svg">
<title>Tic-Tac-Toe</title>
<style>
body {
text-align: center;
font-family: Arial, sans-serif;
}
.board {
display: grid;
grid-template-columns: repeat(3, 100px);
grid-gap: 5px;
width: 310px;
margin: 20px auto;
}
.cell {
width: 100px;
height: 100px;
display: flex;
align-items: center;
justify-content: center;
font-size: 2em;
background: #eee;
cursor: pointer;
border: 2px solid #333;
}
.cell.taken {
cursor: not-allowed;
}
#status {
font-size: 1.5em;
margin: 10px;
}
button {
margin-top: 10px;
padding: 10px;
font-size: 1em;
cursor: pointer;
}
select {
font-size: 1em;
padding: 5px;
margin-top: 20px;
}
</style>
</head>
<body>
<h1>Tic-Tac-Toe</h1>
<img src="/tic_tac_toe.svg" alt="Tic Tac Toe" width="200">
<div>
<label for="gameMode">Choose Game Mode:</label>
<select id="gameMode">
<option value="human">Player vs Player</option>
<option value="bot">Player vs Bot</option>
</select>
</div>
<div id="status">Player X's turn</div>
<div class="board" id="board"></div>
<button onclick="resetGame()">Restart</button>
<script>
const board = document.getElementById("board");
const status = document.getElementById("status");
const gameModeSelect = document.getElementById("gameMode");
let currentPlayer = "X";
let gameBoard = Array(9).fill(null);
let gameMode = "human";
gameModeSelect.addEventListener("change", () => {
gameMode = gameModeSelect.value;
resetGame();
});
function checkWinner() {
const winningCombos = [
[0, 1, 2], [3, 4, 5], [6, 7, 8],
[0, 3, 6], [1, 4, 7], [2, 5, 8],
[0, 4, 8], [2, 4, 6]
];
for (const [a, b, c] of winningCombos) {
if (gameBoard[a] && gameBoard[a] === gameBoard[b] && gameBoard[a] === gameBoard[c]) {
status.innerText = "Player " + gameBoard[a] + " Wins!";
document.querySelectorAll(".cell").forEach(cell => cell.classList.add("taken"));
return true;
}
}
if (!gameBoard.includes(null)) {
status.innerText = "It's a draw!";
return true;
}
return false;
}
function botMove() {
if (checkWinner()) return;
let availableSpots = gameBoard.map((val, idx) => val === null ? idx : null).filter(val => val !== null);
if (availableSpots.length === 0) return;
let botChoice = availableSpots[Math.floor(Math.random() * availableSpots.length)];
gameBoard[botChoice] = "O";
let botCell = document.querySelector("[data-index='" + botChoice + "']");
botCell.innerText = "O";
botCell.classList.add("taken");
if (!checkWinner()) {
currentPlayer = "X";
status.innerText = "Player X's turn";
}
}
function handleClick(event) {
const index = event.target.dataset.index;
if (gameBoard[index] || event.target.classList.contains("taken") || (gameMode === "bot" && currentPlayer === "O")) return;
gameBoard[index] = currentPlayer;
event.target.innerText = currentPlayer;
event.target.classList.add("taken");
if (!checkWinner()) {
if (currentPlayer === "X") {
currentPlayer = "O";
status.innerText = gameMode === "bot" ? "Bot's turn" : "Player O's turn";
if (gameMode === "bot") {
setTimeout(botMove, 500);
}
} else {
currentPlayer = "X";
status.innerText = "Player X's turn";
}
}
}
function resetGame() {
gameBoard.fill(null);
currentPlayer = "X";
status.innerText = "Player X's turn";
board.innerHTML = "";
for (let i = 0; i < 9; i++) {
const cell = document.createElement("div");
cell.classList.add("cell");
cell.dataset.index = i;
cell.addEventListener("click", handleClick);
board.appendChild(cell);
}
if (gameMode === "bot" && currentPlayer === "O") {
setTimeout(botMove, 500);
}
}
resetGame();
</script>
</body>
<footer style="display: flex; justify-content: center; align-items: center; padding: 10px;">
<p style="font-size: 14px; margin: 0;">
Donate:
<span style="font-family: monospace; background-color: #e9ecef; padding: 3px 6px; border-radius: 4px;">
dero1qyqmgwqq8v3mc7guyp2ha0rcven9k8p7h655y33k5vgkg8sv5ka2zqqkxfr40
</span>
</p>
</footer>
</html>
*/'] |