Slick Forums

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

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: I am in some trouble....
PostPosted: Fri May 19, 2017 8:57 am 
Offline

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;
      add3RandomCells();
      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
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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 forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group