Example #1
0
        public static void SortDictKeys(List <DictionaryKey> dkeyMass, int first, int last)
        {
            DictionaryKey p = dkeyMass[(last - first) / 2 + first];
            DictionaryKey temp;
            int           i = first, j = last;

            while (i <= j)
            {
                while (dkeyMass[i].GetWord().Length < p.GetWord().Length&& i <= last)
                {
                    ++i;
                }
                while (dkeyMass[j].GetWord().Length > p.GetWord().Length&& j >= first)
                {
                    --j;
                }
                if (i <= j)
                {
                    temp        = dkeyMass[i];
                    dkeyMass[i] = dkeyMass[j];
                    dkeyMass[j] = temp;
                    ++i; --j;
                }
            }
            if (j > first)
            {
                SortDictKeys(dkeyMass, first, j);
            }
            if (i < last)
            {
                SortDictKeys(dkeyMass, i, last);
            }
        }
Example #2
0
 private void RunGamePC(object sender, EventArgs e)
 {
     if (personMadeTurn)
     {
         if (allCoordinates.Count != 0)
         {
             ChangeCellColorToDefault();
         }
         buttonPersonTurn.Text = "ХОД ИГРОКА";
         List <List <int> >   allPathes = pcTurn.PCMakesPathes();
         List <DictionaryKey> dkeysALL  = pcTurn.PCSetsPathesToWords(allPathes, sortDictionary);
         if (!pcTurn.KeyListIsEmpty(dkeysALL))
         // If PC has word(s) to make turn
         {
             object dkeyTemp = pcTurn.PCChooseWordForTurn(pcLevel, dkeysALL, sortDictionary);
             if (dkeyTemp != null)
             {
                 DictionaryKey dkey = (DictionaryKey)dkeyTemp;
                 pcWord = dkey.GetWord().ToUpper();
                 List <int> path = dkey.GetListKey();
                 for (int k = 0; k < path.Count; k++)
                 {
                     if (Char.Parse(dataGridViewMain.Rows[path[k] / 5].Cells[path[k] % 5].Value.ToString()) == '+')
                     {
                         j = path[k] / 5;
                         i = path[k] % 5;
                     }
                     dataGridViewMain.Rows[path[k] / 5].Cells[path[k] % 5].Value           = pcWord[k];
                     dataGridViewMain.Rows[path[k] / 5].Cells[path[k] % 5].Style.BackColor = Color.Red;
                     Coordinates localCoordinates = new Coordinates(path[k] / 5, path[k] % 5);
                     allCoordinates.Add(localCoordinates);
                 }
                 dataGridViewMain.Refresh();
                 buttonPCTurn.ForeColor = Color.Black;
                 buttonPCTurn.Text      = "ХОД КОМПЬЮТЕРА";
                 SetNeighborPlusOnDataGrid();
                 sortDictionary.Remove(pcWord.ToLower());
                 SetLetterForVertexMass();
                 SetPlusForVertexMass();
                 PCGetPoints();
                 CheckGridForLastTurn();
             }
             else
             {
                 PCSkipsTurn();
             }
         }
         else
         {
             PCSkipsTurn();
         }
     }
     else
     {
         DialogResult result = MessageBox.Show("Вы не составили слово после того, как поставили букву на поле. Продолжить ход?", "Выберите действие", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (result == DialogResult.Yes)
         // Person'll continue making a turn.
         {
             personAddedLetters = true;
             i1 = i;
             j1 = j;
             dataGridViewMain.Rows[j1].Cells[i1].Style.BackColor = System.Drawing.SystemColors.Highlight;
             dataGridViewMain.Rows[j1].Cells[i1].Style.ForeColor = Color.White;
             dataGridViewMain.ClearSelection();
             personMadeTurn = false;
         }
         else
         {
             PersonSkipsTurn(this, e);
         }
     }
 }