![Page 1: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/1.jpg)
The HotCiv GUI
Instantiating the
MiniDraw Framework
![Page 2: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/2.jpg)
CS @ AU Henrik Bærbak Christensen 2
[Demo]
![Page 3: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/3.jpg)
The Framework iteration
Learning Objectives:– Frameworks:
• Configure/specialize MiniDraw to support HotCiv GUI• See MiniDraw as example of a framework• See a lot of patterns in action
– TDD and Stubs• You will develop the GUI the TDD way
– Keep focus & take small steps– No automated testing though...
• You will develop the GUI based only on stubs
– Integration testing• Last piece of the puzzle: Integrate into GUI SemiCiv
CS @ AU Henrik Bærbak Christensen 3
![Page 4: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/4.jpg)
The Exercise Sequence
Basically TDD iterations– 36.37: Observer on Game– 36.38: Create a new Drawing that responds to Game
state changes using the observer• Game → GUI integration [partially solved in CivDrawing!]
– 36.39: Create a Tool to move units• GUI → Game integration
– 36.40 – 36.44: Create tools to do all the other stuff• End of turn, change production, execute unit action, ...
i.e. Add features in fast focused iterations...
CS @ AU Henrik Bærbak Christensen 4
![Page 5: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/5.jpg)
2014 Additions
All boilerplate execution code is part of the provided zip
CS @ AU Henrik Bærbak Christensen 5
![Page 6: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/6.jpg)
Example
Test ‘EndOfTurnTool’
CS @ AU Henrik Bærbak Christensen 6
![Page 7: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/7.jpg)
Make the Tools Context Sensitive
Limit the tool’s applicability to the rectangles that actually define what is being clicked– GfxConstants.java
CS @ AU Henrik Bærbak Christensen 7
![Page 8: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/8.jpg)
Patterns for Integration
![Page 9: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/9.jpg)
CS @ AU Henrik Bærbak Christensen 9
The design
Proper design pattern protocols– Facade pattern [GUI inform Domain]– Observer pattern [Domain inform GUI]– only rely on interfaces
• I can develop the GUI using Stub implementations of the Domain’s Facade and Observer roles
– Facade = Interface Game
– Observer = Interface GameListener
– reuse MiniDraw’s graphical abilities• let someone else do the dirty job...
![Page 10: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/10.jpg)
CS @ AU Henrik Bærbak Christensen 10
GUI
Three layers
Your production code
hotciv.view: HotSpotsfor figures, tools, drawing and
Drawingview etc
MiniDraw
CivDrawing
![Page 11: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/11.jpg)
CS @ AU Henrik Bærbak Christensen 11
Exercise: Compositional?
How does thislook, using acompositionalapproach?
CivDrawing
![Page 12: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/12.jpg)
Present code…
CS @ AU Henrik Bærbak Christensen 12
![Page 13: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/13.jpg)
CS @ AU Henrik Bærbak Christensen 13
Central Protocol
The protocol between GUI and Domain:– GUI Domain
• Facade pattern (Game interface)• MVC + Adapter:
A tool translates mouse clicks to proper method– UnitMoveTool: drag translates into ‘moveUnit’
– EndOfTurnTool: click translates into ‘endOfTurn’…
– GUI Domain• Observer pattern (GameObserver interface)• Drawing must react upon events from domain
– worldChangedAt()
![Page 14: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/14.jpg)
CS @ AU Henrik Bærbak Christensen 14
Example: Moving Units
Moving units means invoking game’s “moveUnit”
The special dSoftArk provided code implements this
boardIterator
worldChangedAt
Civ
![Page 15: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/15.jpg)
CS @ AU Henrik Bærbak Christensen 15
Example: Moving Units
Facade Observer
GUI Domain GUI
worldChangedAt
![Page 16: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/16.jpg)
Brute-force Brute redrawing
Code View
CS @ AU Henrik Bærbak Christensen 16
![Page 17: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/17.jpg)
CS @ AU Henrik Bærbak Christensen 17
Testing without production code?
The GUI can be completely developed without any real domain production code– no Alpha, ..., Delta, nor SemiCiv
Why?– Because I program to an interface!– Game g = new MyParticularStubForThisIteration();– g.moveUnit( ... );– g.endOfTurn();
![Page 18: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/18.jpg)
Example: 36.38
Goal: Implement CivDrawing– Responsibility: – update graphics upon
game state changes
A testing tool to trigger game state changes
CS @ AU Henrik Bærbak Christensen 18
![Page 19: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/19.jpg)
Demo: ant update
CS @ AU Henrik Bærbak Christensen 19
![Page 20: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/20.jpg)
CS @ AU Henrik Bærbak Christensen 20
Test Stubs
Game implementation?– Complete façade, has not sub-
objects
– Units: only three
– moveUnit: only moves red archer…
Conclusion: simple code
But– Sufficient for our sprint goal: to
develop the CivDrawing that responds to unit moves, etc.
![Page 21: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/21.jpg)
CS @ AU Henrik Bærbak Christensen 21
Test Stubs
Requirement:– Enough to test all
GUI related behaviour
– Example• Must be able to
GUI’s behaviour for illegal moves – therefore some moves must be invalid!
![Page 22: The HotCiv GUI Instantiating the MiniDraw Framework](https://reader035.vdocument.in/reader035/viewer/2022081506/5697bfa31a28abf838c969fd/html5/thumbnails/22.jpg)
CS @ AU Henrik Bærbak Christensen 22
What about TDD
Can I develop the GUI by TDD?– Yes: Define a test first, like
• “MapView”: OneStepTest: draw the world…• “TestModelUpdate”: see game state changes reflected• ...• and then implement the proper MiniDraw role
implementations that makes this happen!
– No: I cannot make it automated as I have to visually inspect the result to verify behaviour
• but manual tests are better than no tests!!!• especially when I refactored the damn thing to use MiniDraw
instead of JHotDraw !!!