User prompt
at the beginning make it read because red always starts
User prompt
add an turn idicator that show the color of whos turn it is
User prompt
dont slow down the speed of the discs when falling but make them bounce instead
Code edit (1 edits merged)
Please save this source code
User prompt
make the falling of the discs work
User prompt
make the discs fall from the top of the screen op to their place and make them bounce
User prompt
take the width of the win text in account
Code edit (1 edits merged)
Please save this source code
User prompt
take the win text elements width in accaunt for placing it in the middle
User prompt
remove the debug message
User prompt
display a text if someone wins with the same message as the debug message
User prompt
Please fix the bug: 'ReferenceError: customParticleBurst is not defined' in or related to this line: 'customParticleBurst(players[currentPlayer].color, 1000, 100);' Line Number: 120
User prompt
use a self made function instead of lk.effects.particle becuase it doesnt exist
User prompt
display particles if a player wins
User prompt
go game over after 5 seconds after checkwin is true
User prompt
use the debug message data to calculate a win if 4 of the same color discs are in a row horizontally diagonally and vertically
User prompt
delay the debug message to only send every second
User prompt
only send the debug message every time a new disc gets added to prevent spam
User prompt
only send the debug message every time a new disc gets added
User prompt
make a function that lists what color discs are in what row in what order. list it in the debug console
/****
* Classes
****/
// Disc class for the game pieces
var Disc = Container.expand(function (player) {
var self = Container.call(this);
self.player = player;
var discGraphics = self.attachAsset(player.color, {
anchorX: 0.5,
anchorY: 0.5
});
});
// Grid class for the game board
var Grid = Container.expand(function () {
var self = Container.call(this);
// Method to print the color of discs in each row
self.printRows = function () {
for (var row = 0; row < 6; row++) {
var rowColors = [];
for (var col = 0; col < 7; col++) {
if (self.cells[row][col]) {
rowColors.push(self.cells[row][col].player.color);
} else {
rowColors.push('empty');
}
}
console.log('Row ' + row + ': ' + rowColors.join(', '));
}
};
self.cells = [];
for (var row = 0; row < 6; row++) {
self.cells[row] = [];
for (var col = 0; col < 7; col++) {
self.cells[row][col] = null; // Initialize all cells as empty
}
}
// Method to add a disc to the grid
self.addDisc = function (col, player) {
for (var row = 5; row >= 0; row--) {
if (!self.cells[row][col]) {
var disc = new Disc(player);
disc.x = col * 220 + 360; // Calculate x position based on column
disc.y = row * 220 + 310; // Calculate y position based on row
self.cells[row][col] = disc;
game.addChild(disc);
return true; // Return true if a disc was successfully added
}
}
return false; // Return false if the column is full
};
// Method to check for a win condition
self.checkWin = function () {
// Win checking logic goes here
};
});
var Player = Container.expand(function (color) {
var self = Container.call(this);
self.color = color;
self.score = 0;
self.addScore = function () {
self.score++;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize the game board
var grid = new Grid();
game.addChild(grid);
// Create the players
var players = [new Player('redDisc'), new Player('yellowDisc')];
// Current player's turn: 0 for red, 1 for yellow
var currentPlayer = 0;
// Handle touch events to add discs to the grid
game.on('down', function (obj) {
var event = obj.event;
var pos = event.getLocalPosition(game);
var col = Math.floor((pos.x - 305) / 220); // Calculate column based on touch position
if (col >= 0 && col < 7) {
if (grid.addDisc(col, players[currentPlayer])) {
currentPlayer = (currentPlayer + 1) % 2; // Switch player only if a disc was successfully added
}
}
});
// Main game loop
LK.on('tick', function () {
// Game logic updates, such as checking for win conditions, go here
grid.checkWin();
// Print the color of discs in each row
grid.printRows();
});