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

2020/2/28

Placeholder Help

ItzTigerr ItzTigerr

2020/2/28

#
So im making a place holder for my tic tac toe game and I know that the error im getting in the class is cause I need to put the method in my world codes. I just don't know where
public class PH extends Actor
{
    public boolean touchingX = false;
    public boolean touchingO = false;
    public PH()
    {
        GreenfootImage img = new GreenfootImage(96, 96);
        Color transparent = new Color(0,0,0,0);
        img.setColor (transparent);
        img.fill();
        setImage(img);
    }

    public void act() 
    {
        if(Greenfoot.mousePressed(this))
        {
            Board Board = (Board) getWorld();
            Board.sendMessage(getX(), getY());
        }
    }
    
    public boolean crossIsTouching()
    {
        return isTouching(X.class);
    }
    
    public boolean circleIsTouching()
    {
        return isTouching(O.class);
    }
}
And this is my world code
public class Board extends World
{
    public Board()
    {    
        super(300, 300, 1);
        getBackground();
        GreenfootImage background = getBackground();
        repaint();
        drawLine();
        populate();
    }

    public void drawLine()
    {
        getBackground(). setColor(Color.BLACK);
        getBackground(). drawLine(100, 300, 100, 0);
        getBackground(). drawLine(200, 300, 200, 0);
        getBackground(). drawLine(0, 100, 300, 100);
        getBackground(). drawLine(0, 200, 300, 200);
    }

    public void repaint()
    {
        GreenfootImage background = getBackground();
        background.setColor(new Color(Greenfoot.getRandomNumber(255), Greenfoot.getRandomNumber(255), Greenfoot.getRandomNumber(255)));
        background.fill();
        setBackground(background);
    }

    public void populate()
    {
        addObject(new PH(), getWidth()/2, getHeight()/2);
        addObject(new PH(), 50, 50);
        addObject(new PH(), 150, 50);
        addObject(new PH(), 250, 50);
        addObject(new PH(), 50, 150);
        addObject(new PH(), 150, 150);
        addObject(new PH(), 250, 150);
        addObject(new PH(), 50, 250);
        addObject(new PH(), 150, 250);
        addObject(new PH(), 250, 250);
    }
}
danpost danpost

2020/2/28

#
ItzTigerr wrote...
So im making a place holder for my tic tac toe game and I know that the error im getting in the class is cause I need to put the method in my world codes. I just don't know where << Code Omitted >>
Anywhere within the class that is not within another method. A new image (see line 7 of PH class) is already a transparent one. You can remove lines 8 thru 10. In populate, you should either use all literals or make all depend on the size of the world. At any rate, line 32 places a PH object at the same location as line 37. Remove line 32. Probably not a good idea to allow repaint to have a choice of ALL random colors. A dark color would not be pleasant. Maybe use 128, instead of 255, and since you want brighter colors, add 128 to each of the random values generated -- 128+Greenfoot.getRandomNumber(128) .
ItzTigerr ItzTigerr

2020/3/2

#
danpost wrote...
ItzTigerr wrote...
So im making a place holder for my tic tac toe game and I know that the error im getting in the class is cause I need to put the method in my world codes. I just don't know where << Code Omitted >>
Anywhere within the class that is not within another method. A new image (see line 7 of PH class) is already a transparent one. You can remove lines 8 thru 10. In populate, you should either use all literals or make all depend on the size of the world. At any rate, line 32 places a PH object at the same location as line 37. Remove line 32. Probably not a good idea to allow repaint to have a choice of ALL random colors. A dark color would not be pleasant. Maybe use 128, instead of 255, and since you want brighter colors, add 128 to each of the random values generated -- 128+Greenfoot.getRandomNumber(128) .
Ok thanks but im not sure what to write as for the code that needs to be in the world code. Thank you for helping me clean up my codes tho.
You need to login to post a reply.