public static async Task <TaskResult> CrocoStart(long chatId, User user) { var context = new ApplicationDbContext(); var openGame = await context.Games.Where(x => x.ChatId == chatId && x.Type == GameType.UrCroco && !x.Closed).FirstOrDefaultAsync(); if (openGame != null) { return(new TaskResult(false, $"Oyun boliwatidu\\. [Bëshi](tg://user?id={openGame.StarterUserId})")); } else { var newGame = new Game() { ChatId = chatId, StarterUserId = user.Id, StartUtc = DateTime.UtcNow, Type = GameType.UrCroco }; context.Games.Add(newGame); await context.SaveChangesAsync(); return(new TaskResult(true, $"Oyun bashlandi\\! [Bëshi](tg://user?id={user.Id})")); } }
public static async Task <TaskResult> CrocoNewWord(long chatId, int senderId) { var context = new ApplicationDbContext(); var chatGames = await context.Games.Where(x => x.ChatId == chatId && x.Type == GameType.UrCroco).ToListAsync(); if (chatGames == null || chatGames.Where(x => !x.Closed).Count() == 0) { var word = await GetRandomWord(); var newGame = new Game() { ChatId = chatId, StarterUserId = senderId, StartUtc = DateTime.UtcNow, Question = word.UrText, Type = GameType.UrCroco }; context.Games.Add(newGame); await context.SaveChangesAsync(); return(new TaskResult(true, $"{newGame.Question}")); } var lastGame = chatGames.Where(x => !x.Closed).OrderByDescending(x => x.Id).FirstOrDefault(); if (lastGame.StarterUserId != senderId) { return(new TaskResult(false, "Oyun bëshi siz emes! 😅")); } var newWord = await GetRandomWord(); if (newWord == null) { return(new TaskResult(false, "Söz tallap almidim")); } lastGame.Question = newWord.UrText; context.Entry(lastGame).State = EntityState.Modified; await context.SaveChangesAsync(); return(new TaskResult(true, $"{lastGame.Question}")); }
public static async Task <TaskResult> Start(long chatId) { var context = new ApplicationDbContext(); var openGame = await context.Games.Where(x => x.ChatId == chatId && !x.Closed && (x.Type == GameType.RuToUy || x.Type == GameType.UrToRu)).FirstOrDefaultAsync(); if (openGame != null) { return(new TaskResult(false, $"Oyun boliwatidu. Soal: {openGame.Question}")); } var lastGame = await context.Games.Where(x => x.ChatId == chatId && (x.Type == GameType.RuToUy || x.Type == GameType.UrToRu)).OrderByDescending(x => x.Id).FirstOrDefaultAsync(); if (lastGame == null || lastGame.Closed) { var word = await GetRandomWord(); if (word == null) { return(new TaskResult(false, "Söz tallap almidim")); } GameType gameType = GameType.RuToUy; if (lastGame != null) { if (lastGame.Type == GameType.RuToUy) { gameType = GameType.UrToRu; } } string question = null; string answer = null; if (gameType == GameType.UrToRu) { question = $"{word.UrText}"; answer = word.RuText; } else { question = $"{word.RuText}"; answer = word.UrText; } var newGame = new Game() { ChatId = chatId, StartUtc = DateTime.UtcNow, Question = question, Type = gameType, Closed = false }; context.Games.Add(newGame); await context.SaveChangesAsync(); switch (newGame.Type) { case GameType.RuToUy: return(new TaskResult(true, $"{question} uyghurche qandaq deydu ?\n\nOyun bashlandi! 😃")); case GameType.UrToRu: return(new TaskResult(true, $"{question} rusche qandaq deydu ?\n\nOyun bashlandi! 😃")); default: break; } } return(new TaskResult(false, "Oyun boliwatidu! 😅")); }