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

2018/2/7

What's the problem? :((

ORSODO ORSODO

2018/2/7

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Flagchoose here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Flagchoose extends Actor
{
    /**
     * Act - do whatever the Flagchoose wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    int level=0;
    int coins=100;
    public void act() 
    {
        level++;
        if (level==1) level1();
    }    
    public void level1()
    {
        setImage("romania.png");
        if (pressed3()==true) {getWorld().removeObject(this); Greenfoot.setWorld(new SnakeWorld());}
        if (pressed2()==true) coins-=30;
        if (pressed1()==true) coins-=30;
    }
    //--------------------------------------------------------------------------------------------------------------------------------------------------------------------
    public boolean pressed1()
    {
        boolean pressed;
        pressed=false;
        if (Greenfoot.isKeyDown("1"))  pressed=true;
        return pressed;
    }
    public boolean pressed2()
    {
        boolean pressed;
        pressed=false;
        if (Greenfoot.isKeyDown("2"))  pressed=true;
        return pressed;
    }
    public boolean pressed3()
    {
        boolean pressed;
        pressed=false;
        if (Greenfoot.isKeyDown("3"))  pressed=true;
        return pressed;
    }
}
Super_Hippo Super_Hippo

2018/2/7

#
The level1 method is only executed once in the very first act cycle (when this object is created). Chances are that you can't press 1, 2 or 3 that quickly.
You need to login to post a reply.