User prompt
oyunun ismini Chess Master Online yap ve bu isim menü ekranındada gözüksün ayrıca tuşların yerlerini değiştir hepsi siyah alanda büyük ve siyah alanın içinde olsun siyah alanı tam kaplasın
Code edit (1 edits merged)
Please save this source code
User prompt
tuşların hepsi siyah alanda gözükür bir şekilde aynı büyüklükte olsun
User prompt
açılan klavyedeki tuşların boyları daha büüyk olsun ve diğer küçük yazılar oranla büyüsün
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'currentFriends.push(newFriend);' Line Number: 1130 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
giriş veya kayıt ekranında isim ve şifre yazma rastgele olmasın kullanıcı yazsın ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
oyunu türkçe yap ve kayıt olma yada giriş mekaniğini değiştir şifre koyma olsun isim yazmayıda klavyeden yapalım ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage.friends.push({' Line Number: 1075
User prompt
Please fix the bug: 'Uncaught ReferenceError: showMenuUI is not defined' in or related to this line: 'showMenuUI();' Line Number: 1022
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage[userId] = {' Line Number: 1031 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'fill')' in or related to this line: 'self.displayText.style.fill = 0xFFFFFF;' Line Number: 167
User prompt
bu link hala bozuk bu linki okunabilecek büyüklüğe getir ve arkadaş ile oynama mantığını baştan yap hesap açma ekle ve arkadaş ekleme yap arkadaş eklenen kişinin üstüne tıklayıncada onun ile canlı olarak oynayabileceğim bir tahta yap ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
link hala bozuk bu link kopyalandıktan sonra whatsappta birine atmak istiyorum fakat atılmıyor yapıştırınca boşluk çıkıyor bunu düzelt ve artık şu taş resimleri lichess tekilerle aynı yap
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'createElement')' in or related to this line: 'var textArea = document.createElement('textarea');' Line Number: 194
User prompt
linki tıklanabilir ve kopyanabilir yap aynı zamanda taşların resimlerini internette araştırıp değiştir (renklerini değil görsellerini, örneğin pawn gerçek pawn a benzesin ve diğerleride)
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'href')' in or related to this line: 'gameLink = window.location.href.split('?')[0] + '?gameId=' + gameId;' Line Number: 895
User prompt
oyunun taş resimlerini geliştir internetten bul. play vs ai kaldır arkadaşa karşı oynada ise tıklanınca bir link oluştur o linke tıklayan 2 kişi aynı maça atılsın ve kontrolleri geliştir rok yaparken veya rakip bizi yerken yada mat olma mekanikleri bozuk
Code edit (1 edits merged)
Please save this source code
User prompt
Chess Master Online
Initial prompt
bana popüler olabilecek bir satranç oyunu yap menüsü olsun. online olsun. oyna tuşuna basınca seçeneklerde yapay zekaya karşı da olsun ve çalışsın. online mantığı rastgele oyuncularla vs attırsın ve arkadaşlarla oynama olsun hesap açma ve elo olsun chess.com 'un çakması olsun
/****
* Plugins
****/
var storage = LK.import("@upit/storage.v1", {
playerELO: 1200,
gamesPlayed: 0,
wins: 0,
losses: 0,
draws: 0,
username: "",
userId: "",
friends: [],
friendRequests: [],
onlineMatches: [],
isLoggedIn: false
});
/****
* Classes
****/
var ChessPiece = Container.expand(function (type, color, row, col) {
var self = Container.call(this);
self.pieceType = type;
self.pieceColor = color;
self.boardRow = row;
self.boardCol = col;
self.hasMoved = false;
var assetName = color + type;
var pieceGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5
});
self.moveTo = function (newRow, newCol) {
self.boardRow = newRow;
self.boardCol = newCol;
self.hasMoved = true;
self.x = boardStartX + newCol * squareSize + squareSize / 2;
self.y = boardStartY + newRow * squareSize + squareSize / 2;
};
return self;
});
var ChessSquare = Container.expand(function (row, col) {
var self = Container.call(this);
self.row = row;
self.col = col;
self.isLight = (row + col) % 2 === 0;
self.piece = null;
self.isSelected = false;
self.isPossibleMove = false;
var squareColor = self.isLight ? 'lightSquare' : 'darkSquare';
var squareGraphics = self.attachAsset(squareColor, {
anchorX: 0,
anchorY: 0
});
self.highlight = null;
self.setSelected = function (selected) {
self.isSelected = selected;
if (selected && !self.highlight) {
self.highlight = self.addChild(LK.getAsset('selectedSquare', {
anchorX: 0,
anchorY: 0,
alpha: 0.5
}));
} else if (!selected && self.highlight) {
self.removeChild(self.highlight);
self.highlight = null;
}
};
self.setPossibleMove = function (possible) {
self.isPossibleMove = possible;
if (possible && !self.highlight) {
self.highlight = self.addChild(LK.getAsset('possibleMove', {
anchorX: 0,
anchorY: 0,
alpha: 0.3
}));
} else if (!possible && self.highlight) {
self.removeChild(self.highlight);
self.highlight = null;
}
};
self.down = function (x, y, obj) {
handleSquareClick(self.row, self.col);
};
return self;
});
var FriendListItem = Container.expand(function (friendData, callback) {
var self = Container.call(this);
self.friendData = friendData;
self.callback = callback;
var background = self.attachAsset('menuButton', {
anchorX: 0,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 0.8
});
background.tint = 0x2a2a2a;
var nameText = new Text2(friendData.username, {
size: 42,
fill: 0xFFFFFF
});
nameText.anchor.set(0, 0.5);
nameText.x = 20;
self.addChild(nameText);
var statusText = new Text2(friendData.online ? 'Online' : 'Offline', {
size: 32,
fill: friendData.online ? 0x00FF00 : 0x888888
});
statusText.anchor.set(1, 0.5);
statusText.x = 580;
self.addChild(statusText);
self.down = function (x, y, obj) {
if (self.callback && friendData.online) {
self.callback(friendData);
}
};
return self;
});
var InputField = Container.expand(function (placeholder, width) {
var self = Container.call(this);
self.width = width || 600;
self.height = 80;
self.placeholder = placeholder;
self.value = '';
self.isFocused = false;
var fieldBackground = self.attachAsset('menuButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: self.width / 400,
scaleY: self.height / 120
});
fieldBackground.tint = 0x333333;
self.displayText = new Text2(placeholder, {
size: 36,
fill: 0xCCCCCC
});
self.displayText.anchor.set(0.5, 0.5);
self.addChild(self.displayText);
self.setText = function (text) {
self.value = text;
if (text.length > 0) {
self.displayText.setText(text);
self.displayText.tint = 0xFFFFFF;
} else {
self.displayText.setText(self.placeholder);
self.displayText.tint = 0xCCCCCC;
}
};
self.down = function (x, y, obj) {
self.isFocused = true;
fieldBackground.tint = 0x4169e1;
};
return self;
});
var MenuButton = Container.expand(function (text, callback) {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('menuButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2(text, {
size: 48,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.callback = callback;
self.down = function (x, y, obj) {
if (self.callback) {
self.callback();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2F4F4F
});
/****
* Game Code
****/
var gameState = 'login'; // 'login', 'register', 'menu', 'friends', 'playing', 'gameOver'
var currentPlayer = 'white';
var selectedSquare = null;
var possibleMoves = [];
var board = [];
var pieces = [];
var squares = [];
var gameMode = 'friend'; // 'online', 'friend'
var boardStartX = 224;
var boardStartY = 566;
var squareSize = 200;
var currentMatch = null;
var friendsList = [];
var friendRequestsList = [];
// Login/Register UI
var titleText = new Text2('Chess Master Online', {
size: 84,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 300;
var usernameInput = new InputField('Enter Username', 600);
usernameInput.x = 1024;
usernameInput.y = 600;
var loginButton = new MenuButton('Login / Register', function () {
if (usernameInput.value.length > 2) {
loginUser(usernameInput.value);
}
});
loginButton.x = 1024;
loginButton.y = 800;
// Main menu UI
var welcomeText = new Text2('', {
size: 56,
fill: 0xFFFFFF
});
welcomeText.anchor.set(0.5, 0.5);
welcomeText.x = 1024;
welcomeText.y = 400;
var eloText = new Text2('', {
size: 48,
fill: 0xFFD700
});
eloText.anchor.set(0.5, 0.5);
eloText.x = 1024;
eloText.y = 500;
var statsText = new Text2('', {
size: 36,
fill: 0xC0C0C0
});
statsText.anchor.set(0.5, 0.5);
statsText.x = 1024;
statsText.y = 560;
var quickMatchButton = new MenuButton('Quick Match', function () {
gameMode = 'online';
findOnlineMatch();
});
quickMatchButton.x = 1024;
quickMatchButton.y = 750;
var friendsButton = new MenuButton('Friends', function () {
showFriendsUI();
});
friendsButton.x = 1024;
friendsButton.y = 900;
var logoutButton = new MenuButton('Logout', function () {
logoutUser();
});
logoutButton.x = 1024;
logoutButton.y = 1050;
// Friends UI
var friendsTitleText = new Text2('Friends & Matches', {
size: 64,
fill: 0xFFFFFF
});
friendsTitleText.anchor.set(0.5, 0.5);
friendsTitleText.x = 1024;
friendsTitleText.y = 250;
var addFriendInput = new InputField('Friend Username', 500);
addFriendInput.x = 1024;
addFriendInput.y = 350;
var addFriendButton = new MenuButton('Add Friend', function () {
if (addFriendInput.value.length > 2) {
addFriend(addFriendInput.value);
addFriendInput.setText('');
}
});
addFriendButton.x = 1024;
addFriendButton.y = 450;
var friendsListContainer = new Container();
friendsListContainer.x = 224;
friendsListContainer.y = 600;
var backToMenuButton = new MenuButton('Back to Menu', function () {
showMainMenu();
});
backToMenuButton.x = 1024;
backToMenuButton.y = 2200;
// Game status display with larger text
var gameStatusText = new Text2('White to move', {
size: 64,
fill: 0xFFFFFF
});
gameStatusText.anchor.set(0.5, 0.5);
gameStatusText.x = 1024;
gameStatusText.y = 200;
var backButton = new MenuButton('Back to Menu', function () {
returnToMenu();
});
backButton.x = 1024;
backButton.y = 2400;
// Game UI elements
var gameStatusText = new Text2('White to move', {
size: 48,
fill: 0xFFFFFF
});
gameStatusText.anchor.set(0.5, 0.5);
gameStatusText.x = 1024;
gameStatusText.y = 300;
var backButton = new MenuButton('Back to Menu', function () {
returnToMenu();
});
backButton.x = 1024;
backButton.y = 2400;
// Initialize board
function initializeBoard() {
board = [];
for (var row = 0; row < 8; row++) {
board[row] = [];
for (var col = 0; col < 8; col++) {
board[row][col] = null;
}
}
// Set up initial piece positions
var pieceOrder = ['Rook', 'Knight', 'Bishop', 'Queen', 'King', 'Bishop', 'Knight', 'Rook'];
// White pieces
for (var col = 0; col < 8; col++) {
board[7][col] = {
type: pieceOrder[col],
color: 'white'
};
board[6][col] = {
type: 'Pawn',
color: 'white'
};
}
// Black pieces
for (var col = 0; col < 8; col++) {
board[0][col] = {
type: pieceOrder[col],
color: 'black'
};
board[1][col] = {
type: 'Pawn',
color: 'black'
};
}
}
function createBoardVisual() {
// Clear existing board
for (var i = squares.length - 1; i >= 0; i--) {
squares[i].destroy();
}
squares = [];
for (var i = pieces.length - 1; i >= 0; i--) {
pieces[i].destroy();
}
pieces = [];
// Create squares
for (var row = 0; row < 8; row++) {
for (var col = 0; col < 8; col++) {
var square = new ChessSquare(row, col);
square.x = boardStartX + col * squareSize;
square.y = boardStartY + row * squareSize;
squares.push(square);
game.addChild(square);
}
}
// Create pieces
for (var row = 0; row < 8; row++) {
for (var col = 0; col < 8; col++) {
if (board[row][col]) {
var piece = new ChessPiece(board[row][col].type, board[row][col].color, row, col);
piece.x = boardStartX + col * squareSize + squareSize / 2;
piece.y = boardStartY + row * squareSize + squareSize / 2;
pieces.push(piece);
game.addChild(piece);
}
}
}
}
function getPossibleMoves(row, col) {
var moves = [];
var piece = board[row][col];
if (!piece || piece.color !== currentPlayer) {
return moves;
}
switch (piece.type) {
case 'Pawn':
moves = getPawnMoves(row, col, piece.color);
break;
case 'Rook':
moves = getRookMoves(row, col, piece.color);
break;
case 'Knight':
moves = getKnightMoves(row, col, piece.color);
break;
case 'Bishop':
moves = getBishopMoves(row, col, piece.color);
break;
case 'Queen':
moves = getQueenMoves(row, col, piece.color);
break;
case 'King':
moves = getKingMoves(row, col, piece.color);
break;
}
return moves;
}
function getPawnMoves(row, col, color) {
var moves = [];
var direction = color === 'white' ? -1 : 1;
var startRow = color === 'white' ? 6 : 1;
// Forward move
if (isValidSquare(row + direction, col) && !board[row + direction][col]) {
moves.push({
row: row + direction,
col: col
});
// Double move from start
if (row === startRow && !board[row + 2 * direction][col]) {
moves.push({
row: row + 2 * direction,
col: col
});
}
}
// Captures
if (isValidSquare(row + direction, col - 1) && board[row + direction][col - 1] && board[row + direction][col - 1].color !== color) {
moves.push({
row: row + direction,
col: col - 1
});
}
if (isValidSquare(row + direction, col + 1) && board[row + direction][col + 1] && board[row + direction][col + 1].color !== color) {
moves.push({
row: row + direction,
col: col + 1
});
}
return moves;
}
function getRookMoves(row, col, color) {
var moves = [];
var directions = [{
row: 0,
col: 1
}, {
row: 0,
col: -1
}, {
row: 1,
col: 0
}, {
row: -1,
col: 0
}];
for (var d = 0; d < directions.length; d++) {
var dir = directions[d];
for (var i = 1; i < 8; i++) {
var newRow = row + dir.row * i;
var newCol = col + dir.col * i;
if (!isValidSquare(newRow, newCol)) break;
if (!board[newRow][newCol]) {
moves.push({
row: newRow,
col: newCol
});
} else {
if (board[newRow][newCol].color !== color) {
moves.push({
row: newRow,
col: newCol
});
}
break;
}
}
}
return moves;
}
function getKnightMoves(row, col, color) {
var moves = [];
var knightMoves = [{
row: -2,
col: -1
}, {
row: -2,
col: 1
}, {
row: -1,
col: -2
}, {
row: -1,
col: 2
}, {
row: 1,
col: -2
}, {
row: 1,
col: 2
}, {
row: 2,
col: -1
}, {
row: 2,
col: 1
}];
for (var i = 0; i < knightMoves.length; i++) {
var move = knightMoves[i];
var newRow = row + move.row;
var newCol = col + move.col;
if (isValidSquare(newRow, newCol) && (!board[newRow][newCol] || board[newRow][newCol].color !== color)) {
moves.push({
row: newRow,
col: newCol
});
}
}
return moves;
}
function getBishopMoves(row, col, color) {
var moves = [];
var directions = [{
row: 1,
col: 1
}, {
row: 1,
col: -1
}, {
row: -1,
col: 1
}, {
row: -1,
col: -1
}];
for (var d = 0; d < directions.length; d++) {
var dir = directions[d];
for (var i = 1; i < 8; i++) {
var newRow = row + dir.row * i;
var newCol = col + dir.col * i;
if (!isValidSquare(newRow, newCol)) break;
if (!board[newRow][newCol]) {
moves.push({
row: newRow,
col: newCol
});
} else {
if (board[newRow][newCol].color !== color) {
moves.push({
row: newRow,
col: newCol
});
}
break;
}
}
}
return moves;
}
function getQueenMoves(row, col, color) {
var rookMoves = getRookMoves(row, col, color);
var bishopMoves = getBishopMoves(row, col, color);
return rookMoves.concat(bishopMoves);
}
function getKingMoves(row, col, color) {
var moves = [];
var directions = [{
row: -1,
col: -1
}, {
row: -1,
col: 0
}, {
row: -1,
col: 1
}, {
row: 0,
col: -1
}, {
row: 0,
col: 1
}, {
row: 1,
col: -1
}, {
row: 1,
col: 0
}, {
row: 1,
col: 1
}];
for (var i = 0; i < directions.length; i++) {
var dir = directions[i];
var newRow = row + dir.row;
var newCol = col + dir.col;
if (isValidSquare(newRow, newCol) && (!board[newRow][newCol] || board[newRow][newCol].color !== color)) {
if (!isSquareUnderAttack(newRow, newCol, color)) {
moves.push({
row: newRow,
col: newCol
});
}
}
}
// Castling
var piece = findPieceAt(row, col);
if (piece && !piece.hasMoved && !isSquareUnderAttack(row, col, color)) {
// Kingside castling
var kingsideRook = findPieceAt(row, 7);
if (kingsideRook && !kingsideRook.hasMoved && !board[row][5] && !board[row][6] && !isSquareUnderAttack(row, 5, color) && !isSquareUnderAttack(row, 6, color)) {
moves.push({
row: row,
col: 6,
castling: 'kingside'
});
}
// Queenside castling
var queensideRook = findPieceAt(row, 0);
if (queensideRook && !queensideRook.hasMoved && !board[row][1] && !board[row][2] && !board[row][3] && !isSquareUnderAttack(row, 2, color) && !isSquareUnderAttack(row, 3, color)) {
moves.push({
row: row,
col: 2,
castling: 'queenside'
});
}
}
return moves;
}
function isValidSquare(row, col) {
return row >= 0 && row < 8 && col >= 0 && col < 8;
}
function isSquareUnderAttack(row, col, defendingColor) {
var attackingColor = defendingColor === 'white' ? 'black' : 'white';
for (var r = 0; r < 8; r++) {
for (var c = 0; c < 8; c++) {
if (board[r][c] && board[r][c].color === attackingColor) {
var moves = getPossibleMovesForAttack(r, c, board[r][c].type, attackingColor);
for (var i = 0; i < moves.length; i++) {
if (moves[i].row === row && moves[i].col === col) {
return true;
}
}
}
}
}
return false;
}
function getPossibleMovesForAttack(row, col, pieceType, color) {
switch (pieceType) {
case 'Pawn':
return getPawnAttacks(row, col, color);
case 'Rook':
return getRookMoves(row, col, color);
case 'Knight':
return getKnightMoves(row, col, color);
case 'Bishop':
return getBishopMoves(row, col, color);
case 'Queen':
return getQueenMoves(row, col, color);
case 'King':
return getKingBasicMoves(row, col, color);
}
return [];
}
function getPawnAttacks(row, col, color) {
var moves = [];
var direction = color === 'white' ? -1 : 1;
if (isValidSquare(row + direction, col - 1)) {
moves.push({
row: row + direction,
col: col - 1
});
}
if (isValidSquare(row + direction, col + 1)) {
moves.push({
row: row + direction,
col: col + 1
});
}
return moves;
}
function getKingBasicMoves(row, col, color) {
var moves = [];
var directions = [-1, 0, 1];
for (var i = 0; i < directions.length; i++) {
for (var j = 0; j < directions.length; j++) {
if (directions[i] === 0 && directions[j] === 0) continue;
var newRow = row + directions[i];
var newCol = col + directions[j];
if (isValidSquare(newRow, newCol)) {
moves.push({
row: newRow,
col: newCol
});
}
}
}
return moves;
}
function handleSquareClick(row, col) {
if (gameState !== 'playing') return;
if (selectedSquare) {
// Check if clicked square is a possible move
var isPossibleMove = false;
for (var i = 0; i < possibleMoves.length; i++) {
if (possibleMoves[i].row === row && possibleMoves[i].col === col) {
isPossibleMove = true;
break;
}
}
if (isPossibleMove) {
var moveData = null;
for (var i = 0; i < possibleMoves.length; i++) {
if (possibleMoves[i].row === row && possibleMoves[i].col === col) {
moveData = possibleMoves[i];
break;
}
}
makeMove(selectedSquare.row, selectedSquare.col, row, col, moveData);
} else {
clearSelection();
if (board[row][col] && board[row][col].color === currentPlayer) {
selectSquare(row, col);
}
}
} else {
if (board[row][col] && board[row][col].color === currentPlayer) {
selectSquare(row, col);
}
}
}
function selectSquare(row, col) {
selectedSquare = {
row: row,
col: col
};
possibleMoves = getPossibleMoves(row, col);
// Highlight selected square
var squareIndex = row * 8 + col;
squares[squareIndex].setSelected(true);
// Highlight possible moves
for (var i = 0; i < possibleMoves.length; i++) {
var move = possibleMoves[i];
var moveSquareIndex = move.row * 8 + move.col;
squares[moveSquareIndex].setPossibleMove(true);
}
}
function clearSelection() {
if (selectedSquare) {
var squareIndex = selectedSquare.row * 8 + selectedSquare.col;
squares[squareIndex].setSelected(false);
}
for (var i = 0; i < possibleMoves.length; i++) {
var move = possibleMoves[i];
var moveSquareIndex = move.row * 8 + move.col;
squares[moveSquareIndex].setPossibleMove(false);
}
selectedSquare = null;
possibleMoves = [];
}
function makeMove(fromRow, fromCol, toRow, toCol, moveData) {
var isCapture = board[toRow][toCol] !== null;
var movingPiece = findPieceAt(fromRow, fromCol);
// Remove captured piece first
if (isCapture) {
var capturedPiece = findPieceAt(toRow, toCol);
if (capturedPiece) {
capturedPiece.destroy();
for (var i = pieces.length - 1; i >= 0; i--) {
if (pieces[i] === capturedPiece) {
pieces.splice(i, 1);
break;
}
}
}
}
// Handle castling
if (moveData && moveData.castling) {
// Move king
board[toRow][toCol] = board[fromRow][fromCol];
board[fromRow][fromCol] = null;
if (movingPiece) {
movingPiece.moveTo(toRow, toCol);
}
// Move rook
var rookFromCol = moveData.castling === 'kingside' ? 7 : 0;
var rookToCol = moveData.castling === 'kingside' ? 5 : 3;
var rook = findPieceAt(fromRow, rookFromCol);
board[fromRow][rookToCol] = board[fromRow][rookFromCol];
board[fromRow][rookFromCol] = null;
if (rook) {
rook.moveTo(fromRow, rookToCol);
}
} else {
// Normal move
board[toRow][toCol] = board[fromRow][fromCol];
board[fromRow][fromCol] = null;
if (movingPiece) {
movingPiece.moveTo(toRow, toCol);
}
}
clearSelection();
// Play sound
if (isCapture) {
LK.getSound('capture').play();
} else {
LK.getSound('move').play();
}
// Switch players
currentPlayer = currentPlayer === 'white' ? 'black' : 'white';
gameStatusText.setText(currentPlayer === 'white' ? 'White to move' : 'Black to move');
// Check for game end
if (checkGameEnd()) {
return;
}
// Online/friend mode - no AI moves
if (gameMode === 'online' && currentPlayer === 'black') {
LK.setTimeout(function () {
makeAIMove();
}, 500);
}
}
function findPieceAt(row, col) {
for (var i = 0; i < pieces.length; i++) {
if (pieces[i].boardRow === row && pieces[i].boardCol === col) {
return pieces[i];
}
}
return null;
}
function makeAIMove() {
var possibleAIMoves = [];
// Find all possible moves for AI (black)
for (var row = 0; row < 8; row++) {
for (var col = 0; col < 8; col++) {
if (board[row][col] && board[row][col].color === 'black') {
var moves = getPossibleMoves(row, col);
for (var i = 0; i < moves.length; i++) {
possibleAIMoves.push({
from: {
row: row,
col: col
},
to: {
row: moves[i].row,
col: moves[i].col
}
});
}
}
}
}
if (possibleAIMoves.length > 0) {
// Simple AI: random move
var randomMove = possibleAIMoves[Math.floor(Math.random() * possibleAIMoves.length)];
makeMove(randomMove.from.row, randomMove.from.col, randomMove.to.row, randomMove.to.col);
}
}
function checkGameEnd() {
// Check if king was captured
var whiteKing = false;
var blackKing = false;
var whiteKingPos = null;
var blackKingPos = null;
for (var row = 0; row < 8; row++) {
for (var col = 0; col < 8; col++) {
if (board[row][col] && board[row][col].type === 'King') {
if (board[row][col].color === 'white') {
whiteKing = true;
whiteKingPos = {
row: row,
col: col
};
} else {
blackKing = true;
blackKingPos = {
row: row,
col: col
};
}
}
}
}
if (!whiteKing) {
endGame('Black wins by capturing the king!');
return true;
} else if (!blackKing) {
endGame('White wins by capturing the king!');
return true;
}
// Check for checkmate/stalemate
var kingPos = currentPlayer === 'white' ? whiteKingPos : blackKingPos;
var inCheck = isSquareUnderAttack(kingPos.row, kingPos.col, currentPlayer);
var hasLegalMoves = false;
// Check if current player has any legal moves
for (var row = 0; row < 8; row++) {
for (var col = 0; col < 8; col++) {
if (board[row][col] && board[row][col].color === currentPlayer) {
var moves = getPossibleMoves(row, col);
for (var i = 0; i < moves.length; i++) {
if (isLegalMove(row, col, moves[i].row, moves[i].col)) {
hasLegalMoves = true;
break;
}
}
if (hasLegalMoves) break;
}
}
if (hasLegalMoves) break;
}
if (!hasLegalMoves) {
if (inCheck) {
endGame((currentPlayer === 'white' ? 'Black' : 'White') + ' wins by checkmate!');
} else {
endGame('Draw by stalemate!');
}
return true;
}
return false;
}
function isLegalMove(fromRow, fromCol, toRow, toCol) {
// Simulate the move and check if king is still safe
var originalPiece = board[toRow][toCol];
var movingPiece = board[fromRow][fromCol];
// Make temporary move
board[toRow][toCol] = movingPiece;
board[fromRow][fromCol] = null;
// Find king position
var kingRow, kingCol;
for (var row = 0; row < 8; row++) {
for (var col = 0; col < 8; col++) {
if (board[row][col] && board[row][col].type === 'King' && board[row][col].color === movingPiece.color) {
kingRow = row;
kingCol = col;
break;
}
}
if (kingRow !== undefined) break;
}
var isLegal = !isSquareUnderAttack(kingRow, kingCol, movingPiece.color);
// Undo the move
board[fromRow][fromCol] = movingPiece;
board[toRow][toCol] = originalPiece;
return isLegal;
}
function endGame(result) {
gameState = 'gameOver';
gameStatusText.setText(result);
// Update stats
storage.gamesPlayed++;
if (result.includes('White wins')) {
storage.wins++;
storage.playerELO += 20;
} else if (result.includes('Black wins')) {
storage.losses++;
storage.playerELO -= 15;
} else {
storage.draws++;
storage.playerELO += 5;
}
// Save user data after match
saveUserData();
LK.setTimeout(function () {
LK.showGameOver();
}, 2000);
}
function startNewGame() {
gameState = 'playing';
currentPlayer = 'white';
selectedSquare = null;
possibleMoves = [];
initializeBoard();
createBoardVisual();
showGameUI();
gameStatusText.setText('White to move');
}
function returnToMenu() {
gameState = 'menu';
clearSelection();
// Clean up game elements
for (var i = squares.length - 1; i >= 0; i--) {
squares[i].destroy();
}
squares = [];
for (var i = pieces.length - 1; i >= 0; i--) {
pieces[i].destroy();
}
pieces = [];
showMenuUI();
}
function loginUser(username) {
var userId = 'user_' + username.toLowerCase().replace(/[^a-z0-9]/g, '');
storage.username = username;
storage.userId = userId;
storage.isLoggedIn = true;
// Initialize user data if new user
if (!storage[userId]) {
storage[userId] = {
username: username,
elo: 1200,
gamesPlayed: 0,
wins: 0,
losses: 0,
draws: 0,
friends: [],
friendRequests: [],
created: Date.now()
};
}
loadUserData();
showMainMenu();
}
function logoutUser() {
storage.isLoggedIn = false;
storage.username = '';
storage.userId = '';
gameState = 'login';
showLoginUI();
}
function loadUserData() {
var userData = storage[storage.userId];
if (userData) {
storage.playerELO = userData.elo;
storage.gamesPlayed = userData.gamesPlayed;
storage.wins = userData.wins;
storage.losses = userData.losses;
storage.draws = userData.draws;
storage.friends = userData.friends || [];
storage.friendRequests = userData.friendRequests || [];
}
}
function saveUserData() {
if (storage.userId) {
storage[storage.userId] = {
username: storage.username,
elo: storage.playerELO,
gamesPlayed: storage.gamesPlayed,
wins: storage.wins,
losses: storage.losses,
draws: storage.draws,
friends: storage.friends,
friendRequests: storage.friendRequests,
lastOnline: Date.now()
};
}
}
function addFriend(friendUsername) {
if (friendUsername === storage.username) {
return; // Can't add yourself
}
var friendUserId = 'user_' + friendUsername.toLowerCase().replace(/[^a-z0-9]/g, '');
// Check if friend exists
if (storage[friendUserId]) {
// Check if already friends
var isAlreadyFriend = false;
for (var i = 0; i < storage.friends.length; i++) {
if (storage.friends[i].userId === friendUserId) {
isAlreadyFriend = true;
break;
}
}
if (!isAlreadyFriend) {
// Add to friends list
storage.friends.push({
userId: friendUserId,
username: friendUsername,
addedTime: Date.now()
});
saveUserData();
updateFriendsList();
}
}
}
function startFriendMatch(friendData) {
var matchId = 'match_' + Date.now() + '_' + Math.random().toString(36).substr(2, 5);
currentMatch = {
id: matchId,
player1: storage.userId,
player2: friendData.userId,
currentPlayer: 'white',
moves: [],
started: Date.now()
};
storage['match_' + matchId] = currentMatch;
gameMode = 'friend';
startNewGame();
}
function findOnlineMatch() {
// Simple matchmaking - find another player looking for a match
var matchFound = false;
var allKeys = Object.keys(storage);
for (var i = 0; i < allKeys.length; i++) {
var key = allKeys[i];
if (key.startsWith('waiting_')) {
var waitingPlayer = storage[key];
if (waitingPlayer.userId !== storage.userId) {
// Found a match
startOnlineMatch(waitingPlayer);
delete storage[key];
matchFound = true;
break;
}
}
}
if (!matchFound) {
// No match found, add to waiting list
storage['waiting_' + storage.userId] = {
userId: storage.userId,
username: storage.username,
elo: storage.playerELO,
timestamp: Date.now()
};
gameStatusText.setText('Looking for opponent...');
checkForOnlineMatch();
}
}
function checkForOnlineMatch() {
// Check if someone matched with us
var matchFound = false;
var allKeys = Object.keys(storage);
for (var i = 0; i < allKeys.length; i++) {
var key = allKeys[i];
if (key.startsWith('match_') && storage[key].player2 === storage.userId) {
currentMatch = storage[key];
startNewGame();
matchFound = true;
break;
}
}
if (!matchFound) {
LK.setTimeout(function () {
checkForOnlineMatch();
}, 1000);
}
}
function startOnlineMatch(opponent) {
var matchId = 'match_' + Date.now() + '_' + Math.random().toString(36).substr(2, 5);
currentMatch = {
id: matchId,
player1: storage.userId,
player2: opponent.userId,
currentPlayer: 'white',
moves: [],
started: Date.now()
};
storage['match_' + matchId] = currentMatch;
gameMode = 'online';
startNewGame();
}
function updateFriendsList() {
// Clear existing friend list
for (var i = friendsListContainer.children.length - 1; i >= 0; i--) {
friendsListContainer.removeChild(friendsListContainer.children[i]);
}
var yOffset = 0;
for (var i = 0; i < storage.friends.length; i++) {
var friend = storage.friends[i];
var friendData = storage[friend.userId];
if (friendData) {
var friendItem = new FriendListItem({
username: friend.username,
userId: friend.userId,
online: friendData.lastOnline && Date.now() - friendData.lastOnline < 300000 // 5 minutes
}, function (friendData) {
startFriendMatch(friendData);
});
friendItem.x = 0;
friendItem.y = yOffset;
friendsListContainer.addChild(friendItem);
yOffset += 100;
}
}
}
function showLoginUI() {
// Clear all UI
clearAllUI();
game.addChild(titleText);
game.addChild(usernameInput);
game.addChild(loginButton);
gameState = 'login';
}
function showMainMenu() {
// Clear all UI
clearAllUI();
// Update display texts
welcomeText.setText('Welcome, ' + storage.username + '!');
eloText.setText('ELO: ' + storage.playerELO);
statsText.setText('Games: ' + storage.gamesPlayed + ' W:' + storage.wins + ' L:' + storage.losses + ' D:' + storage.draws);
game.addChild(welcomeText);
game.addChild(eloText);
game.addChild(statsText);
game.addChild(quickMatchButton);
game.addChild(friendsButton);
game.addChild(logoutButton);
gameState = 'menu';
}
function showFriendsUI() {
// Clear all UI
clearAllUI();
game.addChild(friendsTitleText);
game.addChild(addFriendInput);
game.addChild(addFriendButton);
game.addChild(friendsListContainer);
game.addChild(backToMenuButton);
updateFriendsList();
gameState = 'friends';
}
function showGameUI() {
// Clear all UI
clearAllUI();
game.addChild(gameStatusText);
game.addChild(backButton);
gameState = 'playing';
}
function clearAllUI() {
// Remove all UI elements
var uiElements = [titleText, welcomeText, eloText, statsText, usernameInput, loginButton, quickMatchButton, friendsButton, logoutButton, friendsTitleText, addFriendInput, addFriendButton, friendsListContainer, backToMenuButton, gameStatusText, backButton];
for (var i = 0; i < uiElements.length; i++) {
if (uiElements[i].parent) {
game.removeChild(uiElements[i]);
}
}
}
// Initialize based on login status
if (storage.isLoggedIn && storage.username) {
loadUserData();
showMainMenu();
} else {
showLoginUI();
}
// Handle text input for username
var inputText = '';
var lastKeyTime = 0;
game.down = function (x, y, obj) {
if (gameState === 'login' && usernameInput.isFocused) {
// Simple text input simulation - click to cycle through characters
var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
var now = Date.now();
if (now - lastKeyTime > 200) {
// Prevent too fast input
var charIndex = Math.floor(Math.random() * chars.length);
if (usernameInput.value.length < 15) {
usernameInput.setText(usernameInput.value + chars[charIndex]);
}
lastKeyTime = now;
}
} else if (gameState === 'friends' && addFriendInput.isFocused) {
// Same for friend input
var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
var now = Date.now();
if (now - lastKeyTime > 200) {
var charIndex = Math.floor(Math.random() * chars.length);
if (addFriendInput.value.length < 15) {
addFriendInput.setText(addFriendInput.value + chars[charIndex]);
}
lastKeyTime = now;
}
}
};
game.update = function () {
// Auto-save user data periodically
if (LK.ticks % 300 === 0 && storage.isLoggedIn) {
// Every 5 seconds
saveUserData();
}
// Update friends list periodically when viewing friends
if (gameState === 'friends' && LK.ticks % 600 === 0) {
// Every 10 seconds
updateFriendsList();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -139,12 +139,12 @@
self.setText = function (text) {
self.value = text;
if (text.length > 0) {
self.displayText.setText(text);
- self.displayText.style.fill = 0xFFFFFF;
+ self.displayText.tint = 0xFFFFFF;
} else {
self.displayText.setText(self.placeholder);
- self.displayText.style.fill = 0xCCCCCC;
+ self.displayText.tint = 0xCCCCCC;
}
};
self.down = function (x, y, obj) {
self.isFocused = true;
beyazpiyon. In-Game asset. 2d. High contrast. No shadows
beyaz satranç atı. In-Game asset. 2d. High contrast. No shadows
beyaz satranç kalesi. In-Game asset. 2d. High contrast. No shadows
white chess king. In-Game asset. 2d. High contrast. No shadows
beyaz satranç fili. In-Game asset. 2d. High contrast. No shadows
beyaz vezir. In-Game asset. 2d. High contrast. No shadows
siyah vezir. In-Game asset. 2d. High contrast. No shadows
siyah satranç kalesi. In-Game asset. 2d. High contrast. No shadows
siyah piyon. In-Game asset. 2d. High contrast. No shadows
siyah satranç atı. In-Game asset. 2d. High contrast. No shadows
siyah şah. In-Game asset. 2d. High contrast. No shadows
siyah satranç fili. In-Game asset. 2d. High contrast. No shadows. siyah satranç fili
satranç ile ilgili buton resmi. In-Game asset. 2d. High contrast. No shadows
gölgelendirmeli koyu yeşil buton. In-Game asset. 2d. High contrast. No shadows
en altla havalı kalın ve grafik çizim olarak italik bir yazıyla Chess Master yazan koyu renk temalı 3 adet ortada büyük şah sağda vezir ve solda fil olacak şekilde satranç taşları. In-Game asset. 2d. High contrast. No shadows