User prompt
2 tane x yan yana iken 2. x yanına o gelsin
User prompt
basit bir ai karşı oynansın
User prompt
oyuncu x koyduğunda rastgele o koyulsun
User prompt
bu oyun tic tac toe oyunu.X ve O gri kutu görsellerinin üzerine koyulsun
User prompt
x o koyulabilsin
User prompt
yerine grikutularu koy
User prompt
oyundaki küçük kutuları kaldır
User prompt
x o nun üzerinde olduğu kutu görseli grikutu güncellensin
User prompt
healtbar boyutu güncelle
User prompt
oyundaki siyah o assets deki y görseli olsun
User prompt
oyundaki siyah x assets deki x görseli olsun
User prompt
assets paketlerini tic tac toe ya göre düzenle
User prompt
Tic tac Tor oyununa geri dön
User prompt
yapay zeka ya karşı oynansın. vikinglerin kılıcı olsun
User prompt
viking savaş oyunu yap
Code edit (1 edits merged)
Please save this source code
User prompt
Tic Tac Toe Touch
Initial prompt
tic tac toe yap,
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // BoardCell: Represents a single cell in the Tic Tac Toe grid var BoardCell = Container.expand(function () { var self = Container.call(this); // Cell background (box) var cellBg = self.attachAsset('cellBg', { anchorX: 0.5, anchorY: 0.5 }); // Symbol text (X or O) var symbolText = new Text2('', { size: 220, fill: 0x222222 }); symbolText.anchor.set(0.5, 0.5); self.addChild(symbolText); self.symbol = ''; // '', 'X', or 'O' self.row = 0; self.col = 0; self.isActive = true; // Can be tapped self.setSymbol = function (sym) { self.symbol = sym; symbolText.setText(sym); }; self.clear = function () { self.symbol = ''; symbolText.setText(''); self.isActive = true; }; self.flash = function (color, duration) { tween(cellBg, { tint: color }, { duration: duration / 2, easing: tween.easeIn, onFinish: function onFinish() { tween(cellBg, { tint: 0xffffff }, { duration: duration / 2, easing: tween.easeOut }); } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xffffff }); /**** * Game Code ****/ // Board/grid settings var GRID_SIZE = 3; var CELL_SIZE = 500; // px, will be scaled to fit screen var CELL_MARGIN = 18; // px between cells // Center the board var boardWidth = GRID_SIZE * CELL_SIZE + (GRID_SIZE - 1) * CELL_MARGIN; var boardHeight = boardWidth; var boardOriginX = (2048 - boardWidth) / 2; var boardOriginY = (2732 - boardHeight) / 2 + 60; // +60 to avoid top menu // Assets for cells and highlight // Game state var board = []; // 2D array of BoardCell var currentPlayer = 'X'; // 'X' or 'O' var gameActive = true; var moveCount = 0; var winningCells = []; // Array of [row, col] for winning line // GUI: Status text var statusText = new Text2('Player X\'s turn', { size: 110, fill: 0x333333 }); statusText.anchor.set(0.5, 0); LK.gui.top.addChild(statusText); // Helper: Update status text function updateStatusText() { if (!gameActive) { if (winningCells.length > 0) { statusText.setText('Player ' + currentPlayer + ' wins!'); } else { statusText.setText('Draw!'); } } else { statusText.setText('Player ' + currentPlayer + '\'s turn'); } } // Helper: Switch player function switchPlayer() { currentPlayer = currentPlayer === 'X' ? 'O' : 'X'; updateStatusText(); } // Helper: Reset board function resetBoard() { for (var r = 0; r < GRID_SIZE; r++) { for (var c = 0; c < GRID_SIZE; c++) { board[r][c].clear(); } } currentPlayer = 'X'; gameActive = true; moveCount = 0; winningCells = []; updateStatusText(); } // Helper: Highlight winning cells function highlightWinningCells() { for (var i = 0; i < winningCells.length; i++) { var rc = winningCells[i]; board[rc[0]][rc[1]].flash(0x8eea6a, 600); } } // Helper: Check for win/draw function checkGameEnd() { // Check rows, columns, diagonals var lines = []; for (var i = 0; i < GRID_SIZE; i++) { // Rows lines.push([[i, 0], [i, 1], [i, 2]]); // Columns lines.push([[0, i], [1, i], [2, i]]); } // Diagonals lines.push([[0, 0], [1, 1], [2, 2]]); lines.push([[0, 2], [1, 1], [2, 0]]); for (var l = 0; l < lines.length; l++) { var line = lines[l]; var a = board[line[0][0]][line[0][1]].symbol; var b = board[line[1][0]][line[1][1]].symbol; var c = board[line[2][0]][line[2][1]].symbol; if (a && a === b && b === c) { winningCells = line; gameActive = false; updateStatusText(); highlightWinningCells(); LK.setTimeout(function () { LK.showYouWin(); }, 1200); return; } } // Draw if (moveCount >= 9) { gameActive = false; updateStatusText(); LK.setTimeout(function () { LK.showGameOver(); }, 1200); } } // Create board for (var r = 0; r < GRID_SIZE; r++) { board[r] = []; for (var c = 0; c < GRID_SIZE; c++) { var cell = new BoardCell(); cell.x = boardOriginX + c * (CELL_SIZE + CELL_MARGIN) + CELL_SIZE / 2; cell.y = boardOriginY + r * (CELL_SIZE + CELL_MARGIN) + CELL_SIZE / 2; cell.row = r; cell.col = c; cell.clear(); game.addChild(cell); board[r][c] = cell; } } // Touch handler for cells function onCellDown(x, y, obj) { if (!gameActive) return; var cell = obj; if (!cell.isActive || cell.symbol) return; cell.setSymbol(currentPlayer); cell.isActive = false; moveCount++; checkGameEnd(); if (gameActive) { switchPlayer(); } } // Attach down event to each cell for (var r = 0; r < GRID_SIZE; r++) { for (var c = 0; c < GRID_SIZE; c++) { (function (cell) { cell.down = function (x, y, obj) { onCellDown(x, y, cell); }; })(board[r][c]); } } // Reset board on game reset (handled by LK automatically) // But for in-game reset, you could add a button if needed // On game over or win, LK will reset the game automatically // Initial status updateStatusText();
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,205 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+// BoardCell: Represents a single cell in the Tic Tac Toe grid
+var BoardCell = Container.expand(function () {
+ var self = Container.call(this);
+ // Cell background (box)
+ var cellBg = self.attachAsset('cellBg', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Symbol text (X or O)
+ var symbolText = new Text2('', {
+ size: 220,
+ fill: 0x222222
+ });
+ symbolText.anchor.set(0.5, 0.5);
+ self.addChild(symbolText);
+ self.symbol = ''; // '', 'X', or 'O'
+ self.row = 0;
+ self.col = 0;
+ self.isActive = true; // Can be tapped
+ self.setSymbol = function (sym) {
+ self.symbol = sym;
+ symbolText.setText(sym);
+ };
+ self.clear = function () {
+ self.symbol = '';
+ symbolText.setText('');
+ self.isActive = true;
+ };
+ self.flash = function (color, duration) {
+ tween(cellBg, {
+ tint: color
+ }, {
+ duration: duration / 2,
+ easing: tween.easeIn,
+ onFinish: function onFinish() {
+ tween(cellBg, {
+ tint: 0xffffff
+ }, {
+ duration: duration / 2,
+ easing: tween.easeOut
+ });
+ }
+ });
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0xffffff
+});
+
+/****
+* Game Code
+****/
+// Board/grid settings
+var GRID_SIZE = 3;
+var CELL_SIZE = 500; // px, will be scaled to fit screen
+var CELL_MARGIN = 18; // px between cells
+// Center the board
+var boardWidth = GRID_SIZE * CELL_SIZE + (GRID_SIZE - 1) * CELL_MARGIN;
+var boardHeight = boardWidth;
+var boardOriginX = (2048 - boardWidth) / 2;
+var boardOriginY = (2732 - boardHeight) / 2 + 60; // +60 to avoid top menu
+// Assets for cells and highlight
+// Game state
+var board = []; // 2D array of BoardCell
+var currentPlayer = 'X'; // 'X' or 'O'
+var gameActive = true;
+var moveCount = 0;
+var winningCells = []; // Array of [row, col] for winning line
+// GUI: Status text
+var statusText = new Text2('Player X\'s turn', {
+ size: 110,
+ fill: 0x333333
+});
+statusText.anchor.set(0.5, 0);
+LK.gui.top.addChild(statusText);
+// Helper: Update status text
+function updateStatusText() {
+ if (!gameActive) {
+ if (winningCells.length > 0) {
+ statusText.setText('Player ' + currentPlayer + ' wins!');
+ } else {
+ statusText.setText('Draw!');
+ }
+ } else {
+ statusText.setText('Player ' + currentPlayer + '\'s turn');
+ }
+}
+// Helper: Switch player
+function switchPlayer() {
+ currentPlayer = currentPlayer === 'X' ? 'O' : 'X';
+ updateStatusText();
+}
+// Helper: Reset board
+function resetBoard() {
+ for (var r = 0; r < GRID_SIZE; r++) {
+ for (var c = 0; c < GRID_SIZE; c++) {
+ board[r][c].clear();
+ }
+ }
+ currentPlayer = 'X';
+ gameActive = true;
+ moveCount = 0;
+ winningCells = [];
+ updateStatusText();
+}
+// Helper: Highlight winning cells
+function highlightWinningCells() {
+ for (var i = 0; i < winningCells.length; i++) {
+ var rc = winningCells[i];
+ board[rc[0]][rc[1]].flash(0x8eea6a, 600);
+ }
+}
+// Helper: Check for win/draw
+function checkGameEnd() {
+ // Check rows, columns, diagonals
+ var lines = [];
+ for (var i = 0; i < GRID_SIZE; i++) {
+ // Rows
+ lines.push([[i, 0], [i, 1], [i, 2]]);
+ // Columns
+ lines.push([[0, i], [1, i], [2, i]]);
+ }
+ // Diagonals
+ lines.push([[0, 0], [1, 1], [2, 2]]);
+ lines.push([[0, 2], [1, 1], [2, 0]]);
+ for (var l = 0; l < lines.length; l++) {
+ var line = lines[l];
+ var a = board[line[0][0]][line[0][1]].symbol;
+ var b = board[line[1][0]][line[1][1]].symbol;
+ var c = board[line[2][0]][line[2][1]].symbol;
+ if (a && a === b && b === c) {
+ winningCells = line;
+ gameActive = false;
+ updateStatusText();
+ highlightWinningCells();
+ LK.setTimeout(function () {
+ LK.showYouWin();
+ }, 1200);
+ return;
+ }
+ }
+ // Draw
+ if (moveCount >= 9) {
+ gameActive = false;
+ updateStatusText();
+ LK.setTimeout(function () {
+ LK.showGameOver();
+ }, 1200);
+ }
+}
+// Create board
+for (var r = 0; r < GRID_SIZE; r++) {
+ board[r] = [];
+ for (var c = 0; c < GRID_SIZE; c++) {
+ var cell = new BoardCell();
+ cell.x = boardOriginX + c * (CELL_SIZE + CELL_MARGIN) + CELL_SIZE / 2;
+ cell.y = boardOriginY + r * (CELL_SIZE + CELL_MARGIN) + CELL_SIZE / 2;
+ cell.row = r;
+ cell.col = c;
+ cell.clear();
+ game.addChild(cell);
+ board[r][c] = cell;
+ }
+}
+// Touch handler for cells
+function onCellDown(x, y, obj) {
+ if (!gameActive) return;
+ var cell = obj;
+ if (!cell.isActive || cell.symbol) return;
+ cell.setSymbol(currentPlayer);
+ cell.isActive = false;
+ moveCount++;
+ checkGameEnd();
+ if (gameActive) {
+ switchPlayer();
+ }
+}
+// Attach down event to each cell
+for (var r = 0; r < GRID_SIZE; r++) {
+ for (var c = 0; c < GRID_SIZE; c++) {
+ (function (cell) {
+ cell.down = function (x, y, obj) {
+ onCellDown(x, y, cell);
+ };
+ })(board[r][c]);
+ }
+}
+// Reset board on game reset (handled by LK automatically)
+// But for in-game reset, you could add a button if needed
+// On game over or win, LK will reset the game automatically
+// Initial status
+updateStatusText();
\ No newline at end of file