Esempio n. 1
0
 public void ClickResult(CellButton cell, String result)
 {
     if (gameSession == null)
     {
         return;
     }
     if (networkStream == null)
     {
         return;
     }
     if (result == "bombedcell")
     {
         DecLives();
     }
     byte[] bytes = Encoding.UTF8.GetBytes(result + "I:" + cell.i.ToString() + "J:" + cell.j.ToString());
     try
     {
         BinaryWriter writer = new BinaryWriter(networkStream);
         writer.Write(result);
         writer.Write(cell.i);
         writer.Write(cell.j);
     }
     catch
     {
     }
 }
Esempio n. 2
0
        public GameField(int fieldsize, FlowLayoutPanel bordpanel, TextBox tb, bool isenemy)
        {
            gamemove           = true;
            bordsize           = fieldsize;
            cellsleft          = tb;
            cellsleftcount     = fieldsize * fieldsize - bombsnum;
            cellsleft.Text     = cellsleftcount.ToString();
            bord               = bordpanel;
            bord.FlowDirection = FlowDirection.RightToLeft;
            Padding buff = Padding.Empty;

            bord.Margin      = buff;
            bord.Padding     = buff;
            CellButtons      = new CellButton[fieldsize, fieldsize];
            bool[,] bompmask = GenerateBombs(fieldsize, bombsnum);
            bombmask         = bompmask;
            for (int i = 0; i < fieldsize; i++)
            {
                for (int j = 0; j < fieldsize; j++)
                {
                    CellButtons[i, j]         = new CellButton(bompmask[i, j], isenemy, this, i, j);
                    CellButtons[i, j].Margin  = buff;
                    CellButtons[i, j].Padding = buff;
                    bord.Controls.Add(CellButtons[i, j]);
                }
            }
            CalculateAroundBombs(CellButtons);
        }
Esempio n. 3
0
        public void CalculateAroundBombs(CellButton[,] originalcells)
        {
            CellButton[,] cells = new CellButton[bordsize + 2, bordsize + 2];
            int buffsize = bordsize + 2;

            for (int i = 0; i < buffsize; i++)
            {
                for (int j = 0; j < buffsize; j++)
                {
                    cells[i, j] = new CellButton(false, false, this, i, j);
                }
            }
            for (int i = 1; i < buffsize - 1; i++)
            {
                for (int j = 1; j < buffsize - 1; j++)
                {
                    cells[i, j] = originalcells[i - 1, j - 1];
                }
            }

            for (int i = 1; i < buffsize - 1; i++)
            {
                for (int j = 1; j < buffsize - 1; j++)
                {
                    int result = 0;
                    for (int k = i - 1; k <= i + 1; k++)
                    {
                        for (int n = j - 1; n <= j + 1; n++)
                        {
                            if (cells[k, n].IsBombed())
                            {
                                result++;
                            }
                        }
                    }
                    cells[i, j].SetBombsAround(result);
                }
            }
        }