Ejemplo n.º 1
0
        public bool GenQ(int n,Level lv,int[] vn,int[] vndiff)
        {
            if (MainPacks[lv].DBDelete())
            {
                PopupMgr.Singleton.ShowDialog("todo");// emsg);
            }
            MainPacks[lv].Sheets.Clear();
            //if (AltPacks[lv].DBDelete(out emsg))
            //    WPopup.s.ShowDialog(emsg);
            //AltPacks[lv].Sheets.Clear();
            QuestSheet.DBUpdateCurQSId(mDt);
            foreach (QuestSheet qs in MainPacks[lv].Sheets.Values)
            {
                mKeyPack.Sheets.Remove(qs.LvId);
            }
            List <QuestSheet> l;

            if (System.IO.File.Exists("Randomize.txt"))
            {
                l = MainPacks[lv].Genegrate2(n,vn,vndiff);
                //l.InsertRange(l.Count, AltPacks[lv].GenQPack2(n, vn, vndiff));
            }
            else
            {
                l = MainPacks[lv].GenQPack3(n,vn,vndiff);
                //l.InsertRange(l.Count, AltPacks[lv].GenQPack3(n, vn, vndiff));
            }
            mKeyPack.ExtractKey(l);
            return(false);
        }
Ejemplo n.º 2
0
        public QuestSheet RandomizeDeepCopy(Random rand)
        {
            QuestSheet qs = new QuestSheet();

            qs.Lv  = Lv;
            qs.uId = uId;
            foreach (MultiChoiceItem qi in Questions)
            {
                qs.Questions.Add(qi.RandomizeDeepCopy(rand));
            }
            //randomize
            List <MultiChoiceItem> lq = new List <MultiChoiceItem>();
            int n = qs.Questions.Count;

            while (0 < n)
            {
                int idx = rand.Next() % n;
                lq.Add(qs.Questions.ElementAt(idx));
                qs.Questions.RemoveAt(idx);
                --n;
            }
            qs.Questions = lq;

            return(qs);
        }
Ejemplo n.º 3
0
        public static QuestSheetView NewWith(QuestSheet model, double backgroundWidth, double padding, StackPanel UI_container)
        {
            QuestSheetView questSheet = new QuestSheetView();

            questSheet.Model                    = model;
            questSheet.BackgroundWidth          = backgroundWidth;
            questSheet.Padding                  = padding;
            questSheet.UI_Container             = UI_container;
            questSheet.OptionsGroupedByQuestion = new List <ListBox>();
            return(questSheet);
        }
Ejemplo n.º 4
0
        public AnsSheet ExtractKey(QuestSheet qs)
        {
            AnsSheet i = new AnsSheet();

            qs.ExtractKey(i);
            if (!Sheets.ContainsKey(i.uQSLvId))
            {
                Sheets.Add(i.uQSLvId, i);
                return(i);
            }
            return(null);
        }
Ejemplo n.º 5
0
        public QuestSheet DeepCopy()
        {
            QuestSheet qs = new QuestSheet();

            qs.Lv  = Lv;
            qs.uId = uId;
            foreach (MultiChoiceItem qi in Questions)
            {
                qs.Questions.Add(qi.DeepCopy());
            }
            return(qs);
        }
Ejemplo n.º 6
0
        //only Operation1 uses this.
        public bool ReadByte(byte[] buf, ref int offs)
        {
            Sheets.Clear();
            if (buf == null)
            {
                return(true);
            }
            int offs0 = offs;
            int l     = buf.Length - offs;

            if (l < 4)
            {
                return(true);
            }
            int nSh = BitConverter.ToInt32(buf, offs);

            offs += 4;
            l    -= 4;
            if (nSh < 0)
            {
                return(true);
            }
            while (0 < nSh)
            {
                QuestSheet qs = new QuestSheet();
                if (qs.ReadByte(buf, ref offs))
                {
                    return(true);
                }
                if (!Sheets.ContainsKey(qs.uId))
                {
                    //qs.Lv = Lv;//optmz
                    Sheets.Add(qs.uId, qs);
                }
                --nSh;
            }
            mNextQSIdx = 0;
            mMaxQSIdx  = Sheets.Keys.Count - 1;
            return(false);
        }
Ejemplo n.º 7
0
        public List <QuestSheet> GenQPack3(int n, int[] vn, int[] vndiff)
        {
            //string emsg;
            Random            rand = new Random();
            List <QuestSheet> l    = new List <QuestSheet>();
            QuestSheet        qs0  = new QuestSheet();
            //qs0.bAlt = bAlt;
            int j = -1;

            foreach (IUx i in MultiChoiceItem.GetIUs(Lv))
            {
                ++j;
                if (qs0.DBSelect(rand, i, vn[j] - vndiff[j], Difficulty.Easy))
                {
                    //WPopup.s.ShowDialog(emsg);
                    return(new List <QuestSheet>());
                }
                if (qs0.DBSelect(rand, i, vndiff[j], Difficulty.Difficult))
                {
                    //WPopup.s.ShowDialog(emsg);
                    return(new List <QuestSheet>());
                }
            }
            while (0 < n)
            {
                --n;
                QuestSheet qs = qs0.RandomizeDeepCopy(rand);
                qs.Lv = Lv;
                if (!qs.UpdateCurQSId())//todo: better error handle
                {
                    Sheets.Add(qs.uId, qs);
                    l.Add(qs);
                }
            }
            if (DBIns(mDt, l) == null)
            {
                return(l);
            }
            return(new List <QuestSheet>());
        }
Ejemplo n.º 8
0
        public bool DBSelectQS(DateTime dt)//todo void
        {
            MySqlDataReader reader = DBConnect.exeQrySelect("sqz_qsheet", "id",
                                                            "dt='" + dt.ToString(DT._) + "' AND t='" + dt.ToString(DT.hh) +
                                                            "' AND lv='" + Lv.ToString() + "' AND alt=" +
                                                            (IsAlternative ? '1' : '0'));
            List <int> qsids = new List <int>();

            while (reader.Read())
            {
                qsids.Add(reader.GetUInt16(0));
            }
            reader.Close();
            foreach (int qsid in qsids)
            {
                QuestSheet qs = new QuestSheet();
                if (qs.DBSelect(dt, Lv, qsid))
                {
                    return(true);
                }
                Sheets.Add(qs.uId, qs);
            }
            return(false);
        }
Ejemplo n.º 9
0
        public void InitView(QuestSheet qs, double w, DgEvntCB cb)
        {
            throw new NotImplementedException();
            //if (cb != null)
            //    dgSelChgCB = cb;

            //vlbxAns = new ListBox[qs.Questions.Count];
            //vAnsItem = new OptionView[qs.Questions.Count][];

            //int idx = -1;
            //int j = -1;
            //foreach (MultiChoiceItem q in qs.ShallowCopy())
            //{
            //    ++idx;
            //    ListBox lbxAns = new ListBox();
            //    lbxAns.Width = w;
            //    lbxAns.Name = "_" + idx;
            //    //lbxAns.SelectionChanged += Ans_SelectionChanged;
            //    lbxAns.BorderBrush = Theme.Singleton.DefinedColors[(int)BrushId.Ans_TopLine];
            //    lbxAns.BorderThickness = new Thickness(0, 4, 0, 0);
            //    vlbxAns[idx] = lbxAns;
            //    vAnsItem[idx] = new OptionView[MultiChoiceItem.N_OPTIONS];
            //    for (int i = 0; i < MultiChoiceItem.N_OPTIONS; ++i)
            //    {
            //        OptionView ai = new OptionView("xx", i, w);// q.Options[i], i, w);
            //        ++j;//update view from log
            //        if (aAns[j] == Convert.ToByte(true))
            //        {
            //            ai.AnsCellLabel.Content = 'X';
            //            ai.mLbxItem.IsSelected = true;
            //        }
            //        vAnsItem[idx][i] = ai;
            //        lbxAns.Items.Add(ai.lbxi);
            //    }
            //}
        }
Ejemplo n.º 10
0
        public List <QuestSheet> Genegrate2(int n, int[] vn, int[] vndiff)
        {
            List <QuestSheet> l = new List <QuestSheet>();
            int i;

            for (i = 0; i < n; ++i)
            {
                l.Add(new QuestSheet());
            }
            //foreach (QuestSheet qs in l)
            //    qs.bAlt = bAlt;
            i = 0;
            Random rand = new Random();

            foreach (IUx iu in MultiChoiceItem.GetIUs(Lv))
            {
                //
                QuestSheet qs0 = new QuestSheet();
                //qs0.bAlt = bAlt;
                qs0.DBSelect(iu, Difficulty.Easy);
                //
                foreach (QuestSheet qs in l)
                {
                    List <MultiChoiceItem> vq = qs0.ShallowCopy();
                    int ni = vn[i] - vndiff[i];
                    while (0 < ni)
                    {
                        int idx = rand.Next() % ni;
                        qs.Add(vq.ElementAt(idx).DeepCopy());
                        vq.RemoveAt(idx);
                        --ni;
                    }
                }
                //
                qs0 = new QuestSheet();
                //qs0.bAlt = bAlt;
                qs0.DBSelect(iu, Difficulty.Difficult);
                //
                foreach (QuestSheet qs in l)
                {
                    List <MultiChoiceItem> vq = qs0.ShallowCopy();
                    int ni = vndiff[i];
                    while (0 < ni)
                    {
                        int idx = rand.Next() % ni;
                        qs.Add(vq.ElementAt(idx).DeepCopy());
                        vq.RemoveAt(idx);
                        --ni;
                    }
                }
                //
                ++i;
            }
            List <int> eidx = new List <int>();

            i = -1;
            foreach (QuestSheet qs in l)
            {
                qs.Lv = Lv;
                qs.Randomize(rand);
                if (!qs.UpdateCurQSId())//todo: better error handle
                {
                    Sheets.Add(qs.uId, qs);
                }
                else
                {
                    eidx.Add(++i);
                }
            }
            foreach (int idx in eidx)
            {
                l.RemoveAt(idx);
            }

            if (DBIns(mDt, l) == null)
            {
                return(l);
            }
            return(new List <QuestSheet>());
        }