User prompt
separate the total number of rooms in each hotel
Code edit (1 edits merged)
Please save this source code
User prompt
Hotel Room Builder
Initial prompt
BEGIN GAME LOOP HANDLE USER INPUT IF Right Arrow Key Pressed: MOVE to NEXT Hotel (Cyclic: Hotel 1 -> 2 -> 3 -> 4 -> 5 -> 1) IF Left Arrow Key Pressed: MOVE to PREVIOUS Hotel (Cyclic: Hotel 1 -> 5 -> 4 -> 3 -> 2 -> 1) IF 'Add Room' Button Pressed (or equivalent key): IF Current Hotel has < 10 total rooms (across all hotels): ADD 1 Room to Current Hotel UPDATE GAME STATE UPDATE Display to show Current Hotel UPDATE Display to show Rooms in Current Hotel UPDATE Display to show Total Rooms (across all hotels) RENDER GRAPHICS DRAW Current Hotel Scene DRAW UI elements (Room Count, Hotel Name, etc.) END GAME LOOP
/**** * Classes ****/ var AddRoomButton = Container.expand(function () { var self = Container.call(this); var buttonBg = self.attachAsset('add_room_button', { anchorX: 0.5, anchorY: 0.5 }); self.buttonText = self.addChild(new Text2('Add Room', { size: 50, fill: 0xFFFFFF })); self.buttonText.anchor.set(0.5, 0.5); self.down = function (x, y, obj) { if (totalRooms < 10) { if (hotels[currentHotelIndex].addRoom()) { totalRooms++; updateUI(); } } }; self.updateButton = function () { if (totalRooms >= 10) { buttonBg.tint = 0x666666; self.buttonText.setText('Limit Reached'); } else { buttonBg.tint = 0xffffff; self.buttonText.setText('Add Room'); } }; return self; }); var Hotel = Container.expand(function () { var self = Container.call(this); // Hotel background var hotelBg = self.attachAsset('hotel_bg', { anchorX: 0.5, anchorY: 0.5 }); // Properties self.hotelId = 1; self.roomCount = 0; self.rooms = []; self.setHotel = function (id) { self.hotelId = id; self.updateDisplay(); }; self.addRoom = function () { if (self.roomCount < 5) { // Max 5 rooms per hotel for visual purposes var room = self.addChild(LK.getAsset('room', { anchorX: 0.5, anchorY: 0.5 })); // Position rooms in a grid var col = self.roomCount % 3; var row = Math.floor(self.roomCount / 3); room.x = (col - 1) * 90; room.y = (row - 1) * 70; self.rooms.push(room); self.roomCount++; return true; } return false; }; self.updateDisplay = function () { // Clear existing rooms for (var i = 0; i < self.rooms.length; i++) { self.rooms[i].destroy(); } self.rooms = []; // Add rooms based on current count for (var i = 0; i < self.roomCount; i++) { var room = self.addChild(LK.getAsset('room', { anchorX: 0.5, anchorY: 0.5 })); var col = i % 3; var row = Math.floor(i / 3); room.x = (col - 1) * 90; room.y = (row - 1) * 70; self.rooms.push(room); } }; return self; }); var NavigationButton = Container.expand(function () { var self = Container.call(this); var buttonBg = self.attachAsset('nav_button', { anchorX: 0.5, anchorY: 0.5 }); self.isLeft = true; self.buttonText = null; self.setText = function (text) { if (self.buttonText) { self.buttonText.destroy(); } self.buttonText = self.addChild(new Text2(text, { size: 40, fill: 0xFFFFFF })); self.buttonText.anchor.set(0.5, 0.5); }; self.down = function (x, y, obj) { if (self.isLeft) { currentHotelIndex = (currentHotelIndex - 1 + 5) % 5; } else { currentHotelIndex = (currentHotelIndex + 1) % 5; } updateHotelDisplay(); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2c3e50 }); /**** * Game Code ****/ // Game state variables var hotels = []; var currentHotelIndex = 0; var totalRooms = 0; var hotelCounts = [0, 0, 0, 0, 0]; // UI elements var hotelNameText; var currentRoomsText; var totalRoomsText; var leftButton; var rightButton; var addRoomButton; var currentHotel; // Initialize hotels for (var i = 0; i < 5; i++) { hotels.push(new Hotel()); } // Position current hotel in center currentHotel = game.addChild(hotels[0]); currentHotel.x = 1024; currentHotel.y = 900; // Create navigation buttons leftButton = game.addChild(new NavigationButton()); leftButton.isLeft = true; leftButton.setText('<'); leftButton.x = 400; leftButton.y = 900; rightButton = game.addChild(new NavigationButton()); rightButton.isLeft = false; rightButton.setText('>'); rightButton.x = 1648; rightButton.y = 900; // Create add room button addRoomButton = game.addChild(new AddRoomButton()); addRoomButton.x = 1024; addRoomButton.y = 1400; // Create UI text elements hotelNameText = new Text2('Hotel 1', { size: 80, fill: 0xFFFFFF }); hotelNameText.anchor.set(0.5, 0); LK.gui.top.addChild(hotelNameText); hotelNameText.y = 150; currentRoomsText = new Text2('Rooms in this hotel: 0', { size: 50, fill: 0xFFFFFF }); currentRoomsText.anchor.set(0.5, 0); LK.gui.top.addChild(currentRoomsText); currentRoomsText.y = 250; totalRoomsText = new Text2('Total rooms: 0/10', { size: 50, fill: 0xFFFFFF }); totalRoomsText.anchor.set(0.5, 0); LK.gui.top.addChild(totalRoomsText); totalRoomsText.y = 320; function updateHotelDisplay() { // Remove current hotel game.removeChild(currentHotel); // Add new hotel currentHotel = game.addChild(hotels[currentHotelIndex]); currentHotel.x = 1024; currentHotel.y = 900; currentHotel.setHotel(currentHotelIndex + 1); updateUI(); } function updateUI() { hotelNameText.setText('Hotel ' + (currentHotelIndex + 1)); currentRoomsText.setText('Rooms in this hotel: ' + hotelCounts[currentHotelIndex]); totalRoomsText.setText('Total rooms: ' + totalRooms + '/10'); addRoomButton.updateButton(); } // Update hotel counts when rooms are added function updateHotelCounts() { for (var i = 0; i < 5; i++) { hotelCounts[i] = hotels[i].roomCount; } } game.update = function () { updateHotelCounts(); }; // Initialize UI updateUI();
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,211 @@
-/****
+/****
+* Classes
+****/
+var AddRoomButton = Container.expand(function () {
+ var self = Container.call(this);
+ var buttonBg = self.attachAsset('add_room_button', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.buttonText = self.addChild(new Text2('Add Room', {
+ size: 50,
+ fill: 0xFFFFFF
+ }));
+ self.buttonText.anchor.set(0.5, 0.5);
+ self.down = function (x, y, obj) {
+ if (totalRooms < 10) {
+ if (hotels[currentHotelIndex].addRoom()) {
+ totalRooms++;
+ updateUI();
+ }
+ }
+ };
+ self.updateButton = function () {
+ if (totalRooms >= 10) {
+ buttonBg.tint = 0x666666;
+ self.buttonText.setText('Limit Reached');
+ } else {
+ buttonBg.tint = 0xffffff;
+ self.buttonText.setText('Add Room');
+ }
+ };
+ return self;
+});
+var Hotel = Container.expand(function () {
+ var self = Container.call(this);
+ // Hotel background
+ var hotelBg = self.attachAsset('hotel_bg', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Properties
+ self.hotelId = 1;
+ self.roomCount = 0;
+ self.rooms = [];
+ self.setHotel = function (id) {
+ self.hotelId = id;
+ self.updateDisplay();
+ };
+ self.addRoom = function () {
+ if (self.roomCount < 5) {
+ // Max 5 rooms per hotel for visual purposes
+ var room = self.addChild(LK.getAsset('room', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ // Position rooms in a grid
+ var col = self.roomCount % 3;
+ var row = Math.floor(self.roomCount / 3);
+ room.x = (col - 1) * 90;
+ room.y = (row - 1) * 70;
+ self.rooms.push(room);
+ self.roomCount++;
+ return true;
+ }
+ return false;
+ };
+ self.updateDisplay = function () {
+ // Clear existing rooms
+ for (var i = 0; i < self.rooms.length; i++) {
+ self.rooms[i].destroy();
+ }
+ self.rooms = [];
+ // Add rooms based on current count
+ for (var i = 0; i < self.roomCount; i++) {
+ var room = self.addChild(LK.getAsset('room', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ var col = i % 3;
+ var row = Math.floor(i / 3);
+ room.x = (col - 1) * 90;
+ room.y = (row - 1) * 70;
+ self.rooms.push(room);
+ }
+ };
+ return self;
+});
+var NavigationButton = Container.expand(function () {
+ var self = Container.call(this);
+ var buttonBg = self.attachAsset('nav_button', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.isLeft = true;
+ self.buttonText = null;
+ self.setText = function (text) {
+ if (self.buttonText) {
+ self.buttonText.destroy();
+ }
+ self.buttonText = self.addChild(new Text2(text, {
+ size: 40,
+ fill: 0xFFFFFF
+ }));
+ self.buttonText.anchor.set(0.5, 0.5);
+ };
+ self.down = function (x, y, obj) {
+ if (self.isLeft) {
+ currentHotelIndex = (currentHotelIndex - 1 + 5) % 5;
+ } else {
+ currentHotelIndex = (currentHotelIndex + 1) % 5;
+ }
+ updateHotelDisplay();
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2c3e50
+});
+
+/****
+* Game Code
+****/
+// Game state variables
+var hotels = [];
+var currentHotelIndex = 0;
+var totalRooms = 0;
+var hotelCounts = [0, 0, 0, 0, 0];
+// UI elements
+var hotelNameText;
+var currentRoomsText;
+var totalRoomsText;
+var leftButton;
+var rightButton;
+var addRoomButton;
+var currentHotel;
+// Initialize hotels
+for (var i = 0; i < 5; i++) {
+ hotels.push(new Hotel());
+}
+// Position current hotel in center
+currentHotel = game.addChild(hotels[0]);
+currentHotel.x = 1024;
+currentHotel.y = 900;
+// Create navigation buttons
+leftButton = game.addChild(new NavigationButton());
+leftButton.isLeft = true;
+leftButton.setText('<');
+leftButton.x = 400;
+leftButton.y = 900;
+rightButton = game.addChild(new NavigationButton());
+rightButton.isLeft = false;
+rightButton.setText('>');
+rightButton.x = 1648;
+rightButton.y = 900;
+// Create add room button
+addRoomButton = game.addChild(new AddRoomButton());
+addRoomButton.x = 1024;
+addRoomButton.y = 1400;
+// Create UI text elements
+hotelNameText = new Text2('Hotel 1', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+hotelNameText.anchor.set(0.5, 0);
+LK.gui.top.addChild(hotelNameText);
+hotelNameText.y = 150;
+currentRoomsText = new Text2('Rooms in this hotel: 0', {
+ size: 50,
+ fill: 0xFFFFFF
+});
+currentRoomsText.anchor.set(0.5, 0);
+LK.gui.top.addChild(currentRoomsText);
+currentRoomsText.y = 250;
+totalRoomsText = new Text2('Total rooms: 0/10', {
+ size: 50,
+ fill: 0xFFFFFF
+});
+totalRoomsText.anchor.set(0.5, 0);
+LK.gui.top.addChild(totalRoomsText);
+totalRoomsText.y = 320;
+function updateHotelDisplay() {
+ // Remove current hotel
+ game.removeChild(currentHotel);
+ // Add new hotel
+ currentHotel = game.addChild(hotels[currentHotelIndex]);
+ currentHotel.x = 1024;
+ currentHotel.y = 900;
+ currentHotel.setHotel(currentHotelIndex + 1);
+ updateUI();
+}
+function updateUI() {
+ hotelNameText.setText('Hotel ' + (currentHotelIndex + 1));
+ currentRoomsText.setText('Rooms in this hotel: ' + hotelCounts[currentHotelIndex]);
+ totalRoomsText.setText('Total rooms: ' + totalRooms + '/10');
+ addRoomButton.updateButton();
+}
+// Update hotel counts when rooms are added
+function updateHotelCounts() {
+ for (var i = 0; i < 5; i++) {
+ hotelCounts[i] = hotels[i].roomCount;
+ }
+}
+game.update = function () {
+ updateHotelCounts();
+};
+// Initialize UI
+updateUI();
\ No newline at end of file
stickman top view. In-Game asset
empty room top view. In-Game asset. 2d. High contrast. No shadows
full room top view. In-Game asset. 2d. High contrast. No shadows
left arrow. In-Game asset
destroyed and damaged red flag cross the stripe
Hotel wall view from the front with flowers and mosses. In-Game asset
16:9
Building silhouettes. In-Game asset
hotel bar top view. In-Game asset