handle move logic
This commit is contained in:
parent
079fa75df6
commit
2fe479a94b
|
@ -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!";
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue