Skip to content

Commit

Permalink
Tidying up G1HGui.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich2 committed Feb 22, 2023
1 parent 385bf83 commit 6f8f069
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
16 changes: 8 additions & 8 deletions Tiling/ExsSrc/gOne/hp1/G1HExamples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ostrat; package gOne; package hp1
import prid._, phex._, gPlay._

/** 1st example Turn 0 scenario state for Game One hex. */
object G1HScen1 extends H1Scen
object G1HScen1 extends G1HScen
{ override def turn: Int = 0
implicit val gridSys: HGridReg = GSys.g1
val oPlayers: HCenOptLayer[Player] = gridSys.newHCenOptLayer
Expand All @@ -12,7 +12,7 @@ object G1HScen1 extends H1Scen
}

/** 2nd example Turn 0 scenario state for Game One hex. */
object G1HScen2 extends H1Scen
object G1HScen2 extends G1HScen
{ override def turn: Int = 0
implicit val gridSys: HGridReg = GSys.g2
val oPlayers: HCenOptLayer[Player] = gridSys.newHCenOptLayer
Expand All @@ -21,45 +21,45 @@ object G1HScen2 extends H1Scen
}

/** 3rd example Turn 0 scenario state for Game One hex. */
object G1HScen3 extends H1Scen
object G1HScen3 extends G1HScen
{ override def turn: Int = 0
implicit val gridSys: HGridIrr = GSys.g3
val oPlayers: HCenOptLayer[Player] = gridSys.newHCenOptLayer
oPlayers.unsafeSetSomes((4, 4, PlayerA), (10, 6, PlayerB), (8, 8, PlayerC))
}

/** 3rd example Turn 0 scenario state for Game One. */
object G1HScen7 extends H1Scen
object G1HScen7 extends G1HScen
{ override def turn: Int = 0
implicit val gridSys: HGrid = HGridIrr(10, (1, 6), (2, 4), (3, 2), (2, 4), (1, 6))
val oPlayers: HCenOptLayer[Player] = gridSys.newHCenOptLayer
oPlayers.unsafeSetSomes((4, 4, PlayerA), (10, 6, PlayerB), (8, 8, PlayerC))
}

/** 2nd example Turn 0 scenario state for Game One. */
object G1HScen4 extends H1Scen
object G1HScen4 extends G1HScen
{ override def turn: Int = 0
implicit val gridSys: HGridReg = HGridReg(2, 10, 4, 8)
val oPlayers: HCenOptLayer[Player] = gridSys.newHCenOptLayer
oPlayers.unsafeSetSomes((4, 4, PlayerA), (8, 4, PlayerB), (6, 6, PlayerC))
}

/** 8th example Turn 0 scenario state for Game One. An empty regular grid containing no hex tiles. */
object G1HScen8 extends H1Scen
object G1HScen8 extends G1HScen
{ override def turn: Int = 0
implicit val gridSys: HGridReg = HGridReg(4, 2, 4, 2)
val oPlayers: HCenOptLayer[Player] = gridSys.newHCenOptLayer
}

/** 9th example Turn 0 scenario state for Game One. An empty irregular grid containing no hex tiles. */
object G1HScen9 extends H1Scen
object G1HScen9 extends G1HScen
{ override def turn: Int = 0
implicit val gridSys: HGrid = HGridIrr(2)
val oPlayers: HCenOptLayer[Player] = gridSys.newHCenOptLayer
}

/** 10th example Turn 0 scenario state for Game One. Uses an [[HGridIrr]] */
object G1HScen10 extends H1Scen
object G1HScen10 extends G1HScen
{ override def turn: Int = 0
implicit val gridSys: HGrid = HGridIrr(12, (12, 4), (4, 6), (1, 8), (4, 2), (2, 4), (1, 6))
val oPlayers: HCenOptLayer[Player] = gridSys.newHCenOptLayer
Expand Down
16 changes: 8 additions & 8 deletions Tiling/ExsSrc/gOne/hp1/G1HGui.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import pgui._, geom._, prid._, phex._, gPlay._

/** Graphical user interface for Game One example game. Each player can move one hex tile step. Any move to a tile already containing a player or that
* one more than one player is attempting to move to fails. */
case class G1HGui(canv: CanvasPlatform, scenStart: H1Scen, viewIn: HGView) extends HGridSysGui("Game One Gui")
case class G1HGui(canv: CanvasPlatform, scenStart: G1HScen, viewIn: HGView) extends HGridSysGui("Game One Gui")
{
statusText = "Left click on Player to select. Right click on adjacent Hex to set move."
var scen = scenStart
var history: RArr[H1Scen] = RArr(scen)
var history: RArr[G1HScen] = RArr(scen)
implicit def gridSys: HGridSys = scen.gridSys
def players: HCenOptLayer[Player] = scen.oPlayers

implicit val proj: HSysProjection = gridSys.projection(mainPanel)
proj.setView(viewIn)

/** There are no moves set. The Gui is reset to this state at the start of every turn. */
def NoMoves2: HCenStepPairArr[Player] = HCenStepPairArr[Player]()
def NoMoves: HCenStepPairArr[Player] = HCenStepPairArr[Player]()

/** This is the planned moves or orders for the next turn. Note this is just a record of the planned moves it is not graphical display of those
* moves. This data is state for the Gui. */
var moves2 = NoMoves2
var moves: HCenStepPairArr[Player] = NoMoves

val urect = Rect(1.4, 1)

Expand All @@ -43,15 +43,15 @@ case class G1HGui(canv: CanvasPlatform, scenStart: H1Scen, viewIn: HGView) exten
/** Draws the tiles sides (or edges). */
def outerSidesDraw: LinesDraw = proj.outerSidesDraw(2, Colour.Gold)

def moveSegPairs: LineSegPairArr[Player] = moves2.optMapOnA1(_.projLineSeg)
def moveSegPairs: LineSegPairArr[Player] = moves.optMapOnA1(_.projLineSeg)

/** This is the graphical display of the planned move orders. */
def moveGraphics: GraphicElems = moveSegPairs.pairFlatMap{ (seg, pl) => seg.draw(pl.colour).arrow }

/** Creates the turn button and the action to commit on mouse click. */
def bTurn: PolygonCompound = clickButton("Turn " + (scen.turn + 1).toString){_ =>
scen = scen.endTurn(moves2)
moves2 = NoMoves2
scen = scen.endTurn(moves)
moves = NoMoves
repaint()
thisTop()
}
Expand All @@ -69,7 +69,7 @@ case class G1HGui(canv: CanvasPlatform, scenStart: H1Scen, viewIn: HGView) exten

case (RightButton, AnyArrHead(HPlayer(hc1, pl)), hits) => hits.findHCenForEach{ hc2 =>
val newM: Option[HStep] = gridSys.findStep(hc1, hc2)
newM.foreach{ d => moves2 = moves2.replaceA1byA2OrAppend(pl, hc1.andStep(d)) }
newM.foreach{ d => moves = moves.replaceA1byA2OrAppend(pl, hc1.andStep(d)) }
repaint()
}

Expand Down
2 changes: 1 addition & 1 deletion Tiling/ExsSrc/gOne/hp1/G1HLaunch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object G1HLaunch extends GuiLaunchMore
{ val oScen: EMon[Int] = sts.findSetting[Int]("scen")
val num: Int = oScen.getElse(1)

val scen: H1Scen = num match
val scen: G1HScen = num match
{ case 1 => G1HScen1
case 2 => G1HScen2
case 3 => G1HScen3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package ostrat; package gOne; package hp1
import prid._, phex._, gPlay._

/** A scenario turn or state for Game One. Consists of just a turn number and a tile Grid. Each tile can contain a single player or can be empty. */
trait H1Scen extends HSysTurnScen
trait G1HScen extends HSysTurnScen
{ /** An optional player can occupy each tile. This is the only tile data in the game. */
def oPlayers: HCenOptLayer[Player]

/** Resolves turn. Takes a list [[RArr]] of commands consisting in this simple case of (Player, HStep) pairs. The command is passed in as a relative
* move. This is in accordance with the principle in more complex games that the entity issueing the command may not know its real location. */
def endTurn(orderList: HCenStepPairArr[Player]): H1Scen =
def endTurn(orderList: HCenStepPairArr[Player]): G1HScen =
{
val playersKey: Map[Player, HCen] = oPlayers.SomesKeyMap
val targets: HCenBuffLayer[HCenStep] = gridSys.newHCenArrOfBuff
Expand All @@ -25,14 +25,14 @@ trait H1Scen extends HSysTurnScen
val oPlayersNew: HCenOptLayer[Player] = oPlayers.clone
targets.foreach{ (hc2, buff) => buff.foreachLen1(stCenStep => if (oPlayers.tileNone(hc2)) oPlayersNew.unsafeMove(stCenStep.startHC , hc2)) }

H1Scen(turn + 1, gridSys, oPlayersNew)
G1HScen(turn + 1, gridSys, oPlayersNew)
}
}

/** Companion object for OneScen trait, contains factory apply method. */
object H1Scen
object G1HScen
{ /** Factory apply method for OneScen trait. */
def apply(turnIn: Int, gridIn: HGridSys, opIn: HCenOptLayer[Player]): H1Scen = new H1Scen
def apply(turnIn: Int, gridIn: HGridSys, opIn: HCenOptLayer[Player]): G1HScen = new G1HScen
{ override val turn = turnIn
override implicit val gridSys: HGridSys = gridIn
override def oPlayers: HCenOptLayer[Player] = opIn
Expand Down
2 changes: 1 addition & 1 deletion Tiling/TestSrc/phex/G1HScen1Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object G1HScen1Test extends TestSuite
{
val os1: G1HScen1.type = G1HScen1
val g1: HGridReg = os1.gridSys
val os2: H1Scen = os1.endTurn(HCenStepPairArr())
val os2: G1HScen = os1.endTurn(HCenStepPairArr())
val g2: HGridSys = os2.gridSys
// val os3 = os1.endTurn(HCenStepPairArr.reverse((PlayerA, HStepUL), (PlayerB, HStepUL), (PlayerC, HexLt)))
// val g3: HGridSys = os3.gridSys
Expand Down

0 comments on commit 6f8f069

Please sign in to comment.