Use scala Random

This commit is contained in:
Yohann D'ANELLO 2020-04-27 13:49:14 +02:00
parent 3b474963a8
commit 500132a816
2 changed files with 3 additions and 10 deletions

View File

@ -2,7 +2,6 @@ package fr.ynerant.leveleditor.game
import java.awt._
import java.awt.event.{MouseEvent, MouseListener}
import java.util.Random
import fr.ynerant.leveleditor.api.editor.sprites.SpriteRegister
import fr.ynerant.leveleditor.api.editor.{Collision, RawMap}
@ -12,10 +11,10 @@ import fr.ynerant.leveleditor.game.towers._
import javax.swing._
import scala.collection.mutable.ListBuffer
import scala.util.Random
class GameFrame(val map: RawMap) extends JFrame("Jeu") {
final private val RANDOM = new Random
private var round = 0
private var hp = 5
private var reward = 20
@ -115,10 +114,10 @@ class GameFrame(val map: RawMap) extends JFrame("Jeu") {
def tick(): Unit = {
if (mobs.isEmpty && round < 4) {
round += 1
val nb_mobs = round * (RANDOM.nextInt(8) + 1)
val nb_mobs = round * (Random.nextInt(8) + 1)
for (_ <- 1 to nb_mobs) {
val mob = Mob.getRandomMob
do mob.move(RANDOM.nextInt(getMap.getWidth / 16), RANDOM.nextInt(getMap.getHeight / 16)) while ( {
do mob.move(Random.nextInt(getMap.getWidth / 16), Random.nextInt(getMap.getHeight / 16)) while ( {
!getMap.getCase(mob.getX, mob.getY).getCollision.equals(Collision.ANY)
})
getMap.getCase(mob.getX, mob.getY).setCollision(Collision.PARTIAL)

View File

@ -1,14 +1,8 @@
package fr.ynerant.leveleditor.game.towers
import java.util.Random
import fr.ynerant.leveleditor.api.editor.sprites.{Sprite, SpriteRegister}
import fr.ynerant.leveleditor.game.GameFrame
object Tower {
private val RANDOM = new Random
}
abstract class Tower(val x: Int, val y: Int) {
final private val sprite = SpriteRegister.getCategory(getName).getSprites.head
private var remainingTicks = 0L