예제 #1
0
 private void frmMain_Load(object sender, EventArgs e)
 {
     for (int i = 0; i < 9; i++)
     {
         numButtons[i] = $"D{i + 1}";
         for (int j = 0; j < 9; j++)
         {
             tiles[i, j] = new TileLabel(i, j, this);
             this.Controls.Add(tiles[i, j]);
             tiles[i, j].MouseEnter += new EventHandler(tile_MouseEnter);
             tiles[i, j].MouseLeave += new EventHandler(tile_MouseLeave);
             tiles[i, j].Click      += new EventHandler(tile_Click);
         }
     }
     numButtons[9] = "Back";
     if (File.ReadAllText("saved_game.txt") != "")
     {
         btnLoad.Enabled = true;
     }
 }
예제 #2
0
 private void selectTile(TileLabel tile) // "selects" the tile the user clicks, making it orange and flagging it as selected.
                                         //Also highlights the row collumn and 3x3 square in yellow.
 {
     tile.selected  = true;
     tile.BackColor = Color.Orange;
     for (int i = 0; i < 9; i++)
     {
         for (int j = 0; j < 9; j++)
         {
             if (tiles[i, j] == tile)
             {
                 for (int k = 0; k < 9; k++)
                 {
                     if (!tiles[i, k].selected)
                     {                                               //Row
                         tiles[i, k].BackColor = Color.Yellow;
                     }
                     if (!tiles[k, j].selected)
                     {                                               //Collumn
                         tiles[k, j].BackColor = Color.Yellow;
                     }
                 }
                 for (int l = 0; l < 9; l++)
                 {
                     for (int m = 0; m < 9; m++)
                     {
                         if (l / 3 == i / 3 & m / 3 == j / 3 & !tiles[l, m].selected)        //3x3 square
                         {
                             tiles[l, m].BackColor = Color.Yellow;
                         }
                     }
                 }
             }
         }
     }
 }