This site requires JavaScript, please enable it in your browser!
Greenfoot back
TascaLoosaHeart
TascaLoosaHeart wrote ...

2013/6/13

Help Conway's Game of Life

TascaLoosaHeart TascaLoosaHeart

2013/6/13

#
Hey Greenfoot-Community For school I have to create Conway's Game of Life in Greenfoot. The only thing I have already created is the world. But I really don't know what to do now. How can I tell a cell to check, if his neighbour is dead or alive, or how many neighbours are dead or alive? I'm not really trust with Greenfoot so for me its quite hard and my teacher just said: "If you can't create this, you will get a bad mark!" Please help me. This is the world:
import greenfoot.*;  // imports Actor, World, Greenfoot, GreenfootImage

import java.util.Random;


public class GameOfLife extends World
{
    int getHeight;
    int getWidth;
    int a;
    String line;

    public GameOfLife()
    {
        super(50, 50, 10);        
        setBackground("GameOfLife.png");
        populate();

    }

    public void populate()
    {

        for (int i = 0; i < 50; i++)
        {

            for (int j = 0; j < 50; j++)
            {    
                int zufall = Greenfoot.getRandomNumber(100);

                if (zufall < 50)
                {
                    lebendigeZelle lebZ = new lebendigeZelle();
                    addObject(lebZ,i,j);      
                }
                else
                {
                    toteZelle z = new toteZelle();
                    addObject(z,i,j);

                }
            }
        }    

    }  

}
danpost danpost

2013/6/13

#
First, it appears that lines 3, 8, 9, 10, and 11 have no apparent use (they can be removed). Then, you need to make use of the world class 'act' method to control what happens while the scenario is running. Also, you will need to create methods in both the 'lebendigeZelle' and 'toteZelle' classes to determine whether they can remain or be replaced with instances of the other class (you will need instance boolean fields to hold whether they need changed or not). The world act method should iterate through all the actors to check their need to change and then iterate through all the actors again to implement the change.
TascaLoosaHeart TascaLoosaHeart

2013/6/13

#
Yes you're right. I forgot to delete these lines^^ I had the same thought, but I really don't know how to start and which methods I need. And don't wonder about the class names, they're german. But thanks for your help. I'll tell my teacher that he requires too much of me. Because the creation of the world was only possible with his help. I already asked my friends for help but they don't know neither.
You need to login to post a reply.