Skip to content

Added CancelGameCommand to VM#181

Merged
christiannagel merged 3 commits intomainfrom
180-add-ability-to-cancel-game-to-vm
Apr 10, 2024
Merged

Added CancelGameCommand to VM#181
christiannagel merged 3 commits intomainfrom
180-add-ability-to-cancel-game-to-vm

Conversation

@szv
Copy link
Collaborator

@szv szv commented Apr 4, 2024

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.

@szv szv linked an issue Apr 4, 2024 that may be closed by this pull request
@szv szv requested a review from christiannagel April 4, 2024 03:35
Copy link
Contributor

@christiannagel christiannagel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see csproj

@szv szv requested a review from christiannagel April 5, 2024 20:45
@christiannagel christiannagel merged commit 088fb90 into main Apr 10, 2024
@szv szv deleted the 180-add-ability-to-cancel-game-to-vm branch April 10, 2024 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to cancel game to VM

2 participants