예제 #1
0
파일: Form1.cs 프로젝트: Daoi/Scrabble
        //Dropping letter on board
        private void Button_DragDrop(object sender, DragEventArgs e)
        {
            bool   blankTile = false;
            Button btn       = (Button)sender;//The tile the letter is being placed on

            int[] index = BoardHandler.getRowCol(int.Parse(btn.Tag.ToString()));

            //Make sure an adjacent tile contains a letter or is the center piece
            if (!TilePlacement.CheckAdjacent(index[0], index[1], gameBoard))
            {
                e.Effect = DragDropEffects.None;
                return;
            }
            //Save premodified values
            boardAtTurnStart.Add(btn, btn.Text);
            handAtTurnStart.Add(currentTile, currentTile.Text);

            if (currentTile.Text == " ")
            {
                InputBox.SetLanguage(InputBox.Language.English);
                DialogResult res = InputBox.ShowDialog("Select a letter for your tile:",
                                                       "Select a letter",                                                                //Text message (mandatory), Title (optional)
                                                       InputBox.Icon.Information,                                                        //Set icon type (default info)
                                                       InputBox.Buttons.Ok,                                                              //Set buttons (default ok)
                                                       InputBox.Type.ComboBox,                                                           //Set type (default nothing)
                                                       new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
                                                                      "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }, //String field as ComboBox items (default null)
                                                       false,                                                                            //Set visible in taskbar (default false)
                                                       new System.Drawing.Font("Calibri", 10F, System.Drawing.FontStyle.Bold));          //Set font (default by system)
                currentTile.SetTileLetter(InputBox.ResultValue);
                blankTile = true;
            }

            //If it's a preimum board tile, record the multiplier
            if (btn.Text.Equals("Double Word Score") || btn.Text.Equals("*"))
            {
                scoreMultiplier *= 2;
            }
            else if (btn.Text.Equals("Triple Word Score"))
            {
                scoreMultiplier *= 3;
            }
            //Calculate value for premium tiles
            score += CalculateScore.CaluclatePlacedTileScore(btn, currentTile);
            tilesThisTurn.Add(currentTile.Text);

            //Potentially useless
            currentTile.SetBoardPosition(int.Parse(btn.Tag.ToString()));
            //Update board tile
            ib.addTile(new LetterTile(currentTile.Text, currentTile.GetBoardPosition()));

            if (blankTile)
            {
                btn.Text = currentTile.Text;
            }
            else
            {
                btn.Text = e.Data.GetData(DataFormats.StringFormat).ToString();
            }

            btn.AllowDrop = false;
            placements.Add(int.Parse(btn.Tag.ToString()));
            currentTile.Text = "";
        }