connect4 bugfixes

This commit is contained in:
Master Kwoth 2017-08-04 18:12:26 +02:00
parent ec7f69f1c0
commit 47125ed687
3 changed files with 12 additions and 1 deletions

View File

@ -85,6 +85,8 @@ namespace NadekoBot.Modules.Games.Common.Connect4
public void Initialize()
{
if (CurrentPhase != Phase.Joining)
return;
var _ = Task.Run(async () =>
{
await Task.Delay(15000).ConfigureAwait(false);
@ -267,6 +269,7 @@ namespace NadekoBot.Modules.Games.Common.Connect4
if (same == 4)
{
Console.WriteLine($"Won top left diagonal starting from {row + col * NumberOfRows}");
EndGame(Result.CurrentPlayerWon);
break;
}
@ -292,6 +295,7 @@ namespace NadekoBot.Modules.Games.Common.Connect4
if (same == 4)
{
Console.WriteLine($"Won top right diagonal starting from {row + col * NumberOfRows}");
EndGame(Result.CurrentPlayerWon);
break;
}
@ -327,6 +331,8 @@ namespace NadekoBot.Modules.Games.Common.Connect4
private void EndGame(Result result)
{
if (CurrentPhase == Phase.Ended)
return;
var _ = OnGameEnded?.Invoke(this, result);
CurrentPhase = Phase.Ended;
}
@ -351,6 +357,8 @@ namespace NadekoBot.Modules.Games.Common.Connect4
{
OnGameFailedToStart = null;
OnGameStateUpdated = null;
OnGameEnded = null;
_playerTimeoutTimer?.Change(Timeout.Infinite, Timeout.Infinite);
}
}
}

View File

@ -34,6 +34,10 @@ namespace NadekoBot.Modules.Games
Connect4Game game;
if ((game = Games.GetOrAdd(Context.Channel.Id, newGame)) != newGame)
{
if (game.CurrentPhase != Connect4Game.Phase.Joining)
return;
newGame.Dispose();
//means game already exists, try to join
var joined = await game.Join(Context.User.Id, Context.User.ToString()).ConfigureAwait(false);
return;

View File

@ -11,7 +11,6 @@ namespace NadekoBot.Modules.Utility
{
public partial class Utility
{
[NoPublicBot]
public class StreamRoleCommands : NadekoSubmodule<StreamRoleService>
{
[NadekoCommand, Usage, Description, Aliases]