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 ? 'Çevrimiçi' : 'Çevrimdışı', {
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) {
// Clear other input focus first
if (usernameInput && usernameInput !== self) {
usernameInput.isFocused = false;
usernameInput.children[0].tint = 0x333333;
}
if (passwordInput && passwordInput !== self) {
passwordInput.isFocused = false;
passwordInput.children[0].tint = 0x333333;
}
if (addFriendInput && addFriendInput !== self) {
addFriendInput.isFocused = false;
addFriendInput.children[0].tint = 0x333333;
}
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('Çevrimiçi Satranç Ustası', {
size: 84,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 300;
var usernameInput = new InputField('Kullanıcı Adı Girin', 600);
usernameInput.x = 1024;
usernameInput.y = 500;
var passwordInput = new InputField('Şifre Girin', 600);
passwordInput.x = 1024;
passwordInput.y = 650;
var loginButton = new MenuButton('Giriş Yap', function () {
if (usernameInput.value.length > 2 && passwordInput.value.length > 2) {
loginUser(usernameInput.value, passwordInput.value);
}
});
loginButton.x = 1024;
loginButton.y = 800;
var registerButton = new MenuButton('Kayıt Ol', function () {
if (usernameInput.value.length > 2 && passwordInput.value.length > 2) {
registerUser(usernameInput.value, passwordInput.value);
}
});
registerButton.x = 1024;
registerButton.y = 950;
// 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('Hızlı Maç', function () {
gameMode = 'online';
findOnlineMatch();
});
quickMatchButton.x = 1024;
quickMatchButton.y = 750;
var friendsButton = new MenuButton('Arkadaşlar', function () {
showFriendsUI();
});
friendsButton.x = 1024;
friendsButton.y = 900;
var logoutButton = new MenuButton('Çıkış Yap', function () {
logoutUser();
});
logoutButton.x = 1024;
logoutButton.y = 1050;
// Friends UI
var friendsTitleText = new Text2('Arkadaşlar ve Maçlar', {
size: 64,
fill: 0xFFFFFF
});
friendsTitleText.anchor.set(0.5, 0.5);
friendsTitleText.x = 1024;
friendsTitleText.y = 250;
var addFriendInput = new InputField('Arkadaş Kullanıcı Adı', 500);
addFriendInput.x = 1024;
addFriendInput.y = 350;
var addFriendButton = new MenuButton('Arkadaş Ekle', 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('Menüye Dön', function () {
showMainMenu();
});
backToMenuButton.x = 1024;
backToMenuButton.y = 2200;
// Game status display with larger text
var gameStatusText = new Text2('Beyazın hamlesi', {
size: 64,
fill: 0xFFFFFF
});
gameStatusText.anchor.set(0.5, 0.5);
gameStatusText.x = 1024;
gameStatusText.y = 200;
var backButton = new MenuButton('Menüye Dön', function () {
returnToMenu();
});
backButton.x = 1024;
backButton.y = 2400;
// Game UI elements
var gameStatusText = new Text2('Beyazın hamlesi', {
size: 48,
fill: 0xFFFFFF
});
gameStatusText.anchor.set(0.5, 0.5);
gameStatusText.x = 1024;
gameStatusText.y = 300;
var backButton = new MenuButton('Menüye Dön', 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' ? 'Beyazın hamlesi' : 'Siyahın hamlesi');
// 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('Siyah şahı ele geçirerek kazandı!');
return true;
} else if (!blackKing) {
endGame('Beyaz şahı ele geçirerek kazandı!');
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' ? 'Siyah' : 'Beyaz') + ' şah mat ile kazandı!');
} else {
endGame('Pat ile berabere!');
}
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('Beyazın hamlesi');
}
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 = [];
showMainMenu();
}
function loginUser(username, password) {
var userId = 'user_' + username.toLowerCase().replace(/[^a-z0-9]/g, '');
var storedPassword = storage['password_' + userId];
if (storedPassword && storedPassword === password) {
storage.username = username;
storage.userId = userId;
storage.isLoggedIn = true;
loadUserData();
showMainMenu();
} else {
// Wrong password or user doesn't exist
titleText.setText('Hatalı kullanıcı adı veya şifre!');
LK.setTimeout(function () {
titleText.setText('Çevrimiçi Satranç Ustası');
}, 2000);
}
}
function registerUser(username, password) {
var userId = 'user_' + username.toLowerCase().replace(/[^a-z0-9]/g, '');
var storedPassword = storage['password_' + userId];
if (!storedPassword) {
// New user registration
storage['password_' + userId] = password;
storage.username = username;
storage.userId = userId;
storage.isLoggedIn = true;
// Initialize user data for new user
storage.playerELO = 1200;
storage.gamesPlayed = 0;
storage.wins = 0;
storage.losses = 0;
storage.draws = 0;
storage.friends = [];
storage.friendRequests = [];
storage.userCreated = Date.now();
loadUserData();
showMainMenu();
} else {
// User already exists
titleText.setText('Bu kullanıcı adı zaten mevcut!');
LK.setTimeout(function () {
titleText.setText('Çevrimiçi Satranç Ustası');
}, 2000);
}
}
function logoutUser() {
storage.isLoggedIn = false;
storage.username = '';
storage.userId = '';
gameState = 'login';
showLoginUI();
}
function loadUserData() {
// Data is already in storage, no need to load from nested object
// Storage plugin handles persistence automatically
}
function saveUserData() {
if (storage.userId) {
storage.lastOnline = Date.now();
// Storage plugin automatically persists data
}
}
function addFriend(friendUsername) {
if (friendUsername === storage.username) {
return; // Can't add yourself
}
var friendUserId = 'user_' + friendUsername.toLowerCase().replace(/[^a-z0-9]/g, '');
// Check if already friends
var isAlreadyFriend = false;
var currentFriends = storage.friends || [];
for (var i = 0; i < currentFriends.length; i++) {
if (currentFriends[i].userId === friendUserId) {
isAlreadyFriend = true;
break;
}
}
if (!isAlreadyFriend) {
// Add to friends list
var newFriend = {
userId: friendUserId,
username: friendUsername,
addedTime: Date.now()
};
currentFriends.push(newFriend);
storage.friends = currentFriends;
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() {
// Simplified matchmaking - start AI match instead
gameMode = 'online';
startNewGame();
}
function checkForOnlineMatch() {
// Simplified - immediately start AI match
startNewGame();
}
function startOnlineMatch(opponent) {
var matchId = 'match_' + Date.now() + '_' + Math.random().toString(36).substr(2, 5);
currentMatch = {
id: matchId,
player1: storage.userId,
player2: 'ai_opponent',
currentPlayer: 'white',
moves: [],
started: Date.now()
};
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 friendItem = new FriendListItem({
username: friend.username,
userId: friend.userId,
online: true // Simplified - assume friends are online
}, 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(passwordInput);
game.addChild(loginButton);
game.addChild(registerButton);
gameState = 'login';
}
function showMainMenu() {
// Clear all UI
clearAllUI();
// Update display texts
welcomeText.setText('Hoş geldin, ' + storage.username + '!');
eloText.setText('ELO: ' + storage.playerELO);
statsText.setText('Maçlar: ' + storage.gamesPlayed + ' G:' + storage.wins + ' K:' + storage.losses + ' B:' + 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() {
// Hide virtual keyboard first
hideVirtualKeyboard();
// Remove all UI elements
var uiElements = [titleText, welcomeText, eloText, statsText, usernameInput, passwordInput, loginButton, registerButton, 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();
}
// Virtual keyboard system
var virtualKeyboard = null;
var currentInputField = null;
var keyboardVisible = false;
function createVirtualKeyboard() {
var keyboard = new Container();
keyboard.x = 224;
keyboard.y = 1400;
// Keyboard background
var keyboardBg = keyboard.addChild(LK.getAsset('chessBoard', {
anchorX: 0,
anchorY: 0,
scaleX: 1,
scaleY: 0.8
}));
keyboardBg.tint = 0x1a1a1a;
// Create keyboard layout
var layout = [['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'], ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'], ['z', 'x', 'c', 'v', 'b', 'n', 'm', 'DEL'], ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'], ['SPACE', 'DONE']];
var keyWidth = 140;
var keyHeight = 100;
var keySpacing = 20;
for (var row = 0; row < layout.length; row++) {
for (var col = 0; col < layout[row].length; col++) {
var _char = layout[row][col];
var key = new Container();
var startX = row === 1 ? keyWidth * 0.5 : row === 2 ? keyWidth * 1 : 0;
key.x = startX + col * (keyWidth + keySpacing);
key.y = row * (keyHeight + keySpacing);
// Key background
var keyBg = key.addChild(LK.getAsset('menuButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: keyWidth / 400,
scaleY: keyHeight / 120
}));
keyBg.tint = 0x444444;
// Key text
var keyText = new Text2(_char === 'SPACE' ? 'BOŞ' : _char === 'DONE' ? 'TAMAM' : _char, {
size: _char.length > 1 ? 24 : 32,
fill: 0xFFFFFF
});
keyText.anchor.set(0.5, 0.5);
key.addChild(keyText);
// Store character for click handling
key.character = _char;
// Click handler
key.down = function (x, y, obj) {
if (!currentInputField) return;
var _char2 = this.character;
if (_char2 === 'DEL') {
// Delete character
if (currentInputField.value.length > 0) {
currentInputField.setText(currentInputField.value.slice(0, -1));
}
} else if (_char2 === 'SPACE') {
// Add space
if (currentInputField.value.length < 20) {
currentInputField.setText(currentInputField.value + ' ');
}
} else if (_char2 === 'DONE') {
// Hide keyboard
hideVirtualKeyboard();
} else {
// Add character
if (currentInputField.value.length < 20) {
currentInputField.setText(currentInputField.value + _char2);
}
}
};
keyboard.addChild(key);
}
}
return keyboard;
}
function showVirtualKeyboard(inputField) {
if (!virtualKeyboard) {
virtualKeyboard = createVirtualKeyboard();
}
currentInputField = inputField;
keyboardVisible = true;
game.addChild(virtualKeyboard);
}
function hideVirtualKeyboard() {
if (virtualKeyboard && virtualKeyboard.parent) {
game.removeChild(virtualKeyboard);
}
currentInputField = null;
keyboardVisible = false;
}
game.down = function (x, y, obj) {
// Handle virtual keyboard when input fields are focused
if (gameState === 'login' && (usernameInput.isFocused || passwordInput.isFocused)) {
if (usernameInput.isFocused && !keyboardVisible) {
showVirtualKeyboard(usernameInput);
} else if (passwordInput.isFocused && !keyboardVisible) {
showVirtualKeyboard(passwordInput);
}
} else if (gameState === 'friends' && addFriendInput.isFocused && !keyboardVisible) {
showVirtualKeyboard(addFriendInput);
}
};
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
@@ -146,8 +146,21 @@
self.displayText.tint = 0xCCCCCC;
}
};
self.down = function (x, y, obj) {
+ // Clear other input focus first
+ if (usernameInput && usernameInput !== self) {
+ usernameInput.isFocused = false;
+ usernameInput.children[0].tint = 0x333333;
+ }
+ if (passwordInput && passwordInput !== self) {
+ passwordInput.isFocused = false;
+ passwordInput.children[0].tint = 0x333333;
+ }
+ if (addFriendInput && addFriendInput !== self) {
+ addFriendInput.isFocused = false;
+ addFriendInput.children[0].tint = 0x333333;
+ }
self.isFocused = true;
fieldBackground.tint = 0x4169e1;
};
return self;
@@ -1182,8 +1195,10 @@
game.addChild(backButton);
gameState = 'playing';
}
function clearAllUI() {
+ // Hide virtual keyboard first
+ hideVirtualKeyboard();
// Remove all UI elements
var uiElements = [titleText, welcomeText, eloText, statsText, usernameInput, passwordInput, loginButton, registerButton, quickMatchButton, friendsButton, logoutButton, friendsTitleText, addFriendInput, addFriendButton, friendsListContainer, backToMenuButton, gameStatusText, backButton];
for (var i = 0; i < uiElements.length; i++) {
if (uiElements[i].parent) {
@@ -1197,46 +1212,107 @@
showMainMenu();
} else {
showLoginUI();
}
-// Handle text input for username
-var inputText = '';
-var lastKeyTime = 0;
+// Virtual keyboard system
+var virtualKeyboard = null;
+var currentInputField = null;
+var keyboardVisible = false;
+function createVirtualKeyboard() {
+ var keyboard = new Container();
+ keyboard.x = 224;
+ keyboard.y = 1400;
+ // Keyboard background
+ var keyboardBg = keyboard.addChild(LK.getAsset('chessBoard', {
+ anchorX: 0,
+ anchorY: 0,
+ scaleX: 1,
+ scaleY: 0.8
+ }));
+ keyboardBg.tint = 0x1a1a1a;
+ // Create keyboard layout
+ var layout = [['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'], ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'], ['z', 'x', 'c', 'v', 'b', 'n', 'm', 'DEL'], ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'], ['SPACE', 'DONE']];
+ var keyWidth = 140;
+ var keyHeight = 100;
+ var keySpacing = 20;
+ for (var row = 0; row < layout.length; row++) {
+ for (var col = 0; col < layout[row].length; col++) {
+ var _char = layout[row][col];
+ var key = new Container();
+ var startX = row === 1 ? keyWidth * 0.5 : row === 2 ? keyWidth * 1 : 0;
+ key.x = startX + col * (keyWidth + keySpacing);
+ key.y = row * (keyHeight + keySpacing);
+ // Key background
+ var keyBg = key.addChild(LK.getAsset('menuButton', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: keyWidth / 400,
+ scaleY: keyHeight / 120
+ }));
+ keyBg.tint = 0x444444;
+ // Key text
+ var keyText = new Text2(_char === 'SPACE' ? 'BOŞ' : _char === 'DONE' ? 'TAMAM' : _char, {
+ size: _char.length > 1 ? 24 : 32,
+ fill: 0xFFFFFF
+ });
+ keyText.anchor.set(0.5, 0.5);
+ key.addChild(keyText);
+ // Store character for click handling
+ key.character = _char;
+ // Click handler
+ key.down = function (x, y, obj) {
+ if (!currentInputField) return;
+ var _char2 = this.character;
+ if (_char2 === 'DEL') {
+ // Delete character
+ if (currentInputField.value.length > 0) {
+ currentInputField.setText(currentInputField.value.slice(0, -1));
+ }
+ } else if (_char2 === 'SPACE') {
+ // Add space
+ if (currentInputField.value.length < 20) {
+ currentInputField.setText(currentInputField.value + ' ');
+ }
+ } else if (_char2 === 'DONE') {
+ // Hide keyboard
+ hideVirtualKeyboard();
+ } else {
+ // Add character
+ if (currentInputField.value.length < 20) {
+ currentInputField.setText(currentInputField.value + _char2);
+ }
+ }
+ };
+ keyboard.addChild(key);
+ }
+ }
+ return keyboard;
+}
+function showVirtualKeyboard(inputField) {
+ if (!virtualKeyboard) {
+ virtualKeyboard = createVirtualKeyboard();
+ }
+ currentInputField = inputField;
+ keyboardVisible = true;
+ game.addChild(virtualKeyboard);
+}
+function hideVirtualKeyboard() {
+ if (virtualKeyboard && virtualKeyboard.parent) {
+ game.removeChild(virtualKeyboard);
+ }
+ currentInputField = null;
+ keyboardVisible = false;
+}
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;
+ // Handle virtual keyboard when input fields are focused
+ if (gameState === 'login' && (usernameInput.isFocused || passwordInput.isFocused)) {
+ if (usernameInput.isFocused && !keyboardVisible) {
+ showVirtualKeyboard(usernameInput);
+ } else if (passwordInput.isFocused && !keyboardVisible) {
+ showVirtualKeyboard(passwordInput);
}
- } else if (gameState === 'login' && passwordInput.isFocused) {
- // Password input
- var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*';
- var now = Date.now();
- if (now - lastKeyTime > 200) {
- var charIndex = Math.floor(Math.random() * chars.length);
- if (passwordInput.value.length < 20) {
- passwordInput.setText(passwordInput.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;
- }
+ } else if (gameState === 'friends' && addFriendInput.isFocused && !keyboardVisible) {
+ showVirtualKeyboard(addFriendInput);
}
};
game.update = function () {
// Auto-save user data periodically
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