From 2fe479a94bb4086fbb5493399271d8a50c2bc164 Mon Sep 17 00:00:00 2001 From: Benjamin Harris Date: Wed, 10 Jan 2018 16:02:00 -0500 Subject: [PATCH] handle move logic --- Commands/TicTacToe.cs | 12 ++++++++---- Services/StartupService.cs | 1 + Services/TicTacToeService.cs | 6 ------ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Commands/TicTacToe.cs b/Commands/TicTacToe.cs index edcdb25..0828856 100755 --- a/Commands/TicTacToe.cs +++ b/Commands/TicTacToe.cs @@ -88,14 +88,19 @@ namespace dotbot.Commands return true; } - internal string DoMove(SocketUserMessage msg) + internal async string DoMove(SocketUserMessage msg) { + if (!Active || Players[Turn] != msg.Author.Id) return ""; + + await LastMessage.DeleteAsync(); + LastMessage = msg; + await msg.DeleteAsync(); + if (Int32.TryParse(msg.Content, out var move)) if (move > 0 && move < 10) if (!PutPiece(move, Turn)) return $"unable to place your piece. position **{move}** already occupied by {GetPiece(move)}"; else - { if (CheckWin()) { Active = false; @@ -110,8 +115,7 @@ namespace dotbot.Commands { Turn = Turn == ":x:" ? ":o:" : ":x:"; return $""; - } - } + } else return $"**{msg.Content}** is not a valid move. please enter a number between 1 and 9."; else return "your move wasn't even a number... try again!"; } diff --git a/Services/StartupService.cs b/Services/StartupService.cs index e07aab7..1a6bce8 100644 --- a/Services/StartupService.cs +++ b/Services/StartupService.cs @@ -31,6 +31,7 @@ namespace dotbot.Services throw new Exception("Please enter your bot's token into the `_config.json` file found in the applications root directory."); await _discord.LoginAsync(TokenType.Bot, token); + Console.WriteLine(token); await _discord.StartAsync(); await _commands.AddModulesAsync(Assembly.GetEntryAssembly()); diff --git a/Services/TicTacToeService.cs b/Services/TicTacToeService.cs index 633d01b..3a11d73 100755 --- a/Services/TicTacToeService.cs +++ b/Services/TicTacToeService.cs @@ -23,16 +23,10 @@ namespace dotbot.Services { var id = context.Channel.Id; - - if (_activeGames.ContainsKey(id)) { var game = _activeGames[id]; - if (!game.Active || game.Players[game.Turn] != msg.Author.Id) return; - await msg.DeleteAsync(); - await game.LastMessage.DeleteAsync(); await context.Channel.SendMessageAsync($"{game.DoMove(msg)}\n\n{game}"); - game.LastMessage = msg; } }