@@ -59,7 +59,7 @@ private async Task StartGameAsync(CancellationToken cancellationToken)
5959 SelectedFields = Enumerable . Range ( 0 , Game . NumberCodes )
6060 . Select ( i =>
6161 {
62- var field = new Field ( Game . FieldValues [ "colors" ] ) ; // TODO: Hardcoding "colors" is not suitable for all game types
62+ var field = new Field ( ) { PossibleColors = Game . FieldValues [ "colors" ] , PossibleShapes = Game . FieldValues . GetOrDefault ( "shapes" ) } ;
6363 field . PropertyChanged += ( object ? sender , PropertyChangedEventArgs args ) => MakeMoveCommand . NotifyCanExecuteChanged ( ) ;
6464 return field ;
6565 } )
@@ -74,21 +74,18 @@ private async Task MakeMoveAsync(CancellationToken cancellationToken)
7474 if ( Game is null )
7575 throw new InvalidOperationException ( "A game needs to be started before making a move" ) ;
7676
77- var selectedColors = SelectedFields
78- . Select ( x => x . Color )
79- . ToArray ( ) ;
80-
81- if ( selectedColors . Any ( color => color is null ) )
77+ if ( SelectedFields . Any ( field => ! field . IsSet ) )
8278 throw new InvalidOperationException ( "All colors need to be selected before making a move" ) ;
8379
84- WeakReferenceMessenger . Default . Send ( new MakeMoveMessage ( new ( selectedColors ! ) ) ) ;
80+ WeakReferenceMessenger . Default . Send ( new MakeMoveMessage ( new ( SelectedFields ) ) ) ;
8581
82+ var serializedFields = SelectedFields . Select ( field => field . Serialize ( ) ) . ToArray ( ) ;
8683 IsLoading = true ;
8784 try
8885 {
89- var response = await gamesClient . SetMoveAsync ( Game . Id , Game . PlayerName , GameType . Game6x4 , Game . Moves . Count + 1 , selectedColors ! ) ;
86+ var response = await gamesClient . SetMoveAsync ( Game . Id , Game . PlayerName , GameType . Game6x4 , Game . Moves . Count + 1 , serializedFields ) ;
9087
91- var newMove = new Move ( selectedColors ! , response . Results ) ;
88+ var newMove = new Move ( SelectedFields , response . Results ) ;
9289 Game . Moves . Add ( newMove ) ;
9390 WeakReferenceMessenger . Default . Send ( new MakeMoveMessage ( newMove ) ) ;
9491
0 commit comments