コード例 #1
0
ファイル: BigTwo.cs プロジェクト: jeffffc/BigTwoBot
 public void Dispose()
 {
     Players?.Clear();
     Players = null;
     Deck    = null;
     // MessageQueueing = false;
 }
コード例 #2
0
ファイル: BigTwo.cs プロジェクト: jeffffc/BigTwoBot
        public BigTwo(long chatId, User u, string groupName, string chatUsername = null)
        {
            ChatId    = chatId;
            GroupName = groupName;
            Players   = new List <BTPlayer>();
            Deck      = new BTDeck();
            #region Creating New Game - Preparation
            using (var db = new BigTwoDb())
            {
                DbGroup          = db.Groups.FirstOrDefault(x => x.GroupId == ChatId);
                DbGroup.UserName = chatUsername;
                GroupLink        = DbGroup.UserName != null ? $"https://t.me/{DbGroup.UserName}" : DbGroup.GroupLink ?? null;
                LoadLanguage(DbGroup.Language);
                if (DbGroup == null)
                {
                    Bot.RemoveGame(this);
                }
                ChooseCardTime = DbGroup.ChooseCardTime ?? Constants.ChooseCardTime;
                PlayChips      = DbGroup.PlayChips ?? false;
                ChipsPerCard   = DbGroup.ChipsPerCard ?? Constants.ChipsPerCard;
                db.SaveChanges();
                if (GroupLink != null)
                {
                    GroupMarkup = new InlineKeyboardMarkup(
                        new InlineKeyboardButton[][] {
                        new InlineKeyboardUrlButton[] {
                            new InlineKeyboardUrlButton(GetTranslation("BackGroup", GroupName), GroupLink)
                        }
                    });
                }
                BotMarkup = new InlineKeyboardMarkup(
                    new InlineKeyboardButton[][] {
                    new InlineKeyboardButton[] {
                        new InlineKeyboardUrlButton(GetTranslation("GoToBot"), $"https://t.me/{Bot.Me.Username}")
                    }
                });
            }
            // something
            #endregion

            var msg = GetTranslation("NewGame", u.GetName());
            if (PlayChips)
            {
                msg += Environment.NewLine + GetTranslation("GameChipsPerCard", ChipsPerCard);
            }
            // beta message
            msg += Environment.NewLine + Environment.NewLine + GetTranslation("Beta");
            Bot.Send(chatId, msg);
            AddPlayer(u, true);
            Initiator = Players[0];

            new Task(() => { NotifyNextGamePlayers(); }).Start();
            new Thread(GameTimer).Start();
        }