generated from robo-technical-group/javascript-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.ts
145 lines (131 loc) · 3.95 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Monopoly
* Built on
* MakeCode Arcade JavaScript Template v. 4.2.2
* Template last update: 11 Jun 2023 ak
*
* Immediate TODO List
* - [/] Refactor game loop to use an action queue.
* - [/] Handle card actions.
* - [ ] Handle go to any space.
* - [ ] Handle go to space and all pay.
* - [ ] Handle lottery.
* - [ ] Handle selective tax.
* - [ ] Handle roll backward.
* - [ ] Handle skip next turn.
* - [ ] Handle bus options.
* - [ ] Handle gift options.
* - [ ] Handle bankrupt player.
* - [ ] Auction property.
* - [ ] Multiplayer.
* - [ ] Single controller.
* - [ ] Buy/sell houses + mortgage property.
* - [ ] Trade mechanism.
* - [ ] BUG: Roll after card moving to utility is not paying owner.
* - [ ] Show property information as a sprite when purchasing, auctioning, or mortgaging.
* - [ ] Add subclass of action menu for starting a turn with appropriate default actions.
* - Trade
* - Build/Mortgage
* - [ ] Player select a space mechanism.
* - [ ] Allow for restraints (*e.g.*, select only a property, select from one side of the board).
* - [ ] Game select a random space mechanism.
* - [X] Add *Press Your Luck* sound effect. :-)
* - [ ] Perhaps add both "spin" and "bounce" selection mechanisms.
* - [ ] Production version cleanup.
* - [ ] Remove viewing of action queue.
* - [ ] Remove template board images from assets.
*/
/**
* Constants
*/
const HARDWARE: boolean = control.ramSize() < (1024 * 1024)
/**
* Global variables
*/
let g_state: GameState = new GameState()
/**
* Game loops
*/
game.onUpdate(function () {
switch (g_state.Mode) {
case GameMode.Attract:
Attract.update()
break
case GameMode.Settings:
GameSettings.update()
break
case GameMode.FirstRoll:
FirstRoll.update()
if (FirstRoll.ready) {
startGame()
}
break
case GameMode.Main:
update()
break
case GameMode.DiceTest:
DiceTests.update()
break
case GameMode.SpeedDieTest:
DiceTests.update()
break
case GameMode.BoardTest:
BoardTests.update()
break
case GameMode.BackgroundTest:
BackgroundTests.update()
break
} // switch (g_state.Mode)
}) // game.onUpdate()
/**
* Other functions
*/
function startGame(): void {
g_state.Mode = GameMode.NotReady
sprites.allOfKind(SpriteKind.Text).forEach((v: Sprite, index: number) => v.destroy())
g_state.Players.filter((p: Player, index: number) => index > 0)
.forEach((p: Player, index: number) => {
p.Dice.Orientation = DiceOrientation.Vertical
p.Dice.setStartLocation(Board.DICE_BEGIN_X, Board.DICE_BEGIN_Y)
p.Dice.setStopLocation(Board.DICE_END_X, Board.DICE_END_Y)
p.Dice.setLocationChange(5, 0)
p.DoublesRolled = false
p.TurnCount = 0
})
scene.setBackgroundColor(Color.Black)
scene.setBackgroundImage(assets.image`bg`)
g_state.start()
g_state.Mode = GameMode.Main
} // startGame()
function update(): void {
sprites.allOfKind(SpriteKind.BankBump).forEach((value: Sprite, index: number) => {
if (game.runtime() >= value.data['created'] + GameSettings.BANK_BUMP_VISIBLE) {
value.destroy()
}
})
g_state.update()
}
/**
* Main() a.k.a. game.onStart()
*/
game.stats = true
if (settings.exists(Tests.TESTING_KEY)) {
Tests.run()
} else {
Attract.start()
}
/*
if (settings.exists(Tests.TESTING_KEY)) {
Tests.run()
} else {
Attract.start()
}
Tests.startBoardSpaceMenu(0)
Tests.startJailTest(0)
Tests.startAutomatedGame(0)
g_state.testMode = false
Tests.startTestMenu()
FirstRollTests.start(2)
BackgroundTests.setup()
BoardTests.setup()
*/