Example #1
0
        public static BindingList <DICHVU> TimKiemDichVu(string searchStr)
        {
            BindingList <DICHVU> DanhSachDichVu = new BindingList <DICHVU>();
            var temp = new BindingList <DICHVU>(DataProvider.ISCreated.DB.DICHVUs.Where(x => x.TinhTrangTonTai == false).ToList());

            foreach (var item in temp)
            {
                if (item.TenDichVu.ToLower().Contains(searchStr.ToLower()))
                {
                    if (!DanhSachDichVu.Contains(item))
                    {
                        DanhSachDichVu.Add(item);
                    }
                }
                if (item.LOAIDV.TenLoai.ToLower().Contains(searchStr.ToLower()))
                {
                    if (!DanhSachDichVu.Contains(item))
                    {
                        DanhSachDichVu.Add(item);
                    }
                }
                if (item.GiaBan.ToString().ToLower().Contains(searchStr.ToLower()))
                {
                    if (!DanhSachDichVu.Contains(item))
                    {
                        DanhSachDichVu.Add(item);
                    }
                }
            }
            return(DanhSachDichVu);
        }
Example #2
0
        public override bool Remove(WordListEntry item)
        {
            bool existed = list.Contains(item);

            Do(new Deletion(this, IndexOf(item)));
            return(existed);
        }
Example #3
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            if (!File.Exists(Environment.CurrentDirectory + "\\Template.xml"))
            {
                MessageBox.Show("You Don't Have A Template File!", "No Template File", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            var fileSelected = saveFileDialog.ShowDialog();

            if (fileSelected == DialogResult.OK)
            {
                File.Copy(Environment.CurrentDirectory + "\\Template.xml", saveFileDialog.FileName);
                if (!savedConfigs.Contains(saveFileDialog.FileName))
                {
                    savedConfigs.Add(saveFileDialog.FileName);
                    lstItems.SelectedItem = saveFileDialog.FileName;
                }

                LoadConfigFromFile(saveFileDialog.FileName);

                btnDelete.Enabled = true;
                btnLoad.Enabled   = true;
            }
        }
Example #4
0
        public static BindingList <DonHang> TimKiemDonHang(string value, int MANV)
        {
            BindingList <DonHang> donHangs = new BindingList <DonHang>();
            BindingList <DonHang> temp     = new BindingList <DonHang>(DataProvider.ISCreated.DB.DonHangs.Where(x => x.MANV == MANV && x.ISDEL != 1).ToArray());

            foreach (var item in temp)
            {
                if (item.CREADTEDAT.Value.ToString("dd/mm/yyyy").ToLower().Contains(value.ToLower()))
                {
                    if (!donHangs.Contains(item))
                    {
                        donHangs.Add(item);
                    }
                }
                if (TimKiemNhanVien(value) != null)
                {
                    foreach (var item1 in TimKiemNhanVien(value))
                    {
                        if (item1.MANV == item.MANV)
                        {
                            if (!donHangs.Contains(item))
                            {
                                donHangs.Add(item);
                            }
                        }
                    }
                }
            }
            return(donHangs);
        }
Example #5
0
        public void CheckName()
        {
            if (flag == true)
            {
                if (UserList.Contains(Username))
                {
                    String temp;
                    for (int i = 1; ; i++)
                    {
                        temp = Username + i;
                        if (UserList.Contains(temp))
                        {
                        }
                        else
                        {
                            break;
                        }
                    }
                    Username = temp;
                    MessageBox.Show("名字已有人用過,更改名字為:" + temp);
                }

                c.Send("/nu." + Username);
                this.Text = Username + "-" + this.Text;

                flag = false;
            }
            systemflag = true;
        }
 private void AddDefFile(string defFile)
 {
     if (!_defFiles.Contains(defFile))
     {
         _defFiles.Add(defFile);
     }
 }
Example #7
0
        public void AddTarget(IRenderedObject target)
        {
            if (_renderList.Contains(target))
            {
                return;
            }

            _renderList.Add(target);
            target.DrawCallsChanged += target_DrawCallsChanged;

            target.Attach();

            foreach (DrawCallBase call in target.DrawCalls)
            {
                call.Bind();
            }

            _drawCalls.AddRange(target.DrawCalls);
            _drawCalls.Sort(DrawCallSort);

            if (target is ResourceNode)
            {
                _resourceList.Add(target as ResourceNode);
            }

            Invalidate();
        }
Example #8
0
 public void DisplayCommand(CommandEventArgs args)
 {
     if (InvokeRequired)
     {
         Invoke(new Action(() =>
         {
             if (!list.Contains(args))
             {
                 list.Add(args);
             }
             else
             {
                 list[list.IndexOf(args)] = args;
             }
         }));
     }
     else
     {
         if (!list.Contains(args))
         {
             list.Add(args);
         }
         else
         {
             list[list.IndexOf(args)] = args;
         }
     }
 }
        public static BindingList <LOAIPHONG> timKiemLoaiPhong(string value)
        {
            BindingList <LOAIPHONG> NHANVIENs = new BindingList <LOAIPHONG>();
            BindingList <LOAIPHONG> temp      = new BindingList <LOAIPHONG>(DataProvider.ISCreated.DB.LOAIPHONGs.Where(x => (x.TinhTrang == false)).ToArray());

            foreach (var item in temp)
            {
                if (item.LoaiPhongID.ToLower().Contains(value.ToLower()))
                {
                    if (!NHANVIENs.Contains(item))
                    {
                        NHANVIENs.Add(item);
                    }
                }
                else if (item.TenLoai.ToLower().Contains(value.ToLower()))
                {
                    if (!NHANVIENs.Contains(item))
                    {
                        NHANVIENs.Add(item);
                    }
                }
                else if (item.NgayTao.ToString("dd/mm/yyyy").ToLower().Contains(value.ToLower()))
                {
                    if (!NHANVIENs.Contains(item))
                    {
                        NHANVIENs.Add(item);
                    }
                }
            }
            if (NHANVIENs != null)
            {
                return(NHANVIENs);
            }
            return(null);
        }
Example #10
0
        void OnAvailabilityDeviceChanged(object sender, DeviceChangeArgs e)
        {
            if (!e.DevicePath.Contains(SearchPattern))
            {
                return;
            }

            DeviceInformation deviceInfo;

            switch (e.ChangeType)
            {
            case DeviceChange.Added:
                deviceInfo = DeviceManager.EnumerateAllDevices().First(d => d.Path == e.DevicePath);
                Contract.Assert(!AvailableDevices.Contains(deviceInfo));
                InsertDeviceInfo(deviceInfo);
                Log.InfoFormat(Strings.USB_Device_Plugged_0, deviceInfo.Description);
                break;

            case DeviceChange.Removed:
                deviceInfo = AvailableDevices.First(d => d.Path == e.DevicePath);
                Contract.Assert(AvailableDevices.Contains(deviceInfo));
                AvailableDevices.Remove(deviceInfo);
                Log.InfoFormat(Strings.USB_Device_Unplugged_0, deviceInfo.Description);
                break;
            }
        }
Example #11
0
        /// <summary>
        /// Updates the ItemList:
        /// 1. Change Color and add this.Text to ItemSource if ItemSource does not contain this.Text
        /// 2. Remove invalid items from ItemList (except this.Text)
        /// </summary>
        private void UpdateItemSource()
        {
            //Change Color and add this.Text to ItemSource if this.Text is invalid
            if (!_itemSource.Contains(this.Text))
            {
                this.ForeColor = Color.Red;
                if (!this.Items.Contains(this.Text))
                {
                    this.Items.Add(this.Text);
                }
            }
            else
            {
                this.ForeColor = Color.Black;
            }

            //Remove invalid items from ItemList (except this.Text)
            for (int i = this.Items.Count - 1; i >= 0; i--)
            {
                string item = this.Items[i].ToString();
                if (item != this.Text && !_itemSource.Contains(item))
                {
                    this.Items.RemoveAt(i);
                }
            }
        }
Example #12
0
        public static BindingList <LoaiMonAn> TimKiemLoaiMonAn(string value)
        {
            BindingList <LoaiMonAn> loaiMonAns = new BindingList <LoaiMonAn>();
            BindingList <LoaiMonAn> temp       = new BindingList <LoaiMonAn>(DataProvider.ISCreated.DB.LoaiMonAns.Where(x => x.ISDEL != 1).ToArray());

            foreach (var item in temp)
            {
                if (item.MALOAI.ToString().ToLower().Contains(value.ToLower()))
                {
                    if (!loaiMonAns.Contains(item))
                    {
                        loaiMonAns.Add(item);
                    }
                }
                if (item.TENLOAI.ToLower().Contains(value.ToLower()))
                {
                    if (!loaiMonAns.Contains(item))
                    {
                        loaiMonAns.Add(item);
                    }
                }
            }
            if (loaiMonAns.Count > 0)
            {
                return(loaiMonAns);
            }
            return(null);
        }
Example #13
0
        private void buttonRun_Click(object sender, EventArgs e)
        {
            try
            {
                wallid      = textBoxGroupId.Text;
                token       = textBoxToken.Text;
                commentText = richTextBoxComment.Text;
                dir         = textBoxFolder.Text;
                isGroup     = checkBoxIsGroup.Checked;
                deleteImage = checkBoxDelete.Checked;

                //ADD NAME AND SCREEN NAME
                if (isGroup)
                {
                    var tuple = VkApi.getById(token, wallid);
                    screenName = tuple.Item1;
                    // name = tuple.Item2;
                    name   = Win1251ToUtf8(tuple.Item2);
                    wallid = "-" + tuple.Item3;
                }
                else
                {
                    name = screenName = wallid;
                }


                //ADD TO DICT OR UPDATE THREAD
                if (wallDictKeysCopy.Contains(screenName))
                {
                    wallDict[screenName].dir         = dir;
                    wallDict[screenName].commentText = commentText;
                    wallDict[screenName].token       = token;
                    wallDict[screenName].isGroup     = isGroup;
                    wallDict[screenName].deleteImage = deleteImage;

                    makeLog(screenName + " settings updated");
                }
                else
                {
                    Wall wall = new Wall(token, dir, wallid, commentText, isGroup, name, screenName, deleteImage);

                    UploadThread currentThread = new UploadThread(this, wall);
                    wallDict.Add(screenName, currentThread);
                    wallDictKeysCopy.Add(screenName);
                    makeLog(screenName + " NEW thread started");
                    int index = listBoxRunning.FindString(screenName);
                    listBoxRunning.SetSelected(index, true);
                }
            }

            catch (VkApiException ex)
            {
                makeLog(ex.Message);
            }
            catch (Exception ex)
            {
                makeLog(ex.Message);
            }
        }
Example #14
0
 /// <summary>Activate busy spinner.</summary>
 public void AddTask(TaskName name)
 {
     lock (TasksLock)
     {
         if (!Tasks.Contains(name))
         {
             Tasks.Add(name);
         }
         UpdateIcon();
     }
 }
Example #15
0
        private void CheckForObjectSelectionChange(WSceneView view)
        {
            // If we have a gizmo and we're transforming it, don't check for selection change.
            if (m_transformGizmo != null && m_transformGizmo.IsTransforming)
            {
                return;
            }
            if (WInput.GetMouseButtonDown(0) && !WInput.GetMouseButton(1))
            {
                FRay       mouseRay   = view.ProjectScreenToWorld(WInput.MousePosition);
                WActorNode addedActor = Raycast(mouseRay);

                // Check the behaviour of this click to determine appropriate selection modification behaviour.
                // Click w/o Modifiers = Clear Selection, add result to selection
                // Click /w Ctrl = Toggle Selection State
                // Click /w Shift = Add to Selection
                bool ctrlPressed  = WInput.GetKey(Key.LeftCtrl) || WInput.GetKey(Key.RightCtrl);
                bool shiftPressed = WInput.GetKey(Key.LeftShift) || WInput.GetKey(Key.RightShift);

                if (!ctrlPressed & !shiftPressed)
                {
                    ModifySelection(SelectionType.Add, addedActor, true);
                    //m_selectionList.Clear();
                    //if (addedActor != null) m_selectionList.Add(addedActor);
                }
                else if (addedActor != null && (ctrlPressed && !shiftPressed))
                {
                    if (m_selectionList.Contains(addedActor))
                    {
                        ModifySelection(SelectionType.Remove, addedActor, false);
                    }
                    //m_selectionList.Remove(addedActor);
                    else
                    {
                        ModifySelection(SelectionType.Add, addedActor, false);
                    }
                    //m_selectionList.Add(addedActor);
                }
                else if (addedActor != null && shiftPressed)
                {
                    if (!m_selectionList.Contains(addedActor))
                    {
                        ModifySelection(SelectionType.Add, addedActor, false);
                    }
                    //m_selectionList.Add(addedActor);
                }

                if (m_transformGizmo != null && m_selectionList.Count > 0)
                {
                    m_transformGizmo.SetPosition(m_selectionList[0].Transform.Position);
                    m_transformGizmo.SetLocalRotation(m_selectionList[0].Transform.Rotation);
                }
            }
        }
Example #16
0
 /// <summary>
 /// Removes/Adds the "Redirects" option from/to the list
 /// </summary>
 public static void AddRemoveRedirects()
 {
     if (Variables.LangCode != LangCodeEnum.en && listItems.Contains(redirectLProvider))
     {
         listItems.Remove(redirectLProvider);
     }
     else if (!listItems.Contains(redirectLProvider))
     {
         listItems.Add(redirectLProvider);
     }
 }
Example #17
0
        //updates the save location and backup frequency in a temporary data structure
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            string selectedItem = this.comboBoxSaves.GetItemText(this.comboBoxSaves.SelectedItem);

            settings[selectedItem] = int.Parse(this.comboBoxFrequency.GetItemText(this.comboBoxFrequency.SelectedItem));

            if (!saveLocations.Contains(selectedItem))
            {
                saveLocations.Add(selectedItem);
            }
        }
        public static void AddFile(ResourceNode r)
        {
            string path = r._origPath.Substring(Program.RootPath.Length).Replace('\\', '/');

            if (!_openedFilePaths.Contains(path))
            {
                _openedFiles.Add(r);
                _openedFilePaths.Add(path);

                RunTime.Log("Loaded " + path);
            }
        }
Example #19
0
        /// <summary>
        /// Simple launch tube assignment.
        /// </summary>
        /// <param name="tube">launch tube to be assigned.</param>
        public void assignLaunchTube(MissileLauncherTN tube)
        {
            if (m_lLinkedWeapons.Contains(tube) == false)
            {
                m_lLinkedWeapons.Add(tube);

                if (tube.mFC != this)
                {
                    tube.AssignMFC(this);
                }
            }
        }
Example #20
0
        public void AddFiles()
        {
            try
            {
                // loop through the list objects in the open files and add them to the list box
                foreach (GroupSheetCollection gsc in Globals.ThisAddIn.masterGroupCollection)
                {
                    if (gsc.WBName != Globals.ThisAddIn.Application.ActiveWorkbook.Name)
                    {
                        Excel.Workbook gsWB     = ExcelHelpers.GetWorkbook(Globals.ThisAddIn.Application, gsc.WBName);
                        bool           amisaved = gsWB.Saved;

                        for (int j = 0; j < gsc.Count; j++)
                        {
                            GroupSheet gs = gsc.Item(j);

                            if (ExcelHelpers.GetWorksheetbyGUID(gsWB, gs.WSGUID) != null)
                            {
                                if (gs.adjustedDataSheet)
                                {
                                    string nm = gs.Name == null?gs.WSName() : gs.Name + " -- " + gs.WSName();

                                    string disp = " (" + gsc.WBName + ") " + nm;

                                    try
                                    {
                                        DetailTable dt = new DetailTable(gs.WS.ListObjects.get_Item(1), nm, numberOfSources, fromActual, hasProd, hasBuildSqFt, true, fromEnergyCost);
                                        if (dt.SQLStatement != "")
                                        {
                                            SourceFile sf = new SourceFile(dt.SQLStatement, disp, gsWB.FullName, false);
                                            if (!files.Contains(sf))
                                            {
                                                files.Add(sf);
                                            }
                                        }
                                    }
                                    catch
                                    {
                                        continue;
                                    }
                                }
                            }
                        }
                        gsWB.Saved = amisaved;
                    }
                }
                AddFilesToList();
            }
            catch
            {
            }
        }
Example #21
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     using (FormPromptNumber dialog = new FormPromptNumber("Add Index...", "Index")) {
         if (dialog.ShowDialog(this) == DialogResult.OK)
         {
             PlaylistItem item = new PlaylistItem(dialog.Value1);
             if (!list.Contains(item))
             {
                 list.Add(item);
             }
         }
     }
 }
 public void AddComponent(BasicNewtonian component, int numberAdded)
 {
     if (!ComponentList.Contains(component))
     {
         ComponentList.Add(component);
         ComponentCount.Add(numberAdded);
     }
     else
     {
         int index = ComponentList.IndexOf(component);
         ComponentCount[index] += numberAdded;
     }
 }
Example #23
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (selectedActor == null)
            {
                return;
            }

            if (movieActors.Contains(selectedActor))
            {
                return;
            }

            movieActors.Add(selectedActor);
        }
        public static BindingList <BANGTHAMSO> timKiemThamSo(string value)
        {
            BindingList <BANGTHAMSO> NHANVIENs = new BindingList <BANGTHAMSO>();
            BindingList <BANGTHAMSO> temp      = new BindingList <BANGTHAMSO>(DataProvider.ISCreated.DB.BANGTHAMSOes.Where(x => (x.TinhTrang == false)).ToArray());

            foreach (var item in temp)
            {
                if (item.TenThamSo.ToString().ToLower().Contains(value.ToLower()))
                {
                    if (!NHANVIENs.Contains(item))
                    {
                        NHANVIENs.Add(item);
                    }
                }
                if (item.GiaTri.ToString().ToLower().Contains(value.ToLower()))
                {
                    if (!NHANVIENs.Contains(item))
                    {
                        NHANVIENs.Add(item);
                    }
                }
                if (item.MaThamSo.ToLower().Contains(value.ToLower()))
                {
                    if (!NHANVIENs.Contains(item))
                    {
                        NHANVIENs.Add(item);
                    }
                }
                if (item.KieuDuLieu.ToLower().Contains(value.ToLower()))
                {
                    if (!NHANVIENs.Contains(item))
                    {
                        NHANVIENs.Add(item);
                    }
                }
                else if (item.NgayTao.ToString("dd/mm/yyyy").ToLower().Contains(value.ToLower()))
                {
                    if (!NHANVIENs.Contains(item))
                    {
                        NHANVIENs.Add(item);
                    }
                }
            }
            if (NHANVIENs != null)
            {
                return(NHANVIENs);
            }
            return(null);
        }
Example #25
0
 private void buttonAddChair_Click(object sender, EventArgs e)
 {
     if (dataGridViewComitee.CurrentRow.Index != -1)
     {
         User toAdd = (Model.User)dataGridViewComitee.CurrentRow.DataBoundItem;
         if (addedChairs.Contains(toAdd) || addedPCMembers.Contains(toAdd))
         {
             MessageBox.Show("Already a Chair/PC Member");
         }
         else
         {
             addedChairs.Add(toAdd);
         }
     }
 }
Example #26
0
 private void ProviderAdded(IListProvider provider)
 {
     if (!_listProviders.Contains(provider))
     {
         _listProviders.Add(provider);
     }
 }
Example #27
0
        private void rightFileComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            FileInfo rightFile = rightFileComboBox.SelectedItem as FileInfo;

            foreach (FileInfo f in rightFilesList)
            {
                if (!leftFilesList.Contains(f))
                {
                    leftFilesList.Add(f);
                    break;
                }
            }
            leftFilesList.Remove(rightFile);
            int index = (RightSelectedIndex < LeftSelectedIndex) ? LeftSelectedIndex : RightSelectedIndex;

            ByteBlock.Load(rightFile, rightBlocksList);
            if (RightSelectedIndex == index)
            {
                UpdateLineOverLine();
            }
            else
            {
                RightSelectedIndex = index;
            }
        }
        public static BindingList <Twitter.User> GetNotFollowingList(List <Twitter.User> ListFriends, List <Twitter.User> ListFollowers)
        {
            List <Twitter.User> ListFollowersAndInclude = new List <Twitter.User>(ListFriends);
            List <Twitter.User> ListFriendsInclude      = Serializer.ReadListXML(Constants.FriendsFollowers.NeverFollow.ToString());

            if (ListFriendsInclude != null)
            {
                foreach (Twitter.User user in ListFriendsInclude)
                {
                    if (!ListFollowersAndInclude.Exists(x => x.UserId == user.UserId))
                    {
                        ListFollowersAndInclude.Add(user);
                    }
                }
            }

            BindingList <Twitter.User> notfollowingList = new BindingList <Twitter.User>();

            foreach (Twitter.User friend in ListFollowers)
            {
                if (!ListFollowersAndInclude.Exists(x => x.UserId == friend.UserId))
                {
                    if (!notfollowingList.Contains(friend))
                    {
                        notfollowingList.Add(friend);
                    }
                }
            }
            return(notfollowingList);
        }
Example #29
0
        /// <summary>
        /// The generate picture gallery.
        /// </summary>
        private static void GeneratePictureGallery()
        {
            bool changed = false;

            for (int index = 0; index < MovieDatabase.Count; index++)
            {
                MovieModel movie = MovieDatabase[index];
                if (!inGallery.Contains(movie.MovieUniqueId))
                {
                    if (movie.SmallPoster != null)
                    {
                        var galleryItem = new GalleryItem(movie.SmallPoster, movie.Title, string.Empty)
                        {
                            Tag = movie.MovieUniqueId
                        };

                        if (!galleryGroup.Items.Contains(galleryItem))
                        {
                            galleryGroup.Items.Add(galleryItem);
                            inGallery.Add(movie.MovieUniqueId);

                            changed = true;
                        }
                    }
                }
            }

            if (changed)
            {
                GalleryChanged(null, null);
            }
        }
Example #30
0
        private void leftFileComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            FileInfo leftFile = leftFileComboBox.SelectedItem as FileInfo;

            foreach (FileInfo f in leftFilesList)
            {
                if (!rightFilesList.Contains(f))
                {
                    rightFilesList.Add(f);
                    break;
                }
            }
            rightFilesList.Remove(leftFile);

            int index = (LeftSelectedIndex < RightSelectedIndex) ? RightSelectedIndex : LeftSelectedIndex;

            ByteBlock.Load(leftFile, leftBlocksList);
            if (LeftSelectedIndex == index)
            {
                UpdateLineOverLine();
            }
            else
            {
                LeftSelectedIndex = index;
            }
        }
Example #31
0
        public void groupEditFormFill()
        {
            var list = new BindingList<string>();
            var q = Query.EQ("_id", ObjectId.Parse(Properties.Settings.Default.groupID));
            var resdoc = collection.FindOneAs<Group>(q);
            foreach (var res in resdoc.days)
                list.Add(res.ToString());

            numTE.Text = resdoc.num;
            lvlComboBox.Text = resdoc.lvl;
            timeTE.Text = resdoc.time;
            durationTE.Text = resdoc.duration;

            for (int count = 0; count < daysSelector.Properties.Items.Count; count++)
            {
                if (list.Contains(daysSelector.Properties.Items[count].ToString()))
                {
                    daysSelector.Properties.Items[count].CheckState = CheckState.Checked;
                }
            }
        }
Example #32
0
        public FreeCell(IHTMLElement spawn)
        //: base(spawn)
        {

            System.Console.WriteLine("--- freecell ---");

            BackgroundImage.ToDocumentBackground();

            System.Console.WriteLine("adding card infos... ");

            MyDeck.UnusedCards.Add(CardInfo.FullDeck());

            var images = new List<IHTMLImage>();

            foreach (CardInfo v in MyDeck.UnusedCards.ToArray())
            {
                images.Add(v.ToImage("assets/CardGames/cards"));
            }

            var king = new KingIcon(new Point(500, 100));



            //Timer.While(
            //    delegate
            //    {
            //        var ready = true;

            //        foreach (IHTMLImage image in images.ToArray())
            //        {
            //            if (!image.complete)
            //            {
            //                Console.WriteLine(image.src);

            //                ready = false;
            //                break;
            //            }
            //        }

            //        return !ready;
            //    }
            //    ,
            //    delegate
            //    {
            var status = new StatusInfo();

            status.Update();

            MyDeck.Stacks.ListChanged +=
                (sender, args) =>
                {

                    if (args.ListChangedType == ListChangedType.ItemAdded)
                    {
                        var s = MyDeck.Stacks[args.NewIndex];

                        s.SetBackground(MyDeck.GfxPath + "/spider.empty.png");
                    }
                };

            System.Console.WriteLine("creating stacklists... ");

            PlayStacks = MyDeck.CreateStackList();
            TempStacks = MyDeck.CreateStackList();
            GoalStacks = MyDeck.CreateStackList();




            var usesound_cookie = Storage["usesound"];

            status.MoveTo(new Point(500, 20));
            status.Update();
            status.SoundSettingChanged +=
                delegate
                {
                    sounds.Enabled = status.UseSounds;
                    usesound_cookie.BooleanValue = status.UseSounds;
                };

            status.UseSounds = usesound_cookie.BooleanValue;

            #region rules
            MyDeck.ApplyCardRules += delegate(Card e)
            {
                e.Enabled = true;
                e.Moved +=
                    delegate
                    {
                        status.Moves++;
                        status.Update();


                    };

                #region automove


                e.Drag.MiddleClick +=
                    delegate
                    {
                        TryAutoMove(e);
                    };

                e.DoubleClick +=
                    delegate
                    {
                        TryAutoMove(e);
                    };
                #endregion

                e.Drag.DragStop +=
                    delegate
                    {
                        sounds.PlaySoundDrop();
                    };

                e.Drag.DragStart +=
                    delegate
                    {
                        sounds.PlaySoundDrag();

                    };

                // rules for starting a drag
                e.Drag.DragStartValidate +=
                    delegate(Predicate p)
                    {
                        if (UseNoValidationCheat)
                            return;

                        // cannot remove cards from goal stack
                        if (GoalStacks.Contains(e.CurrentStack))
                        {
                            p.Value = false;

                            return;
                        }

                        // cannot drag a pile of cards
                        if (e.HasStackedCards)
                            p.Value = false;
                    };

                // rules for ending a drag
                e.ValidateDragStop +=
                    delegate(Predicate<CardStack> p)
                    {
                        if (UseNoValidationCheat)
                            return;

                        if (IsStackTypeAndDoesNotFit(e, PlayStacks, p, IsFitForPlayStack))
                        {
                            p.Target = null;
                        }
                        else if (IsStackTypeAndDoesNotFit(e, TempStacks, p, IsFitForTempStack))
                        {
                            p.Target = null;
                        }
                        else if (IsStackTypeAndDoesNotFit(e, GoalStacks, p, IsFitForGoalStack))
                        {
                            p.Target = null;
                        }


                    };


            };
            #endregion

            GoalStacks.ListChanged +=
                (sender0, args0) =>
                {
                    if (args0.ListChangedType == ListChangedType.ItemAdded)
                    {
                        var s = GoalStacks[args0.NewIndex];

                        s.Cards.ListChanged +=

                            (sender1, args1) =>
                            {
                                if (args1.ListChangedType == ListChangedType.ItemAdded)
                                {
                                    var u = s.Cards[args1.NewIndex];
                                    // hide the previous, as we never need it to be seen again
                                    status.CardsLeft--;
                                    status.Update();

                                    #region end suit
                                    if (u.Info.Rank == CardInfo.RankEnum.Rank2)
                                    {
                                        s.Enabled = false;

                                        if (status.CardsLeft == 0)
                                        {
                                            king.IsSmile = true;
                                            king.Update();


                                            sounds.PlaySoundWin();
                                        }

                                        // check for victory?
                                    }
                                    #endregion

                                }
                            };

                        // each card on top of eachother
                        s.CardMargin *= 0;
                    }
                };

            System.Console.WriteLine("creating tempstack... ");

            TempStacks.Add(
                new CardStack(new Point(100, 100)),
                new CardStack(new Point(200, 100)),
                new CardStack(new Point(300, 100)),
                new CardStack(new Point(400, 100))
            );


            System.Console.WriteLine("creating goalstack... ");

            GoalStacks.Add(
                new CardStack(new Point(600, 100)),
                new CardStack(new Point(700, 100)),
                new CardStack(new Point(800, 100)),
                new CardStack(new Point(900, 100))
            );

            System.Console.WriteLine("creating playstack... ");

            PlayStacks.Add(
                new CardStack(new Point(150, 240), MyDeck.FetchCards(7)),
                new CardStack(new Point(250, 240), MyDeck.FetchCards(7)),
                new CardStack(new Point(350, 240), MyDeck.FetchCards(7)),
                new CardStack(new Point(450, 240), MyDeck.FetchCards(7)),
                new CardStack(new Point(550, 240), MyDeck.FetchCards(6)),
                new CardStack(new Point(650, 240), MyDeck.FetchCards(6)),
                new CardStack(new Point(750, 240), MyDeck.FetchCards(6)),
                new CardStack(new Point(850, 240), MyDeck.FetchCards(6))
                );

            System.Console.WriteLine("updating status... ");

            status.Moves = 0;
            status.CardsLeft = MyDeck.Cards.Count;
            status.Update();
            //}, 300
            //);

        }
Example #33
0
        public Spider(IHTMLElement spawn)
        //: base(spawn)
        {
            MyStatus.Visible = false;

            System.Console.WriteLine("--- spider ---");

            BackgroundImage.ToDocumentBackground();

            Native.Document.body.style.overflow = IStyle.OverflowEnum.hidden;

            var level = LevelEasy;

            if (Native.Document.location.search == "?hard")
                level = LevelHard;

            if (Native.Document.location.search == "?medium")
                level = LevelMedium;

            var top = CardInfo.Height / 2 + 12;
            var bottom = 500;



            MyStatus.MoveTo(new Point(500, bottom));
            var usesound_cookie = Storage["usesound"];

            MyStatus.Update();
            MyStatus.SoundSettingChanged +=
                delegate
                {
                    MySounds.Enabled = MyStatus.UseSounds;
                    usesound_cookie.BooleanValue = MyStatus.UseSounds;
                };

            MyStatus.UseSounds = usesound_cookie.BooleanValue;

            Native.Window.onresize +=
                delegate
                {
                    MyStatus.MoveTo(new Point(500, BottomY));

                    foreach (CardStack v in DealStacks)
                    {
                        v.MoveTo(new Point(v.Position.X, BottomY));
                    }

                };

            System.Console.WriteLine("adding card infos... ");

            MyDeck.UnusedCards.AddRange(CardInfo.By(2, level));

            MyDeck.RankConverter = RankConverter;

            System.Console.WriteLine("creating stacklists... ");

            DealStacks = MyDeck.CreateStackList();
            PlayStacks = MyDeck.CreateStackList();
            DeadStacks = MyDeck.CreateStackList();

            PlayStacks.ListChanged +=
                (sender, args) =>
                {
                    if (args.ListChangedType == ListChangedType.ItemAdded)
                    {
                        var s = PlayStacks[args.NewIndex];

                        s.SetBackground(MyDeck.GfxPath + "/spider.empty.png");

                    }
                };

            DeadStacks.ListChanged +=
                (sender, args) =>
                {
                    if (args.ListChangedType == ListChangedType.ItemAdded)
                    {
                        var s = DeadStacks[args.NewIndex];

                        s.Control.Hide();

                        s.CardMargin = new Point(2, 0);

                        s.Cards.ListChanged +=
                            (sender2, args2) =>
                            {
                                if (args2.ListChangedType == ListChangedType.ItemAdded)
                                    s[args2.NewIndex].Enabled = false;

                            };

                    }
                };





            #region drag rules
            MyDeck.ApplyCardRules += delegate(Card c)
            {
                c.Info.CustomBackground = "spider";
                c.Update();

                c.Moved +=
                    delegate
                    {
                        if (!this.MyStatus.Ready)
                            return;

                        //AddScore(1);

                        // check for good suit

                        var s = c.CurrentStack;

                        CheckForGoodSuit(s);

                    };

                #region sounds
                c.Drag.DragStop +=
                    delegate
                    {
                        MySounds.PlaySoundDrop();
                    };

                c.Drag.DragStart +=
                    delegate
                    {
                        MySounds.PlaySoundDrag();

                    };
                #endregion

                #region automove
                c.DoubleClick += delegate
                {
                    TryAutoMove(c);
                };

                c.Drag.MiddleClick += delegate
                {
                    TryAutoMove(c);
                };


                #endregion

                // rules for starting a drag
                c.Drag.DragStartValidate +=
                    delegate(Predicate p)
                    {
                        if (!MyStatus.Ready)
                        {
                            p.Value = false;

                            return;
                        }

                        if (CheatNoValidation)
                            return;

                        p.Value = Predicate.Invoke(c, IsDraggableFormPlayStack);


                    };

                // rules for ending a drag
                c.ValidateDragStop +=
                    delegate(Predicate<CardStack> p)
                    {
                        if (CheatNoValidation)
                            return;


                        if (Predicate.Invoke(p.Target, c, IsFitForPlayStack))
                        {
                            return;
                        }

                        p.Target = null;
                    };
            };
            #endregion



            System.Console.WriteLine("creating playstack... ");

            PlayStacks.Add(
                new CardStack(new Point(50, top), MyDeck.FetchCards(5)),
                new CardStack(new Point(150, top), MyDeck.FetchCards(5)),
                new CardStack(new Point(250, top), MyDeck.FetchCards(5)),
                new CardStack(new Point(350, top), MyDeck.FetchCards(5)),
                new CardStack(new Point(450, top), MyDeck.FetchCards(4)),
                new CardStack(new Point(550, top), MyDeck.FetchCards(4)),
                new CardStack(new Point(650, top), MyDeck.FetchCards(4)),
                new CardStack(new Point(750, top), MyDeck.FetchCards(4)),
                new CardStack(new Point(850, top), MyDeck.FetchCards(4)),
                new CardStack(new Point(950, top), MyDeck.FetchCards(4))
                );


            PlayStacks.ForEach(
                (System.Action<CardStack>)
                delegate(CardStack s)
                {
                    s.Cards.ListChanged +=
                        (sender, args) =>
                        {
                            if (args.ListChangedType == ListChangedType.ItemDeleted)
                                if (MyStatus.Ready)
                                    s.RevealLastCard();
                        };


                    s.CardsMovedToStack +=
                        delegate
                        {
                            if (MyStatus.Ready)
                            {
                                MyStatus.Score--;
                                MyStatus.Moves++;

                                MyStatus.Update();
                            }
                        };
                }
            );



            DealStacks.ListChanged +=
                (sender, args) =>
                {
                    if (args.ListChangedType == ListChangedType.ItemAdded)
                    {
                        var s = DealStacks[args.NewIndex];

                        s.CardMargin *= 0;
                        s.Update();

                        s.Click +=
                            delegate
                            {
                                if (DealStacks.Contains(s))
                                {
                                    if (MyStatus.Ready)
                                        DealRow(null);
                                }
                                else
                                {
                                    System.Console.WriteLine("whoops wrong stack click ");

                                }
                            };
                    }
                };

            System.Console.WriteLine("creating dealstack... ");

            var dealpoint = new Point(860, bottom);

            while (MyDeck.UnusedCards.Count > 0)
            {
                DealStacks.Add(
                    new CardStack(dealpoint, MyDeck.FetchCards(10))
                );

                dealpoint -= new Point(10, 0);
            }

            DeadStacks.Add(new CardStack(new Point(150, bottom)));

            if (CheatReveal)
                DoCheatRevealAllCards();


            MyDeck.ToConsole();




            DealRow(
                delegate
                {

                    MyStatus.Ready = true;
                    MyStatus.Score = 500;
                    MyStatus.Moves = 0;
                    MyStatus.Visible = true;
                    MyStatus.Update();
                }
            );
        }
        /// <summary>
        /// Builds the master tv media database.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.</param>
        private static void BuildMasterTvMediaDatabase(object sender, DoWorkEventArgs e)
        {
            masterTvMediaDatabase = new BindingList<string>();

            foreach (var series in TvDBFactory.TvDatabase)
            {
                foreach (var season in series.Value.Seasons)
                {
                    foreach (Episode episode in season.Value.Episodes)
                    {
                        string filePath = episode.CurrentFilenameAndPath;

                        if (!string.IsNullOrEmpty(filePath))
                        {
                            // var check = (from m in masterTvMediaDatabase where m == filePath select m).SingleOrDefault();
                            if (!masterTvMediaDatabase.Contains(filePath))
                            {
                                masterTvMediaDatabase.Add(filePath);
                            }
                        }
                    }
                }
            }
        }
Example #35
0
        /// <summary>
        /// Handles the RunWorkerCompleted event of the bgw control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.ComponentModel.RunWorkerCompletedEventArgs"/> instance containing the event data.</param>
        private void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.initializing = false;
            this.btnOK.Enabled = true;
            this.layoutControlItemScrape.Visibility = LayoutVisibility.Always;
            this.layoutControlItemProgress.Visibility = LayoutVisibility.Never;
            grpMain.Enabled = true;
            if (ImportMoviesFactory.ImportDuplicatesDatabase.Count > 0)
            {
                string movies = "";
                BindingList<string> moviesCounted = new BindingList<string>();
                foreach (var movie in ImportMoviesFactory.ImportDuplicatesDatabase)
                {
                    var result = (from m in ImportMoviesFactory.ImportDuplicatesDatabase where (m.Title.ToLower().Trim() == movie.Title.ToLower().Trim()) select m).ToList();
                    if (result.Count > 1)
                    {
                        if (!moviesCounted.Contains(movie.Title))
                        {
                            movies += movie.Title + " (multiple), ";
                            moviesCounted.Add(movie.Title);
                        }
                    }
                    else
                    {
                        movies += movie.Title + ", ";
                    }
                }
                XtraMessageBox.Show(string.Format("{0} scanned movies already exists in the database:\n{1}", 
                    ImportMoviesFactory.ImportDuplicatesDatabase.Count, movies.Substring(0, movies.Length - 2)), "Duplicate movies found");

                InternalApps.Logs.Log.WriteToLog(LogSeverity.Info, 0, string.Format("{0} duplicate movies found: {1}",
                    ImportMoviesFactory.ImportDuplicatesDatabase.Count, movies.Substring(0, movies.Length - 2)), "ImportMoviesUC > RunWorkerCompleted");
            }
        }
Example #36
0
        private bool CheckLabelsListWithXml(out string summary_results)
        {
            TextWriter summary_file_csv = null;
            TextWriter summary_file_html = null;

            bool Is_LabelsList_Valid = true;
            summary_results = "";

            string[] str_temp;

            try
            {

                DateTime start_time, end_time;
                TimeSpan ts, ts_start, ts_end, total_time, total_time_inv;
                string category, current_label, readline;

                //Create Summary Lists
                BindingList<string> List_Annotated = new BindingList<string>();
                BindingList<string> List_NoAnnotated = new BindingList<string>();
                BindingList<string> List_Invalid = new BindingList<string>();

                BindingList<TimeSpan> List_Time = new BindingList<TimeSpan>();
                BindingList<TimeSpan> List_Time_Inv = new BindingList<TimeSpan>();

                BindingList<string> List_Current_XML;

                //Create the files for summarizing results
                // Create the csv file
                if (File.Exists(Folder_audioannotation + "AnnotationSummary.csv"))
                { File.Delete(Folder_audioannotation + "AnnotationSummary.csv"); }

                summary_file_csv = new StreamWriter(Folder_audioannotation + "AnnotationSummary.csv");
                summary_file_csv.WriteLine("Label,Time(hh:mm:ss)");

                // Create the html file
                if (File.Exists(Folder_audioannotation + "AnnotationSummary.html"))
                { File.Delete(Folder_audioannotation + "AnnotationSummary.html"); }

                summary_file_html = new StreamWriter(Folder_audioannotation + "AnnotationSummary.html");

                summary_file_html.WriteLine("<table border=\"1\">\n");
                summary_file_html.WriteLine("<tr><td>Label</td><td>Time(hh:mm:ss)</td></tr>");

                // ---------- Load labels ------------------

                int count = 0;
                int index = 0;

                for (int c = 1; c <= 2; c++)
                {
                    //Initialize lists
                    List_Annotated.Clear();
                    List_NoAnnotated.Clear();
                    List_Invalid.Clear();
                    List_Time.Clear();
                    List_Time_Inv.Clear();

                    total_time = TimeSpan.Zero;
                    total_time_inv = TimeSpan.Zero;

                    //Indicate the category
                    if (c == 1)
                    {
                        count = LabelsList_1.Count;
                        List_Current_XML = list_category_1;
                        //category = "Postures";
                        category = list_category_name[0];

                    }
                    else
                    {
                        count = LabelsList_2.Count;
                        List_Current_XML = list_category_2;
                        //category = "Activities";
                        category = list_category_name[1];
                    }

                    //Read each item from the list
                    for (int i = 0; i < count; i++)
                    {
                        if (c == 1)
                        { readline = LabelsList_1[i]; }
                        else
                        { readline = LabelsList_2[i]; }

                        string[] tokens = readline.Split(';');

                        //Check the row has valid start/end times
                        if (tokens[0].CompareTo("ok") == 0)
                        {
                            current_label = tokens[5];

                            //filter labels comming from blank rows
                            if (current_label.Trim().CompareTo("") != 0)
                            {

                                //Check if the label is valid according to the Xml protocol list
                                //if not, flag the label as invalid
                                if (List_Current_XML.Contains(current_label))
                                {
                                    //Start Time
                                    str_temp = tokens[3].Split('.');

                                    start_time = DateTime.Parse(StartDate + " " + str_temp[0]);
                                    ts_start = (start_time - new DateTime(1970, 1, 1, 0, 0, 0));

                                    //Stop Time
                                    str_temp = tokens[4].Split('.');

                                    end_time = DateTime.Parse(EndDate + " " + str_temp[0]);
                                    ts_end = (end_time - new DateTime(1970, 1, 1, 0, 0, 0));

                                    ts = ts_end.Subtract(ts_start);

                                    total_time = total_time + ts;

                                        if (!List_Annotated.Contains(current_label))
                                        {
                                            List_Annotated.Add(current_label);
                                            List_Time.Add(ts);
                                        }
                                        else
                                        {
                                            index = List_Annotated.IndexOf(current_label);
                                            //ts_start = List_Time[index];
                                            //ts = ts + ts_start;
                                            List_Time[index] = ts + List_Time[index];
                                        }

                                    //Check if the total time spend on this label makes sense (greater than 0)
                                    //If so, add the label to the annotated list
                                    //Otherwise, highlighted as problematic and don't generate the xml file
                                    if ( ts.TotalSeconds == 0)
                                    {
                                        Is_LabelsList_Valid = false;

                                        #region  highlight label in yellow

                                        int iloop = 0;
                                        int irow = 0;

                                        while(iloop <2)
                                        {
                                           if(iloop == 0)
                                           {   //Highlight Start Row
                                               irow = Int32.Parse(tokens[1]);
                                           }
                                           else if(iloop == 1)
                                           {    //Highlight End Row
                                                irow = Int32.Parse(tokens[2]);
                                           }

                                           iloop++;

                                           if (c == 1)
                                           {
                                                dataGridView1.Rows[irow].Cells[C1.category_label].Style.BackColor = System.Drawing.Color.Khaki;
                                                dataGridView1.Rows[irow].Cells[C1.category_label].Style.ForeColor = System.Drawing.Color.DimGray;

                                                dataGridView1.Rows[irow].Cells[C1.StartEnd].Style.BackColor = System.Drawing.Color.Khaki;
                                                dataGridView1.Rows[irow].Cells[C1.StartEnd].Style.ForeColor = System.Drawing.Color.DimGray;
                                           }
                                            else if (c == 2)
                                            {
                                                dataGridView1.Rows[irow].Cells[C2.category_label].Style.BackColor = System.Drawing.Color.Khaki;
                                                dataGridView1.Rows[irow].Cells[C2.category_label].Style.BackColor = System.Drawing.Color.DimGray;

                                                dataGridView1.Rows[irow].Cells[C2.StartEnd].Style.BackColor = System.Drawing.Color.Khaki;
                                                dataGridView1.Rows[irow].Cells[C2.StartEnd].Style.ForeColor = System.Drawing.Color.DimGray;
                                            }

                                        }

                                        #endregion

                                    }

                                }
                                // if label not found in xml protocol, flag as invalid
                                else
                                {
                                    Is_LabelsList_Valid = false;

                                    #region higlight row in red
                                        int iloop = 0;
                                        int irow = 0;

                                        while (iloop < 2)
                                        {
                                            if (iloop == 0)
                                            {   //Highlight Start Row
                                                irow = Int32.Parse(tokens[1]);
                                            }
                                            else if (iloop == 1)
                                            {    //Highlight End Row
                                                irow = Int32.Parse(tokens[2]);
                                            }

                                            iloop++;

                                            if (c == 1)
                                            {
                                                dataGridView1.Rows[irow].Cells[C1.category_label].Style.BackColor = System.Drawing.Color.Tomato;
                                                dataGridView1.Rows[irow].Cells[C1.category_label].Style.ForeColor = System.Drawing.Color.White;

                                                dataGridView1.Rows[irow].Cells[C1.StartEnd].Style.BackColor = System.Drawing.Color.Tomato;
                                                dataGridView1.Rows[irow].Cells[C1.StartEnd].Style.ForeColor = System.Drawing.Color.White;
                                            }
                                            else if (c == 2)
                                            {
                                                dataGridView1.Rows[irow].Cells[C2.category_label].Style.BackColor = System.Drawing.Color.Tomato;
                                                dataGridView1.Rows[irow].Cells[C2.category_label].Style.BackColor = System.Drawing.Color.White;

                                                dataGridView1.Rows[irow].Cells[C2.StartEnd].Style.BackColor = System.Drawing.Color.Tomato;
                                                dataGridView1.Rows[irow].Cells[C2.StartEnd].Style.ForeColor = System.Drawing.Color.White;
                                            }

                                        }

                                    #endregion

                                    //Start Time
                                    str_temp = tokens[3].Split('.');

                                    start_time = DateTime.Parse(StartDate + " " + str_temp[0]);
                                    ts_start = (start_time - new DateTime(1970, 1, 1, 0, 0, 0));

                                    //Stop Time
                                    str_temp = tokens[4].Split('.');

                                    end_time = DateTime.Parse(EndDate + " " + str_temp[0]);
                                    ts_end = (end_time - new DateTime(1970, 1, 1, 0, 0, 0));

                                    ts = ts_end.Subtract(ts_start);
                                    total_time_inv = total_time_inv + ts;

                                    if (!List_Invalid.Contains(current_label))
                                    {
                                        List_Invalid.Add(current_label);
                                        List_Time_Inv.Add(ts);
                                    }
                                    else
                                    {
                                        index = List_Invalid.IndexOf(current_label);
                                        ts_start = List_Time_Inv[index];
                                        ts = ts + ts_start;
                                        List_Time_Inv[index] = ts;
                                    }
                                }

                            }
                            //else (if label == blank), do nothing

                        }//if token ok

                    }//for labels list per category

                    //------------------------------------------
                    //Compute the No-Annotated Labels
                    //check for blank labels
                    foreach(string ilabel in List_Current_XML)
                    {
                        if (ilabel.Trim().CompareTo("") != 0)
                        {
                            if (!List_Annotated.Contains(ilabel))
                            {
                                List_NoAnnotated.Add(ilabel);
                            }
                        }
                        //else if(label == blank), do nothing
                    }

                    //------------------------------------------
                    // Write the summary of results to file
                    //-------------------------------------------
                    string font_color_open = "";
                    string font_color_close = "";

                    // Annotatated List
                    summary_file_csv.WriteLine("Annotated "+ category + ",");
                    summary_results = summary_results + "Annotated " + category + ":,," + "#" + ";";

                    summary_file_html.WriteLine("<tr bgcolor=\"#E6E6E6\">\n<td><strong>Annotated " + category + "</strong></td><td>&nbsp;</td></tr>");

                    int it = 0;
                    foreach (string clabel in List_Annotated)
                    {
                        ts = List_Time[it];

                        // Save record to the correspondent session
                        summary_file_csv.WriteLine(clabel + "," + ts.ToString());
                        summary_file_html.WriteLine("<tr>\n<td>" + clabel + "</td><td>" + ts.ToString() + "</td></tr>");
                        summary_results = summary_results + clabel + "," + ts.ToString() + ";";
                        it++;
                    }

                    summary_file_csv.WriteLine("Total Time Annotated "+ category + "," + total_time.ToString());
                    summary_file_csv.WriteLine("");

                    font_color_open = "<strong><font color=\"#4E8975\">";
                    font_color_close = "</font><strong>";
                    summary_file_html.WriteLine("<tr>\n<td>"+ font_color_open +"Total Time Annotated " + category + font_color_close +"</td>" +
                                                      "<td>"+ font_color_open + total_time.ToString() + font_color_close + "</td></tr>");
                    summary_file_html.WriteLine("<tr>\n<td>&nbsp;</td><td>&nbsp;</td></tr>");

                    summary_results = summary_results + "Total Time Annotated " + category + "," + total_time.ToString() + ",##;";
                    summary_results = summary_results +";";

                    // No Annotated List
                    summary_file_csv.WriteLine("No Annotated " + category + " in Xml Protocol,");
                    summary_file_html.WriteLine("<tr bgcolor=\"#E6E6E6\">\n<td><strong>No Annotated " + category + " in Xml Protocol</strong></td><td>&nbsp;</td></tr>");
                    summary_results = summary_results + "No Annotated " + category + " in Xml Protocol:,,#" + ";";

                    foreach (string jlabel in List_NoAnnotated)
                    {   summary_file_csv.WriteLine(jlabel);
                        summary_file_html.WriteLine("<tr>\n<td>" + jlabel + "</td><td>&nbsp;</td></tr>");
                        summary_results = summary_results + jlabel + ";";
                    }

                    summary_file_csv.WriteLine("");
                    summary_file_html.WriteLine("<tr>\n<td>&nbsp;</td><td>&nbsp;</td></tr>");
                    summary_results = summary_results + ";";

                    summary_file_csv.WriteLine("Invalid " + category + ",");
                    summary_file_html.WriteLine("<tr bgcolor=\"#E6E6E6\">\n<td><strong> Invalid " + category + "</strong></td><td>&nbsp;</td></tr>");
                    summary_results = summary_results + "Invalid " + category + ":,," + "#" + ";";

                    font_color_open = "<font color=\"#FA5858\">";
                    font_color_close = "</font>";

                    it = 0;
                    foreach (string klabel in List_Invalid)
                    {
                        ts = List_Time_Inv[it];

                        // Save record to the correspondent session
                        summary_file_csv.WriteLine(klabel + "," + ts.ToString());
                        summary_file_html.WriteLine("<tr>\n<td>" + font_color_open + klabel + font_color_close + "</td>" +
                                                          "<td>" + font_color_open + ts.ToString() + font_color_close + "</td></tr>");
                        summary_results = summary_results + klabel + "," + ts.ToString() + ",###;";

                        it++;
                    }

                    summary_file_csv.WriteLine("Total Time Invalid " + category + "," + total_time_inv.ToString());
                    summary_file_csv.WriteLine("");

                    font_color_open = "<strong><font color=\"#FA5858\">";
                    font_color_close = "</font></strong>";
                    summary_file_html.WriteLine("<tr>\n<td>"+ font_color_open + "Total Time Invalid " + category + font_color_close+"</td>" +
                                                "<td>"+ font_color_open + total_time_inv.ToString() + font_color_close + "</td></tr>");
                    summary_file_html.WriteLine("<tr>\n<td>&nbsp;</td><td>&nbsp;</td></tr>");

                    summary_results = summary_results + "Total Time Invalid " + category + "," + total_time_inv.ToString() + ",#-;";
                    summary_results = summary_results + ";";

                   //--------------------------------------------

                }//for each category label

                // Close summary file csv
                summary_file_csv.Flush();
                summary_file_csv.Close();

                // Close summary file csv
                summary_file_html.WriteLine("</table>");
                summary_file_html.Flush();
                summary_file_html.Close();

                return Is_LabelsList_Valid;
            }
            catch
            {
                Is_LabelsList_Valid = false;

                if (summary_file_csv != null)
                {
                    summary_file_csv.Flush();
                    summary_file_csv.Close();

                }

                if (summary_file_html != null)
                {
                    summary_file_html.Flush();
                    summary_file_html.Close();

                }

                return Is_LabelsList_Valid;
            }
        }
Example #37
0
        private static BindingList<PlayListItem> GetOrderedPlayListItems(List<PlayListItem> list)
        {
            var result = new BindingList<PlayListItem>();
            foreach (var playListItem in list.Where(playListItem => playListItem != null && !result.Contains(playListItem)))
            {
                if (playListItem.Group <= 0)
                {
                    result.Add(playListItem);
                    continue;
                }

                result.Add(playListItem);
                var item = playListItem;
                foreach (var groupedItemToAdd in list.Where(p => p != item && p.Group == item.Group))
                    result.Add(groupedItemToAdd);
            }

            return result;
        }
        public SolitaireGame()
        {
            Width = DefaultWidth;
            Height = DefaultHeight;

            System.Console.WriteLine("--- solitare ---");

            this.MyStatus = new StatusControl().AttachContainerTo(this).MoveContainerTo(
                (DefaultWidth - StatusControl.Width) / 2,
                (DefaultHeight - StatusControl.Height)
            );


            var GameOverBox = new TextBox
            {
                Width = DefaultWidth,
                TextAlignment = System.Windows.TextAlignment.Center,
                Foreground = Brushes.White,
                Background = Brushes.Transparent,
                BorderThickness = new Thickness(0),
                IsReadOnly = true,
                FontSize = 24,
            }.MoveTo(0, DefaultHeight / 2).AttachTo(this);


            // add autoscroll ?
            this.MyDeck.SizeTo(DefaultWidth, DefaultHeight);
            this.MyDeck.AttachContainerTo(this);
            this.MyDeck.GetRank = e => (int)RankMapping[e];


            System.Console.WriteLine("adding card infos... ");

            MyDeck.UnusedCards.AddRange(CardInfo.FullDeck());

            this.MyStatus.Score = -1;
            this.MyStatus.CardsLeft = this.MyDeck.UnusedCards.Count;
            this.MyStatus.Update();


            MyDeck.Stacks.ListChanged +=
                (sender, args) =>
                {
                    if (args.ListChangedType == ListChangedType.ItemAdded)
                    {
                        // fixme: dynamically set backside for this card

                        //var s = MyDeck.Stacks[args.NewIndex];
                        //s.SetBackground(MyDeck.GfxPath + "/spider.empty.png");
                    }
                };


            System.Console.WriteLine("creating stacklists... ");

            PlayStacks = MyDeck.CreateStackList();
            TempStacks = MyDeck.CreateStackList();
            GoalStacks = MyDeck.CreateStackList();

            PlayStacks.ForEachNewItem(
                delegate(CardStack s)
                {
                    s.CardMargin = new Vector { Y = 20 };
                    s.Update();

                    s.Cards.ListChanged +=
                        (sender, args) =>
                        {
                            if (args.ListChangedType == ListChangedType.ItemDeleted)
                                s.RevealLastCard();
                        };

                }
            );



            GameOver += delegate
            {
                GameOverBox.Text = "Congratulations! You Won!";
            };


            System.Console.WriteLine("creating goalstack... ");

            var Margin = (DefaultWidth - CardInfo.Width * 7) / 8;

            var ReserveStack = new CardStack().MoveTo(Margin, Margin);
            var UsedChoiceStack = new CardStack().MoveTo(Margin + CardInfo.Width + Margin, Margin);
            var ChoiceStack = new CardStack().MoveTo(Margin + CardInfo.Width + Margin, Margin);


            TempStacks.AddRange(
                ReserveStack,
                UsedChoiceStack,
                ChoiceStack
            );


            ReserveStack.CardMargin.X = 0;
            ReserveStack.CardMargin.Y = 0;

            UsedChoiceStack.CardMargin.X = 0;
            UsedChoiceStack.CardMargin.Y = 0;

            ChoiceStack.CardMargin.X = 20;
            ChoiceStack.CardMargin.Y = 0;



            #region rules
            Func<bool> Rule_WinConditionMet =
                delegate
                {
                    if (PlayStacks.All(s => s.Cards.Count > 0))
                        return false;

                    if (TempStacks.All(s => s.Cards.Count == 0))
                        return false;

                    return true;
                };

            Func<Card, Card, bool> RuleForStackingCardsInGoalStack =
                (Previous, Current) =>
                {
                    if (Cheat)
                        return true;

                    if (Previous == null)
                        return Current.Info.Rank == CardInfo.RankEnum.RankAce;

                    if (Previous.Info.Suit != Current.Info.Suit)
                        return false;

                    if (Previous.Rank != Current.Rank + 1)
                        return false;

                    return true;
                };

            Func<Card, Card, bool> RuleForStackingCardsInPlayStack =
                (Previous, Current) =>
                {
                    if (Cheat)
                        return true;

                    if (Previous.Info.SuitColor == Current.Info.SuitColor)
                        return false;

                    if (Previous.Rank + 1 != Current.Rank)
                        return false;

                    return true;
                };

            #endregion

            MyDeck.ApplyCardRules += delegate(Card card)
            {
                card.MovedByLocalPlayer +=
                    delegate
                    {
                        MyStatus.Moves++;
                        MyStatus.Update();

                    };

                card.ValidateDragStart =
                    delegate
                    {
                        if (Cheat)
                            return true;

                        // cannot remove cards from goal stack
                        if (GoalStacks.Contains(card))
                            return false;

                        if (TempStacks.Contains(card))
                        {
                            return (card == ChoiceStack.LastOrDefault());
                        }

                        // cannot drag a pile of cards unless alternate colors and descending numbers
                        return card.SelectedCards.AllWithPrevious(RuleForStackingCardsInPlayStack);
                    };


                card.ValidateDragStop =
                    CandidateStack =>
                    {
                        if (Cheat)
                            return true;

                        if (TempStacks.Contains(CandidateStack))
                        {
                            return false;
                        }

                        if (PlayStacks.Contains(CandidateStack))
                        {
                            if (CandidateStack.Cards.Count == 0)
                                return card.Info.Rank == CardInfo.RankEnum.RankKing;


                            return (RuleForStackingCardsInPlayStack(CandidateStack.Cards.Last(), card));
                        }

                        if (GoalStacks.Contains(CandidateStack))
                        {
                            if (card.StackedCards.Length > 0)
                                return false;

                            return (RuleForStackingCardsInGoalStack(CandidateStack.Cards.LastOrDefault(), card));

                        }

                        return false;
                    };
            };



            GoalStacks.ForEachNewItem(
                s =>
                {
                    s.CardMargin.X = 0;
                    s.CardMargin.Y = 0;

                    s.Cards.ForEachNewItem(
                        card =>
                        {
                            this.MyStatus.CardsLeft--;
                            this.MyStatus.Update();

                            if (card.Info.Rank == CardInfo.RankEnum.RankKing)
                            {

                                card.VisibleSide = Card.SideEnum.BackSide;


                                if (Rule_WinConditionMet())
                                {
                                    // winner!
                                    MyDeck.Sounds.win();

                                    if (this.GameOver != null)
                                        this.GameOver();
                                }
                            }
                        }
                    );
                }
            );
            GoalStacks.AddRange(
                Enumerable.Range(0, 4).ToArray(
                    i => new CardStack().MoveTo(DefaultWidth - ((CardInfo.Width + Margin) * 4) + i * (CardInfo.Width + Margin), Margin)
                )
            );

            System.Console.WriteLine("creating playstack... ");

            PlayStacks.AddRange(
                Enumerable.Range(0, 7).ToArray(
                    i => new CardStack().MoveTo(Margin + i * (CardInfo.Width + Margin), Margin * 3 + CardInfo.Height).Apply(s => s.Cards.AddRange(MyDeck.FetchCards(i + 1)))
                )
            );

            ReserveStack.Cards.AddRange(MyDeck.FetchCards(MyDeck.UnusedCards.Count));
            ReserveStack.Update();

            PlayStacks.ForEach(k => k.Last().VisibleSide = Card.SideEnum.TopSide);


            UsedChoiceStack.Cards.ForEachNewItem(
                card => card.VisibleSide = Card.SideEnum.BackSide
            );

            ChoiceStack.Cards.ForEachNewItem(
                card => card.VisibleSide = Card.SideEnum.TopSide
            );

            ChoiceStack.Click +=
                delegate
                {
                    ChoiceStack.Update();
                }
            ;

            ReserveStack.Overlay.Cursor = Cursors.Hand;
            ReserveStack.Cards.ForEachNewItem(
                card => card.VisibleSide = Card.SideEnum.BackSide
            );





            var ReserveStackEnabled = true;

            ReserveStack.Click +=
                delegate
                {
                    if (!ReserveStackEnabled)
                        return;

                    if (ReserveStack.Cards.Count == 0)
                    {
                        MyDeck.Sounds.deal();

                        ChoiceStack.FirstOrDefault().Apply(
                            card =>
                            {

                                card.AnimatedMoveToStack(ReserveStack, null, null);
                            }
                        );

                        UsedChoiceStack.FirstOrDefault().Apply(
                            card =>
                            {

                                card.AnimatedMoveToStack(ReserveStack, null, null);
                            }
                        );
                    }
                    else
                    {
                        ReserveStackEnabled = false;


                        ChoiceStack.Cards.ToArray().ForEach(
                            card =>
                            {
                                card.AttachToStack(UsedChoiceStack);
                            }
                        );
                        UsedChoiceStack.Update();

                        3.Times(
                            SignalNext =>
                                ReserveStack.LastOrDefault().Apply(
                                    card =>
                                    {
                                        card.BringToFront();

                                        Console.WriteLine(card.ToString());

                                        card.AnimatedMoveToStack(ChoiceStack, null, null);

                                        MyDeck.Sounds.deal();

                                        200.AtDelay(SignalNext);
                                    }
                                )
                        );

                    }


                    // a timepoint when movements are done.. this should ba an event actually
                    2000.AtDelay(() => ReserveStackEnabled = true);

                };
        }
Example #39
0
        public SpiderGame(CardInfo.SuitEnum[] level)
        {
            Width = DefaultWidth;
            Height = DefaultHeight;

            //this.ClipTo(0, 0, DefaultWidth, DefaultHeight);

            var GameOverBox = new TextBox
            {
                Width = DefaultWidth,
                TextAlignment = System.Windows.TextAlignment.Center,
                Foreground = Brushes.White,
                Background = Brushes.Transparent,
                BorderThickness = new Thickness(0),
                IsReadOnly = true,
                FontSize = 24,
            }.MoveTo(0, DefaultHeight / 2).AttachTo(this);

            GameOver += delegate
            {
                GameOverBox.Text = "Congratulations! You Won!";
            };


            // add autoscroll ?
            this.MyDeck.SizeTo(DefaultWidth, DefaultHeight);
            this.MyDeck.AttachContainerTo(this);
            this.MyDeck.GetRank = e => (int)RankMapping[e];
            this.MyDeck.CardCustomBackgroundSource = new Abstractatech.Avalon.Cards.Avalon.Images.spider().Source;


            //this.MyDeck.Overlay.Opacity = 0.6;

            MyStatus = new StatusControl().AttachContainerTo(this).MoveContainerTo(
                (DefaultWidth - StatusControl.Width) / 2,
                (DefaultHeight - StatusControl.Height)
            );
            MyStatus.Container.Hide();

            System.Console.WriteLine("--- spider ---");






            System.Console.WriteLine("adding card infos... ");

            MyDeck.UnusedCards.AddRange(CardInfo.By(2, level));




            System.Console.WriteLine("creating stacklists... ");

            DealStacks = MyDeck.CreateStackList();
            PlayStacks = MyDeck.CreateStackList();
            DeadStacks = MyDeck.CreateStackList();

            PlayStacks.ListChanged +=
                (sender, args) =>
                {
                    if (args.ListChangedType == ListChangedType.ItemAdded)
                    {
                        var s = PlayStacks[args.NewIndex];


                    }

                };



            DeadStacks.ListChanged +=
                (sender, args) =>
                {
                    if (args.ListChangedType == ListChangedType.ItemAdded)
                    {
                        var s = DeadStacks[args.NewIndex];

                        //s.Control.Hide();

                        s.CardMargin = new Vector { X = 2, Y = 0 };

                        s.Cards.ListChanged +=
                            (sender2, args2) =>
                            {
                                if (args2.ListChangedType == ListChangedType.ItemAdded)
                                {
                                    //s[args2.NewIndex].Enabled = false;
                                }

                            };

                    }
                };


            #region drag rules
            MyDeck.ApplyCardRules += delegate(Card c)
            {
                c.Moved +=
                     delegate
                     {
                         if (c.StackedCards.Length == 0)
                         {
                             CheckForGoodSuit(c.CurrentStack);

                             MyStatus.Moves++;
                             MyStatus.Score--;

                             MyStatus.Update();
                         }

                         CheckForWin();
                     };

                c.ValidateDragStart +=
                    delegate
                    {
                        if (Cheat)
                            return true;

                        return c.SelectedCards.AllWithPrevious(
                            (Previous, Current) =>
                            {
                                if (Previous.Info.Suit != Current.Info.Suit)
                                    return false;

                                return Previous.Rank + 1 == Current.Rank;
                            }
                        );
                    };

                c.ValidateDragStop +=
                    CandidateStack =>
                    {
                        if (Cheat)
                            return true;


                        if (PlayStacks.Contains(CandidateStack))
                        {
                            if (CandidateStack.Cards.Count == 0)
                                return true;

                            var Candidate = CandidateStack.Last();

                            // we do not care about the suit

                            if (c.Rank == Candidate.Rank + 1)
                                //if (c.Info.Suit == Candidate.Info.Suit)
                                return true;

                            return false;
                        }

                        return false;
                    };
            };

            #endregion

            System.Console.WriteLine("creating playstack... ");

            var Margin = (DefaultWidth - CardInfo.Width * 10) / 11;


            PlayStacks.AddRange(
                Enumerable.Range(0, 10).ToArray(
                i =>
                    new CardStack
                    {
                        Name = "PlayStack " + i,
                        CardMargin = new Vector { Y = 20 }
                    }.MoveTo(
                        Margin + i * (CardInfo.Width + Margin),
                        Margin + 40
                    ).Apply(
                        s =>
                        {
                            if (i < 4)
                                s.Cards.AddRange(MyDeck.FetchCards(5));
                            else
                                s.Cards.AddRange(MyDeck.FetchCards(4));

                            if (Cheat)
                                s.Cards.ForEach(k => k.VisibleSide = Card.SideEnum.TopSide);

                        }
                    )
                )
            );


            PlayStacks.ForEach(
                delegate(CardStack s)
                {

                    s.Cards.ListChanged +=
                        (sender, args) =>
                        {
                            if (args.ListChangedType == ListChangedType.ItemDeleted)
                                //if (MyStatus.Ready)
                                s.RevealLastCard();
                        };

                }
            );


            DealStacks.ListChanged +=
                (sender, args) =>
                {
                    if (args.ListChangedType == ListChangedType.ItemAdded)
                    {
                        var s = DealStacks[args.NewIndex];

                        s.CardMargin = new Vector { Y = 0, X = 0 };
                        s.Update();

                        s.Click +=
                            delegate
                            {
                                if (DealStacks.Contains(s))
                                {
                                    //if (MyStatus.Ready)
                                    DealRow(null);
                                }
                                else
                                {
                                    System.Console.WriteLine("whoops wrong stack click - " + args.NewIndex);

                                }
                            };
                    }
                };


            System.Console.WriteLine("creating dealstack... ");

            var dealpoint = new Point
            {
                X = DefaultWidth - CardInfo.Width - Margin,
                Y = DefaultHeight - CardInfo.Height - Margin - 17 - Margin
            };


            while (MyDeck.UnusedCards.Count > 0)
            {
                var s = new CardStack { MyDeck.FetchCards(10) };
                //s.Overlay.Opacity = 1;
                s.Name = "DealStack";

                DealStacks.Add(
                    s.MoveTo(Convert.ToInt32(dealpoint.X), Convert.ToInt32(dealpoint.Y))
                );

                dealpoint.X -= 10;
            }

            // we will collect cards here
            DeadStacks.Add(new CardStack().MoveTo(Margin, Convert.ToInt32(dealpoint.Y)));



            DealRow(
                delegate
                {

                    MyStatus.Score = 500;
                    MyStatus.Moves = 0;
                    MyStatus.Update();
                    MyStatus.Container.Show();
                }
            );



        }
 /// <summary>
 /// Get a list of the shipclasses in orbit. this wll be needed to help prune repair/refit/scrap operation options.
 /// </summary>
 /// <param name="CurrentFaction">Current faction from the economics handler</param>
 /// <param name="CurrentPopulation">Current Population from the economics handler.</param>  
 /// <param name="ClassesInOrbit">List of shipclasses in orbit around CurrentPopulation.</param>        
 private static void GetShipClassesInOrbit(Faction CurrentFaction, Population CurrentPopulation, ref BindingList<ShipClassTN> ClassesInOrbit)
 {
     ClassesInOrbit.Clear();
     foreach (TaskGroupTN CurrentTaskGroup in CurrentPopulation.Planet.TaskGroupsInOrbit)
     {
         if (CurrentTaskGroup.TaskGroupFaction == CurrentFaction)
         {
             foreach (ShipTN CurrentShip in CurrentTaskGroup.Ships)
             {
                 if (ClassesInOrbit.Contains(CurrentShip.ShipClass) == false)
                     ClassesInOrbit.Add(CurrentShip.ShipClass);
             }
         }
     }
 }
Example #41
0
        public FreeCellGame()
        {
            Width = DefaultWidth;
            Height = DefaultHeight;


            var Margin = (DefaultWidth - CardInfo.Width * 8) / 9;

            var GameOverBox = new TextBox
            {
                Width = DefaultWidth,
                TextAlignment = System.Windows.TextAlignment.Center,
                Foreground = Brushes.White,
                Background = Brushes.Transparent,
                BorderThickness = new Thickness(0),
                IsReadOnly = true,
                FontSize = 24,
            }.MoveTo(0, DefaultHeight / 2).AttachTo(this);

            GameOver += delegate
            {
                GameOverBox.Text = "Congratulations! You Won!";
            };

            #region king
            var KingCanvas = new Canvas
            {
                Width = 96,
                Height = 96
            }.AttachTo(this).MoveTo(
                (DefaultWidth - 32) / 2,
                Margin * 2 + (CardInfo.Height - 32) / 2
            );

            var KingRight = new kingbitm().AttachTo(KingCanvas);

            var KingLeft = new kingleft().AttachTo(KingCanvas);

            var KingSmile = new kingsmil().AttachTo(KingCanvas);

            KingSmile.Hide();

            #endregion

            this.MyDeck.Overlay.MouseMove +=
                (sender, args) =>
                {
                    var p = args.GetPosition(this.MyDeck.Overlay);

                    if (p.X < DefaultWidth / 2)
                    {
                        KingLeft.Show();
                        KingRight.Hide();
                    }
                    else
                    {
                        KingLeft.Hide();
                        KingRight.Show();
                    }
                };

            this.MyStatus = new StatusControl().AttachContainerTo(this).MoveContainerTo(
                (DefaultWidth - StatusControl.Width) / 2,
                (DefaultHeight - StatusControl.Height)
            );



            //this.MyStatus.Container.Hide();

            // add autoscroll ?
            this.MyDeck.SizeTo(DefaultWidth, DefaultHeight);
            this.MyDeck.AttachContainerTo(this);
            this.MyDeck.GetRank = e => (int)RankMapping[e];

            System.Console.WriteLine("--- freecell ---");

            System.Console.WriteLine("adding card infos... ");

            MyDeck.UnusedCards.AddRange(CardInfo.FullDeck());

            this.MyStatus.CardsLeft = MyDeck.UnusedCards.Count;
            this.MyStatus.Score = -1;
            this.MyStatus.Update();

            System.Console.WriteLine("creating stacklists... ");

            PlayStacks = MyDeck.CreateStackList();
            PlayStacks.ForEachNewItem(
                k =>
                {
                    k.CardMargin = new Vector { Y = 20 };
                    k.Update();
                }
            );

            TempStacks = MyDeck.CreateStackList();

            Func<bool> Rule_WinConditionMet =
                delegate
                {
                    if (PlayStacks.All(s => s.Cards.Count > 0))
                        return false;

                    if (TempStacks.All(s => s.Cards.Count == 0))
                        return false;

                    return true;
                };

            Action MyStatus_UpdateCardsLeft =
                delegate
                {

                    MyStatus.CardsLeft = 0;

                    PlayStacks.ForEach(q => MyStatus.CardsLeft += q.Cards.Count);
                    TempStacks.ForEach(q => MyStatus.CardsLeft += q.Cards.Count);
                };

            GoalStacks = MyDeck.CreateStackList();
            GoalStacks.ForEachNewItem(
                k =>
                {

                    k.CardMargin.Y = 0;

                    k.Cards.ForEachNewItem(
                        card =>
                        {
                            Console.WriteLine("GoalStacks ForEachNewItem " + new { k.CardMargin.Y });

                            if (card.Info.Rank == CardInfo.RankEnum.RankKing)
                            {
                                KingSmile.Show();

                                card.VisibleSide = Card.SideEnum.BackSide;


                                if (Rule_WinConditionMet())
                                {
                                    // winner!
                                    MyDeck.Sounds.win();

                                    if (this.GameOver != null)
                                        this.GameOver();
                                }
                                else
                                {
                                    600.AtDelay(KingSmile.Hide);
                                }
                            }


                            MyStatus_UpdateCardsLeft();
                            MyStatus.Update();
                        }
                    );
                }
            );

            Func<Card, Card, bool> RuleForStackingCardsInGoalStack =
                (Previous, Current) =>
                {
                    if (Cheat)
                        return true;

                    if (Previous == null)
                        return Current.Info.Rank == CardInfo.RankEnum.RankAce;

                    if (Previous.Info.Suit != Current.Info.Suit)
                        return false;

                    if (Previous.Rank != Current.Rank + 1)
                        return false;

                    return true;
                };

            Func<Card, Card, bool> RuleForStackingCardsInPlayStack =
                (Previous, Current) =>
                {
                    if (Cheat)
                        return true;

                    if (Previous.Info.SuitColor == Current.Info.SuitColor)
                        return false;

                    if (Previous.Rank + 1 != Current.Rank)
                        return false;

                    return true;
                };


            #region rules
            MyDeck.ApplyCardRules += delegate(Card card)
            {

                #region MovedByLocalPlayer
                card.MovedByLocalPlayer +=
                    delegate
                    {
                        var FrozenTokens = new
                        {
                            card.CurrentStack,
                            card.PreviousStack
                        };

                        Console.WriteLine(new { HistoryMove = card, StackedCards = card.StackedCards.Length, Previous = card.PreviousStack, Current = card.CurrentStack }.ToString());

                        History.History.Add(
                            delegate
                            {


                                // we already are at the state we want to be
                                if (card.CurrentStack == FrozenTokens.PreviousStack)
                                    return;

                                card.VisibleSide = Card.SideEnum.TopSide;
                                card.AnimatedMoveToStack(FrozenTokens.PreviousStack, null);


                                this.MyDeck.Sounds.deal();

                                MyStatus.Moves--;
                                MyStatus_UpdateCardsLeft();
                                MyStatus.Update();
                            },
                            delegate
                            {
                                MyStatus.Moves++;
                                MyStatus.Update();

                                // we already are at the state we want to be
                                if (card.CurrentStack == FrozenTokens.CurrentStack)
                                    return;



                                card.AnimatedMoveToStack(FrozenTokens.CurrentStack, null);
                                this.MyDeck.Sounds.deal();



                            }
                        );
                    };
                #endregion


                card.VisibleSide = Card.SideEnum.TopSide;

                card.ValidateDragStart =
                    delegate
                    {
                        if (Cheat)
                            return true;

                        // cannot remove cards from goal stack
                        if (GoalStacks.Contains(card))
                            return false;

                        // cannot drag a pile of cards unless alternate colors and descending numbers
                        return card.SelectedCards.AllWithPrevious(RuleForStackingCardsInPlayStack);
                    };

                card.ValidateDragStop =
                    CandidateStack =>
                    {
                        if (Cheat)
                            return true;

                        if (TempStacks.Contains(CandidateStack))
                        {
                            // temp only holds one card
                            if (CandidateStack.Cards.Count > 0)
                                return false;

                            // and only one card can be inserted
                            if (card.StackedCards.Length > 0)
                                return false;

                            return true;
                        }

                        if (PlayStacks.Contains(CandidateStack))
                        {
                            if (CandidateStack.Cards.Count == 0)
                                return true;


                            return (RuleForStackingCardsInPlayStack(CandidateStack.Cards.Last(), card));
                        }

                        if (GoalStacks.Contains(CandidateStack))
                        {
                            if (CandidateStack.Cards.Count == 0)
                            {

                                return (RuleForStackingCardsInGoalStack(null, card));
                            }

                            return (RuleForStackingCardsInGoalStack(CandidateStack.Cards.Last(), card));

                        }

                        return false;
                    };
            };
            #endregion


            System.Console.WriteLine("creating goalstack... ");


            GoalStacks.AddRange(
                Enumerable.Range(0, 4).ToArray(
                    i =>
                        new CardStack
                        {
                            Name = "GoalStack " + i
                        }.MoveTo(
                            DefaultWidth - Margin / 2 - ((CardInfo.Width + Margin / 2) * 4) + i * (CardInfo.Width + Margin / 2),
                            Margin * 2
                        )
                )
            );

            System.Console.WriteLine("creating tempstack... ");


            TempStacks.AddRange(
                Enumerable.Range(0, 4).ToArray(
                    i => new CardStack
                    {
                        Name = "TempStack " + i
                    }.MoveTo(
                        Margin + i * (CardInfo.Width + Margin / 2),
                        Margin * 2
                    )
                )
            );

            System.Console.WriteLine("creating playstack... ");

            PlayStacks.AddRange(
                Enumerable.Range(0, 8).ToArray(
                    i => new CardStack
                    {
                        Name = "PlayStack " + i
                    }.MoveTo(
                        Margin + (i) * (CardInfo.Width + Margin),
                        Margin * 4 + CardInfo.Height
                    ).Apply(
                        s =>
                        {
                            var Count = 6;

                            if (i < 4)
                                Count = 7;

                            s.Cards.AddRange(MyDeck.FetchCards(Count));
                        }
                    )
                )
            );

        }