started work on ttt
This commit is contained in:
parent
91efe4db48
commit
a8124cf1f2
127
src/NadekoBot/Modules/Games/Commands/TicTacToe.cs
Normal file
127
src/NadekoBot/Modules/Games/Commands/TicTacToe.cs
Normal file
@ -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<ulong, TicTacToe> _openGames = new ConcurrentDictionary<ulong, TicTacToe>();
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,7 +15,6 @@ namespace NadekoBot.Modules.Games
|
|||||||
{
|
{
|
||||||
private static string[] _8BallResponses { get; } = NadekoBot.BotConfig.EightBallResponses.Select(ebr => ebr.Text).ToArray();
|
private static string[] _8BallResponses { get; } = NadekoBot.BotConfig.EightBallResponses.Select(ebr => ebr.Text).ToArray();
|
||||||
|
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
public async Task Choose([Remainder] string list = null)
|
public async Task Choose([Remainder] string list = null)
|
||||||
{
|
{
|
||||||
|
@ -906,7 +906,7 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 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..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string betroll_desc {
|
public static string betroll_desc {
|
||||||
get {
|
get {
|
||||||
@ -1041,7 +1041,7 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 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..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string byemsg_desc {
|
public static string byemsg_desc {
|
||||||
get {
|
get {
|
||||||
@ -3066,7 +3066,7 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 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..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string greetdmmsg_desc {
|
public static string greetdmmsg_desc {
|
||||||
get {
|
get {
|
||||||
@ -3093,7 +3093,7 @@ namespace NadekoBot.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 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..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string greetmsg_desc {
|
public static string greetmsg_desc {
|
||||||
get {
|
get {
|
||||||
|
@ -184,7 +184,7 @@
|
|||||||
<value>greetmsg</value>
|
<value>greetmsg</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="greetmsg_desc" xml:space="preserve">
|
<data name="greetmsg_desc" xml:space="preserve">
|
||||||
<value>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.</value>
|
<value>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.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="greetmsg_usage" xml:space="preserve">
|
<data name="greetmsg_usage" xml:space="preserve">
|
||||||
<value>`{0}greetmsg Welcome, %user%.`</value>
|
<value>`{0}greetmsg Welcome, %user%.`</value>
|
||||||
@ -202,7 +202,7 @@
|
|||||||
<value>byemsg</value>
|
<value>byemsg</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="byemsg_desc" xml:space="preserve">
|
<data name="byemsg_desc" xml:space="preserve">
|
||||||
<value>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.</value>
|
<value>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.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="byemsg_usage" xml:space="preserve">
|
<data name="byemsg_usage" xml:space="preserve">
|
||||||
<value>`{0}byemsg %user% has left.`</value>
|
<value>`{0}byemsg %user% has left.`</value>
|
||||||
@ -1273,7 +1273,7 @@
|
|||||||
<value>betroll br</value>
|
<value>betroll br</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="betroll_desc" xml:space="preserve">
|
<data name="betroll_desc" xml:space="preserve">
|
||||||
<value>Bets a certain amount of currency and rolls a dice. Rolling over 66 yields x2 of your currency, over 90 - x3 and 100 x10.</value>
|
<value>Bets a certain amount of currency and rolls a dice. Rolling over 66 yields x2 of your currency, over 90 - x4 and 100 x10.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="betroll_usage" xml:space="preserve">
|
<data name="betroll_usage" xml:space="preserve">
|
||||||
<value>`{0}br 5`</value>
|
<value>`{0}br 5`</value>
|
||||||
@ -2311,7 +2311,7 @@
|
|||||||
<value>`{0}greetdmmsg Welcome to the server, %user%`.</value>
|
<value>`{0}greetdmmsg Welcome to the server, %user%`.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="greetdmmsg_desc" xml:space="preserve">
|
<data name="greetdmmsg_desc" xml:space="preserve">
|
||||||
<value>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.</value>
|
<value>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.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="cash_desc" xml:space="preserve">
|
<data name="cash_desc" xml:space="preserve">
|
||||||
<value>Check how much currency a person has. (Defaults to yourself)</value>
|
<value>Check how much currency a person has. (Defaults to yourself)</value>
|
||||||
|
Loading…
Reference in New Issue
Block a user