Use scala Random
This commit is contained in:
parent
3b474963a8
commit
500132a816
|
@ -2,7 +2,6 @@ package fr.ynerant.leveleditor.game
|
||||||
|
|
||||||
import java.awt._
|
import java.awt._
|
||||||
import java.awt.event.{MouseEvent, MouseListener}
|
import java.awt.event.{MouseEvent, MouseListener}
|
||||||
import java.util.Random
|
|
||||||
|
|
||||||
import fr.ynerant.leveleditor.api.editor.sprites.SpriteRegister
|
import fr.ynerant.leveleditor.api.editor.sprites.SpriteRegister
|
||||||
import fr.ynerant.leveleditor.api.editor.{Collision, RawMap}
|
import fr.ynerant.leveleditor.api.editor.{Collision, RawMap}
|
||||||
|
@ -12,10 +11,10 @@ import fr.ynerant.leveleditor.game.towers._
|
||||||
import javax.swing._
|
import javax.swing._
|
||||||
|
|
||||||
import scala.collection.mutable.ListBuffer
|
import scala.collection.mutable.ListBuffer
|
||||||
|
import scala.util.Random
|
||||||
|
|
||||||
|
|
||||||
class GameFrame(val map: RawMap) extends JFrame("Jeu") {
|
class GameFrame(val map: RawMap) extends JFrame("Jeu") {
|
||||||
final private val RANDOM = new Random
|
|
||||||
private var round = 0
|
private var round = 0
|
||||||
private var hp = 5
|
private var hp = 5
|
||||||
private var reward = 20
|
private var reward = 20
|
||||||
|
@ -115,10 +114,10 @@ class GameFrame(val map: RawMap) extends JFrame("Jeu") {
|
||||||
def tick(): Unit = {
|
def tick(): Unit = {
|
||||||
if (mobs.isEmpty && round < 4) {
|
if (mobs.isEmpty && round < 4) {
|
||||||
round += 1
|
round += 1
|
||||||
val nb_mobs = round * (RANDOM.nextInt(8) + 1)
|
val nb_mobs = round * (Random.nextInt(8) + 1)
|
||||||
for (_ <- 1 to nb_mobs) {
|
for (_ <- 1 to nb_mobs) {
|
||||||
val mob = Mob.getRandomMob
|
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).getCollision.equals(Collision.ANY)
|
||||||
})
|
})
|
||||||
getMap.getCase(mob.getX, mob.getY).setCollision(Collision.PARTIAL)
|
getMap.getCase(mob.getX, mob.getY).setCollision(Collision.PARTIAL)
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
package fr.ynerant.leveleditor.game.towers
|
package fr.ynerant.leveleditor.game.towers
|
||||||
|
|
||||||
import java.util.Random
|
|
||||||
|
|
||||||
import fr.ynerant.leveleditor.api.editor.sprites.{Sprite, SpriteRegister}
|
import fr.ynerant.leveleditor.api.editor.sprites.{Sprite, SpriteRegister}
|
||||||
import fr.ynerant.leveleditor.game.GameFrame
|
import fr.ynerant.leveleditor.game.GameFrame
|
||||||
|
|
||||||
object Tower {
|
|
||||||
private val RANDOM = new Random
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class Tower(val x: Int, val y: Int) {
|
abstract class Tower(val x: Int, val y: Int) {
|
||||||
final private val sprite = SpriteRegister.getCategory(getName).getSprites.head
|
final private val sprite = SpriteRegister.getCategory(getName).getSprites.head
|
||||||
private var remainingTicks = 0L
|
private var remainingTicks = 0L
|
||||||
|
|
Loading…
Reference in New Issue