Skip to content

Commit

Permalink
#206 Modifying Game 2 to fit with first version of DiceLess.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich2 committed Feb 24, 2023
1 parent 026f57f commit 3272ccd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
3 changes: 2 additions & 1 deletion Tiling/ExsSrc/gTwo/h2p/G2HExamples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
61 changes: 35 additions & 26 deletions Tiling/ExsSrc/gTwo/h2p/G2HGui.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3272ccd

Please sign in to comment.