User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'trim')' in or related to this line: 'if (roomName !== 'Enter room name...' && roomName.trim() !== '') {' Line Number: 291
User prompt
yes it's good but add main menu create room join add settings and languages and develop more more mini games
User prompt
yes it's good but add main menu create room join add settings and languages and develop more more mini games
Code edit (1 edits merged)
Please save this source code
User prompt
Chat Party Games
Initial prompt
place to chat but basic games can be played
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { username: "Player", color: "#3498db", rooms: [] }); /**** * Classes ****/ var Avatar = Container.expand(function () { var self = Container.call(this); var avatarGraphic = self.attachAsset('avatar', { anchorX: 0.5, anchorY: 0.5 }); self.nameText = new Text2('Player', { size: 24, fill: 0xFFFFFF }); self.nameText.anchor.set(0.5, 0); self.nameText.y = 80; self.addChild(self.nameText); self.setName = function (name) { self.nameText.setText(name); }; self.setColor = function (color) { avatarGraphic.tint = parseInt(color.replace('#', '0x')); }; self.down = function (x, y, obj) { LK.getSound('select').play(); }; return self; }); var Button = Container.expand(function (text, width, height, color) { var self = Container.call(this); var buttonWidth = width || 180; var buttonHeight = height || 60; var buttonColor = color || 'gameButton'; var buttonGraphic = self.attachAsset(buttonColor, { anchorX: 0.5, anchorY: 0.5, width: buttonWidth, height: buttonHeight }); self.label = new Text2(text, { size: 28, fill: 0xFFFFFF }); self.label.anchor.set(0.5, 0.5); self.addChild(self.label); self.setLabel = function (newText) { self.label.setText(newText); }; self.down = function (x, y, obj) { tween(buttonGraphic, { scaleX: 0.95, scaleY: 0.95 }, { duration: 100 }); LK.getSound('select').play(); }; self.up = function (x, y, obj) { tween(buttonGraphic, { scaleX: 1, scaleY: 1 }, { duration: 100 }); }; return self; }); var ChatBubble = Container.expand(function (message, isUser) { var self = Container.call(this); var bubbleGraphic = self.attachAsset('chatBubble', { anchorX: 0, anchorY: 0 }); if (isUser) { bubbleGraphic.tint = 0xDCF8C6; // Light green for user messages } self.messageText = new Text2(message, { size: 24, fill: 0x333333 }); self.messageText.x = 20; self.messageText.y = 15; self.addChild(self.messageText); // Adjust height based on content var textHeight = self.messageText.height + 30; var bubbleHeight = Math.max(textHeight, 60); bubbleGraphic.height = bubbleHeight; return self; }); var ChatPanel = Container.expand(function () { var self = Container.call(this); var panelGraphic = self.attachAsset('chatPanel', { anchorX: 0, anchorY: 0 }); self.messages = []; self.messageContainer = new Container(); self.addChild(self.messageContainer); self.messageContainer.x = 50; self.messageContainer.y = 20; self.inputField = self.addChild(LK.getAsset('inputField', { anchorX: 0, anchorY: 0 })); self.inputField.x = 50; self.inputField.y = panelGraphic.height - 80; self.inputText = new Text2('Type a message...', { size: 24, fill: 0x888888 }); self.inputText.x = self.inputField.x + 20; self.inputText.y = self.inputField.y + 18; self.addChild(self.inputText); var sendButton = new Button('Send', 80, 60, 'sendButton'); sendButton.x = self.inputField.x + self.inputField.width + 40; sendButton.y = self.inputField.y + 30; self.addChild(sendButton); self.addMessage = function (message, isUser) { var bubble = new ChatBubble(message, isUser); if (self.messages.length > 0) { var lastMessage = self.messages[self.messages.length - 1]; bubble.y = lastMessage.y + lastMessage.height + 10; } self.messages.push(bubble); self.messageContainer.addChild(bubble); // Limit messages and scroll if needed if (self.messages.length > 8) { var oldMessage = self.messages.shift(); self.messageContainer.removeChild(oldMessage); // Adjust positions for (var i = 0; i < self.messages.length; i++) { if (i === 0) { self.messages[i].y = 0; } else { self.messages[i].y = self.messages[i - 1].y + self.messages[i - 1].height + 10; } } } LK.getSound('message').play(); }; self.clearMessages = function () { for (var i = 0; i < self.messages.length; i++) { self.messageContainer.removeChild(self.messages[i]); } self.messages = []; }; self.sendMessage = function () { if (self.inputText.text !== 'Type a message...' && self.inputText.text.trim() !== '') { var message = self.inputText.text; self.addMessage(message, true); self.inputText.setText('Type a message...'); // Simulate response after delay LK.setTimeout(function () { var responses = ["That's interesting!", "I see what you mean.", "Let's play a game instead?", "Cool! Want to try tic-tac-toe?", "I agree completely."]; var randomResponse = responses[Math.floor(Math.random() * responses.length)]; self.addMessage(randomResponse, false); }, 1000 + Math.random() * 1000); return message; } return null; }; // Input field interaction self.inputField.down = function () { if (self.inputText.text === 'Type a message...') { self.inputText.setText(''); self.inputText.style.fill = "#333333"; } }; sendButton.down = function () { sendButton.up(); self.sendMessage(); }; return self; }); var RoomListItem = Container.expand(function (roomName, playerCount) { var self = Container.call(this); var itemGraphic = self.attachAsset('roomListItem', { anchorX: 0, anchorY: 0 }); self.roomNameText = new Text2(roomName, { size: 28, fill: 0x333333 }); self.roomNameText.x = 20; self.roomNameText.y = 15; self.addChild(self.roomNameText); self.playerCountText = new Text2(playerCount + " players", { size: 20, fill: 0x888888 }); self.playerCountText.x = 20; self.playerCountText.y = 50; self.addChild(self.playerCountText); var joinButton = new Button('Join', 120, 50, 'joinButton'); joinButton.x = itemGraphic.width - 80; joinButton.y = itemGraphic.height / 2; self.addChild(joinButton); self.down = function () { tween(itemGraphic, { tint: 0xf0f0f0 }, { duration: 100 }); }; self.up = function () { tween(itemGraphic, { tint: 0xffffff }, { duration: 100 }); }; joinButton.down = function () { joinButton.up(); if (typeof self.onJoin === 'function') { self.onJoin(roomName); } }; return self; }); var TicTacToeGame = Container.expand(function () { var self = Container.call(this); var boardGraphic = self.attachAsset('tictactoeBoard', { anchorX: 0.5, anchorY: 0.5 }); self.cells = []; self.gameBoard = [['', '', ''], ['', '', ''], ['', '', '']]; self.currentPlayer = 'X'; self.gameActive = true; // Create cells for (var row = 0; row < 3; row++) { for (var col = 0; col < 3; col++) { var cell = self.addChild(LK.getAsset('tictactoeCell', { anchorX: 0.5, anchorY: 0.5 })); cell.row = row; cell.col = col; cell.x = (col - 1) * 150; cell.y = (row - 1) * 150; cell.content = ''; cell.down = function () { if (self.gameActive && this.content === '') { self.makeMove(this.row, this.col); } }; self.cells.push(cell); } } self.statusText = new Text2("Player X's turn", { size: 32, fill: 0x333333 }); self.statusText.anchor.set(0.5, 0); self.statusText.y = boardGraphic.height / 2 + 40; self.addChild(self.statusText); self.makeMove = function (row, col) { if (!self.gameActive || self.gameBoard[row][col] !== '') { return; } // Update game board self.gameBoard[row][col] = self.currentPlayer; // Find the cell and update visually for (var i = 0; i < self.cells.length; i++) { var cell = self.cells[i]; if (cell.row === row && cell.col === col) { cell.content = self.currentPlayer; if (self.currentPlayer === 'X') { var x = cell.addChild(LK.getAsset('tictactoeX', { anchorX: 0.5, anchorY: 0.5 })); tween(x, { scaleX: 1, scaleY: 1 }, { duration: 200, easing: tween.bounceOut, onStart: function onStart() { x.scaleX = 0; x.scaleY = 0; } }); } else { var o = cell.addChild(LK.getAsset('tictactoeO', { anchorX: 0.5, anchorY: 0.5 })); tween(o, { scaleX: 1, scaleY: 1 }, { duration: 200, easing: tween.bounceOut, onStart: function onStart() { o.scaleX = 0; o.scaleY = 0; } }); } break; } } LK.getSound('select').play(); // Check for winner var winner = self.checkWinner(); if (winner) { self.gameActive = false; self.statusText.setText('Player ' + winner + ' wins!'); LK.getSound('gameover').play(); LK.setTimeout(function () { if (typeof self.onGameOver === 'function') { self.onGameOver(winner); } }, 2000); } else if (self.checkDraw()) { self.gameActive = false; self.statusText.setText("It's a draw!"); LK.getSound('gameover').play(); LK.setTimeout(function () { if (typeof self.onGameOver === 'function') { self.onGameOver(null); } }, 2000); } else { // Switch player self.currentPlayer = self.currentPlayer === 'X' ? 'O' : 'X'; self.statusText.setText("Player " + self.currentPlayer + "'s turn"); // If current player is O (AI), make an automated move if (self.currentPlayer === 'O') { LK.setTimeout(function () { self.makeAIMove(); }, 1000); } } }; self.checkWinner = function () { var lines = [ // Rows [[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]], [[2, 0], [2, 1], [2, 2]], // Columns [[0, 0], [1, 0], [2, 0]], [[0, 1], [1, 1], [2, 1]], [[0, 2], [1, 2], [2, 2]], // Diagonals [[0, 0], [1, 1], [2, 2]], [[0, 2], [1, 1], [2, 0]]]; for (var i = 0; i < lines.length; i++) { var _lines$i = _slicedToArray(lines[i], 3), _lines$i$ = _slicedToArray(_lines$i[0], 2), a = _lines$i$[0], b = _lines$i$[1], _lines$i$2 = _slicedToArray(_lines$i[1], 2), c = _lines$i$2[0], d = _lines$i$2[1], _lines$i$3 = _slicedToArray(_lines$i[2], 2), e = _lines$i$3[0], f = _lines$i$3[1]; if (self.gameBoard[a][b] && self.gameBoard[a][b] === self.gameBoard[c][d] && self.gameBoard[a][b] === self.gameBoard[e][f]) { return self.gameBoard[a][b]; } } return null; }; self.checkDraw = function () { for (var row = 0; row < 3; row++) { for (var col = 0; col < 3; col++) { if (self.gameBoard[row][col] === '') { return false; } } } return true; }; self.makeAIMove = function () { if (!self.gameActive) return; // Find empty cells var emptyCells = []; for (var row = 0; row < 3; row++) { for (var col = 0; col < 3; col++) { if (self.gameBoard[row][col] === '') { emptyCells.push({ row: row, col: col }); } } } if (emptyCells.length > 0) { var randomCell = emptyCells[Math.floor(Math.random() * emptyCells.length)]; self.makeMove(randomCell.row, randomCell.col); } }; self.reset = function () { // Clear the board for (var row = 0; row < 3; row++) { for (var col = 0; col < 3; col++) { self.gameBoard[row][col] = ''; } } // Reset cell visuals for (var i = 0; i < self.cells.length; i++) { var cell = self.cells[i]; cell.content = ''; // Remove all children (X or O graphics) while (cell.children.length > 0) { cell.removeChild(cell.children[0]); } } self.currentPlayer = 'X'; self.gameActive = true; self.statusText.setText("Player X's turn"); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xf5f7fa }); /**** * Game Code ****/ // Main app state function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } var currentScreen = 'lobby'; // 'lobby', 'room', 'game' var username = storage.username || 'Player'; var avatarColor = storage.color || '#3498db'; var currentRoomName = ''; // Create UI containers for different screens var lobbyScreen = new Container(); var roomScreen = new Container(); var gameScreen = new Container(); // Set up lobby screen var lobbyTitle = new Text2('Chat Party Games', { size: 80, fill: 0x2C3E50 }); lobbyTitle.anchor.set(0.5, 0); lobbyTitle.x = 2048 / 2; lobbyTitle.y = 100; lobbyScreen.addChild(lobbyTitle); var usernameText = new Text2('Your Name: ' + username, { size: 32, fill: 0x666666 }); usernameText.anchor.set(0.5, 0); usernameText.x = 2048 / 2; usernameText.y = 250; lobbyScreen.addChild(usernameText); var avatar = new Avatar(); avatar.x = 2048 / 2; avatar.y = 400; avatar.setName(username); avatar.setColor(avatarColor); lobbyScreen.addChild(avatar); var roomListTitle = new Text2('Available Rooms', { size: 40, fill: 0x2C3E50 }); roomListTitle.anchor.set(0.5, 0); roomListTitle.x = 2048 / 2; roomListTitle.y = 600; lobbyScreen.addChild(roomListTitle); // Create sample room list var roomList = new Container(); roomList.x = (2048 - 700) / 2; roomList.y = 680; lobbyScreen.addChild(roomList); var createRoomButton = new Button('Create Room', 250, 80); createRoomButton.x = 2048 / 2; createRoomButton.y = 2600; lobbyScreen.addChild(createRoomButton); // Setup room screen var roomTitle = new Text2('Room: Lobby', { size: 40, fill: 0x2C3E50 }); roomTitle.anchor.set(0.5, 0); roomTitle.x = 2048 / 2; roomTitle.y = 50; roomScreen.addChild(roomTitle); var chatPanel = new ChatPanel(); chatPanel.x = (2048 - 800) / 2; chatPanel.y = 120; roomScreen.addChild(chatPanel); var gameButtonsContainer = new Container(); gameButtonsContainer.x = 2048 / 2; gameButtonsContainer.y = 2000; roomScreen.addChild(gameButtonsContainer); var tictactoeButton = new Button('Tic-Tac-Toe', 250, 80); tictactoeButton.x = 0; tictactoeButton.y = 0; gameButtonsContainer.addChild(tictactoeButton); var backToLobbyButton = new Button('Back to Lobby', 250, 80); backToLobbyButton.x = 0; backToLobbyButton.y = 100; gameButtonsContainer.addChild(backToLobbyButton); // Setup game screen var gameTitle = new Text2('Tic-Tac-Toe', { size: 40, fill: 0x2C3E50 }); gameTitle.anchor.set(0.5, 0); gameTitle.x = 2048 / 2; gameTitle.y = 50; gameScreen.addChild(gameTitle); var ticTacToeGame = new TicTacToeGame(); ticTacToeGame.x = 2048 / 2; ticTacToeGame.y = 2732 / 2 - 200; gameScreen.addChild(ticTacToeGame); var backToRoomButton = new Button('Back to Room', 250, 80); backToRoomButton.x = 2048 / 2; backToRoomButton.y = 2500; gameScreen.addChild(backToRoomButton); // Add main container to game game.addChild(lobbyScreen); game.addChild(roomScreen); game.addChild(gameScreen); // Initially hide room and game screens roomScreen.visible = false; gameScreen.visible = false; // Function to switch between screens function showScreen(screenName) { lobbyScreen.visible = false; roomScreen.visible = false; gameScreen.visible = false; currentScreen = screenName; if (screenName === 'lobby') { lobbyScreen.visible = true; populateRoomList(); } else if (screenName === 'room') { roomScreen.visible = true; roomTitle.setText('Room: ' + currentRoomName); chatPanel.clearMessages(); chatPanel.addMessage('Welcome to ' + currentRoomName + '!', false); } else if (screenName === 'game') { gameScreen.visible = true; ticTacToeGame.reset(); } } // Populate the room list with sample rooms function populateRoomList() { // Clear existing rooms while (roomList.children.length > 0) { roomList.removeChild(roomList.children[0]); } // Sample rooms var rooms = [{ name: 'Game Night', players: 4 }, { name: 'Casual Fun', players: 2 }, { name: 'Board Game Lovers', players: 7 }, { name: 'Quick Games', players: 3 }]; // Add stored rooms if any if (storage.rooms && storage.rooms.length > 0) { for (var i = 0; i < storage.rooms.length; i++) { rooms.push({ name: storage.rooms[i], players: Math.floor(Math.random() * 5) + 1 }); } } for (var i = 0; i < rooms.length; i++) { var roomItem = new RoomListItem(rooms[i].name, rooms[i].players); roomItem.y = i * 100; roomList.addChild(roomItem); roomItem.onJoin = function (roomName) { currentRoomName = roomName; showScreen('room'); }; } } // Event Handlers createRoomButton.down = function () { createRoomButton.up(); // Generate random room name var adjectives = ['Cool', 'Fun', 'Happy', 'Super', 'Amazing']; var nouns = ['Gamers', 'Players', 'Friends', 'Squad', 'Team']; var randomRoomName = adjectives[Math.floor(Math.random() * adjectives.length)] + ' ' + nouns[Math.floor(Math.random() * nouns.length)]; // Store new room if (!storage.rooms) storage.rooms = []; storage.rooms.push(randomRoomName); // Join the new room currentRoomName = randomRoomName; showScreen('room'); }; tictactoeButton.down = function () { tictactoeButton.up(); showScreen('game'); }; backToLobbyButton.down = function () { backToLobbyButton.up(); showScreen('lobby'); }; backToRoomButton.down = function () { backToRoomButton.up(); showScreen('room'); }; ticTacToeGame.onGameOver = function (winner) { if (winner) { chatPanel.addMessage('You ' + (winner === 'X' ? 'won' : 'lost') + ' the Tic-Tac-Toe game!', false); } else { chatPanel.addMessage('The Tic-Tac-Toe game ended in a draw!', false); } LK.setTimeout(function () { showScreen('room'); }, 1000); }; // Initialize the game populateRoomList(); LK.playMusic('bgmusic'); // Update loop game.update = function () { // Nothing needed in update loop for this game }; // Initial setup showScreen('lobby');
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,682 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1", {
+ username: "Player",
+ color: "#3498db",
+ rooms: []
+});
+
+/****
+* Classes
+****/
+var Avatar = Container.expand(function () {
+ var self = Container.call(this);
+ var avatarGraphic = self.attachAsset('avatar', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.nameText = new Text2('Player', {
+ size: 24,
+ fill: 0xFFFFFF
+ });
+ self.nameText.anchor.set(0.5, 0);
+ self.nameText.y = 80;
+ self.addChild(self.nameText);
+ self.setName = function (name) {
+ self.nameText.setText(name);
+ };
+ self.setColor = function (color) {
+ avatarGraphic.tint = parseInt(color.replace('#', '0x'));
+ };
+ self.down = function (x, y, obj) {
+ LK.getSound('select').play();
+ };
+ return self;
+});
+var Button = Container.expand(function (text, width, height, color) {
+ var self = Container.call(this);
+ var buttonWidth = width || 180;
+ var buttonHeight = height || 60;
+ var buttonColor = color || 'gameButton';
+ var buttonGraphic = self.attachAsset(buttonColor, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ width: buttonWidth,
+ height: buttonHeight
+ });
+ self.label = new Text2(text, {
+ size: 28,
+ fill: 0xFFFFFF
+ });
+ self.label.anchor.set(0.5, 0.5);
+ self.addChild(self.label);
+ self.setLabel = function (newText) {
+ self.label.setText(newText);
+ };
+ self.down = function (x, y, obj) {
+ tween(buttonGraphic, {
+ scaleX: 0.95,
+ scaleY: 0.95
+ }, {
+ duration: 100
+ });
+ LK.getSound('select').play();
+ };
+ self.up = function (x, y, obj) {
+ tween(buttonGraphic, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 100
+ });
+ };
+ return self;
+});
+var ChatBubble = Container.expand(function (message, isUser) {
+ var self = Container.call(this);
+ var bubbleGraphic = self.attachAsset('chatBubble', {
+ anchorX: 0,
+ anchorY: 0
+ });
+ if (isUser) {
+ bubbleGraphic.tint = 0xDCF8C6; // Light green for user messages
+ }
+ self.messageText = new Text2(message, {
+ size: 24,
+ fill: 0x333333
+ });
+ self.messageText.x = 20;
+ self.messageText.y = 15;
+ self.addChild(self.messageText);
+ // Adjust height based on content
+ var textHeight = self.messageText.height + 30;
+ var bubbleHeight = Math.max(textHeight, 60);
+ bubbleGraphic.height = bubbleHeight;
+ return self;
+});
+var ChatPanel = Container.expand(function () {
+ var self = Container.call(this);
+ var panelGraphic = self.attachAsset('chatPanel', {
+ anchorX: 0,
+ anchorY: 0
+ });
+ self.messages = [];
+ self.messageContainer = new Container();
+ self.addChild(self.messageContainer);
+ self.messageContainer.x = 50;
+ self.messageContainer.y = 20;
+ self.inputField = self.addChild(LK.getAsset('inputField', {
+ anchorX: 0,
+ anchorY: 0
+ }));
+ self.inputField.x = 50;
+ self.inputField.y = panelGraphic.height - 80;
+ self.inputText = new Text2('Type a message...', {
+ size: 24,
+ fill: 0x888888
+ });
+ self.inputText.x = self.inputField.x + 20;
+ self.inputText.y = self.inputField.y + 18;
+ self.addChild(self.inputText);
+ var sendButton = new Button('Send', 80, 60, 'sendButton');
+ sendButton.x = self.inputField.x + self.inputField.width + 40;
+ sendButton.y = self.inputField.y + 30;
+ self.addChild(sendButton);
+ self.addMessage = function (message, isUser) {
+ var bubble = new ChatBubble(message, isUser);
+ if (self.messages.length > 0) {
+ var lastMessage = self.messages[self.messages.length - 1];
+ bubble.y = lastMessage.y + lastMessage.height + 10;
+ }
+ self.messages.push(bubble);
+ self.messageContainer.addChild(bubble);
+ // Limit messages and scroll if needed
+ if (self.messages.length > 8) {
+ var oldMessage = self.messages.shift();
+ self.messageContainer.removeChild(oldMessage);
+ // Adjust positions
+ for (var i = 0; i < self.messages.length; i++) {
+ if (i === 0) {
+ self.messages[i].y = 0;
+ } else {
+ self.messages[i].y = self.messages[i - 1].y + self.messages[i - 1].height + 10;
+ }
+ }
+ }
+ LK.getSound('message').play();
+ };
+ self.clearMessages = function () {
+ for (var i = 0; i < self.messages.length; i++) {
+ self.messageContainer.removeChild(self.messages[i]);
+ }
+ self.messages = [];
+ };
+ self.sendMessage = function () {
+ if (self.inputText.text !== 'Type a message...' && self.inputText.text.trim() !== '') {
+ var message = self.inputText.text;
+ self.addMessage(message, true);
+ self.inputText.setText('Type a message...');
+ // Simulate response after delay
+ LK.setTimeout(function () {
+ var responses = ["That's interesting!", "I see what you mean.", "Let's play a game instead?", "Cool! Want to try tic-tac-toe?", "I agree completely."];
+ var randomResponse = responses[Math.floor(Math.random() * responses.length)];
+ self.addMessage(randomResponse, false);
+ }, 1000 + Math.random() * 1000);
+ return message;
+ }
+ return null;
+ };
+ // Input field interaction
+ self.inputField.down = function () {
+ if (self.inputText.text === 'Type a message...') {
+ self.inputText.setText('');
+ self.inputText.style.fill = "#333333";
+ }
+ };
+ sendButton.down = function () {
+ sendButton.up();
+ self.sendMessage();
+ };
+ return self;
+});
+var RoomListItem = Container.expand(function (roomName, playerCount) {
+ var self = Container.call(this);
+ var itemGraphic = self.attachAsset('roomListItem', {
+ anchorX: 0,
+ anchorY: 0
+ });
+ self.roomNameText = new Text2(roomName, {
+ size: 28,
+ fill: 0x333333
+ });
+ self.roomNameText.x = 20;
+ self.roomNameText.y = 15;
+ self.addChild(self.roomNameText);
+ self.playerCountText = new Text2(playerCount + " players", {
+ size: 20,
+ fill: 0x888888
+ });
+ self.playerCountText.x = 20;
+ self.playerCountText.y = 50;
+ self.addChild(self.playerCountText);
+ var joinButton = new Button('Join', 120, 50, 'joinButton');
+ joinButton.x = itemGraphic.width - 80;
+ joinButton.y = itemGraphic.height / 2;
+ self.addChild(joinButton);
+ self.down = function () {
+ tween(itemGraphic, {
+ tint: 0xf0f0f0
+ }, {
+ duration: 100
+ });
+ };
+ self.up = function () {
+ tween(itemGraphic, {
+ tint: 0xffffff
+ }, {
+ duration: 100
+ });
+ };
+ joinButton.down = function () {
+ joinButton.up();
+ if (typeof self.onJoin === 'function') {
+ self.onJoin(roomName);
+ }
+ };
+ return self;
+});
+var TicTacToeGame = Container.expand(function () {
+ var self = Container.call(this);
+ var boardGraphic = self.attachAsset('tictactoeBoard', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.cells = [];
+ self.gameBoard = [['', '', ''], ['', '', ''], ['', '', '']];
+ self.currentPlayer = 'X';
+ self.gameActive = true;
+ // Create cells
+ for (var row = 0; row < 3; row++) {
+ for (var col = 0; col < 3; col++) {
+ var cell = self.addChild(LK.getAsset('tictactoeCell', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ cell.row = row;
+ cell.col = col;
+ cell.x = (col - 1) * 150;
+ cell.y = (row - 1) * 150;
+ cell.content = '';
+ cell.down = function () {
+ if (self.gameActive && this.content === '') {
+ self.makeMove(this.row, this.col);
+ }
+ };
+ self.cells.push(cell);
+ }
+ }
+ self.statusText = new Text2("Player X's turn", {
+ size: 32,
+ fill: 0x333333
+ });
+ self.statusText.anchor.set(0.5, 0);
+ self.statusText.y = boardGraphic.height / 2 + 40;
+ self.addChild(self.statusText);
+ self.makeMove = function (row, col) {
+ if (!self.gameActive || self.gameBoard[row][col] !== '') {
+ return;
+ }
+ // Update game board
+ self.gameBoard[row][col] = self.currentPlayer;
+ // Find the cell and update visually
+ for (var i = 0; i < self.cells.length; i++) {
+ var cell = self.cells[i];
+ if (cell.row === row && cell.col === col) {
+ cell.content = self.currentPlayer;
+ if (self.currentPlayer === 'X') {
+ var x = cell.addChild(LK.getAsset('tictactoeX', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ tween(x, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 200,
+ easing: tween.bounceOut,
+ onStart: function onStart() {
+ x.scaleX = 0;
+ x.scaleY = 0;
+ }
+ });
+ } else {
+ var o = cell.addChild(LK.getAsset('tictactoeO', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ tween(o, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 200,
+ easing: tween.bounceOut,
+ onStart: function onStart() {
+ o.scaleX = 0;
+ o.scaleY = 0;
+ }
+ });
+ }
+ break;
+ }
+ }
+ LK.getSound('select').play();
+ // Check for winner
+ var winner = self.checkWinner();
+ if (winner) {
+ self.gameActive = false;
+ self.statusText.setText('Player ' + winner + ' wins!');
+ LK.getSound('gameover').play();
+ LK.setTimeout(function () {
+ if (typeof self.onGameOver === 'function') {
+ self.onGameOver(winner);
+ }
+ }, 2000);
+ } else if (self.checkDraw()) {
+ self.gameActive = false;
+ self.statusText.setText("It's a draw!");
+ LK.getSound('gameover').play();
+ LK.setTimeout(function () {
+ if (typeof self.onGameOver === 'function') {
+ self.onGameOver(null);
+ }
+ }, 2000);
+ } else {
+ // Switch player
+ self.currentPlayer = self.currentPlayer === 'X' ? 'O' : 'X';
+ self.statusText.setText("Player " + self.currentPlayer + "'s turn");
+ // If current player is O (AI), make an automated move
+ if (self.currentPlayer === 'O') {
+ LK.setTimeout(function () {
+ self.makeAIMove();
+ }, 1000);
+ }
+ }
+ };
+ self.checkWinner = function () {
+ var lines = [
+ // Rows
+ [[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]], [[2, 0], [2, 1], [2, 2]],
+ // Columns
+ [[0, 0], [1, 0], [2, 0]], [[0, 1], [1, 1], [2, 1]], [[0, 2], [1, 2], [2, 2]],
+ // Diagonals
+ [[0, 0], [1, 1], [2, 2]], [[0, 2], [1, 1], [2, 0]]];
+ for (var i = 0; i < lines.length; i++) {
+ var _lines$i = _slicedToArray(lines[i], 3),
+ _lines$i$ = _slicedToArray(_lines$i[0], 2),
+ a = _lines$i$[0],
+ b = _lines$i$[1],
+ _lines$i$2 = _slicedToArray(_lines$i[1], 2),
+ c = _lines$i$2[0],
+ d = _lines$i$2[1],
+ _lines$i$3 = _slicedToArray(_lines$i[2], 2),
+ e = _lines$i$3[0],
+ f = _lines$i$3[1];
+ if (self.gameBoard[a][b] && self.gameBoard[a][b] === self.gameBoard[c][d] && self.gameBoard[a][b] === self.gameBoard[e][f]) {
+ return self.gameBoard[a][b];
+ }
+ }
+ return null;
+ };
+ self.checkDraw = function () {
+ for (var row = 0; row < 3; row++) {
+ for (var col = 0; col < 3; col++) {
+ if (self.gameBoard[row][col] === '') {
+ return false;
+ }
+ }
+ }
+ return true;
+ };
+ self.makeAIMove = function () {
+ if (!self.gameActive) return;
+ // Find empty cells
+ var emptyCells = [];
+ for (var row = 0; row < 3; row++) {
+ for (var col = 0; col < 3; col++) {
+ if (self.gameBoard[row][col] === '') {
+ emptyCells.push({
+ row: row,
+ col: col
+ });
+ }
+ }
+ }
+ if (emptyCells.length > 0) {
+ var randomCell = emptyCells[Math.floor(Math.random() * emptyCells.length)];
+ self.makeMove(randomCell.row, randomCell.col);
+ }
+ };
+ self.reset = function () {
+ // Clear the board
+ for (var row = 0; row < 3; row++) {
+ for (var col = 0; col < 3; col++) {
+ self.gameBoard[row][col] = '';
+ }
+ }
+ // Reset cell visuals
+ for (var i = 0; i < self.cells.length; i++) {
+ var cell = self.cells[i];
+ cell.content = '';
+ // Remove all children (X or O graphics)
+ while (cell.children.length > 0) {
+ cell.removeChild(cell.children[0]);
+ }
+ }
+ self.currentPlayer = 'X';
+ self.gameActive = true;
+ self.statusText.setText("Player X's turn");
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0xf5f7fa
+});
+
+/****
+* Game Code
+****/
+// Main app state
+function _slicedToArray(r, e) {
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
+}
+function _nonIterableRest() {
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
+}
+function _unsupportedIterableToArray(r, a) {
+ if (r) {
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
+ var t = {}.toString.call(r).slice(8, -1);
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
+ }
+}
+function _arrayLikeToArray(r, a) {
+ (null == a || a > r.length) && (a = r.length);
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
+ return n;
+}
+function _iterableToArrayLimit(r, l) {
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
+ if (null != t) {
+ var e,
+ n,
+ i,
+ u,
+ a = [],
+ f = !0,
+ o = !1;
+ try {
+ if (i = (t = t.call(r)).next, 0 === l) {
+ if (Object(t) !== t) return;
+ f = !1;
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
+ } catch (r) {
+ o = !0, n = r;
+ } finally {
+ try {
+ if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
+ } finally {
+ if (o) throw n;
+ }
+ }
+ return a;
+ }
+}
+function _arrayWithHoles(r) {
+ if (Array.isArray(r)) return r;
+}
+var currentScreen = 'lobby'; // 'lobby', 'room', 'game'
+var username = storage.username || 'Player';
+var avatarColor = storage.color || '#3498db';
+var currentRoomName = '';
+// Create UI containers for different screens
+var lobbyScreen = new Container();
+var roomScreen = new Container();
+var gameScreen = new Container();
+// Set up lobby screen
+var lobbyTitle = new Text2('Chat Party Games', {
+ size: 80,
+ fill: 0x2C3E50
+});
+lobbyTitle.anchor.set(0.5, 0);
+lobbyTitle.x = 2048 / 2;
+lobbyTitle.y = 100;
+lobbyScreen.addChild(lobbyTitle);
+var usernameText = new Text2('Your Name: ' + username, {
+ size: 32,
+ fill: 0x666666
+});
+usernameText.anchor.set(0.5, 0);
+usernameText.x = 2048 / 2;
+usernameText.y = 250;
+lobbyScreen.addChild(usernameText);
+var avatar = new Avatar();
+avatar.x = 2048 / 2;
+avatar.y = 400;
+avatar.setName(username);
+avatar.setColor(avatarColor);
+lobbyScreen.addChild(avatar);
+var roomListTitle = new Text2('Available Rooms', {
+ size: 40,
+ fill: 0x2C3E50
+});
+roomListTitle.anchor.set(0.5, 0);
+roomListTitle.x = 2048 / 2;
+roomListTitle.y = 600;
+lobbyScreen.addChild(roomListTitle);
+// Create sample room list
+var roomList = new Container();
+roomList.x = (2048 - 700) / 2;
+roomList.y = 680;
+lobbyScreen.addChild(roomList);
+var createRoomButton = new Button('Create Room', 250, 80);
+createRoomButton.x = 2048 / 2;
+createRoomButton.y = 2600;
+lobbyScreen.addChild(createRoomButton);
+// Setup room screen
+var roomTitle = new Text2('Room: Lobby', {
+ size: 40,
+ fill: 0x2C3E50
+});
+roomTitle.anchor.set(0.5, 0);
+roomTitle.x = 2048 / 2;
+roomTitle.y = 50;
+roomScreen.addChild(roomTitle);
+var chatPanel = new ChatPanel();
+chatPanel.x = (2048 - 800) / 2;
+chatPanel.y = 120;
+roomScreen.addChild(chatPanel);
+var gameButtonsContainer = new Container();
+gameButtonsContainer.x = 2048 / 2;
+gameButtonsContainer.y = 2000;
+roomScreen.addChild(gameButtonsContainer);
+var tictactoeButton = new Button('Tic-Tac-Toe', 250, 80);
+tictactoeButton.x = 0;
+tictactoeButton.y = 0;
+gameButtonsContainer.addChild(tictactoeButton);
+var backToLobbyButton = new Button('Back to Lobby', 250, 80);
+backToLobbyButton.x = 0;
+backToLobbyButton.y = 100;
+gameButtonsContainer.addChild(backToLobbyButton);
+// Setup game screen
+var gameTitle = new Text2('Tic-Tac-Toe', {
+ size: 40,
+ fill: 0x2C3E50
+});
+gameTitle.anchor.set(0.5, 0);
+gameTitle.x = 2048 / 2;
+gameTitle.y = 50;
+gameScreen.addChild(gameTitle);
+var ticTacToeGame = new TicTacToeGame();
+ticTacToeGame.x = 2048 / 2;
+ticTacToeGame.y = 2732 / 2 - 200;
+gameScreen.addChild(ticTacToeGame);
+var backToRoomButton = new Button('Back to Room', 250, 80);
+backToRoomButton.x = 2048 / 2;
+backToRoomButton.y = 2500;
+gameScreen.addChild(backToRoomButton);
+// Add main container to game
+game.addChild(lobbyScreen);
+game.addChild(roomScreen);
+game.addChild(gameScreen);
+// Initially hide room and game screens
+roomScreen.visible = false;
+gameScreen.visible = false;
+// Function to switch between screens
+function showScreen(screenName) {
+ lobbyScreen.visible = false;
+ roomScreen.visible = false;
+ gameScreen.visible = false;
+ currentScreen = screenName;
+ if (screenName === 'lobby') {
+ lobbyScreen.visible = true;
+ populateRoomList();
+ } else if (screenName === 'room') {
+ roomScreen.visible = true;
+ roomTitle.setText('Room: ' + currentRoomName);
+ chatPanel.clearMessages();
+ chatPanel.addMessage('Welcome to ' + currentRoomName + '!', false);
+ } else if (screenName === 'game') {
+ gameScreen.visible = true;
+ ticTacToeGame.reset();
+ }
+}
+// Populate the room list with sample rooms
+function populateRoomList() {
+ // Clear existing rooms
+ while (roomList.children.length > 0) {
+ roomList.removeChild(roomList.children[0]);
+ }
+ // Sample rooms
+ var rooms = [{
+ name: 'Game Night',
+ players: 4
+ }, {
+ name: 'Casual Fun',
+ players: 2
+ }, {
+ name: 'Board Game Lovers',
+ players: 7
+ }, {
+ name: 'Quick Games',
+ players: 3
+ }];
+ // Add stored rooms if any
+ if (storage.rooms && storage.rooms.length > 0) {
+ for (var i = 0; i < storage.rooms.length; i++) {
+ rooms.push({
+ name: storage.rooms[i],
+ players: Math.floor(Math.random() * 5) + 1
+ });
+ }
+ }
+ for (var i = 0; i < rooms.length; i++) {
+ var roomItem = new RoomListItem(rooms[i].name, rooms[i].players);
+ roomItem.y = i * 100;
+ roomList.addChild(roomItem);
+ roomItem.onJoin = function (roomName) {
+ currentRoomName = roomName;
+ showScreen('room');
+ };
+ }
+}
+// Event Handlers
+createRoomButton.down = function () {
+ createRoomButton.up();
+ // Generate random room name
+ var adjectives = ['Cool', 'Fun', 'Happy', 'Super', 'Amazing'];
+ var nouns = ['Gamers', 'Players', 'Friends', 'Squad', 'Team'];
+ var randomRoomName = adjectives[Math.floor(Math.random() * adjectives.length)] + ' ' + nouns[Math.floor(Math.random() * nouns.length)];
+ // Store new room
+ if (!storage.rooms) storage.rooms = [];
+ storage.rooms.push(randomRoomName);
+ // Join the new room
+ currentRoomName = randomRoomName;
+ showScreen('room');
+};
+tictactoeButton.down = function () {
+ tictactoeButton.up();
+ showScreen('game');
+};
+backToLobbyButton.down = function () {
+ backToLobbyButton.up();
+ showScreen('lobby');
+};
+backToRoomButton.down = function () {
+ backToRoomButton.up();
+ showScreen('room');
+};
+ticTacToeGame.onGameOver = function (winner) {
+ if (winner) {
+ chatPanel.addMessage('You ' + (winner === 'X' ? 'won' : 'lost') + ' the Tic-Tac-Toe game!', false);
+ } else {
+ chatPanel.addMessage('The Tic-Tac-Toe game ended in a draw!', false);
+ }
+ LK.setTimeout(function () {
+ showScreen('room');
+ }, 1000);
+};
+// Initialize the game
+populateRoomList();
+LK.playMusic('bgmusic');
+// Update loop
+game.update = function () {
+ // Nothing needed in update loop for this game
+};
+// Initial setup
+showScreen('lobby');
\ No newline at end of file