Beispiel #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);
     }
 }
 private void OnEnemyPassedBy(Enemy enemy)
 {
     Lives = Math.Max(0, Lives - 1);
     if (Lives == 0 && !gameEnded)
     {
         gameEnded = true;
         PlayerLost.Dispatch();
     }
 }
Beispiel #3
0
 public void Setup(int humanParts, int normalParts, GameController gameController)
 {
     selectedHumanBlocks = new List <bool>();
     for (int i = 0; i < humanParts; ++i)
     {
         selectedHumanBlocks.Add(false);
     }
     maxHumanParts  = humanParts;
     maxNormalParts = normalParts;
     uiController.UpdateMeatLeftText(maxNormalParts);
     playerLost += gameController.PlayerLost;
 }
    public void InvokePlayerLost()
    {
        if (!playerLostInvoked)
        {
            playerLostInvoked = true;
            PlayerLost?.Invoke();
            theScoreKeeper.SubtractLife();
        }

        if (!gameOverInkvoked)
        {
            InvokeGameOver();
        }
    }
Beispiel #5
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);
 }
 protected override void Start()
 {
     base.Start();
     PlayerLost.AddListener(OnPlayerLost);
     EnemyBorn.AddListener(OnEnemyBorn);
 }
Beispiel #7
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;
                }
            }
        }
Beispiel #8
0
 // --------------------------------------------------------------------------------------------
 private void LoseGame()
 {
     PlayerLost?.Invoke(this, new PlayerEventArgs(this));
 }
Beispiel #9
0
 protected virtual void OnPlayerLost(int score)
 {
     PlayerLost?.Invoke(score);
 }