Skip to content

Commit

Permalink
output actions to text area
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrupkin committed Mar 12, 2016
1 parent 82ebf21 commit aeed4b0
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 55 deletions.
Binary file modified src/main/resources/rex/area-2.xp
Binary file not shown.
Binary file modified src/main/resources/rex/area-3.xp
Binary file not shown.
Binary file removed src/main/resources/rex/level-1.xp
Binary file not shown.
Binary file removed src/main/resources/rex/level-2.xp
Binary file not shown.
Binary file removed src/main/resources/rex/level.xp
Binary file not shown.
29 changes: 25 additions & 4 deletions src/main/resources/views/Console.css
Expand Up @@ -4,18 +4,39 @@

.dark, .dark .label {
-fx-background-color: black;
-fx-font-size: 11pt;
-fx-font-size: 16pt;
-fx-font-family: "Segoe UI Semibold";
-fx-text-fill: white;
}

.text-area {
-fx-font-size: 12pt;
.text-area:disabled {
-fx-background-color: black;
-fx-font-size: 24pt;
-fx-font-family: "Segoe UI Semibold";
-fx-text-fill: white;
-fx-opacity: 1.0;
}

.text-area .scroll-pane:disabled {
-fx-background-color: transparent;
-fx-opacity: 1.0;
}

.text-area .scroll-bar:vertical:disabled {
-fx-opacity: 0.0;
}

.text-area .scroll-pane .viewport {
-fx-background-color: transparent;
}


.text-area .scroll-pane .content {
-fx-background-color: transparent;
}

.text-area .content {
.text-area .scroll-pane:disabled .content {
-fx-opacity: 1.0;
-fx-background-color: black;
}

Expand Down
40 changes: 37 additions & 3 deletions src/main/resources/views/Game.fxml
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<GridPane fx:id="rootPane" alignment="TOP_CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="1024.0" prefWidth="1280.0" styleClass="dark-background" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<GridPane fx:id="rootPane" alignment="TOP_CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="1024.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<columnConstraints>
<ColumnConstraints hgrow="NEVER" minWidth="10.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
Expand All @@ -15,7 +16,40 @@
</rowConstraints>
<children>
<Pane fx:id="consolePane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="200.0" minWidth="400.0" style="-fx-border-color: white;" styleClass="dark-background" GridPane.halignment="LEFT" GridPane.valignment="TOP" />
<VBox prefHeight="200.0" prefWidth="100.0" GridPane.columnIndex="1" />
<TextArea disable="true" prefHeight="200.0" prefWidth="200.0" style="-fx-border-color: white;" styleClass="dark-background" GridPane.columnSpan="2147483647" GridPane.rowIndex="1" />
<GridPane styleClass="dark" GridPane.columnIndex="1">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="435.0" minWidth="120.0" prefWidth="120.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="789.0" minWidth="10.0" prefWidth="774.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
</rowConstraints>
<children>
<Label text="Hit Points:" />
<Label text="Attack:" GridPane.rowIndex="2" />
<Label layoutX="10.0" layoutY="75.0" text="Damage:" GridPane.rowIndex="3" />
<Label layoutX="10.0" layoutY="175.0" text="Modifier:" GridPane.rowIndex="6" />
<Label layoutX="10.0" layoutY="180.0" text="Defense:" GridPane.rowIndex="4" />
<Label fx:id="hitPoints" layoutX="10.0" layoutY="60.0" text="0" GridPane.columnIndex="1" />
<Label fx:id="attack" layoutX="10.0" layoutY="140.0" text="0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label fx:id="damage" layoutX="10.0" layoutY="100.0" text="0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label fx:id="modifier" layoutX="10.0" layoutY="20.0" text="0" GridPane.columnIndex="1" GridPane.rowIndex="6" />
<Label fx:id="defense" layoutX="10.0" layoutY="180.0" text="0" GridPane.columnIndex="1" GridPane.rowIndex="4" />
</children>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</GridPane>
<TextArea fx:id="textArea" disable="true" prefHeight="200.0" prefWidth="200.0" style="-fx-border-color: white;" GridPane.columnSpan="2147483647" GridPane.rowIndex="1" />
</children>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</GridPane>
34 changes: 32 additions & 2 deletions src/main/scala/controller/Game.scala
@@ -1,6 +1,7 @@
package controller

import javafx.fxml.FXML
import javafx.scene.control.{TextArea, Label}
import javafx.scene.layout.Pane

import control.ConsoleFx
Expand All @@ -21,10 +22,21 @@ trait Game { self: Controller =>

@FXML var consolePane: Pane = _

@FXML var hitPoints: Label = _

@FXML var damage: Label = _

@FXML var attack: Label = _
@FXML var modifier: Label = _

@FXML var defense: Label = _

@FXML var textArea: TextArea = _


val console = new ConsoleFx()

def initialize(): Unit = {

new sfxl.Pane(consolePane) {
filterEvent(sfxi.KeyEvent.KeyPressed) {
(event: sfxi.KeyEvent) => handleKeyPressed(event)
Expand All @@ -45,11 +57,26 @@ trait Game { self: Controller =>

override def update(elapsed: Int): Unit = {
console.draw(world)
updatePlayerInfo()

if (world.player.hitPoints <= 0) {
changeState(new GameController(WorldBuilder()))
}
}

def updatePlayerInfo(): Unit = {
import world._

hitPoints.setText(player.hitPoints.toString)

damage.setText(player.damage.toString)

attack.setText(player.attackRating.toString)
modifier.setText(player.modifier().toString)

defense.setText(player.defenseRating.toString)
}

def handleMouseMove(event: sfxi.MouseEvent): Unit = {
for (p <- mouseToPoint(event)) {
console.cursor = Some(p)
Expand All @@ -71,7 +98,10 @@ trait Game { self: Controller =>
code match {
case ESCAPE => exit()
case TAB => world.player.nextAction()
case _ => direction.map( p => if (event.controlDown) world.specialAction(p) else world.action(p) )
case _ => direction.map( p => {
val text = if (event.controlDown) world.specialAction(p) else world.action(p)
textArea.appendText(text)
} )
}
}

Expand Down
48 changes: 30 additions & 18 deletions src/main/scala/model/Agent.scala
Expand Up @@ -3,6 +3,7 @@ package model
import org.mtrupkin.console.ScreenChar
import org.mtrupkin.core.{Size, Point}

import scala.collection.mutable.ListBuffer
import scala.util.Random

/**
Expand All @@ -14,21 +15,26 @@ trait Agent {

// combat stats
var damage: Int = 1
var attack: Int = 1
def modifier(): Int = 1
var defense: Int = 1
var attackRating: Int = 1

// situational modifiers
def modifier(): Int = 0
var defenseRating: Int = 1

val sc: ScreenChar
}

case class Monster(
val name: String,
var position: Point,
var hitPoints: Int,
val sc: ScreenChar) extends Agent {
def attack(player: Player): Unit = {
def attack(player: Player): Option[String] = {
val bonusDamage = Combat.bonusDamage(this, player)

player.hitPoints -= bonusDamage
if (bonusDamage > 0 ) {
player.hitPoints -= bonusDamage
Some(s"Player damaged: $bonusDamage")
} else None
}
}

Expand All @@ -48,24 +54,26 @@ class Player(

def action(): Action = actions(currentActionIndex)

def attack(monster: Monster): Unit = {
def attack(monster: Monster): String = {
val bonusDamage = Combat.bonusDamage(this, monster)
val totalDamage = damage + bonusDamage
println(s"attack damage: $totalDamage")

monster.hitPoints -= totalDamage

s"Attack ${monster.name}: $totalDamage"
}

sealed trait Action {
def perform(world: World, direction: Point): Unit
def perform(world: World, direction: Point): Option[String]
}
// move 2 squares
case object Dash extends Action {
def perform(world: World, direction: Point): Unit = {
val canDash = world.attackOrMove(direction)
def perform(world: World, direction: Point): Option[String] = {
val (canDash, firstText) = world.attackOrMove(direction)
if (canDash) {
world.attackOrMove(direction)
}
val (_, secondText) = world.attackOrMove(direction)
secondText
} else firstText
}
}

Expand All @@ -79,19 +87,23 @@ class Player(
} yield p0
}

def perform(world: World, direction: Point): Unit = {
def perform(world: World, direction: Point): Option[String] = {
val origin = position + direction
val textList = ListBuffer[String]()
neighbors(origin).foreach(p => {
world.monsters.find(_.position == p).map(m => attack(m))
world.monsters.find(_.position == p).map(m => textList += attack(m))
})
if (textList.isEmpty) None else Some(textList.mkString("\n"))
}
}
// attack 3x3 around player
case object Blast extends Action {
def perform(world: World, direction: Point): Unit = {
def perform(world: World, direction: Point): Option[String] = {
val textList = ListBuffer[String]()
position.neighbors().foreach(p => {
world.monsters.find(_.position == p).map(m => attack(m))
world.monsters.find(_.position == p).map(m => textList += attack(m))
})
if (textList.isEmpty) None else Some(textList.mkString("\n"))
}
}
}
Expand All @@ -110,7 +122,7 @@ object Combat {
}

def bonusDamage(offense: Agent, defense: Agent): Int = {
val multiplier = Math.max(offense.attack - defense.defense, 1)
val multiplier = Math.max(offense.attackRating - defense.defenseRating, 1)
bonusDamage(offense.damage, multiplier, offense.modifier())
}

Expand Down

0 comments on commit aeed4b0

Please sign in to comment.