diff --git a/src/NadekoBot/Modules/Games/Commands/TicTacToe.cs b/src/NadekoBot/Modules/Games/Commands/TicTacToe.cs new file mode 100644 index 00000000..54afcab9 --- /dev/null +++ b/src/NadekoBot/Modules/Games/Commands/TicTacToe.cs @@ -0,0 +1,127 @@ +using Discord; +using Discord.Commands; +using NadekoBot.Attributes; +using NadekoBot.Extensions; +using NLog; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NadekoBot.Modules.Games +{ + public partial class Games + { + [Group] + public class TicTacToeCommands : ModuleBase + { + //channelId/game + private static readonly ConcurrentDictionary _openGames = new ConcurrentDictionary(); + private readonly Logger _log; + + public TicTacToeCommands() + { + _log = LogManager.GetCurrentClassLogger(); + } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task Ttt(IGuildUser secondUser) + { + var channel = (ITextChannel)Context.Channel; + + + TicTacToe game; + if (_openGames.TryRemove(channel.Id, out game)) // joining open game + { + if (!game.Join((IGuildUser)Context.User)) + { + await Context.Channel.SendErrorAsync("You can't play against yourself. Game stopped.").ConfigureAwait(false); + return; + } + var _ = Task.Run(() => game.Start()); + _log.Warn($"User {Context.User} joined a TicTacToe game."); + return; + } + game = new TicTacToe(channel, (IGuildUser)Context.User); + if (_openGames.TryAdd(Context.Channel.Id, game)) + { + _log.Warn($"User {Context.User} created a TicTacToe game."); + await Context.Channel.SendConfirmAsync("Tic Tac Toe game created. Waiting for another user.").ConfigureAwait(false); + } + } + } + + public class TicTacToe + { + + private readonly ITextChannel _channel; + private readonly Logger _log; + private readonly IGuildUser[] _users; + private readonly int?[,] _state; + + public TicTacToe(ITextChannel channel, IGuildUser firstUser) + { + _channel = channel; + _users = new IGuildUser[2] { firstUser, null }; + _state = new int?[3, 3] { + { null, null, null }, + { null, 1, 1 }, + { 0, null, 0 }, + }; + + _log = LogManager.GetCurrentClassLogger(); + } + + public string GetState() + { + var sb = new StringBuilder(); + for (int i = 0; i < _state.GetLength(0); i++) + { + for (int j = 0; j < _state.GetLength(1); j++) + { + sb.Append(GetIcon(_state[i, j])); + if (j < _state.GetLength(1) - 1) + sb.Append("┃"); + } + if (i < _state.GetLength(0) - 1) + sb.AppendLine("\n──────────"); + } + + return sb.ToString(); + } + + public EmbedBuilder GetEmbed() => + new EmbedBuilder() + .WithOkColor() + .WithDescription(GetState()) + .WithAuthor(eab => eab.WithName("Tic Tac Toe")) + .WithTitle($"{_users[0]} vs {_users[1]}"); + + private static string GetIcon(int? val) + { + switch (val) + { + case 0: + return "❌"; + case 1: + return "⭕"; + default: + return "⬛"; + } + } + + public Task Start() + { + return Task.CompletedTask; + } + + public void Join(IGuildUser user) + { + + } + } + } +} diff --git a/src/NadekoBot/Modules/Games/Games.cs b/src/NadekoBot/Modules/Games/Games.cs index 6faf288c..b4107acd 100644 --- a/src/NadekoBot/Modules/Games/Games.cs +++ b/src/NadekoBot/Modules/Games/Games.cs @@ -15,7 +15,6 @@ namespace NadekoBot.Modules.Games { private static string[] _8BallResponses { get; } = NadekoBot.BotConfig.EightBallResponses.Select(ebr => ebr.Text).ToArray(); - [NadekoCommand, Usage, Description, Aliases] public async Task Choose([Remainder] string list = null) { diff --git a/src/NadekoBot/Resources/CommandStrings.Designer.cs b/src/NadekoBot/Resources/CommandStrings.Designer.cs index 6c880516..fef3709d 100644 --- a/src/NadekoBot/Resources/CommandStrings.Designer.cs +++ b/src/NadekoBot/Resources/CommandStrings.Designer.cs @@ -906,7 +906,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Bets a certain amount of currency and rolls a dice. Rolling over 66 yields x2 of your currency, over 90 - x3 and 100 x10.. + /// Looks up a localized string similar to Bets a certain amount of currency and rolls a dice. Rolling over 66 yields x2 of your currency, over 90 - x4 and 100 x10.. /// public static string betroll_desc { get { @@ -1041,7 +1041,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Sets a new leave announcement message. Type %user% if you want to show the name the user who left. Type %id% to show id. Using this command with no message will show the current bye message.. + /// Looks up a localized string similar to Sets a new leave announcement message. Type %user% if you want to show the name the user who left. Type %id% to show id. Using this command with no message will show the current bye message. You can use embed json from <http://nadekobot.xyz/embedbuilder/> instead of a regular text, if you want the message to be embedded.. /// public static string byemsg_desc { get { @@ -3066,7 +3066,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Sets a new join announcement message which will be sent to the user who joined. Type %user% if you want to mention the new member. Using it with no message will show the current DM greet message.. + /// Looks up a localized string similar to Sets a new join announcement message which will be sent to the user who joined. Type %user% if you want to mention the new member. Using it with no message will show the current DM greet message. You can use embed json from <http://nadekobot.xyz/embedbuilder/> instead of a regular text, if you want the message to be embedded.. /// public static string greetdmmsg_desc { get { @@ -3093,7 +3093,7 @@ namespace NadekoBot.Resources { } /// - /// Looks up a localized string similar to Sets a new join announcement message which will be shown in the server's channel. Type %user% if you want to mention the new member. Using it with no message will show the current greet message.. + /// Looks up a localized string similar to Sets a new join announcement message which will be shown in the server's channel. Type %user% if you want to mention the new member. Using it with no message will show the current greet message. You can use embed json from <http://nadekobot.xyz/embedbuilder/> instead of a regular text, if you want the message to be embedded.. /// public static string greetmsg_desc { get { diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 0f03e989..fb6d8b15 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -184,7 +184,7 @@ greetmsg - Sets a new join announcement message which will be shown in the server's channel. Type %user% if you want to mention the new member. Using it with no message will show the current greet message. + Sets a new join announcement message which will be shown in the server's channel. Type %user% if you want to mention the new member. Using it with no message will show the current greet message. You can use embed json from <http://nadekobot.xyz/embedbuilder/> instead of a regular text, if you want the message to be embedded. `{0}greetmsg Welcome, %user%.` @@ -202,7 +202,7 @@ byemsg - Sets a new leave announcement message. Type %user% if you want to show the name the user who left. Type %id% to show id. Using this command with no message will show the current bye message. + Sets a new leave announcement message. Type %user% if you want to show the name the user who left. Type %id% to show id. Using this command with no message will show the current bye message. You can use embed json from <http://nadekobot.xyz/embedbuilder/> instead of a regular text, if you want the message to be embedded. `{0}byemsg %user% has left.` @@ -1273,7 +1273,7 @@ betroll br - Bets a certain amount of currency and rolls a dice. Rolling over 66 yields x2 of your currency, over 90 - x3 and 100 x10. + Bets a certain amount of currency and rolls a dice. Rolling over 66 yields x2 of your currency, over 90 - x4 and 100 x10. `{0}br 5` @@ -2311,7 +2311,7 @@ `{0}greetdmmsg Welcome to the server, %user%`. - Sets a new join announcement message which will be sent to the user who joined. Type %user% if you want to mention the new member. Using it with no message will show the current DM greet message. + Sets a new join announcement message which will be sent to the user who joined. Type %user% if you want to mention the new member. Using it with no message will show the current DM greet message. You can use embed json from <http://nadekobot.xyz/embedbuilder/> instead of a regular text, if you want the message to be embedded. Check how much currency a person has. (Defaults to yourself)