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

2019/2/16

Type in player names

marenss marenss

2019/2/16

#
Hi, i came to a problem with my Greenfoot Nine Man Morris version, when i tried to write the code to make it possible for the players to type in their names befor playing. Is there a way to do so?
danpost danpost

2019/2/16

#
marenss wrote...
i came to a problem with my Greenfoot Nine Man Morris version, when i tried to write the code to make it possible for the players to type in their names befor playing. Is there a way to do so?
There are ways. Show what you tried.
marenss marenss

2019/2/16

#
int x;
    int y;
    String name;
    boolean a = true;
    boolean b = true;

public void nameneingeben()
    {
        int i = 0;
        int c = getWorldOfType(Startseite.class).namengesetzt;
        klickerkennen();
        if((x<= 400 && x >= 100) && (y<=250 && y>=180) && a == true)
        {
            setImage(new GreenfootImage("name", 60, Color.WHITE, new Color(0, 0, 0, 0)));
            c++;
            a = false;
        }
        if((x>= 400 && x <= 700) && (y<=250 && y>=180) && b == true)
        {
            setImage(new GreenfootImage("name", 60, Color.WHITE, new Color(0, 0, 0, 0)));
            c++;
            b = false;
        }
        getWorldOfType(Startseite.class).namengesetzt = c;
    }
What i wanted to do is to use a GreenfootImage to display the typed text. but i have no clue how to make the "name" in the method individual. My idea was to create a new object:
public Anzeigeweiss(String text)
    {
        setImage(new GreenfootImage(text, 60, Color.WHITE, new Color(0, 0, 0, 0)));
    }
to do so. But i can´t figure out how to create on of this objects without giving the "text" in the code
danpost danpost

2019/2/16

#
marenss wrote...
<< Code Omitted >> What i wanted to do is to use a GreenfootImage to display the typed text. but i have no clue how to make the "name" in the method individual. My idea was to create a new object: << Code Omitted >> to do so. But i can´t figure out how to create on of this objects without giving the "text" in the code
"typed text"? where is the code that allows user input?
You need to login to post a reply.