Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Codebreaker.ViewModels/Codebreaker.ViewModels.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
<PackageReference Include="CNinnovation.Codebreaker.GamesClient" Version="3.6.0-beta.21" />
</ItemGroup>

Expand Down
22 changes: 0 additions & 22 deletions src/Codebreaker.ViewModels/Components/GameViewModel.cs

This file was deleted.

14 changes: 0 additions & 14 deletions src/Codebreaker.ViewModels/Components/MoveViewModel.cs

This file was deleted.

6 changes: 6 additions & 0 deletions src/Codebreaker.ViewModels/Messages/GameEndedMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Codebreaker.ViewModels.Messages;

public record class GameEndedMessage(Game Game)
{
public bool IsVictory => Game.IsVictory;
}
3 changes: 3 additions & 0 deletions src/Codebreaker.ViewModels/Messages/GameStartedMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Codebreaker.ViewModels.Messages;

public record class GameStartedMessage(Game Game);
9 changes: 9 additions & 0 deletions src/Codebreaker.ViewModels/Messages/MakeMoveMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Codebreaker.ViewModels.Messages;

public record class MakeMoveMessage(Move Move)
{
/// <summary>
/// Specifies if the move was already made.
/// </summary>
public bool IsSet => Move.KeyPegs is not null;
}
9 changes: 9 additions & 0 deletions src/Codebreaker.ViewModels/Models/Field.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Codebreaker.ViewModels.Models;

public partial class Field(string[] possibleColors) : ObservableObject
{
[ObservableProperty]
private string? _color;

public string[] PossibleColors { get; init; } = possibleColors;
}
27 changes: 13 additions & 14 deletions src/Codebreaker.ViewModels/Models/Game.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
namespace Codebreaker.ViewModels.Models;

public partial class Game(
Guid gameId,
Guid id,
GameType gameType,
string playerName,
DateTime startTime,
int numberCodes,
int maxMoves) : ObservableObject
int maxMoves,
IDictionary<string, string[]> fieldValues) : ObservableObject
{
/// <summary>
/// Gets the unique identifier of the game.
/// </summary>
public Guid GameId { get; private set; } = gameId;
public Guid Id { get; private set; } = id;

/// <summary>
/// Gets the type of the game. <see cref="GameType"/>
Expand All @@ -37,20 +38,15 @@ public partial class Game(
/// Gets the end time of the game or null if it did not end yet. This value is set from a game guess anylzer after the game was ended.
/// </summary>
[ObservableProperty]
private string? _endTime;
[NotifyPropertyChangedFor(nameof(IsFinished))]
private DateTime? _endTime;

/// <summary>
/// Gets the duration of the game or null if it did not end yet
/// </summary>
[ObservableProperty]
private TimeSpan? _duration;

/// <summary>
/// Gets the last move number. This number is set from an game move analyer after the move was set.
/// </summary>
[ObservableProperty]
private int _lastMoveNumber;

/// <summary>
/// Gets the number of codes the player needs to fill.
/// </summary>
Expand All @@ -61,6 +57,11 @@ public partial class Game(
/// </summary>
public int MaxMoves { get; private set; } = maxMoves;

/// <summary>
/// Gets a boolean value indicating if the game is finished.
/// </summary>
public bool IsFinished => EndTime is not null;

/// <summary>
/// Did the player win the game?
/// </summary>
Expand All @@ -70,12 +71,10 @@ public partial class Game(
/// <summary>
/// A list of possible field values the user has to chose from
/// </summary>
public required IDictionary<string, string[]> FieldValues { get; init; }
public IDictionary<string, string[]> FieldValues { get; init; } = fieldValues;

/// <summary>
/// A list of moves the player made
/// </summary>
public ICollection<Move> Moves { get; } = new ObservableCollection<Move>();

public override string ToString() => $"{GameId}:{GameType} - {StartTime}";
public ObservableCollection<Move> Moves { get; } = [];
}
22 changes: 7 additions & 15 deletions src/Codebreaker.ViewModels/Models/Move.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
namespace Codebreaker.ViewModels.Models;
public partial class Move(Guid moveId, int moveNumber) : ObservableObject
{
public Guid MoveId { get; private set; } = moveId;

/// <summary>
/// The move number for this move within the associated game.
/// </summary>
[ObservableProperty]
private int _moveNumber = moveNumber;

public class Move(ICollection<string> guessPegs, ICollection<string>? keyPegs = null)
{
/// <summary>
/// The guess pegs from the user for this move.
/// </summary>
public ObservableCollection<string> GuessPegs { get; } = [];
public ICollection<string> GuessPegs { get; } = guessPegs;

/// <summary>
/// The result from the analyer for this move based on the associated game that contains the move.
/// </summary>
public ObservableCollection<string> KeyPegs { get; } = [];

public override string ToString() => $"{MoveNumber}. " +
$"{string.Join('#', GuessPegs)} : " +
$"{string.Join('#', KeyPegs)}";
/// <remarks>
/// Null if the move was not analyzed yet.
/// </remarks>
public ICollection<string>? KeyPegs { get; } = keyPegs;
}
Loading