public static async void UpdateMessage(GameStruct game, ulong userId) { try { var globalAccount = Global.Client.GetUser(userId); var chanelGuil = game.Message.Channel as IGuildChannel; var account = UserAccounts.GetAccount(globalAccount, chanelGuil.Guild.Id); if (game.Score > account.Best2048Score) { account.Best2048Score = game.Score; UserAccounts.SaveAccounts(chanelGuil.Guild.Id); } var builder = new StringBuilder(); builder.Append("Score: "); builder.Append(game.Score); builder.Append("\nMoves: "); builder.Append(game.Move); builder.Append("\n```cpp\n"); builder.Append(FormatBoard(game.Grid)); if (game.State == GameWork.GameState.Lost) { builder.Clear(); builder.Append("lol, you died, lol-lol you died\n"); builder.Append("Score: "); builder.Append(game.Score); EndGame(userId); } else if (game.State == GameWork.GameState.Won) { builder.Clear(); builder.Append("**well done**\n"); //btw there is no winning point lol builder.Append("Score: "); builder.Append(game.Score); EndGame(userId); } builder.Append($"\n```"); await game.Message.ModifyAsync(m => m.Content = builder.ToString()); } catch { // ignored } }
public static void CreateNewGame(ulong userId, RestUserMessage message) { var game = new GameStruct { Grid = GameWork.GetNewGameBoard(), Score = 0, State = GameWork.GameState.Playing, PlayerId = userId, Message = message, Move = 0 //////////////////// }; Games.Add(game); UpdateMessage(game, userId); }