1 Star 0 Fork 78

黄佳豪/asteroids

forked from 吕焱飞/asteroids 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Space.java 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
黄佳豪 提交于 2021-05-07 17:15 . S.
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();
}
public Counter getCounter(){
return scoreCounter;
}
/**
* 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/hjhzero/asteroids.git
git@gitee.com:hjhzero/asteroids.git
hjhzero
asteroids
asteroids
master

搜索帮助