Пример #1
0
 /// <summary>
 /// Move the snake and check if game over
 /// </summary>
 private void TryMove()
 {
     if (GameArray.TryMove(SnakeMovement) == MovementResult.GameOver)
     {
         PlayerLost?.Invoke(this, EventArgs.Empty);
     }
 }
Пример #2
0
    public void InvokePlayerLost()
    {
        if (!playerLostInvoked)
        {
            playerLostInvoked = true;
            PlayerLost?.Invoke();
            theScoreKeeper.SubtractLife();
        }

        if (!gameOverInkvoked)
        {
            InvokeGameOver();
        }
    }
Пример #3
0
 private void CreateNewShape()
 {
     ClearPreviousCurrentShapePosition();
     CurrentShape = ShapeFactory.CreateRandomShape();
     //check if the position we want to place current shape is occupied by another item
     foreach (var item in CurrentShape)
     {
         if (GameArray[item.Row, item.Column] != null)
         {
             PlayerLost?.Invoke(this, EventArgs.Empty);
             return;
         }
     }
     PlaceCurrentShape();
     GameUpdated?.Invoke(this, EventArgs.Empty);
 }
Пример #4
0
        private void Minesweeper_MouseClick(object sender, MouseEventArgs e)
        {
            if (!GameOver)
            {
                int  x = e.X; int y = e.Y;
                bool FitsByX = (x <= Starting.X + this.Size && x >= Starting.X);
                bool FitsByY = (y <= Starting.Y + this.Size && y >= Starting.Y);

                if (FitsByX && FitsByY)
                {
                    bool isLeft   = e.Button.Equals(MouseButtons.Left);
                    bool isRight  = e.Button.Equals(MouseButtons.Right);
                    bool isMiddle = e.Button.Equals(MouseButtons.Middle);
                    int  CellSize = this.Size / this.Settings.Width;
                    int  i        = (x - Starting.X) / CellSize;
                    int  j        = (y - Starting.Y) / CellSize;
                    if (isMiddle)
                    {
                        if (board[i, j].State.Equals(Enums.CellState.Uncovered))
                        {
                            List <Cell> cells     = board[i, j].Neighbours;
                            List <Cell> mines     = board[i, j].Neighbours.Where(x => x.IsMine == true).ToList();
                            List <Cell> nonMine   = board[i, j].Neighbours.Where(x => x.IsMine == false).ToList();
                            bool        AllMarked = true;
                            foreach (Cell mine in mines)
                            {
                                if (!mine.State.Equals(Enums.CellState.Flag))
                                {
                                    AllMarked = false;
                                    break;
                                }
                            }
                            if (AllMarked)
                            {
                                foreach (Cell cell in nonMine)
                                {
                                    cell.Uncover(g);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (isLeft)
                        {
                            if (!board[i, j].State.Equals(Enums.CellState.Flag))
                            {
                                if (board[i, j].IsMine)
                                {
                                    GameOver = true;
                                    for (int n = 0; n < this.Settings.Width; n++)
                                    {
                                        for (int m = 0; m < this.Settings.Height; m++)
                                        {
                                            if (board[n, m].IsMine)
                                            {
                                                board[n, m].State = Enums.CellState.Mine;
                                                board[n, m].Draw(g);
                                            }
                                        }
                                    }
                                    PlayerLost?.Invoke(this, EventArgs.Empty);
                                    return;
                                }
                                else
                                {
                                    board[i, j].Uncover(g);
                                }
                            }
                        }
                        else
                        {
                            if (isRight)
                            {
                                board[i, j].TryPlaceFlag(g);
                            }
                        }
                    }
                }
                int CoveredCount = 0;
                for (int i = 0; i < this.Settings.Width; i++)
                {
                    for (int j = 0; j < this.Settings.Height; j++)
                    {
                        if (!board[i, j].IsMine && board[i, j].State.Equals(Enums.CellState.Covered))
                        {
                            CoveredCount++;
                        }
                    }
                }
                if (CoveredCount == 0)
                {
                    PlayerWon?.Invoke(this, EventArgs.Empty);
                    GameOver = true;
                    return;
                }
            }
        }
Пример #5
0
 // --------------------------------------------------------------------------------------------
 private void LoseGame()
 {
     PlayerLost?.Invoke(this, new PlayerEventArgs(this));
 }
Пример #6
0
 protected virtual void OnPlayerLost(int score)
 {
     PlayerLost?.Invoke(score);
 }