handle move logic
This commit is contained in:
parent
079fa75df6
commit
2fe479a94b
|
@ -88,14 +88,19 @@ namespace dotbot.Commands
|
||||||
return true;
|
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 (Int32.TryParse(msg.Content, out var move))
|
||||||
if (move > 0 && move < 10)
|
if (move > 0 && move < 10)
|
||||||
if (!PutPiece(move, Turn))
|
if (!PutPiece(move, Turn))
|
||||||
return $"unable to place your piece. position **{move}** already occupied by {GetPiece(move)}";
|
return $"unable to place your piece. position **{move}** already occupied by {GetPiece(move)}";
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if (CheckWin())
|
if (CheckWin())
|
||||||
{
|
{
|
||||||
Active = false;
|
Active = false;
|
||||||
|
@ -110,8 +115,7 @@ namespace dotbot.Commands
|
||||||
{
|
{
|
||||||
Turn = Turn == ":x:" ? ":o:" : ":x:";
|
Turn = Turn == ":x:" ? ":o:" : ":x:";
|
||||||
return $"";
|
return $"";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else return $"**{msg.Content}** is not a valid move. please enter a number between 1 and 9.";
|
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!";
|
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.");
|
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);
|
await _discord.LoginAsync(TokenType.Bot, token);
|
||||||
|
Console.WriteLine(token);
|
||||||
await _discord.StartAsync();
|
await _discord.StartAsync();
|
||||||
|
|
||||||
await _commands.AddModulesAsync(Assembly.GetEntryAssembly());
|
await _commands.AddModulesAsync(Assembly.GetEntryAssembly());
|
||||||
|
|
|
@ -23,16 +23,10 @@ namespace dotbot.Services
|
||||||
{
|
{
|
||||||
var id = context.Channel.Id;
|
var id = context.Channel.Id;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (_activeGames.ContainsKey(id))
|
if (_activeGames.ContainsKey(id))
|
||||||
{
|
{
|
||||||
var game = _activeGames[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}");
|
await context.Channel.SendMessageAsync($"{game.DoMove(msg)}\n\n{game}");
|
||||||
game.LastMessage = msg;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue