@@ -31,12 +31,10 @@ public class BeamSimulator : IActor
31
31
32
32
private bool _hitUnplaced ;
33
33
34
- private int _beamStrength ;
35
-
36
34
private long _frame ;
37
35
38
- public int BeamStrength => _beamStrength ;
39
-
36
+ public int BeamStrength { get ; private set ; }
37
+
40
38
public State State { private get ; set ; }
41
39
42
40
public bool IsComplete { get ; private set ; }
@@ -87,7 +85,7 @@ private void SimulateBeams(SpriteBatch spriteBatch)
87
85
88
86
_hitMirrors . Clear ( ) ;
89
87
90
- _beamStrength = 0 ;
88
+ BeamStrength = 0 ;
91
89
92
90
_hitUnplaced = false ;
93
91
@@ -141,9 +139,9 @@ private void SimulateBeam(SpriteBatch spriteBatch, Start start, int beamSteps, i
141
139
var oldDx = dX ;
142
140
var oldDy = dY ;
143
141
144
- while ( x >= 0 && x < Constants . MapSize * BeamFactor && y >= 0 && y < Constants . MapSize * BeamFactor )
142
+ while ( x is >= 0 and < Constants . MapSize * BeamFactor && y is >= 0 and < Constants . MapSize * BeamFactor )
145
143
{
146
- _beamStrength ++ ;
144
+ BeamStrength ++ ;
147
145
148
146
beamSteps ++ ;
149
147
@@ -168,18 +166,12 @@ private void SimulateBeam(SpriteBatch spriteBatch, Start start, int beamSteps, i
168
166
169
167
if ( result . Mirror != '\0 ' )
170
168
{
171
- switch ( result . Mirror )
169
+ ( dX , dY ) = result . Mirror switch
172
170
{
173
- case '\\ ' :
174
- ( dX , dY ) = ( dY , dX ) ;
175
-
176
- break ;
177
-
178
- case '/' :
179
- ( dX , dY ) = ( - dY , - dX ) ;
180
-
181
- break ;
182
- }
171
+ '\\ ' => ( dY , dX ) ,
172
+ '/' => ( - dY , - dX ) ,
173
+ _ => ( dX , dY )
174
+ } ;
183
175
}
184
176
}
185
177
@@ -226,32 +218,30 @@ private void SimulateBeam(SpriteBatch spriteBatch, Start start, int beamSteps, i
226
218
}
227
219
}
228
220
229
- if ( mirror == '|' || mirror == '-' )
221
+ if ( mirror is '|' or '-' )
230
222
{
231
- if ( mirror == '|' && dX != 0 )
223
+ switch ( mirror )
232
224
{
233
- _splitters . Enqueue ( ( x / BeamFactor , y / BeamFactor , Direction . North , beamSteps , colorIndex , colorDirection ) ) ;
234
- _splitters . Enqueue ( ( x / BeamFactor , y / BeamFactor , Direction . South , beamSteps , colorIndex , colorDirection ) ) ;
235
-
236
- spriteBatch . Draw ( _beams ,
237
- new Vector2 ( x * BeamSize , Constants . TopOffset + y * BeamSize ) ,
238
- new Rectangle ( dX == 1 ? 3 * BeamSize : 2 * BeamSize , 0 , 7 , 7 ) , _palette [ colorIndex ] ,
239
- 0 , Vector2 . Zero , Vector2 . One , SpriteEffects . None , .2f ) ;
240
-
241
- return ( mirror , true ) ;
242
- }
243
-
244
- if ( mirror == '-' && dY != 0 )
245
- {
246
- _splitters . Enqueue ( ( x / BeamFactor , y / BeamFactor , Direction . East , beamSteps , colorIndex , colorDirection ) ) ;
247
- _splitters . Enqueue ( ( x / BeamFactor , y / BeamFactor , Direction . West , beamSteps , colorIndex , colorDirection ) ) ;
248
-
249
- spriteBatch . Draw ( _beams ,
250
- new Vector2 ( x * BeamSize , Constants . TopOffset + y * BeamSize ) ,
251
- new Rectangle ( dY == 1 ? 2 * BeamSize : 3 * BeamSize , 0 , 7 , 7 ) , _palette [ colorIndex ] ,
252
- 0 , Vector2 . Zero , Vector2 . One , SpriteEffects . None , .2f ) ;
253
-
254
- return ( mirror , true ) ;
225
+ case '|' when dX != 0 :
226
+ _splitters . Enqueue ( ( x / BeamFactor , y / BeamFactor , Direction . North , beamSteps , colorIndex , colorDirection ) ) ;
227
+ _splitters . Enqueue ( ( x / BeamFactor , y / BeamFactor , Direction . South , beamSteps , colorIndex , colorDirection ) ) ;
228
+
229
+ spriteBatch . Draw ( _beams ,
230
+ new Vector2 ( x * BeamSize , Constants . TopOffset + y * BeamSize ) ,
231
+ new Rectangle ( dX == 1 ? 3 * BeamSize : 2 * BeamSize , 0 , 7 , 7 ) , _palette [ colorIndex ] ,
232
+ 0 , Vector2 . Zero , Vector2 . One , SpriteEffects . None , .2f ) ;
233
+
234
+ return ( mirror , true ) ;
235
+ case '-' when dY != 0 :
236
+ _splitters . Enqueue ( ( x / BeamFactor , y / BeamFactor , Direction . East , beamSteps , colorIndex , colorDirection ) ) ;
237
+ _splitters . Enqueue ( ( x / BeamFactor , y / BeamFactor , Direction . West , beamSteps , colorIndex , colorDirection ) ) ;
238
+
239
+ spriteBatch . Draw ( _beams ,
240
+ new Vector2 ( x * BeamSize , Constants . TopOffset + y * BeamSize ) ,
241
+ new Rectangle ( dY == 1 ? 2 * BeamSize : 3 * BeamSize , 0 , 7 , 7 ) , _palette [ colorIndex ] ,
242
+ 0 , Vector2 . Zero , Vector2 . One , SpriteEffects . None , .2f ) ;
243
+
244
+ return ( mirror , true ) ;
255
245
}
256
246
}
257
247
@@ -317,30 +307,17 @@ private void DrawBeam(SpriteBatch spriteBatch, int x, int y, int dX, int dY, int
317
307
}
318
308
else
319
309
{
320
- switch ( oldDx )
310
+ beam = oldDx switch
321
311
{
322
- case 1 :
323
- beam = dY == 1 ? 3 : 5 ;
324
- break ;
325
-
326
- case - 1 :
327
- beam = dY == 1 ? 4 : 2 ;
328
- break ;
329
-
330
- default :
331
- switch ( oldDy )
332
- {
333
- case 1 :
334
- beam = dX == 1 ? 2 : 5 ;
335
- break ;
336
-
337
- case - 1 :
338
- beam = dX == 1 ? 4 : 3 ;
339
- break ;
340
- }
341
-
342
- break ;
343
- }
312
+ 1 => dY == 1 ? 3 : 5 ,
313
+ - 1 => dY == 1 ? 4 : 2 ,
314
+ _ => oldDy switch
315
+ {
316
+ 1 => dX == 1 ? 2 : 5 ,
317
+ - 1 => dX == 1 ? 4 : 3 ,
318
+ _ => beam
319
+ }
320
+ } ;
344
321
}
345
322
346
323
spriteBatch . Draw ( _beams ,
0 commit comments