Exemple #1
0
        public Board()
        {
            spaces = new Space[HEIGHT, WIDTH];
            for (int y = 0; y < HEIGHT; y++)
            {
                for (int x = 0; x < WIDTH; x++)
                {
                    spaces[y, x] = new Space(this, y, x);
                    spaces[y, x].Revealed += new EventHandler<EventArgs>(spaceRevealedHandler);
                    spaces[y, x].FlagToggled += new EventHandler<EventArgs>(Board_FlagToggled);
                }
            }

            for (int i = 0; i < BOMBS; i++)
            {
                Random r = new Random();
                Space s;
                do
                {
                    s = spaces[r.Next(0, HEIGHT), r.Next(0, WIDTH)];
                } while (s.IsBomb);
                s.isbomb = true;
            }
        }
Exemple #2
0
        public List<Space> AdjacentSpaces(Space s)
        {
            List<Space> retval =  new List<Space>();
            for (int x = -1; x <= 1; x++)
            {
                for (int y = -1; y <= 1; y++)
                {
                    if (x == 0 && y == 0) continue;
                    if (s.colnum + x < 0 || s.colnum + x >= WIDTH ||
                        s.rownum + y < 0 || s.rownum + y >= HEIGHT) continue;

                    retval.Add(this.spaces[s.rownum + y, s.colnum + x]);
                }
            }
            return retval;
        }
Exemple #3
0
 public int AdjacentBombCount(Space s)
 {
     return AdjacentSpaces(s).FindAll(delegate(Space sp) { return sp.IsBomb; }).Count;
 }
Exemple #4
0
 protected bool Equals(Space other)
 {
     return(_amount == other._amount);
 }