Exemplo n.º 1
0
        //Creates a tile with the provided properties
        //coords - coordinates of the tile on form
        //dimensions - size of the tile
        //value - type/value of the tile (1,2,3...8, m)
        //bottom_pic - picture shown when tile is revealed
        //flag_pic - picture shown when tile is marked
        //mine_blown - picture shown when the tile is a mine and it's blown
        //isEmpty - whether the tile is 0 or not
        //gridCoords - coordinates on the game grid
        //mine - boolean saying whether the tile is a mine
        public Tile(Point coords, Size dimensions, char value, Image bottom_pic, Image tile_pic, Image flag_pic, Image mine_blown, bool isEmpty, Point gridCoords, bool mine)
        {
            //set up all of the fields
            isMine          = mine;
            this.empty      = isEmpty;
            this.GridCoords = gridCoords;

            flag            = flag_pic;
            hidden          = tile_pic;
            this.mine_blown = mine_blown;

            //set up the PictureBoxes
            Button             = new PictureBox();
            Button.Image       = tile_pic;
            Button.Location    = coords;
            Button.Size        = dimensions;
            Button.Name        = Convert.ToString(value);
            Button.Visible     = true;
            Button.MouseClick += new MouseEventHandler(tileClicked);

            Image_Container       = new PictureBox();
            Image_Container.Image = bottom_pic;
            Image_Container.SetBounds(coords.X, coords.Y, dimensions.Width, dimensions.Height);
            Image_Container.Name = Convert.ToString(value);

            //set initial tile state to hidden
            state = Constants.TileState.Hidden;
        }
Exemplo n.º 2
0
    public void UpdateState(Constants.TileState state)
    {
        _tileState = state;
        Sprite sprite;

        switch (_tileState)
        {
        default:
        case Constants.TileState.Off:
        case Constants.TileState.Default:
            sprite = _tileData.Default;
            break;

        case Constants.TileState.A:
            sprite = _tileData.A;
            break;

        case Constants.TileState.B:
            sprite = _tileData.B;
            break;

        case Constants.TileState.C:
            sprite = _tileData.C;
            break;
        }

        _tile.sprite = sprite;
    }
Exemplo n.º 3
0
        //method that reveals the tile manually
        public void Open()
        {
            state          = Constants.TileState.Revealed; //change state
            Button.Visible = false;                        //reveal

            if (!isMine)
            {
                TileClickedEvent(this, null);                //raise event
            }
        }
Exemplo n.º 4
0
 //method marks the tile
 public void Mark()
 {
     //if current state isn't hidden (is marked) - remove mark
     if (state != Constants.TileState.Hidden)
     {
         state        = Constants.TileState.Hidden;
         Button.Image = hidden;
     }
     else
     {            //otherwise - mark the tile
         state        = Constants.TileState.Marked;
         Button.Image = flag;
     }
 }
Exemplo n.º 5
0
        //method called when the tile is clicked
        protected void tileClicked(object src, MouseEventArgs args)
        {
            //if game is over, user can't click tiles
            if (Control.curState != Constants.GameState.GameOver)
            {
                //check which mouse button was clicked
                switch (args.Button)
                {
                case MouseButtons.Right:                        //if right button was clicked, play sound and rise appropriate event
                    Control.rightclick.Play();
                    TileMarkedEvent(this, null);
                    break;

                case MouseButtons.Left:          //if left mouse button was clicked
                    if (state != Constants.TileState.Marked)
                    {                            //only do stuff if the tile isn't marked
                        Control.button_click.Play();
                        //reveal the value
                        state          = Constants.TileState.Revealed;
                        Button.Visible = false;

                        //raise tile clicked event
                        TileClickedEvent(this, null);
                        if (empty)
                        {                                //if tile was empty, raise emptyOpenedEvent
                            EmptyOpenedEvent(this, null);
                        }
                        else if (isMine)
                        {                                //if tile is mine, play sound and raise MineOpenedEvent
                            Control.explosion.Play();
                            Image_Container.Image = mine_blown;
                            MineOpenedEvent(this, null);
                        }
                    }
                    break;
                }
            }
        }
Exemplo n.º 6
0
 public void TurnOff()
 {
     _tileState = Constants.TileState.Off;
     gameObject.SetActive(false);
 }
Exemplo n.º 7
0
 public Tile(int tileIndex, int tileSet, object tileState)
 {
     this.tileIndex = tileIndex;
     this.tileSet   = tileSet;
     this.tileState = (Constants.TileState)tileState;
 }
Exemplo n.º 8
0
    private void UpdateTileState()
    {
        _hasMove            = false;
        _matchCountsByTypes = new Dictionary <Constants.TileType, int>();
        for (int y = 0; y < _rows; y++)
        {
            for (int x = 0; x < _columns; x++)
            {
                Tile parent = _tiles[x, y];
                int  count  = parent.Flood.Count;
                //current board have move(blast)
                if (count >= Rules.minBlastCount)
                {
                    _hasMove = true;
                }


                if (_matchCountsByTypes.ContainsKey(parent.TileType))
                {
                    _matchCountsByTypes[parent.TileType] += 1;
                }
                else
                {
                    _matchCountsByTypes[parent.TileType] = 1;
                }

                if (count > Rules.defaultMinMax.MAX)
                {
                    Constants.TileState state = Constants.TileState.Default;
                    if (count >= Rules.aMinMax.MIN && count <= Rules.aMinMax.MAX)
                    {
                        state = Constants.TileState.A;
                    }
                    if (count >= Rules.bMinMax.MIN && count <= Rules.bMinMax.MAX)
                    {
                        state = Constants.TileState.B;
                    }
                    if (count >= Rules.cMinMax.MIN && count <= Rules.cMinMax.MAX)
                    {
                        state = Constants.TileState.C;
                    }

                    foreach (var tile in parent.Flood)
                    {
                        tile.UpdateState(state);
                    }
                }
            }
        }

        _hasMatch = false;

        //Check if the board has a "minBlastCount" pair if not no more move, end game
        foreach (var count in _matchCountsByTypes.Values)
        {
            if (count >= Rules.minBlastCount)
            {
                _hasMatch = true;
            }
        }

        //current board has "minBlastCount" but not in this sequence
        if (!_hasMove)
        {
            Shuffle();
        }
    }