From 3272ccd8bafda1ef966fa18ddd196e3565729e76 Mon Sep 17 00:00:00 2001 From: Rich2 Date: Fri, 24 Feb 2023 14:47:14 +0000 Subject: [PATCH] #206 Modifying Game 2 to fit with first version of DiceLess. --- Tiling/ExsSrc/gTwo/h2p/G2HExamples.scala | 3 +- Tiling/ExsSrc/gTwo/h2p/G2HGui.scala | 61 ++++++++++++++---------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/Tiling/ExsSrc/gTwo/h2p/G2HExamples.scala b/Tiling/ExsSrc/gTwo/h2p/G2HExamples.scala index 1b9ea540b..680b82291 100644 --- a/Tiling/ExsSrc/gTwo/h2p/G2HExamples.scala +++ b/Tiling/ExsSrc/gTwo/h2p/G2HExamples.scala @@ -7,10 +7,11 @@ object G2HScen1 extends G2HScen { override def turn: Int = 0 implicit val gridSys: HGridReg = GSys.g1 val oPlayers: HCenOptLayer[Player] = gridSys.newHCenOptLayer + oPlayers.unsafeSetSome(6, 2, PlayerA) oPlayers.unsafeSetSome(4, 4, PlayerA) oPlayers.unsafeSetSomes((4, 8, PlayerB), (6, 10, PlayerC)) - override def playerOrders: HDirnPathPairArr[Player] = HDirnPathPairArr[Player](PlayerA.hPath(4, 4, HexDR, HexLt), + override def playerOrders: HDirnPathPairArr[Player] = HDirnPathPairArr[Player](PlayerA.hPath(6, 2, HexDR, HexUL), PlayerA.hPath(4, 4, HexDR, HexLt), PlayerB.hPath(4, 8, HexDL, HexRt), PlayerC.hPath(6, 10, HexLt, HexDR, HexDL)) } diff --git a/Tiling/ExsSrc/gTwo/h2p/G2HGui.scala b/Tiling/ExsSrc/gTwo/h2p/G2HGui.scala index e56441e89..b7861e7e0 100644 --- a/Tiling/ExsSrc/gTwo/h2p/G2HGui.scala +++ b/Tiling/ExsSrc/gTwo/h2p/G2HGui.scala @@ -3,52 +3,61 @@ package ostrat; package gTwo; package h2p import pgui._, geom._, prid._, phex._, gPlay._ /** Graphical user interface for example game 3. A hex based game like game 1, that introduces multi turn directives. */ -case class G2HGui(canv: CanvasPlatform, scenStart: G2HScen, viewIn: HGView) extends HGridSysGui("Game Three Gui") -{ +case class G2HGui(canv: CanvasPlatform, scenStart: G2HScen, viewIn: HGView) extends HGridSysGui("Game Two Hex Gui") { statusText = "Left click on Player to select. Right click on adjacent Hex to set move." var scen = scenStart var history: RArr[G2HScen] = RArr(scen) + implicit def gridSys: HGridSys = scen.gridSys + def players: HCenOptLayer[Player] = scen.oPlayers + implicit val proj: HSysProjection = gridSys.projection(mainPanel) proj.setView(viewIn) /** 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. */ + * moves. This data is state for the Gui. */ var moves: HDirnPathPairArr[Player] = scen.playerOrders val urect = Rect(1.4, 1) - def units: GraphicElems = players.projSomeHcPtMap{ (p, hc, pt) => - val str = ptScale.scaledStr(170, p.toString + "\n" + hc.strComma, 150, p.charStr + "\n" + hc.strComma, 60, p.charStr) - urect.scale(80).slate(pt).fillDrawTextActive(p.colour, HPlayer(hc, p), str, 24, 2.0) - } + def frame: GraphicElems = + { + def units: GraphicElems = players.projSomeHcPtMap { (p, hc, pt) => + val str = ptScale.scaledStr(170, p.toString + "\n" + hc.strComma, 150, p.charStr + "\n" + hc.strComma, 60, p.charStr) + urect.scale(80).slate(pt).fillDrawTextActive(p.colour, HPlayer(hc, p), str, 24, 2.0) + } - /** [[TextGraphic]]s to display the [[HCen]] coordinate in the tiles that have no unit counters. */ - def hexStrs: RArr[TextGraphic] = players.projNoneHcPtMap{ (hc, pt) => TextGraphic(hc.strComma, 20, pt) } + /** [[TextGraphic]]s to display the [[HCen]] coordinate in the tiles that have no unit counters. */ + def hexStrs: RArr[TextGraphic] = players.projNoneHcPtMap { (hc, pt) => TextGraphic(hc.strComma, 20, pt) } - /** This makes the tiles active. They respond to mouse clicks. It does not paint or draw the tiles. */ - def actives: RArr[PolygonActive] = proj.tileActives + /** This makes the tiles active. They respond to mouse clicks. It does not paint or draw the tiles. */ + def actives: RArr[PolygonActive] = proj.tileActives - /** Draws the tiles sides (or edges). */ - def sidesDraw: LinesDraw = proj.sidesDraw() + /** Draws the tiles sides (or edges). */ + def sidesDraw: LinesDraw = proj.sidesDraw() - /** This is the graphical display of the planned move orders. */ - def moveGraphics: RArr[LineSegDraw] = players.someHCFlatMap { (p, hc) => - val lps1 = moves.flatMapOnA1{path => path.segHCs } - val lps2 = proj.transLineSegPairs(lps1) - lps2.pairMap((ls, p) => ls.draw(p.colour)) - } + /** This is the graphical display of the planned move orders. */ + def moveGraphics: RArr[LineSegDraw] = players.someHCFlatMap { (p, hc) => + val lps1 = moves.flatMapOnA1 { path => path.segHCs } + val lps2 = proj.transLineSegPairs(lps1) + lps2.pairMap((ls, p) => ls.draw(p.colour)) + } + + def moves2: RPairArr[LineSegHCArr, Player] = moves.mapOnA1(_.segHCs) + + def moves3: RPairArr[LineSegHCArr, Player] = moves2.mapOnA1(_.init) - def moves2: RPairArr[LineSegHCArr, Player] = moves.mapOnA1(_.segHCs) + def moves3a: LineSegHCPairArr[Player] = moves3.flatMapOnA1(lsa => lsa) - def moves3: RPairArr[LineSegHCArr, Player] = moves2.mapOnA1(_.init) - def moves3a: LineSegHCPairArr[Player] = moves3.flatMapOnA1(lsa => lsa) - def moveGraphics3 = proj.transLineSegPairs(moves3a).pairMap((ls, p) => ls.draw(p.colour)) + def moveGraphics3 = proj.transLineSegPairs(moves3a).pairMap((ls, p) => ls.draw(p.colour)) - def moves4: LineSegHCPairArr[Player] = moves2.optMapOnA1(_.lastOpt) - def moveGraphics4 = proj.transLineSegPairs(moves4).pairFlatMap((ls, p) => ls.draw(p.colour).arrow) + def moves4: LineSegHCPairArr[Player] = moves2.optMapOnA1(_.lastOpt) + def moveGraphics4 = proj.transLineSegPairs(moves4).pairFlatMap((ls, p) => ls.draw(p.colour).arrow) + + actives ++ units ++ hexStrs +% sidesDraw ++ moveGraphics3 ++ moveGraphics4 +} /** Creates the turn button and the action to commit on mouse click. */ def bTurn: PolygonCompound = clickButton("Turn " + (scen.turn + 1).toString){_ => scen = scen.endTurn(moves) @@ -77,7 +86,7 @@ case class G2HGui(canv: CanvasPlatform, scenStart: G2HScen, viewIn: HGView) exte } thisTop() - def frame: GraphicElems = actives ++ units ++ hexStrs +% sidesDraw ++ moveGraphics3 ++ moveGraphics4 + proj.getFrame = () => frame proj.setStatusText = { str => statusText = str