private void InitializeButtonLetters(List <Button> btnLettersToReplace, int maxLettersToReplace) { btnLetters = new List <Button>(); indicesLettersToReplace = new List <int>(); Letter letter = new Letter(); int x = 30; /* Places the buttons on the form , with the same * letters as in the main game form */ for (int i = 0; i < maxLettersToReplace; i++) { Button button = new Button() { Font = new Font("Cooper Black", 12F, FontStyle.Bold, GraphicsUnit.Point, 177), Location = new Point(x, 10), Size = new Size(30, 30), TabIndex = i, Tag = false, Text = btnLettersToReplace[i].Text }; button.BackColor = letter.GetColor(button.Text[0]); button.Click += new EventHandler(btnLetters_Click); btnLetters.Add(button); Controls.Add(button); x += 30; } }
private void InitializeLettersValuesGridView() { dgvLettersValues = new DataGridView() { AllowUserToResizeRows = false, AllowUserToResizeColumns = false, RowHeadersVisible = false, ColumnHeadersVisible = false, Enabled = false, Visible = false, Location = new Point(503, 18), Size = new Size(83, 445) }; DataGridViewTextBoxColumn letters = new DataGridViewTextBoxColumn(); DataGridViewTextBoxColumn points = new DataGridViewTextBoxColumn(); letters.Width = 40; points.Width = 40; dgvLettersValues.Columns.AddRange(new DataGridViewColumn[] { letters, points }); for (char ch = 'A'; ch <= 'Z'; ch++) { if (ch < 'Z') { dgvLettersValues.Rows.Add(); } Letter letter = new Letter(); DataGridViewRow currentRow = dgvLettersValues.Rows[ch - 'A']; currentRow.Height = 17; currentRow.Cells[0].Value = ch; currentRow.Cells[1].Value = letter.GetPoints(ch); // Updates row color , according to the color of the letter (for each letter) currentRow.DefaultCellStyle.BackColor = letter.GetColor(ch); } Controls.Add(dgvLettersValues); }
private void InitializeButtonLetters() { btnLetters = new Button[26]; int x = 300; int y = 10; char letter = 'A'; for (int i = 0; i < btnLetters.Length; i++) { btnLetters[i] = new Button() { Text = letter.ToString(), Location = new Point(x, y), Size = new Size(30, 30), Tag = lettersValues.FirstOrDefault(kvp => kvp.Key.Contains(letter)).Value }; btnLetters[i].Click += new EventHandler(btnLetters_Click); Controls.Add(btnLetters[i]); btnLetters[i].BringToFront(); x += 30; if (i % 6 == 5) { x = 300; y += 30; } letter++; } for (int i = 0; i < btnLetters.Length; i++) { ToolTip toolTip = new ToolTip(); toolTip.SetToolTip(btnLetters[i], btnLetters[i].Tag.ToString()); // So we see the buttons colors according to their real value, when form loads Letter lett = new Letter(); btnLetters[i].BackColor = lett.GetColor(btnLetters[i].Text[0]); } }
private void InitializeButtonLetters() { btnLetters = new List <Button>(); randomLetters = new Random(); Letter letter = new Letter(); int subtractionValue; int x; // Calculates the x position of the leftmost letter button, on letters surfaces subtractionValue = MAX_LETTERS_CAN_HOLD + 1 - MAX_LETTERS_CAN_HOLD % 2; x = 41 + 15 * (15 - subtractionValue); for (int i = 0; i < MAX_LETTERS_CAN_HOLD; i++) { char randomLetter = (char)randomLetters.Next('A', 'Z' + 2); if (randomLetter == 'Z' + 1) { randomLetter = ' '; } Button button = new Button() { Font = new Font("Cooper Black", 12F, FontStyle.Bold, GraphicsUnit.Point, 177), Location = new Point(x, 496), Size = new Size(30, 30), TabIndex = BOARD_SIZE + i, Text = randomLetter.ToString(), BackColor = letter.GetColor(randomLetter) }; button.MouseDown += new MouseEventHandler(btnLetters_MouseDown); btnLetters.Add(button); Controls.Add(button); x += 30; } }
/* Fills the empty labels locations with the new * random-generated letters , generated in this method . * The new letters locations are taken from the * already-filled emptyLabelsLocations List */ private void AddNewLettersToSurface(List <Point> emptyLabelsLocations) { Letter letter = new Letter(); int numOfLettersToAdd = Math.Min(wordPutOnBoard.Count, numOfLettersRemaining); for (int i = 0; i < numOfLettersToAdd; i++) { btnLetters.Remove(wordPutOnBoard[i]); char randomLetter = (char)randomLetters.Next('A', 'Z' + 2); if (randomLetter == 'Z' + 1) { randomLetter = ' '; } Button btnNewLetter = new Button() { Font = new Font("Cooper Black", 12F, FontStyle.Bold, GraphicsUnit.Point, 177), Location = emptyLabelsLocations[i], Size = new Size(30, 30), TabIndex = wordPutOnBoard[i].TabIndex, Text = randomLetter.ToString(), BackColor = letter.GetColor(randomLetter) }; btnNewLetter.MouseDown += new MouseEventHandler(btnLetters_MouseDown); btnLetters.Add(btnNewLetter); this.Controls.Add(btnNewLetter); // Displays the new letter on letters surface btnNewLetter.BringToFront(); } }
private void UpdateLetterToolTip() { btnLetterRandomValue.Visible = false; lblEnterNewValue.Visible = false; udcLetterNewValue.Visible = false; // Shows the new value of the letter , as its tooltip text ToolTip toolTip = new ToolTip(); toolTip.SetToolTip(btnLetter, btnLetter.Tag.ToString()); // So when we update letter's value, its button's color will be changed accordingly Letter letter = new Letter(); btnLetter.BackColor = letter.GetColor(btnLetter.Text[0]); btnLetter.Focus(); }
private void btnPass_Click(object sender, EventArgs e) { if (numOfLettersRemaining == 0) // can't pass anymore { MessageBox.Show("Game Over\nFinal score : " + score, Application.ProductName); this.Close(); } /* If there are no empty labels on the letters surface , * then sort btnLetters by their X-coordinates : * this sort makes the letters on frmPass to appear in * the same order as they appear on the letters surface */ if (GetEmptyLabelsLocations().Count == 0) { btnLetters.Sort((b1, b2) => b1.Location.X.CompareTo(b2.Location.X)); } /* Passes the buttons letters to frmPass constructor, * because the same letters must appear on frmPass */ frmPass passForm = new frmPass(btnLetters, MAX_LETTERS_CAN_HOLD); passForm.ShowDialog(); List <int> indicesLettersToReplace = passForm.GetIndicesLettersToReplace(); /* If at least one letter has been replaced , and we * passed MAX_CONSECUTIVE_PASSES times , then the game * is over */ if (indicesLettersToReplace.Count > 0) { numOfConsecutivePasses++; if (numOfConsecutivePasses == MAX_CONSECUTIVE_PASSES) { MessageBox.Show("Game Over\nFinal score : " + score, Application.ProductName); this.Close(); } } Letter letter = new Letter(); /* The following foreach statement actually replaces * the letters of the buttons we selected on frmPass */ foreach (int indice in indicesLettersToReplace) { char randomLetter = (char)randomLetters.Next('A', 'Z' + 2); if (randomLetter == 'Z' + 1) { randomLetter = ' '; } this.btnLetters[indice].Text = randomLetter.ToString(); this.btnLetters[indice].BackColor = letter.GetColor(randomLetter); } if (!isFirstMove) { return; } // Following code is executed only if we're in the first move btnFirstWordHint.Visible = true; lstBestWords.Visible = false; }