|
1 | | -package model; |
2 | | - |
3 | | -import SystemLib.Miscellaneous.EdgeRising; |
4 | | -import SystemLib.CounterTimer.Timer; |
5 | | -import SystemLib.CounterTimer.StopWatch; |
6 | | - |
7 | | -class GameController { |
8 | | - |
9 | | - Timer timer; |
10 | | - StopWatch stopWatch; |
11 | | - EdgeRising edgeDetect; |
12 | | - characteristic real gameTime = 120.0; |
13 | | - characteristic real scoringZone = 0.2; |
14 | | - @set |
15 | | - private real ballPosition = 0.0; |
16 | | - @set |
17 | | - private boolean startGame = false; |
18 | | - @get |
19 | | - private real score = 0.0; |
20 | | - |
21 | | - @no_side_effect |
22 | | - boolean isInScoringZone() { |
23 | | - return(abs(ballPosition - 0.5) <= (scoringZone / 2.0)); |
24 | | - } |
25 | | - |
26 | | - boolean isStartGameButtonPushed() { |
27 | | - edgeDetect.compute(startGame); |
28 | | - return edgeDetect.value(); |
29 | | - } |
30 | | - |
31 | | - @no_side_effect |
32 | | - public GameControllerStatemachineStates gameState() { |
33 | | - return EvaluatorStatemachine.getState(); |
34 | | - } |
35 | | - |
36 | | - @no_side_effect |
37 | | - public real getTime() { |
38 | | - return timer.getTime() / gameTime; |
39 | | - } |
40 | | - |
41 | | - boolean isCanceled() { |
42 | | - if ((gameTime - timer.getTime()) <= 2.0) { |
43 | | - return false; |
44 | | - } |
45 | | - edgeDetect.compute(startGame); |
46 | | - return edgeDetect.value(); |
47 | | - } |
48 | | - |
49 | | - @generated("statemachine", "000000") |
50 | | - public void periodicTrigger() triggers EvaluatorStatemachine; |
51 | | - |
52 | | - @generated("statemachine", "bdee0ede") |
53 | | - statemachine EvaluatorStatemachine default trigger periodicTrigger using GameControllerStatemachineStates { |
54 | | - start Idle; |
55 | | - |
56 | | - state Idle { |
57 | | - transition isStartGameButtonPushed() to GameRunning; |
58 | | - } |
59 | | - |
60 | | - state GameRunning { |
61 | | - entry { |
62 | | - timer.begin(gameTime); |
63 | | - stopWatch.reset(); |
64 | | - score = 0.0; |
65 | | - } |
66 | | - static { |
67 | | - timer.compute(); |
68 | | - } |
69 | | - transition timer.isElapsed() to Idle; |
70 | | - transition isCanceled() to Idle; |
71 | | - start NotInScoringZone; |
72 | | - |
73 | | - state IncreaseScore { |
74 | | - static { |
75 | | - stopWatch.compute(); |
76 | | - score = stopWatch.value(); |
77 | | - } |
78 | | - transition !isInScoringZone() to NotInScoringZone; |
79 | | - } |
80 | | - |
81 | | - state NotInScoringZone { |
82 | | - transition isInScoringZone() to IncreaseScore; |
83 | | - } |
84 | | - } |
85 | | - } |
86 | | -} |
87 | | - |
88 | | -@generated("statemachine", "000000") |
89 | | -type GameControllerStatemachineStates is enum { |
90 | | - Idle, |
91 | | - GameRunning, |
92 | | - NotInScoringZone, |
93 | | - IncreaseScore |
94 | | -}; |
| 1 | +package model; |
| 2 | + |
| 3 | +import SystemLib.Miscellaneous.EdgeRising; |
| 4 | +import SystemLib.CounterTimer.Timer; |
| 5 | +import SystemLib.CounterTimer.StopWatch; |
| 6 | + |
| 7 | +class GameController { |
| 8 | + |
| 9 | + Timer timer; |
| 10 | + StopWatch stopWatch; |
| 11 | + EdgeRising edgeDetect; |
| 12 | + characteristic real gameTime = 120.0; |
| 13 | + characteristic real scoringZone = 0.2; |
| 14 | + @set |
| 15 | + private real ballPosition = 0.0; |
| 16 | + @set |
| 17 | + private boolean startGame = false; |
| 18 | + @get |
| 19 | + private real score = 0.0; |
| 20 | + |
| 21 | + @no_side_effect |
| 22 | + boolean isInScoringZone() { |
| 23 | + return(abs(ballPosition - 0.5) <= (scoringZone / 2.0)); |
| 24 | + } |
| 25 | + |
| 26 | + boolean isStartGameButtonPushed() { |
| 27 | + edgeDetect.compute(startGame); |
| 28 | + return edgeDetect.value(); |
| 29 | + } |
| 30 | + |
| 31 | + @no_side_effect |
| 32 | + public GameControllerStatemachineStates gameState() { |
| 33 | + return EvaluatorStatemachine.getState(); |
| 34 | + } |
| 35 | + |
| 36 | + @no_side_effect |
| 37 | + public real getTime() { |
| 38 | + return timer.getTime() / gameTime; |
| 39 | + } |
| 40 | + |
| 41 | + boolean isCanceled() { |
| 42 | + if ((gameTime - timer.getTime()) <= 2.0) { |
| 43 | + return false; |
| 44 | + } |
| 45 | + edgeDetect.compute(startGame); |
| 46 | + return edgeDetect.value(); |
| 47 | + } |
| 48 | + |
| 49 | + @generated("statemachine", "000000") |
| 50 | + public void periodicTrigger() triggers EvaluatorStatemachine; |
| 51 | + |
| 52 | + @generated("statemachine", "bdee0ede") |
| 53 | + statemachine EvaluatorStatemachine default trigger periodicTrigger using GameControllerStatemachineStates { |
| 54 | + start Idle; |
| 55 | + |
| 56 | + state Idle { |
| 57 | + transition isStartGameButtonPushed() to GameRunning; |
| 58 | + } |
| 59 | + |
| 60 | + state GameRunning { |
| 61 | + entry { |
| 62 | + timer.begin(gameTime); |
| 63 | + stopWatch.reset(); |
| 64 | + score = 0.0; |
| 65 | + } |
| 66 | + static { |
| 67 | + timer.compute(); |
| 68 | + } |
| 69 | + transition timer.isElapsed() to Idle; |
| 70 | + transition isCanceled() to Idle; |
| 71 | + start NotInScoringZone; |
| 72 | + |
| 73 | + state IncreaseScore { |
| 74 | + static { |
| 75 | + stopWatch.compute(); |
| 76 | + score = stopWatch.value(); |
| 77 | + } |
| 78 | + transition !isInScoringZone() to NotInScoringZone; |
| 79 | + } |
| 80 | + |
| 81 | + state NotInScoringZone { |
| 82 | + transition isInScoringZone() to IncreaseScore; |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +@generated("statemachine", "000000") |
| 89 | +type GameControllerStatemachineStates is enum { |
| 90 | + Idle, |
| 91 | + GameRunning, |
| 92 | + NotInScoringZone, |
| 93 | + IncreaseScore |
| 94 | +}; |
0 commit comments