1 Star 0 Fork 79

lelouch/asteroids

forked from 吕焱飞/asteroids 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Space.java 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
luyanfei78 提交于 2020-04-15 10:17 . asteroids initialized.
import greenfoot.*;
/**
* Space. Something for rockets to fly in.
*
* @author Michael Kölling
* @version 1.1
*/
public class Space extends World
{
private Counter scoreCounter;
private int startAsteroids = 3;
/**
* Create the space and all objects within it.
*/
public Space()
{
super(600, 500, 1);
GreenfootImage background = getBackground();
background.setColor(Color.BLACK);
background.fill();
Rocket rocket = new Rocket();
addObject(rocket, getWidth()/2 + 100, getHeight()/2);
addAsteroids(startAsteroids);
scoreCounter = new Counter("Score: ");
addObject(scoreCounter, 60, 480);
Explosion.initializeImages();
ProtonWave.initializeImages();
}
/**
* Add a given number of asteroids to our world. Asteroids are only added into
* the left half of the world.
*/
private void addAsteroids(int count)
{
for(int i = 0; i < count; i++)
{
int x = Greenfoot.getRandomNumber(getWidth()/2);
int y = Greenfoot.getRandomNumber(getHeight()/2);
addObject(new Asteroid(), x, y);
}
}
/**
* This method is called when the game is over to display the final score.
*/
public void gameOver()
{
// TODO: show the score board here. Currently missing.
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/lelouch527/asteroids.git
git@gitee.com:lelouch527/asteroids.git
lelouch527
asteroids
asteroids
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385