Adding Properties to a Process Type
What You Will Learn
- To inherit a process type and add properties
- To use dashed gates.
The Process Type DoubleGame
Even with a "jackpot" feature, winning "a lot" with the DemonGame takes some time... Suppose now that you would like to add a function that doubles the "stake" of the game, whenever you want, so that you have the possibility to win more.
A way to do this is to:
- Create a process type DoubleGame, that inherits the properties of the process type Game, with the following additions:
- Declaration of a variable Stake of type integer.
- Initialization of Stake to 1, by redefining the start transition.
- Reception of a signal DoubleStake that doubles the value of Stake.
- Redefinition of the transitions Winning and Losing to add/deduct the current Stake from the score Count.
- The resulting graph is depicted below. Create it in the same way as you have learned from the previous exercises, and save it on the file new_doublegame.spt. Then close the diagram in the SDL Editor (Close Diagram from the File menu).
- This diagram is also available as the file double.spt, if you wish to make a copy (or use it as is) instead of drawing the diagram.
Note:
The diagram contains a dashed gate symbol G5, where the signal DoubleStake is conveyed. You use dashed gates to refer to gates that are already defined in the supertype (the type that you inherit from), to distinguish from situations where you have to add a new gate.
To dash a gate:
- Make sure the gate is selected.
- Select the Dash command from the Edit menu of the SDL Editor (this command toggles between Dash/Undash).
|
Figure 161 : The process type DoubleGame
|
- Add a process type reference symbol DoubleGame, and a process instantiation symbol with the text "DoubleGame (0,1):DoubleGame" to the block diagram GameBlock; see below.
- This version of the diagram is also available as the file gameblock3.sbk. To use it instead of drawing the diagram, close the GameBlock diagram in the SDL Editor, and connect the GameBlock diagram in the Organizer to the new file.
- Also add the signals NewDoubleGame and DoubleStake to the signal list on the signal route R1, and DoubleStake to the signal list to the process -DoubleGame; see below.
Figure 162 : The resulting block GameBlock
|
- Add the new signals NewDoubleGame and DoubleStake at the system level (in the DemonGame diagram), both in the signal declaration, and in the signal list on the channel C1.
- You have to make these changes yourself.
- Extend the process Main with the code to receive the signal -DoubleStake, and the code to receive the signal NewDoubleGame and create an instance of the game DoubleGame; see below.
- This version of the Main diagram is also available as the file main3.spr, if you wish use it instead of editing the diagram. In the Organizer, connect the diagram to this file.
Figure 163 : New code in process Main
|
- If needed in the Organizer, connect the process type diagram DoubleGame to the file new_doublegame.spt that you created earlier.
Simulating the DoubleGame
You may simulate the DoubleGame in a similar way as the -JackpotGame (the DoubleGame is started with the signal -NewDoubleGame).
- To play the game in a realistic way, also add a button Double to the Simulator UI, with the text "Double" and the command
Output-to DoubleStake Main; go
- Try for instance the following tactic: whenever your score is negative, double the stake.