Exemplo n.º 1
0
        public static void CreateNewGame(ulong userId, RestUserMessage message)
        {
            var game = new G2048Game()
            {
                Grid     = Game2048.GetNewGameBoard(),
                Score    = 0,
                State    = Game2048.GameState.Playing,
                PlayerId = userId,
                Message  = message,
                Move     = 0
            };

            games.Add(game);
            UpdateMessage(game, userId);
        }
Exemplo n.º 2
0
        public static async void UpdateMessage(G2048Game game, ulong userId)
        {
            try
            {
                var globalAccount = Global.Client.GetUser(userId);
                var chanelGuil    = game.Message.Channel as IGuildChannel;
                var account       = GlobalUserAccounts.GetUserAccount(globalAccount);
                if (game.Score > account.Best2048Score)
                {
                    account.Best2048Score = game.Score;
                    GlobalUserAccounts.SaveAccounts(chanelGuil.Guild.Id);
                }
                var builder = new StringBuilder();
                builder.Append("Score: ");
                builder.Append(game.Score);
                builder.Append("\nMove: ");
                builder.Append(game.Move);
                builder.Append("\n```cpp\n");
                builder.Append(FormatBoard(game.Grid));

                if (game.State == Game2048.GameState.Lost)
                {
                    builder.Clear();
                    builder.Append("YOU LOST\n");
                    builder.Append("Score: ");
                    builder.Append(game.Score);

                    games.Remove(game);
                }
                else if (game.State == Game2048.GameState.Won)
                {
                    builder.Clear();
                    builder.Append("**YOU WON**\n");
                    builder.Append("Score: ");
                    builder.Append(game.Score);

                    games.Remove(game);
                }

                builder.Append("\n```");

                await game.Message.ModifyAsync(m => m.Content = builder.ToString());
            }
            catch
            {
                // ignored
            }
        }