User prompt
Player 1, Player 2'nun karesinin üstüne koyabilir, boyadığı karenin üstüne koyabilir. Player 2'de Player 1'in karesinin üstüne koyabilir.
User prompt
20 tane kara hakkımız olsun hatta 25 tane kara hakkımız olsun.
User prompt
Mavi kişi kendi önceki koyduğu karenin yanına koyabilir, kırmızı kişi ise kendi koyduğu önceki karenin yanına koyabilir. Başlarken ilk önce kendi kalelerinin yanına koyabilirler.
Code edit (1 edits merged)
Please save this source code
User prompt
Territory Takeover
Initial prompt
Create a 2-player turn-based strategy game on a chessboard-like grid. Player 1 is blue and Player 2 is red. Each player can only click adjacent tiles from their last move and has 10 tile painting turns. If one player surrounds the other’s castle with their color, they win. If a player runs out of moves without surrounding the enemy, they lose. When a player captures the opponent’s tile, they don’t lose a turn.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var GridTile = Container.expand(function () {
var self = Container.call(this);
self.gridX = 0;
self.gridY = 0;
self.owner = 0; // 0 = empty, 1 = blue, 2 = red
self.isCastle = false;
self.tileGraphics = null;
self.init = function (gridX, gridY, owner, isCastle) {
self.gridX = gridX;
self.gridY = gridY;
self.owner = owner;
self.isCastle = isCastle;
var assetId = 'emptyTile';
if (isCastle && owner === 1) assetId = 'blueCastle';else if (isCastle && owner === 2) assetId = 'redCastle';else if (owner === 1) assetId = 'blueTile';else if (owner === 2) assetId = 'redTile';
if (self.tileGraphics) self.removeChild(self.tileGraphics);
self.tileGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
};
self.setOwner = function (newOwner) {
self.owner = newOwner;
var assetId = 'emptyTile';
if (newOwner === 1) assetId = 'blueTile';else if (newOwner === 2) assetId = 'redTile';
if (self.tileGraphics) self.removeChild(self.tileGraphics);
self.tileGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
};
self.highlight = function () {
if (self.tileGraphics) self.removeChild(self.tileGraphics);
self.tileGraphics = self.attachAsset('highlightTile', {
anchorX: 0.5,
anchorY: 0.5
});
};
self.down = function (x, y, obj) {
handleTileClick(self.gridX, self.gridY);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x333333
});
/****
* Game Code
****/
var GRID_SIZE = 8;
var TILE_SIZE = 128;
var MAX_TURNS = 10;
var gameGrid = [];
var currentPlayer = 1; // 1 = blue, 2 = red
var turnCount = 0;
var lastMoveX = -1;
var lastMoveY = -1;
var gameActive = true;
var gameResult = null; // null = ongoing, 'win' = current player won, 'lose' = current player lost
var boardContainer = new Container();
game.addChild(boardContainer);
// Initialize game board
function initBoard() {
gameGrid = [];
for (var y = 0; y < GRID_SIZE; y++) {
gameGrid[y] = [];
for (var x = 0; x < GRID_SIZE; x++) {
var tile = new GridTile();
gameGrid[y][x] = tile;
boardContainer.addChild(tile);
var owner = 0;
var isCastle = false;
if (y === 0 && x === GRID_SIZE / 2) {
owner = 1;
isCastle = true;
} else if (y === GRID_SIZE - 1 && x === GRID_SIZE / 2) {
owner = 2;
isCastle = true;
}
tile.init(x, y, owner, isCastle);
tile.x = x * TILE_SIZE + TILE_SIZE / 2 + (2048 - GRID_SIZE * TILE_SIZE) / 2;
tile.y = y * TILE_SIZE + TILE_SIZE / 2 + (2732 - GRID_SIZE * TILE_SIZE) / 2;
}
}
lastMoveX = GRID_SIZE / 2;
lastMoveY = 0;
currentPlayer = 1;
turnCount = 0;
gameActive = true;
gameResult = null;
updateUI();
}
function getAdjacentTiles(x, y) {
var adjacent = [];
var directions = [[0, -1], [1, 0], [0, 1], [-1, 0], [-1, -1], [1, -1], [-1, 1], [1, 1]];
for (var i = 0; i < directions.length; i++) {
var nx = x + directions[i][0];
var ny = y + directions[i][1];
if (nx >= 0 && nx < GRID_SIZE && ny >= 0 && ny < GRID_SIZE) {
adjacent.push({
x: nx,
y: ny
});
}
}
return adjacent;
}
function getValidMoves() {
if (turnCount === 0) {
var validMoves = [];
for (var y = 0; y < GRID_SIZE; y++) {
for (var x = 0; x < GRID_SIZE; x++) {
if (gameGrid[y][x].owner === 0) {
validMoves.push({
x: x,
y: y
});
}
}
}
return validMoves;
} else {
return getAdjacentTiles(lastMoveX, lastMoveY);
}
}
function clearHighlights() {
for (var y = 0; y < GRID_SIZE; y++) {
for (var x = 0; x < GRID_SIZE; x++) {
var tile = gameGrid[y][x];
var owner = tile.owner;
var isCastle = tile.isCastle;
tile.init(x, y, owner, isCastle);
}
}
}
function highlightValidMoves() {
clearHighlights();
var validMoves = getValidMoves();
for (var i = 0; i < validMoves.length; i++) {
var move = validMoves[i];
if (gameGrid[move.y][move.x].owner === 0) {
gameGrid[move.y][move.x].highlight();
}
}
}
function handleTileClick(x, y) {
if (!gameActive) return;
var validMoves = getValidMoves();
var isValid = false;
for (var i = 0; i < validMoves.length; i++) {
if (validMoves[i].x === x && validMoves[i].y === y) {
isValid = true;
break;
}
}
if (!isValid) return;
var tile = gameGrid[y][x];
if (tile.owner !== 0 && tile.owner !== currentPlayer) {
tile.setOwner(currentPlayer);
LK.getSound('capture').play();
} else if (tile.owner === 0) {
tile.setOwner(currentPlayer);
LK.getSound('paint').play();
turnCount++;
}
lastMoveX = x;
lastMoveY = y;
if (turnCount >= MAX_TURNS) {
checkWinCondition();
} else {
switchPlayer();
}
}
function isCastleSurrounded(castleX, castleY, playerToCheck) {
var directions = [[0, -1], [1, 0], [0, 1], [-1, 0], [-1, -1], [1, -1], [-1, 1], [1, 1]];
for (var i = 0; i < directions.length; i++) {
var nx = castleX + directions[i][0];
var ny = castleY + directions[i][1];
if (nx >= 0 && nx < GRID_SIZE && ny >= 0 && ny < GRID_SIZE) {
if (gameGrid[ny][nx].owner !== playerToCheck) {
return false;
}
}
}
return true;
}
function checkWinCondition() {
gameActive = false;
var opponentCastleX, opponentCastleY;
if (currentPlayer === 1) {
opponentCastleX = GRID_SIZE / 2;
opponentCastleY = GRID_SIZE - 1;
} else {
opponentCastleX = GRID_SIZE / 2;
opponentCastleY = 0;
}
if (isCastleSurrounded(opponentCastleX, opponentCastleY, currentPlayer)) {
gameResult = 'win';
LK.getSound('win').play();
LK.setTimeout(function () {
LK.showYouWin();
}, 1000);
} else {
gameResult = 'lose';
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
}
}
function switchPlayer() {
currentPlayer = currentPlayer === 1 ? 2 : 1;
updateUI();
highlightValidMoves();
}
function updateUI() {
if (turnStatusText) {
turnStatusText.setText('Player ' + currentPlayer + ' - Turn ' + turnCount + '/' + MAX_TURNS);
}
}
var turnStatusText = new Text2('Player 1 - Turn 0/10', {
size: 60,
fill: '#FFFFFF'
});
turnStatusText.anchor.set(0.5, 0);
LK.gui.top.addChild(turnStatusText);
initBoard();
highlightValidMoves();
game.update = function () {
// Game updates handled through user interactions
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,242 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var GridTile = Container.expand(function () {
+ var self = Container.call(this);
+ self.gridX = 0;
+ self.gridY = 0;
+ self.owner = 0; // 0 = empty, 1 = blue, 2 = red
+ self.isCastle = false;
+ self.tileGraphics = null;
+ self.init = function (gridX, gridY, owner, isCastle) {
+ self.gridX = gridX;
+ self.gridY = gridY;
+ self.owner = owner;
+ self.isCastle = isCastle;
+ var assetId = 'emptyTile';
+ if (isCastle && owner === 1) assetId = 'blueCastle';else if (isCastle && owner === 2) assetId = 'redCastle';else if (owner === 1) assetId = 'blueTile';else if (owner === 2) assetId = 'redTile';
+ if (self.tileGraphics) self.removeChild(self.tileGraphics);
+ self.tileGraphics = self.attachAsset(assetId, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ };
+ self.setOwner = function (newOwner) {
+ self.owner = newOwner;
+ var assetId = 'emptyTile';
+ if (newOwner === 1) assetId = 'blueTile';else if (newOwner === 2) assetId = 'redTile';
+ if (self.tileGraphics) self.removeChild(self.tileGraphics);
+ self.tileGraphics = self.attachAsset(assetId, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ };
+ self.highlight = function () {
+ if (self.tileGraphics) self.removeChild(self.tileGraphics);
+ self.tileGraphics = self.attachAsset('highlightTile', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ };
+ self.down = function (x, y, obj) {
+ handleTileClick(self.gridX, self.gridY);
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x333333
+});
+
+/****
+* Game Code
+****/
+var GRID_SIZE = 8;
+var TILE_SIZE = 128;
+var MAX_TURNS = 10;
+var gameGrid = [];
+var currentPlayer = 1; // 1 = blue, 2 = red
+var turnCount = 0;
+var lastMoveX = -1;
+var lastMoveY = -1;
+var gameActive = true;
+var gameResult = null; // null = ongoing, 'win' = current player won, 'lose' = current player lost
+var boardContainer = new Container();
+game.addChild(boardContainer);
+// Initialize game board
+function initBoard() {
+ gameGrid = [];
+ for (var y = 0; y < GRID_SIZE; y++) {
+ gameGrid[y] = [];
+ for (var x = 0; x < GRID_SIZE; x++) {
+ var tile = new GridTile();
+ gameGrid[y][x] = tile;
+ boardContainer.addChild(tile);
+ var owner = 0;
+ var isCastle = false;
+ if (y === 0 && x === GRID_SIZE / 2) {
+ owner = 1;
+ isCastle = true;
+ } else if (y === GRID_SIZE - 1 && x === GRID_SIZE / 2) {
+ owner = 2;
+ isCastle = true;
+ }
+ tile.init(x, y, owner, isCastle);
+ tile.x = x * TILE_SIZE + TILE_SIZE / 2 + (2048 - GRID_SIZE * TILE_SIZE) / 2;
+ tile.y = y * TILE_SIZE + TILE_SIZE / 2 + (2732 - GRID_SIZE * TILE_SIZE) / 2;
+ }
+ }
+ lastMoveX = GRID_SIZE / 2;
+ lastMoveY = 0;
+ currentPlayer = 1;
+ turnCount = 0;
+ gameActive = true;
+ gameResult = null;
+ updateUI();
+}
+function getAdjacentTiles(x, y) {
+ var adjacent = [];
+ var directions = [[0, -1], [1, 0], [0, 1], [-1, 0], [-1, -1], [1, -1], [-1, 1], [1, 1]];
+ for (var i = 0; i < directions.length; i++) {
+ var nx = x + directions[i][0];
+ var ny = y + directions[i][1];
+ if (nx >= 0 && nx < GRID_SIZE && ny >= 0 && ny < GRID_SIZE) {
+ adjacent.push({
+ x: nx,
+ y: ny
+ });
+ }
+ }
+ return adjacent;
+}
+function getValidMoves() {
+ if (turnCount === 0) {
+ var validMoves = [];
+ for (var y = 0; y < GRID_SIZE; y++) {
+ for (var x = 0; x < GRID_SIZE; x++) {
+ if (gameGrid[y][x].owner === 0) {
+ validMoves.push({
+ x: x,
+ y: y
+ });
+ }
+ }
+ }
+ return validMoves;
+ } else {
+ return getAdjacentTiles(lastMoveX, lastMoveY);
+ }
+}
+function clearHighlights() {
+ for (var y = 0; y < GRID_SIZE; y++) {
+ for (var x = 0; x < GRID_SIZE; x++) {
+ var tile = gameGrid[y][x];
+ var owner = tile.owner;
+ var isCastle = tile.isCastle;
+ tile.init(x, y, owner, isCastle);
+ }
+ }
+}
+function highlightValidMoves() {
+ clearHighlights();
+ var validMoves = getValidMoves();
+ for (var i = 0; i < validMoves.length; i++) {
+ var move = validMoves[i];
+ if (gameGrid[move.y][move.x].owner === 0) {
+ gameGrid[move.y][move.x].highlight();
+ }
+ }
+}
+function handleTileClick(x, y) {
+ if (!gameActive) return;
+ var validMoves = getValidMoves();
+ var isValid = false;
+ for (var i = 0; i < validMoves.length; i++) {
+ if (validMoves[i].x === x && validMoves[i].y === y) {
+ isValid = true;
+ break;
+ }
+ }
+ if (!isValid) return;
+ var tile = gameGrid[y][x];
+ if (tile.owner !== 0 && tile.owner !== currentPlayer) {
+ tile.setOwner(currentPlayer);
+ LK.getSound('capture').play();
+ } else if (tile.owner === 0) {
+ tile.setOwner(currentPlayer);
+ LK.getSound('paint').play();
+ turnCount++;
+ }
+ lastMoveX = x;
+ lastMoveY = y;
+ if (turnCount >= MAX_TURNS) {
+ checkWinCondition();
+ } else {
+ switchPlayer();
+ }
+}
+function isCastleSurrounded(castleX, castleY, playerToCheck) {
+ var directions = [[0, -1], [1, 0], [0, 1], [-1, 0], [-1, -1], [1, -1], [-1, 1], [1, 1]];
+ for (var i = 0; i < directions.length; i++) {
+ var nx = castleX + directions[i][0];
+ var ny = castleY + directions[i][1];
+ if (nx >= 0 && nx < GRID_SIZE && ny >= 0 && ny < GRID_SIZE) {
+ if (gameGrid[ny][nx].owner !== playerToCheck) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+function checkWinCondition() {
+ gameActive = false;
+ var opponentCastleX, opponentCastleY;
+ if (currentPlayer === 1) {
+ opponentCastleX = GRID_SIZE / 2;
+ opponentCastleY = GRID_SIZE - 1;
+ } else {
+ opponentCastleX = GRID_SIZE / 2;
+ opponentCastleY = 0;
+ }
+ if (isCastleSurrounded(opponentCastleX, opponentCastleY, currentPlayer)) {
+ gameResult = 'win';
+ LK.getSound('win').play();
+ LK.setTimeout(function () {
+ LK.showYouWin();
+ }, 1000);
+ } else {
+ gameResult = 'lose';
+ LK.setTimeout(function () {
+ LK.showGameOver();
+ }, 1000);
+ }
+}
+function switchPlayer() {
+ currentPlayer = currentPlayer === 1 ? 2 : 1;
+ updateUI();
+ highlightValidMoves();
+}
+function updateUI() {
+ if (turnStatusText) {
+ turnStatusText.setText('Player ' + currentPlayer + ' - Turn ' + turnCount + '/' + MAX_TURNS);
+ }
+}
+var turnStatusText = new Text2('Player 1 - Turn 0/10', {
+ size: 60,
+ fill: '#FFFFFF'
+});
+turnStatusText.anchor.set(0.5, 0);
+LK.gui.top.addChild(turnStatusText);
+initBoard();
+highlightValidMoves();
+game.update = function () {
+ // Game updates handled through user interactions
+};
\ No newline at end of file