Skip to content

Commit

Permalink
Merge pull request #7 from Lyra1337/feature/card-shuffling
Browse files Browse the repository at this point in the history
added card shuffling sound
  • Loading branch information
TimGeDev authored Nov 27, 2024
2 parents 3e537b8 + 5defb5a commit 93e65d6
Show file tree
Hide file tree
Showing 6 changed files with 371 additions and 372 deletions.
243 changes: 122 additions & 121 deletions PlanningPoker.Web/Game/GameInstance.cs
Original file line number Diff line number Diff line change
@@ -1,121 +1,122 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;

namespace PlanningPoker.Web.Game
{
public class GameInstance
{
public event EventHandler Changed;
public event EventHandler<PlaySoundEventArgs> PlaySound;

private static readonly ConcurrentDictionary<string, GameInstance> instances = new ConcurrentDictionary<string, GameInstance>();

public static List<string[]> Decks { get; } = new List<string[]>()
{
new []{ "❓", "0", "0.5", "1", "2", "3", "5", "8", "13", "20", "40", "100", "☕" }
};

public string[] CardDeck => GameInstance.Decks.Single();

public string Hash { get; private set; }

public List<Player> Players { get; } = new List<Player>();

public List<Round> Rounds { get; } = new List<Round>() { new Round() };

public Round CurrentRound => this.Rounds.LastOrDefault();

public int RoundNumber => this.Rounds.Count;

public void NewRound()
{
this.Rounds.Add(new Round());
this.RaiseChanged();
}

internal void Join(Player player)
{
if (this.Players.Any(x => x.Secret == player.Secret) == false)
{
this.Players.Add(player);
}

this.RaiseChanged();
}

private void RaiseChanged()
{
this.Changed?.Invoke(this, EventArgs.Empty);
}

internal static GameInstance Find(string hash)
{
if (GameInstance.instances.TryGetValue(hash, out var instance) == false)
{
instance = new GameInstance()
{
Hash = hash
};

GameInstance.instances[hash] = instance;
}

return instance;
}

internal void ChangePlayersName(Player player, string playerName)
{
player.Name = playerName;
this.RaiseChanged();
}

internal void Vote(Player player, string card)
{
if (this.Players.Contains(player) == false)
{
this.Players.Add(player);
}

this.CurrentRound.Cards[player] = card;
this.RaiseChanged();
this.RaisePlaySound("place-card");
}

internal void StartNewRound()
{
this.Rounds.Add(new Round());
this.RaiseChanged();
}

internal void RevealCards()
{
this.CurrentRound.IsRevealed = true;
this.RaiseChanged();
this.RaisePlaySound("turn-cards");
}

internal void RemovePlayer(Player player)
{
this.Players.Remove(player);

if (this.Players.Any() == false)
{
GameInstance.instances.Remove(this.Hash, out var _);
}

this.RaiseChanged();
}

internal void PlayBingSound()
{
this.RaisePlaySound("bing-sound");
}

private void RaisePlaySound(string sound)
{
this.PlaySound?.Invoke(this, new PlaySoundEventArgs(sound));
}
}
}
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;

namespace PlanningPoker.Web.Game
{
public class GameInstance
{
public event EventHandler Changed;
public event EventHandler<PlaySoundEventArgs> PlaySound;

private static readonly ConcurrentDictionary<string, GameInstance> instances = new ConcurrentDictionary<string, GameInstance>();

public static List<string[]> Decks { get; } = new List<string[]>()
{
new []{ "❓", "0", "0.5", "1", "2", "3", "5", "8", "13", "20", "40", "100", "☕" }
};

public string[] CardDeck => GameInstance.Decks.Single();

public string Hash { get; private set; }

public List<Player> Players { get; } = new List<Player>();

public List<Round> Rounds { get; } = new List<Round>() { new Round() };

public Round CurrentRound => this.Rounds.LastOrDefault();

public int RoundNumber => this.Rounds.Count;

public void NewRound()
{
this.Rounds.Add(new Round());
this.RaiseChanged();
}

internal void Join(Player player)
{
if (this.Players.Any(x => x.Secret == player.Secret) == false)
{
this.Players.Add(player);
}

this.RaiseChanged();
}

private void RaiseChanged()
{
this.Changed?.Invoke(this, EventArgs.Empty);
}

internal static GameInstance Find(string hash)
{
if (GameInstance.instances.TryGetValue(hash, out var instance) == false)
{
instance = new GameInstance()
{
Hash = hash
};

GameInstance.instances[hash] = instance;
}

return instance;
}

internal void ChangePlayersName(Player player, string playerName)
{
player.Name = playerName;
this.RaiseChanged();
}

internal void Vote(Player player, string card)
{
if (this.Players.Contains(player) == false)
{
this.Players.Add(player);
}

this.CurrentRound.Cards[player] = card;
this.RaiseChanged();
this.RaisePlaySound("place-card");
}

internal void StartNewRound()
{
this.Rounds.Add(new Round());
this.RaiseChanged();
this.RaisePlaySound("shuffle-cards");
}

internal void RevealCards()
{
this.CurrentRound.IsRevealed = true;
this.RaiseChanged();
this.RaisePlaySound("turn-cards");
}

internal void RemovePlayer(Player player)
{
this.Players.Remove(player);

if (this.Players.Any() == false)
{
GameInstance.instances.Remove(this.Hash, out var _);
}

this.RaiseChanged();
}

internal void PlayBingSound()
{
this.RaisePlaySound("bing-sound");
}

private void RaisePlaySound(string sound)
{
this.PlaySound?.Invoke(this, new PlaySoundEventArgs(sound));
}
}
}
32 changes: 14 additions & 18 deletions PlanningPoker.Web/PlanningPoker.Web.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageReference Include="System.Text.Encodings.Web" Version="9.0.0" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
<PackageReference Include="Toolbelt.AspNetCore.CssLiveReloader" Version="1.1.4" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\audio\" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
<PackageReference Include="System.Text.Encodings.Web" Version="9.0.0" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
<PackageReference Include="Toolbelt.AspNetCore.CssLiveReloader" Version="1.1.4" />
</ItemGroup>

</Project>
Loading

0 comments on commit 93e65d6

Please sign in to comment.