↖️ Back to specs

classDiagram
direction BT

class Updatable {
  <<interface>>
  +update()
}

class Drawable {
  <<interface>>
  +draw()
}

class GameElement:::italics {
  <<abstract>>
  #Pose pose
  #Vector2D velocity
  #double radius
  #boolean destroyed
  +GameElement(pose Pose, velocity Vector2D, radius double)
  +getPose() Pose
  +getVelocity() Vector2D
  +getRadius() double
  +isDestroyed() boolean
  +setDestroyed(destroyed boolean)
  +checkCollision(other GameElement) boolean
  +update()
}
GameElement ..|> Updatable
GameElement ..|> Drawable

class Ship
Ship: +int SHIP_WIDTH {readOnly=10}$
Ship: +int SHIP_HEIGHT {readOnly=20}$
Ship: +double SHIP_TURN {readOnly=0.1}$
Ship: +double SHIP_MOVE {readOnly=0.1}$
Ship: +double FRICTION {readOnly=0.02}$
Ship: +Ship()
Ship: +turnLeft()
Ship: +turnRight()
Ship: +thrust()
Ship: +update()
Ship: +draw()
Ship --|> GameElement

class Bullet 
Bullet: +double BULLET_RADIUS {readOnly=1.5}$
Bullet: +int BULLET_SPEED {readOnly=20}$
Bullet: +int BULLET_DURATION {readOnly=20}$
Bullet: -int counter
Bullet: +Bullet(pose Pose)
Bullet: +update()
Bullet: +draw()

Bullet --|> GameElement

class Enemy:::italics {
  <<abstract>>
  #int points
  +Enemy(speed double, radius double, points int)
  +getPoints() int
}
Enemy --|> GameElement

class AsteroidSize {
  <<enumeration>>
  SMALL
  MEDIUM
  LARGE
  -int radius
  -int points
  -AsteroidSize(radius int, points int)
  +getRadius() int
  +getPoints() int
  +randomSize()$ AsteroidSize
}
AsteroidSize <.. Asteroid

class Asteroid 
Asteroid: +int ASTEROID_SPEED {readOnly=1}$
Asteroid: +Asteroid(size AsteroidSize)
Asteroid: +draw()

Asteroid --|> Enemy

class Saucer 
Saucer: +int HALF_WIDTH {readOnly=10}$
Saucer: +int HALF_HEIGHT {readOnly=5}$
Saucer: +int SAUCER_SPEED {readOnly=2}$
Saucer: +int SAUCER_POINTS {readOnly=400}$
Saucer: +double SPAWN_PROB {readOnly=0.002}$
Saucer: +double TURN_PROB {readOnly=0.05}$
Saucer: +Saucer()
Saucer: +update()
Saucer: +draw()

Saucer --|> Enemy

class Star
Star: -Point location
Star: +int STAR_RADIUS {readOnly=1}$
Star: +Star(x double, y double)
Star: +getLocation() Point
Star: +draw()
Star ..|> Drawable

class NumericDisplay {
  -String prefix
  -int value
  -Point location
  +NumericDisplay(xPos int, yPos int, prefix String, value int)
  +getLocation() Point
  +getValue() int
  +setValue(value int)
  +draw()
}
NumericDisplay ..|> Drawable
classDiagram
class Playable {
  <<interface>>
  +update()
  +draw()
  +startGame()
}
class AsteroidsGame
AsteroidsGame: +int LIVES {readOnly=3}$
AsteroidsGame: -ArrayList~Drawable~ drawElements
AsteroidsGame: -ArrayList~Updatable~ updateElements
AsteroidsGame: -ArrayList~GameElement~ shipAndBullets
AsteroidsGame: -ArrayList~Enemy~ enemies
AsteroidsGame: -Ship ship
AsteroidsGame: -NumericDisplay score
AsteroidsGame: -NumericDisplay lives
AsteroidsGame: +AsteroidsGame()
AsteroidsGame: +addEnemy(enemy Enemy)
AsteroidsGame: -newStars()
AsteroidsGame: -newEnemies()
AsteroidsGame: -newShip()
AsteroidsGame: -handleKeyboardInput()
AsteroidsGame: +update()
AsteroidsGame: +draw()
AsteroidsGame: +handleCollisions()
AsteroidsGame: +removeDestroyedBullets()
AsteroidsGame: +removeDestroyedEnemies()
AsteroidsGame: +startGame()
AsteroidsGame: #randomXPosition()$ double
AsteroidsGame: #randomYPosition()$ double
AsteroidsGame: #randomHeading()$ double
AsteroidsGame ..|> Playable