Slick Forums

Discuss the Slick 2D Library
 It is currently Tue Jul 25, 2017 12:46 am

 All times are UTC

 Page 1 of 1 [ 1 post ]
 Print view Previous topic | Next topic
Author Message
 Post subject: I am in some trouble....Posted: Fri May 19, 2017 8:57 am

Joined: Fri May 19, 2017 8:50 am
Posts: 1
I am doing a shoot'em up game and got stuck in the generation.
The game is about a starship shooting medicine on infected cells. The contamination is based on the Conway's Game of life. I don't know why my algorithm isn t working.
Here it is:
(the array is a 2D array of boolean)
Code:
private int checkNeighbour(boolean[][] grid, int i, int j) {
int counter = 0;
if (grid[i - 1][j - 1] == true) {
counter++;
}
if (grid[i - 1][j] == true) {
counter++;
}
if (grid[i - 1][j + 1] == true) {
counter++;
}
if (grid[i][j - 1] == true) {
counter++;
}
if (grid[i][j + 1] == true) {
counter++;
}
if (grid[i + 1][j - 1] == true) {
counter++;
}
if (grid[i + 1][j] == true) {
counter++;
}
if (grid[i + 1][j + 1] == true) {
counter++;
}
return counter;
}

public void checkGrid() {
boolean[][] newGrid = cellsGrid;
arrayTrick(newGrid, cellsGrid);

for (int i = 1; i < newGrid.length - 1; i++) {
for (int j = 1; j < newGrid.length - 1; j++) {
int liveOrDie = checkNeighbour(cellsGrid, i, j);
switch (liveOrDie) {
case 2:
if (cellsGrid[i][j] == true) {
newGrid[i][j] = true;
}
break;
case 3:
newGrid[i][j] = true;
break;
default:
newGrid[i][j] = false;
break;
}
}
}

cellsGrid = newGrid;
}

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 1 post ]

 All times are UTC

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ General    Games / Demos    Help / Discussion    Community Projects    Game Ideas/Design    Slick Competition 2011    Android Slick - LWJGL 2D Game Library    Announcements    Bug Reports / RFE    Extensions    Contribution depot Related Libraries and Tools    Phys2D    Tiled    TWL    Fizzy    Artemis Archive    Resolved Bugs/RFE    Useful Posts