我试图获得一个功能,当你按下回车键时,你开始游戏,但它不起作用。没有错误。我遵循了一个教程。
这是我的代码:
import greenfoot.*;
/**
* Write a description of class Menu here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Menu extends World
{
/**
* Constructor for objects of class Menu.
*
*/
public Menu()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(800, 500, 1);
prepare();
}
public void start()
{
{
if(Greenfoot.isKeyDown("ENTER"))
{
MinionWorld MinionWorld= new MinionWorld();
Greenfoot.setWorld(MinionWorld);
}
}
}
/**
* Prepare the world for the start of the program. That is: create the initial
* objects and add them to the world.
*/
private void prepare()
{
Controls controls = new Controls();
addObject(controls, 300, 100);
controls.setLocation(175, 50);
}
}