From 344f71192f9266788ced5be5de490edeffc262b2 Mon Sep 17 00:00:00 2001 From: dalyjame Date: Wed, 20 Nov 2019 11:57:55 -0500 Subject: [PATCH] A bunch of stuff from a long while ago that I forgot to commit. --- FakeMon/src/fmon/Game.scala | 2 + FakeMon/src/fmon/GameManager.scala | 31 +++++++++ FakeMon/src/fmon/battle/BattleEngine.scala | 7 +- FakeMon/src/fmon/battle/BattleUI.scala | 80 ++++++++++++++++++++++ FakeMon/src/fmon/battle/battle.fxml | 4 +- FakeMon/src/fmon/stat/Gene.scala | 7 +- FakeMon/src/fmon/world/ui/GameView.fxml | 2 +- FakeMon/src/fmon/world/ui/GameView.scala | 19 +++-- 8 files changed, 139 insertions(+), 13 deletions(-) create mode 100644 FakeMon/src/fmon/GameManager.scala diff --git a/FakeMon/src/fmon/Game.scala b/FakeMon/src/fmon/Game.scala index bbfa049..e066f21 100644 --- a/FakeMon/src/fmon/Game.scala +++ b/FakeMon/src/fmon/Game.scala @@ -20,6 +20,7 @@ object Game { class Game extends Application { override def start(primaryStage: Stage): Unit = { + /* val url = getClass.getResource("battle/battle.fxml") val loader = new FXMLLoader(url) val root: Parent = loader.load() @@ -43,5 +44,6 @@ class Game extends Application { primaryStage.setTitle(Config.title) primaryStage.setScene(scene) primaryStage.show() + */ } } \ No newline at end of file diff --git a/FakeMon/src/fmon/GameManager.scala b/FakeMon/src/fmon/GameManager.scala new file mode 100644 index 0000000..ba2cedd --- /dev/null +++ b/FakeMon/src/fmon/GameManager.scala @@ -0,0 +1,31 @@ +package fmon + +import scalafx.scene.Scene + +import scalafx.Includes._ +import scalafx.scene.Node +import scalafx.scene.Parent +import scalafx.stage.Stage + +import fmon.world.ui.GameView + +object GameManager { + var currLevel: Parent = _ + var currController: GameView = _ + + var currView: Parent = _ + + var root: Stage = _ + + def setView(view: Parent): Unit = { + currController.timer.stop() + currView = view + root.scene().root = view + } + + def restoreMap(): Unit = { + currView = currLevel + root.scene().root = currView + currController.timer.start() + } +} \ No newline at end of file diff --git a/FakeMon/src/fmon/battle/BattleEngine.scala b/FakeMon/src/fmon/battle/BattleEngine.scala index e0a8b4e..b9ca72f 100644 --- a/FakeMon/src/fmon/battle/BattleEngine.scala +++ b/FakeMon/src/fmon/battle/BattleEngine.scala @@ -2,6 +2,7 @@ package fmon.battle import scala.util.Random +import fmon._ import fmon.battle.msg._ import fmon.stat._ import fmon.stat.Statistic._ @@ -39,10 +40,11 @@ class BattleEngine(val player: Party, val enemy: Party)(implicit val reader: Sig if (!player.lead.isAlive) { if (player.canFight) { - val replace = player.pollReplacement(enemy) - player.switchIn(replace) + val replace = player.pollReplacement(enemy) + player.switchIn(replace) } else { this ! Message(s"${player.trainer} has lost!") + GameManager.restoreMap() } } if (!enemy.lead.isAlive) { @@ -51,6 +53,7 @@ class BattleEngine(val player: Party, val enemy: Party)(implicit val reader: Sig enemy.switchIn(replace) } else { this ! Message(s"${enemy.trainer} has lost!") + GameManager.restoreMap() } } } diff --git a/FakeMon/src/fmon/battle/BattleUI.scala b/FakeMon/src/fmon/battle/BattleUI.scala index 9b935c9..4837e61 100644 --- a/FakeMon/src/fmon/battle/BattleUI.scala +++ b/FakeMon/src/fmon/battle/BattleUI.scala @@ -3,12 +3,16 @@ package fmon.battle import java.io._ import java.util.concurrent.locks.{Condition, ReentrantLock} +import scala.util.Random + +import javafx.application.Application import javafx.application.Platform import javafx.fxml.FXML import javafx.fxml.FXMLLoader import javafx.fxml.JavaFXBuilderFactory import javafx.scene.{control => jfxsc} import javafx.scene.image.ImageView +import javafx.stage.Stage import scalafx.Includes._ import scalafx.animation._ @@ -23,6 +27,7 @@ import scalafx.scene.text.Font import scalafx.scene.transform.Rotate import scalafx.util.Duration +import fmon.GameManager import fmon.battle.msg._ import fmon.draw._ import fmon.stat._ @@ -46,7 +51,24 @@ class BattleUI extends SignalConsumer { private val lock = new ReentrantLock() private val finishedPlaying = lock.newCondition() + def beginWildBattle(player: Party, wild: Monster)(implicit rng: Random) { + implicit val consumer = this + setEngine(new BattleEngine( + player, + new Party(BattleUI.WildTrainer, new MonsterPtr(wild), IndexedSeq()) + )) + this ! Message(s"A wild ${wild.name} appeared!") + } + + def beginTrainerBattle(player: Party, trainer: Party)(implicit rng: Random) { + implicit val consumer = this + setEngine(new BattleEngine(player, trainer)) + this ! Message(s"${trainer.trainer} wants to fight!") + this ! Message(s"${trainer.trainer} sent out ${trainer.lead}") + } + def setEngine(engine: BattleEngine): Unit = { + messages.clear() this.engine = engine updateUI() } @@ -204,4 +226,62 @@ class BattleUI extends SignalConsumer { controller.setup(move, onMove) button } +} + +import javafx.scene.Scene + +import fmon.Config +import fmon.stat.Gender + +object BattleUI { + final val WildTrainer = TrainerID("Wild", Gender.Neuter, 0) + + def startWildBattle(): Unit = { + val url = getClass.getResource("battle.fxml") + val loader = new FXMLLoader(url) + val root: javafx.scene.Parent = loader.load() + implicit val controller = loader.getController[BattleUI]() + + implicit val rng = new scala.util.Random() + val form1 = Form("Diabolo") + val form2 = Form("Chanilla") + val movepool1 = IndexedSeq(Move("eruption"), Move("willowisp"), Move("thunderbolt"), Move("thunderwave"), Move("thundershock")) + val movepool2 = IndexedSeq(Move("tackle")) + val p1 = TrainerID("Jaeda", Gender.Female, 0) + val party1 = new Party(p1, new MonsterPtr(Monster.generate("Allied Mon", p1, 500, form1, movepool1)), IndexedSeq()) + val monster = Monster.generate(null, WildTrainer, 500, form2, movepool2) + controller.beginWildBattle(party1, monster) + GameManager.setView(root) + } + + class GameApp extends Application { + override def start(primaryStage: Stage): Unit = { + val url = getClass.getResource("battle.fxml") + val loader = new FXMLLoader(url) + val root: javafx.scene.Parent = loader.load() + implicit val controller = loader.getController[BattleUI]() + val scene: Scene = new Scene(root) + + implicit val rng = new scala.util.Random() + val form1 = Form("Diabolo") + val form2 = Form("Chanilla") + val movepool1 = IndexedSeq(Move("eruption"), Move("willowisp"), Move("thunderbolt"), Move("thunderwave"), Move("thundershock")) + val movepool2 = IndexedSeq(Move("tackle")) + val p1 = TrainerID("Jaeda", Gender.Female, 0) + val p2 = TrainerID("Wild Monster", Gender.Male, 0) + val party1 = new Party(p1, new MonsterPtr(Monster.generate("Allied Mon", p1, 500, form1, movepool1)), IndexedSeq()) + val party2 = new Party(p2, new MonsterPtr(Monster.generate("Wild Mon", p2, 500, form2, movepool2)), IndexedSeq( + Monster.generate("Sideboard Mon", p2, 500, form2, movepool2) + )) + controller.beginTrainerBattle(party1, party2) + + primaryStage.setTitle(Config.title) + primaryStage.setScene(scene) + primaryStage.show() + } + } + + def main(args: Array[String]): Unit = { + Application.launch(classOf[GameApp], args: _*) + } } \ No newline at end of file diff --git a/FakeMon/src/fmon/battle/battle.fxml b/FakeMon/src/fmon/battle/battle.fxml index 886e214..e0903c1 100644 --- a/FakeMon/src/fmon/battle/battle.fxml +++ b/FakeMon/src/fmon/battle/battle.fxml @@ -12,7 +12,7 @@ - + @@ -53,7 +53,7 @@ - + diff --git a/FakeMon/src/fmon/stat/Gene.scala b/FakeMon/src/fmon/stat/Gene.scala index deb01e8..6acf984 100644 --- a/FakeMon/src/fmon/stat/Gene.scala +++ b/FakeMon/src/fmon/stat/Gene.scala @@ -2,15 +2,18 @@ package fmon.stat import scala.util.Random +import fmon._ + case class Gene(val gender : Gender, val nature : Nature, val ivs : Map[Stat, Int], ot : TrainerID) { } object Gene { final val MaxIV = 31 - def randomGene(ot : TrainerID, form : Form)(implicit rng : Random) = { + + def randomGene(ot : TrainerID, form : Form)(implicit rng : Random): Gene = { val gender = Gender.Neuter // TODO - val ivs = Statistic.values.map(s => (s, rng.nextInt(MaxIV + 1))).toMap + val ivs = Statistic.values.toSeq.map(s => (s, rng.nextInt(MaxIV + 1))).toMap Gene(gender, Nature.randomNature, ivs, ot) } } \ No newline at end of file diff --git a/FakeMon/src/fmon/world/ui/GameView.fxml b/FakeMon/src/fmon/world/ui/GameView.fxml index 5943167..5f25396 100644 --- a/FakeMon/src/fmon/world/ui/GameView.fxml +++ b/FakeMon/src/fmon/world/ui/GameView.fxml @@ -5,7 +5,7 @@ - + diff --git a/FakeMon/src/fmon/world/ui/GameView.scala b/FakeMon/src/fmon/world/ui/GameView.scala index 0020ab1..814fbe3 100644 --- a/FakeMon/src/fmon/world/ui/GameView.scala +++ b/FakeMon/src/fmon/world/ui/GameView.scala @@ -26,6 +26,7 @@ import scalafx.util.Duration import FileChooser.ExtensionFilter import fmon._ +import fmon.battle.BattleUI import fmon.draw._ import fmon.script.action.MessageAction import fmon.util.Direction @@ -98,6 +99,7 @@ class GameView { case KeyCode.A | KeyCode.Left => setDir(West) case KeyCode.S | KeyCode.Down => setDir(South) case KeyCode.Space => activate() + case KeyCode.BackQuote => beginWildBattle() case _ => () } } @@ -112,6 +114,10 @@ class GameView { } } + def beginWildBattle(): Unit = { + BattleUI.startWildBattle() + } + def activate(): Unit = { if (hero.move.direction == Direction.Stationary) { val dir = Direction.byName(hero.sprite.pose) @@ -281,19 +287,20 @@ object GameView { val stageFile = Config.homedir + raw"Progena\Data\outside.map" val level = GameMap.loadFrom(new File(stageFile)) controller.loadLevel(level) - //val builderLoader = new FXMLLoader(getClass.getResource("ElementBuilder.fxml")) - //val builder: Parent = builderLoader.load() - //val builderController = builderLoader.getController[ElementBuilder]() - - //controller.pane.children = builder - //controller.builder = builderController val scene: Scene = new Scene(root) + + GameManager.root = primaryStage + GameManager.currLevel = root + GameManager.currController = controller + GameManager.currView = root + primaryStage.setScene(scene) primaryStage.width = 1280 primaryStage.height = 800 //primaryStage.maximized = true primaryStage.show() + } }