CodebreakerApp / Codebreaker.Xaml

MIT License
0 stars 1 forks source link

Added CancelGameCommand to VM #181

Closed szv closed 1 month ago

szv commented 1 month ago

Pull Request Summary

This pull request includes several significant changes to the game functionality in the Codebreaker project. The main focus of these changes is to introduce the ability to cancel a game and handle the associated scenarios.

Package Update

The CNinnovation.Codebreaker.GamesClient package in Codebreaker.ViewModels.csproj was updated from 3.6.0-beta.21 to 3.6.0-beta.24. This update is necessary to keep the project up-to-date with the latest features and improvements of the package.

New Class and Method

A new class GameCancelledMessage was added to GameCancelledMessage.cs. This class is used to send a message when a game is cancelled.

In GamePageViewModel.cs, a new method CanCancelGame was added. This method checks if a game can be cancelled by verifying that the game is not null and not finished. This is a crucial check to prevent any unwanted behavior or errors.

Game Cancellation

A new RelayCommand attribute was added to a new method CancelGameAsync. This method is responsible for cancelling the game if it is not null. If the game is null, it throws an InvalidOperationException, ensuring that the game exists before attempting to cancel it.

The CancelGameAsync method also handles different scenarios that might occur during the cancellation process. If the game cannot be cancelled due to a BadRequest HTTP status code, it shows an info bar message "Could not cancel the game". If there are networking issues, it shows an info bar message "Networking issues". These messages provide feedback to the user about the status of the cancellation process.

After successfully cancelling the game, the method sets the game to null and sends a GameCancelledMessage. This design decision ensures that the game state is properly reset after cancellation and that other parts of the application are notified about the cancellation.