User prompt
add a shop so you can buy skins ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
When I'm winning in tic-tac-toe, it doesn't give me a point. So when you win in tic-tac-toe, it gives the player a point and makes the X disappear. Actually, no, restart the game.
User prompt
If it is 3 in a row, give the player a point. If it is any kind of line, like a diagonal line, or a line going up, give the X a point. But if it's 4-0, don't give X a point.
User prompt
If X wins, give them one win, and if O wins, don't give X a win, and make it so if O wins, you win.
User prompt
add a menu screen that you can play multiplayer or play with an AI
User prompt
Make tic-tac-toe
Code edit (1 edits merged)
Please save this source code
User prompt
Ultimate Tic-Tac-Toe Arena
Initial prompt
can you make tic-tac-toe like better so you could have like multiplayer custom modes
/****
* Classes
****/
var TicTacToeCell = Container.expand(function (row, col) {
var self = Container.call(this);
self.row = row;
self.col = col;
self.state = 'empty'; // 'empty', 'X', 'O'
// Create border
var border = self.attachAsset('cellBorder', {
anchorX: 0.5,
anchorY: 0.5
});
// Create empty cell background
var cellBg = self.attachAsset('cellEmpty', {
anchorX: 0.5,
anchorY: 0.5
});
var symbol = null;
self.placeSymbol = function (symbolType) {
if (self.state !== 'empty') return false;
self.state = symbolType;
if (symbolType === 'X') {
symbol = self.attachAsset('symbolX', {
anchorX: 0.5,
anchorY: 0.5
});
} else if (symbolType === 'O') {
symbol = self.attachAsset('symbolO', {
anchorX: 0.5,
anchorY: 0.5
});
}
LK.getSound('placeSymbol').play();
return true;
};
self.reset = function () {
self.state = 'empty';
if (symbol) {
symbol.destroy();
symbol = null;
}
};
self.down = function (x, y, obj) {
if (gameState === 'playing' && self.state === 'empty') {
if (self.placeSymbol(currentPlayer)) {
checkWin();
if (gameState === 'playing') {
currentPlayer = currentPlayer === 'X' ? 'O' : 'X';
updateUI();
}
}
}
};
return self;
});
/****
* Initialize Game
****/
// Game variables
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var gridSize = 3;
var cells = [];
var currentPlayer = 'X';
var gameState = 'playing'; // 'playing', 'won', 'draw'
var winner = null;
// UI elements
var statusText = new Text2('Player X\'s Turn', {
size: 80,
fill: 0x333333
});
statusText.anchor.set(0.5, 0);
LK.gui.top.addChild(statusText);
var resetButton = new Text2('Reset Game', {
size: 60,
fill: 0x666666
});
resetButton.anchor.set(0.5, 1);
LK.gui.bottom.addChild(resetButton);
// Initialize grid
function initializeGrid() {
// Clear existing cells
for (var i = 0; i < cells.length; i++) {
for (var j = 0; j < cells[i].length; j++) {
if (cells[i][j]) {
cells[i][j].destroy();
}
}
}
cells = [];
var cellSize = 220;
var gridWidth = gridSize * cellSize;
var gridHeight = gridSize * cellSize;
var startX = (2048 - gridWidth) / 2 + cellSize / 2;
var startY = (2732 - gridHeight) / 2 + cellSize / 2;
for (var row = 0; row < gridSize; row++) {
cells[row] = [];
for (var col = 0; col < gridSize; col++) {
var cell = new TicTacToeCell(row, col);
cell.x = startX + col * cellSize;
cell.y = startY + row * cellSize;
cells[row][col] = cell;
game.addChild(cell);
}
}
}
function checkWin() {
// Check rows
for (var row = 0; row < gridSize; row++) {
var allSame = true;
var firstCell = cells[row][0].state;
if (firstCell === 'empty') continue;
for (var col = 1; col < gridSize; col++) {
if (cells[row][col].state !== firstCell) {
allSame = false;
break;
}
}
if (allSame) {
gameState = 'won';
winner = firstCell;
LK.getSound('winSound').play();
return;
}
}
// Check columns
for (var col = 0; col < gridSize; col++) {
var allSame = true;
var firstCell = cells[0][col].state;
if (firstCell === 'empty') continue;
for (var row = 1; row < gridSize; row++) {
if (cells[row][col].state !== firstCell) {
allSame = false;
break;
}
}
if (allSame) {
gameState = 'won';
winner = firstCell;
LK.getSound('winSound').play();
return;
}
}
// Check diagonal (top-left to bottom-right)
var allSame = true;
var firstCell = cells[0][0].state;
if (firstCell !== 'empty') {
for (var i = 1; i < gridSize; i++) {
if (cells[i][i].state !== firstCell) {
allSame = false;
break;
}
}
if (allSame) {
gameState = 'won';
winner = firstCell;
LK.getSound('winSound').play();
return;
}
}
// Check diagonal (top-right to bottom-left)
allSame = true;
firstCell = cells[0][gridSize - 1].state;
if (firstCell !== 'empty') {
for (var i = 1; i < gridSize; i++) {
if (cells[i][gridSize - 1 - i].state !== firstCell) {
allSame = false;
break;
}
}
if (allSame) {
gameState = 'won';
winner = firstCell;
LK.getSound('winSound').play();
return;
}
}
// Check for draw
var allFilled = true;
for (var row = 0; row < gridSize; row++) {
for (var col = 0; col < gridSize; col++) {
if (cells[row][col].state === 'empty') {
allFilled = false;
break;
}
}
if (!allFilled) break;
}
if (allFilled) {
gameState = 'draw';
}
}
function updateUI() {
if (gameState === 'won') {
statusText.setText('Player ' + winner + ' Wins!');
} else if (gameState === 'draw') {
statusText.setText('It\'s a Draw!');
} else {
statusText.setText('Player ' + currentPlayer + '\'s Turn');
}
}
function resetGame() {
gameState = 'playing';
currentPlayer = 'X';
winner = null;
for (var row = 0; row < gridSize; row++) {
for (var col = 0; col < gridSize; col++) {
cells[row][col].reset();
}
}
updateUI();
}
// Reset button functionality
resetButton.down = function (x, y, obj) {
resetGame();
};
// Initialize the game
initializeGrid();
updateUI(); ===================================================================
--- original.js
+++ change.js
@@ -1,521 +1,227 @@
/****
-* Plugins
-****/
-var tween = LK.import("@upit/tween.v1");
-var storage = LK.import("@upit/storage.v1");
-
-/****
* Classes
****/
-var GameGrid = Container.expand(function (gridSize, cellSize) {
+var TicTacToeCell = Container.expand(function (row, col) {
var self = Container.call(this);
- self.gridSize = gridSize;
- self.cellSize = cellSize;
- self.cells = [];
- self.winCondition = Math.min(gridSize, 5);
- // Initialize grid array
- for (var row = 0; row < gridSize; row++) {
- self.cells[row] = [];
- for (var col = 0; col < gridSize; col++) {
- self.cells[row][col] = null;
- }
- }
- self.createVisualGrid = function () {
- var totalSize = gridSize * cellSize;
- var startX = -totalSize / 2 + cellSize / 2;
- var startY = -totalSize / 2 + cellSize / 2;
- // Create cells
- for (var row = 0; row < gridSize; row++) {
- for (var col = 0; col < gridSize; col++) {
- var cell = new GridCell(row, col, cellSize);
- cell.x = startX + col * cellSize;
- cell.y = startY + row * cellSize;
- self.addChild(cell);
- self.cells[row][col] = cell;
- }
- }
- // Create grid lines
- for (var i = 1; i < gridSize; i++) {
- // Vertical lines
- var vLine = self.attachAsset('gridLine', {
- anchorX: 0.5,
- anchorY: 0.5,
- scaleX: 1,
- scaleY: totalSize / 8
- });
- vLine.x = startX + i * cellSize - cellSize / 2;
- vLine.y = 0;
- // Horizontal lines
- var hLine = self.attachAsset('gridLine', {
- anchorX: 0.5,
- anchorY: 0.5,
- scaleX: totalSize / 600,
- scaleY: 1,
- rotation: Math.PI / 2
- });
- hLine.x = 0;
- hLine.y = startY + i * cellSize - cellSize / 2;
- }
- };
- self.checkWinner = function () {
- // Check rows
- for (var row = 0; row < gridSize; row++) {
- for (var col = 0; col <= gridSize - self.winCondition; col++) {
- var symbol = self.cells[row][col].symbol;
- if (symbol) {
- var count = 1;
- for (var k = 1; k < self.winCondition; k++) {
- if (self.cells[row][col + k].symbol === symbol) {
- count++;
- } else {
- break;
- }
- }
- if (count === self.winCondition) return symbol;
- }
- }
- }
- // Check columns
- for (var col = 0; col < gridSize; col++) {
- for (var row = 0; row <= gridSize - self.winCondition; row++) {
- var symbol = self.cells[row][col].symbol;
- if (symbol) {
- var count = 1;
- for (var k = 1; k < self.winCondition; k++) {
- if (self.cells[row + k][col].symbol === symbol) {
- count++;
- } else {
- break;
- }
- }
- if (count === self.winCondition) return symbol;
- }
- }
- }
- // Check diagonals
- for (var row = 0; row <= gridSize - self.winCondition; row++) {
- for (var col = 0; col <= gridSize - self.winCondition; col++) {
- var symbol = self.cells[row][col].symbol;
- if (symbol) {
- var count = 1;
- for (var k = 1; k < self.winCondition; k++) {
- if (self.cells[row + k][col + k].symbol === symbol) {
- count++;
- } else {
- break;
- }
- }
- if (count === self.winCondition) return symbol;
- }
- }
- }
- // Check anti-diagonals
- for (var row = 0; row <= gridSize - self.winCondition; row++) {
- for (var col = self.winCondition - 1; col < gridSize; col++) {
- var symbol = self.cells[row][col].symbol;
- if (symbol) {
- var count = 1;
- for (var k = 1; k < self.winCondition; k++) {
- if (self.cells[row + k][col - k].symbol === symbol) {
- count++;
- } else {
- break;
- }
- }
- if (count === self.winCondition) return symbol;
- }
- }
- }
- return null;
- };
- self.isFull = function () {
- for (var row = 0; row < gridSize; row++) {
- for (var col = 0; col < gridSize; col++) {
- if (self.cells[row][col].symbol === null) {
- return false;
- }
- }
- }
- return true;
- };
- self.getEmptyCells = function () {
- var emptyCells = [];
- for (var row = 0; row < gridSize; row++) {
- for (var col = 0; col < gridSize; col++) {
- if (self.cells[row][col].symbol === null) {
- emptyCells.push({
- row: row,
- col: col
- });
- }
- }
- }
- return emptyCells;
- };
- self.createVisualGrid();
- return self;
-});
-var GridCell = Container.expand(function (row, col, size) {
- var self = Container.call(this);
self.row = row;
self.col = col;
- self.cellSize = size;
- self.symbol = null; // 'X', 'O', or null
- var background = self.attachAsset('cellBackground', {
+ self.state = 'empty'; // 'empty', 'X', 'O'
+ // Create border
+ var border = self.attachAsset('cellBorder', {
anchorX: 0.5,
- anchorY: 0.5,
- scaleX: self.cellSize / 180,
- scaleY: self.cellSize / 180
+ anchorY: 0.5
});
- var highlight = self.attachAsset('cellHighlight', {
+ // Create empty cell background
+ var cellBg = self.attachAsset('cellEmpty', {
anchorX: 0.5,
- anchorY: 0.5,
- scaleX: self.cellSize / 180,
- scaleY: self.cellSize / 180,
- alpha: 0
+ anchorY: 0.5
});
- self.symbolGraphic = null;
- self.setSymbol = function (symbol) {
- if (self.symbol !== null) return false;
- self.symbol = symbol;
- if (symbol === 'X') {
- self.symbolGraphic = self.attachAsset('xSymbol', {
+ var symbol = null;
+ self.placeSymbol = function (symbolType) {
+ if (self.state !== 'empty') return false;
+ self.state = symbolType;
+ if (symbolType === 'X') {
+ symbol = self.attachAsset('symbolX', {
anchorX: 0.5,
- anchorY: 0.5,
- scaleX: self.cellSize * 0.6 / 120,
- scaleY: self.cellSize * 0.6 / 120,
- rotation: Math.PI / 4
+ anchorY: 0.5
});
- } else if (symbol === 'O') {
- self.symbolGraphic = self.attachAsset('oSymbol', {
+ } else if (symbolType === 'O') {
+ symbol = self.attachAsset('symbolO', {
anchorX: 0.5,
- anchorY: 0.5,
- scaleX: self.cellSize * 0.6 / 120,
- scaleY: self.cellSize * 0.6 / 120
+ anchorY: 0.5
});
}
- if (self.symbolGraphic) {
- self.symbolGraphic.alpha = 0;
- tween(self.symbolGraphic, {
- alpha: 1,
- scaleX: self.symbolGraphic.scaleX * 1.2,
- scaleY: self.symbolGraphic.scaleY * 1.2
- }, {
- duration: 200,
- easing: tween.easeOut,
- onFinish: function onFinish() {
- tween(self.symbolGraphic, {
- scaleX: self.symbolGraphic.scaleX / 1.2,
- scaleY: self.symbolGraphic.scaleY / 1.2
- }, {
- duration: 100,
- easing: tween.easeIn
- });
- }
- });
- }
+ LK.getSound('placeSymbol').play();
return true;
};
- self.showHighlight = function () {
- tween(highlight, {
- alpha: 0.3
- }, {
- duration: 150
- });
- };
- self.hideHighlight = function () {
- tween(highlight, {
- alpha: 0
- }, {
- duration: 150
- });
- };
- self.down = function (x, y, obj) {
- if (gameState === 'playing' && self.symbol === null && currentPlayer === 'human') {
- if (self.setSymbol(playerSymbol)) {
- LK.getSound('placeSymbol').play();
- makeMove(self.row, self.col);
- }
+ self.reset = function () {
+ self.state = 'empty';
+ if (symbol) {
+ symbol.destroy();
+ symbol = null;
}
};
- self.move = function (x, y, obj) {
- if (gameState === 'playing' && self.symbol === null) {
- self.showHighlight();
- }
- };
- return self;
-});
-var MenuButton = Container.expand(function (text, width, height) {
- var self = Container.call(this);
- var button = self.attachAsset('menuButton', {
- anchorX: 0.5,
- anchorY: 0.5,
- scaleX: width / 400,
- scaleY: height / 80
- });
- var buttonText = new Text2(text, {
- size: 40,
- fill: 0xFFFFFF
- });
- buttonText.anchor.set(0.5, 0.5);
- self.addChild(buttonText);
self.down = function (x, y, obj) {
- LK.getSound('buttonClick').play();
- tween(self, {
- scaleX: 0.95,
- scaleY: 0.95
- }, {
- duration: 100,
- onFinish: function onFinish() {
- tween(self, {
- scaleX: 1,
- scaleY: 1
- }, {
- duration: 100
- });
+ if (gameState === 'playing' && self.state === 'empty') {
+ if (self.placeSymbol(currentPlayer)) {
+ checkWin();
+ if (gameState === 'playing') {
+ currentPlayer = currentPlayer === 'X' ? 'O' : 'X';
+ updateUI();
+ }
}
- });
- if (self.onClick) {
- self.onClick();
}
};
return self;
});
/****
* Initialize Game
****/
+// Game variables
var game = new LK.Game({
- backgroundColor: 0x1a252f
+ backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
-var gameState = 'menu'; // 'menu', 'playing', 'gameOver'
-var currentGridSize = 3;
-var currentGrid = null;
-var currentPlayer = 'human'; // 'human', 'ai'
-var playerSymbol = 'X';
-var aiSymbol = 'O';
-var gameMode = 'classic'; // 'classic', 'timed', 'powerup'
-var aiDifficulty = 'medium'; // 'easy', 'medium', 'hard'
-// UI Elements
-var titleText = new Text2('Ultimate Tic-Tac-Toe', {
+// Game variables
+var gridSize = 3;
+var cells = [];
+var currentPlayer = 'X';
+var gameState = 'playing'; // 'playing', 'won', 'draw'
+var winner = null;
+// UI elements
+var statusText = new Text2('Player X\'s Turn', {
size: 80,
- fill: 0x3498DB
+ fill: 0x333333
});
-titleText.anchor.set(0.5, 0.5);
-titleText.x = 1024;
-titleText.y = 400;
-var instructionText = new Text2('Choose your grid size:', {
- size: 50,
- fill: 0xECF0F1
-});
-instructionText.anchor.set(0.5, 0.5);
-instructionText.x = 1024;
-instructionText.y = 600;
-var statusText = new Text2('', {
+statusText.anchor.set(0.5, 0);
+LK.gui.top.addChild(statusText);
+var resetButton = new Text2('Reset Game', {
size: 60,
- fill: 0xE74C3C
+ fill: 0x666666
});
-statusText.anchor.set(0.5, 0.5);
-var scoreText = new Text2('Score: 0', {
- size: 50,
- fill: 0xF39C12
-});
-scoreText.anchor.set(0.5, 0);
-// Menu buttons
-var button3x3 = new MenuButton('3x3 Classic', 300, 80);
-button3x3.x = 1024;
-button3x3.y = 800;
-button3x3.onClick = function () {
- startGame(3);
-};
-var button5x5 = new MenuButton('5x5 Strategic', 300, 80);
-button5x5.x = 1024;
-button5x5.y = 920;
-button5x5.onClick = function () {
- startGame(5);
-};
-var button7x7 = new MenuButton('7x7 Epic', 300, 80);
-button7x7.x = 1024;
-button7x7.y = 1040;
-button7x7.onClick = function () {
- startGame(7);
-};
-var backButton = new MenuButton('Back to Menu', 250, 60);
-backButton.x = 1024;
-backButton.y = 2500;
-backButton.onClick = function () {
- showMenu();
-};
-// Add score to GUI
-LK.gui.top.addChild(scoreText);
-// Game functions
-function showMenu() {
- gameState = 'menu';
- // Clear game elements
- if (currentGrid) {
- currentGrid.destroy();
- currentGrid = null;
+resetButton.anchor.set(0.5, 1);
+LK.gui.bottom.addChild(resetButton);
+// Initialize grid
+function initializeGrid() {
+ // Clear existing cells
+ for (var i = 0; i < cells.length; i++) {
+ for (var j = 0; j < cells[i].length; j++) {
+ if (cells[i][j]) {
+ cells[i][j].destroy();
+ }
+ }
}
- // Show menu elements
- game.addChild(titleText);
- game.addChild(instructionText);
- game.addChild(button3x3);
- game.addChild(button5x5);
- game.addChild(button7x7);
- // Hide game elements
- if (statusText.parent) {
- statusText.parent.removeChild(statusText);
+ cells = [];
+ var cellSize = 220;
+ var gridWidth = gridSize * cellSize;
+ var gridHeight = gridSize * cellSize;
+ var startX = (2048 - gridWidth) / 2 + cellSize / 2;
+ var startY = (2732 - gridHeight) / 2 + cellSize / 2;
+ for (var row = 0; row < gridSize; row++) {
+ cells[row] = [];
+ for (var col = 0; col < gridSize; col++) {
+ var cell = new TicTacToeCell(row, col);
+ cell.x = startX + col * cellSize;
+ cell.y = startY + row * cellSize;
+ cells[row][col] = cell;
+ game.addChild(cell);
+ }
}
- if (backButton.parent) {
- backButton.parent.removeChild(backButton);
- }
}
-function startGame(gridSize) {
- gameState = 'playing';
- currentGridSize = gridSize;
- currentPlayer = 'human';
- // Hide menu elements
- game.removeChild(titleText);
- game.removeChild(instructionText);
- game.removeChild(button3x3);
- game.removeChild(button5x5);
- game.removeChild(button7x7);
- // Create game grid
- var cellSize = Math.min(200, 1400 / gridSize);
- currentGrid = new GameGrid(gridSize, cellSize);
- currentGrid.x = 1024;
- currentGrid.y = 1366;
- game.addChild(currentGrid);
- // Show game UI
- statusText.setText("Your turn (X)");
- statusText.x = 1024;
- statusText.y = 200;
- game.addChild(statusText);
- game.addChild(backButton);
- scoreText.setText('Score: ' + LK.getScore());
-}
-function makeMove(row, col) {
- if (gameState !== 'playing') return;
- var winner = currentGrid.checkWinner();
- if (winner) {
- endGame(winner);
- return;
- }
- if (currentGrid.isFull()) {
- endGame('tie');
- return;
- }
- // Switch to AI turn
- currentPlayer = 'ai';
- statusText.setText("AI thinking...");
- LK.setTimeout(function () {
- makeAIMove();
- }, 500);
-}
-function makeAIMove() {
- if (gameState !== 'playing') return;
- var emptyCells = currentGrid.getEmptyCells();
- if (emptyCells.length === 0) return;
- var move;
- if (aiDifficulty === 'easy') {
- // Random move
- move = emptyCells[Math.floor(Math.random() * emptyCells.length)];
- } else {
- // Try to win or block player
- move = getBestMove();
- if (!move) {
- move = emptyCells[Math.floor(Math.random() * emptyCells.length)];
+function checkWin() {
+ // Check rows
+ for (var row = 0; row < gridSize; row++) {
+ var allSame = true;
+ var firstCell = cells[row][0].state;
+ if (firstCell === 'empty') continue;
+ for (var col = 1; col < gridSize; col++) {
+ if (cells[row][col].state !== firstCell) {
+ allSame = false;
+ break;
+ }
}
+ if (allSame) {
+ gameState = 'won';
+ winner = firstCell;
+ LK.getSound('winSound').play();
+ return;
+ }
}
- if (currentGrid.cells[move.row][move.col].setSymbol(aiSymbol)) {
- LK.getSound('placeSymbol').play();
- var winner = currentGrid.checkWinner();
- if (winner) {
- endGame(winner);
+ // Check columns
+ for (var col = 0; col < gridSize; col++) {
+ var allSame = true;
+ var firstCell = cells[0][col].state;
+ if (firstCell === 'empty') continue;
+ for (var row = 1; row < gridSize; row++) {
+ if (cells[row][col].state !== firstCell) {
+ allSame = false;
+ break;
+ }
+ }
+ if (allSame) {
+ gameState = 'won';
+ winner = firstCell;
+ LK.getSound('winSound').play();
return;
}
- if (currentGrid.isFull()) {
- endGame('tie');
+ }
+ // Check diagonal (top-left to bottom-right)
+ var allSame = true;
+ var firstCell = cells[0][0].state;
+ if (firstCell !== 'empty') {
+ for (var i = 1; i < gridSize; i++) {
+ if (cells[i][i].state !== firstCell) {
+ allSame = false;
+ break;
+ }
+ }
+ if (allSame) {
+ gameState = 'won';
+ winner = firstCell;
+ LK.getSound('winSound').play();
return;
}
- // Switch back to human
- currentPlayer = 'human';
- statusText.setText("Your turn (X)");
}
-}
-function getBestMove() {
- var emptyCells = currentGrid.getEmptyCells();
- // Check if AI can win
- for (var i = 0; i < emptyCells.length; i++) {
- var cell = emptyCells[i];
- currentGrid.cells[cell.row][cell.col].symbol = aiSymbol;
- if (currentGrid.checkWinner() === aiSymbol) {
- currentGrid.cells[cell.row][cell.col].symbol = null;
- return cell;
+ // Check diagonal (top-right to bottom-left)
+ allSame = true;
+ firstCell = cells[0][gridSize - 1].state;
+ if (firstCell !== 'empty') {
+ for (var i = 1; i < gridSize; i++) {
+ if (cells[i][gridSize - 1 - i].state !== firstCell) {
+ allSame = false;
+ break;
+ }
}
- currentGrid.cells[cell.row][cell.col].symbol = null;
+ if (allSame) {
+ gameState = 'won';
+ winner = firstCell;
+ LK.getSound('winSound').play();
+ return;
+ }
}
- // Check if AI needs to block player
- for (var i = 0; i < emptyCells.length; i++) {
- var cell = emptyCells[i];
- currentGrid.cells[cell.row][cell.col].symbol = playerSymbol;
- if (currentGrid.checkWinner() === playerSymbol) {
- currentGrid.cells[cell.row][cell.col].symbol = null;
- return cell;
+ // Check for draw
+ var allFilled = true;
+ for (var row = 0; row < gridSize; row++) {
+ for (var col = 0; col < gridSize; col++) {
+ if (cells[row][col].state === 'empty') {
+ allFilled = false;
+ break;
+ }
}
- currentGrid.cells[cell.row][cell.col].symbol = null;
+ if (!allFilled) break;
}
- return null;
+ if (allFilled) {
+ gameState = 'draw';
+ }
}
-function endGame(winner) {
- gameState = 'gameOver';
- if (winner === playerSymbol) {
- statusText.setText("You Win!");
- statusText.tint = 0x2ecc71;
- LK.getSound('gameWin').play();
- // Award points based on grid size
- var points = currentGridSize * 10;
- LK.setScore(LK.getScore() + points);
- scoreText.setText('Score: ' + LK.getScore());
- // Check for win condition
- if (LK.getScore() >= 100) {
- LK.setTimeout(function () {
- LK.showYouWin();
- }, 2000);
- }
- } else if (winner === aiSymbol) {
- statusText.setText("AI Wins!");
- statusText.tint = 0xe74c3c;
+function updateUI() {
+ if (gameState === 'won') {
+ statusText.setText('Player ' + winner + ' Wins!');
+ } else if (gameState === 'draw') {
+ statusText.setText('It\'s a Draw!');
} else {
- statusText.setText("It's a Tie!");
- statusText.tint = 0xf39c12;
- // Small points for tie
- LK.setScore(LK.getScore() + 5);
- scoreText.setText('Score: ' + LK.getScore());
+ statusText.setText('Player ' + currentPlayer + '\'s Turn');
}
- // Reset to menu after delay
- LK.setTimeout(function () {
- showMenu();
- statusText.tint = 0xe74c3c;
- }, 3000);
}
-// Initialize storage
-var playerStats = storage.stats || {
- gamesWon: 0,
- totalGames: 0,
- bestScore: 0
-};
-// Update best score
-if (LK.getScore() > playerStats.bestScore) {
- playerStats.bestScore = LK.getScore();
- storage.stats = playerStats;
+function resetGame() {
+ gameState = 'playing';
+ currentPlayer = 'X';
+ winner = null;
+ for (var row = 0; row < gridSize; row++) {
+ for (var col = 0; col < gridSize; col++) {
+ cells[row][col].reset();
+ }
+ }
+ updateUI();
}
-// Start with menu
-showMenu();
-game.update = function () {
- // Update game logic if needed
-};
\ No newline at end of file
+// Reset button functionality
+resetButton.down = function (x, y, obj) {
+ resetGame();
+};
+// Initialize the game
+initializeGrid();
+updateUI();
\ No newline at end of file