Exemplo n.º 1
0
 public void RevealSquare(int row, int col)
 {
     if (gameOver || board[row, col].IsRevealed)
     {
         return;
     }
     board[row, col].IsRevealed = true;
     if (board[row, col].IsFlagged)
     {
         UnflagSquare(row, col);
     }
     if (board[row, col].IsMine)
     {
         MineRevealed.Raise(this, new SquareEventArgs(row, col));
         gameOver = true;
         timer.Stop();
         GameLost.Raise(this, EventArgs.Empty);
     }
     else
     {
         SafeSquareRevealed.Raise(this, new SquareEventArgs(row, col, board[row, col].AdjacentMines));
         if (board[row, col].AdjacentMines == 0)
         {
             RevealEmptySquares(row, col);
         }
     }
     if (CheckGameWon())
     {
         OnGameWon();
     }
 }
Exemplo n.º 2
0
    private void LoseGame(Cell failReason)
    {
        IsGameRunning = false;

        foreach (var cell in cells)
        {
            if (cell.Data.Bomb && !cell.Data.Opened)
            {
                cell.Open();
            }

            cell.UpdateAppearance();

            if (cell == failReason)
            {
                cell.MakeBgRed();
            }

            if (!cell.Data.Bomb && cell.Data.Marked)
            {
                cell.ShowMistakenMark();
            }
        }

        GameLost.SafeInvoke();
    }
Exemplo n.º 3
0
        public void LoseGame()
        {
            if (_isPlaying == true)
            {
                _isPlaying = false;
            }

            GameLost?.Invoke();
        }
Exemplo n.º 4
0
        public void Explore()
        {
            if (InvaderDeck.IsEmpty)
            {
                SendGameEndData();
                GameLost?.Invoke();
                return;
            }

            _currentExplore = InvaderDeck.Dequeue();
            SendExploreData();
        }
Exemplo n.º 5
0
        private void SpawnPiece()
        {
            CurrentPiece = TetrisPiece.Spawn(this);

            if (CurrentPiece == null)
            {
                State = TetrisBoardState.Stopped;
                GameLost?.Invoke(this, EventArgs.Empty);
                return;
            }

            CurrentPiece.Draw();
        }
Exemplo n.º 6
0
        private bool CheckIfGameIsEnded()
        {
            if (_map.GetCells().Any(x => x.State == CellState.Boom))
            {
                GameLost.Raise(this, EventArgs.Empty);
                return(true);
            }

            if (_map.GetCells().All(x => x.State != CellState.Unknown))
            {
                GameSolved.Raise(this, EventArgs.Empty);
                return(true);
            }
            return(false);
        }
Exemplo n.º 7
0
    private void ExplodeNextBomb()
    {
        cellsWithBombs.Remove(nextCellToExplode);
        var explosion = Instantiate(explosionPrefab);

        Destroy(explosion.gameObject, explosionPrefab.main.duration);
        explosion.transform.position = nextCellToExplode.transform.position - new Vector3(0, 0, 0.1f);

        if (cellsWithBombs.Count > 0)
        {
            nextCellToExplode = cellsWithBombs[RandomGen.Next(cellsWithBombs.Count)];

            Invoke("ExplodeNextBomb", delayBetweenExplosions);
        }
        else
        {
            GameLost.Invoke();
        }
    }
Exemplo n.º 8
0
    void OnCollisionEnter(Collision collision)
    {
        if ((collision.collider.tag == "Food") && !Movement.TailUnits.Contains(collision.gameObject))
        {
            points++;

            collision.gameObject.tag = "Obstacle";

            collision.gameObject.transform.position = new Vector3(0, 0, -21);

            Movement.TailUnits.Add(collision.gameObject);

            Instantiate(TailObject, new Vector3(Random.Range(-16, 17), Random.Range(-9, 10)), new Quaternion());
        }
        else if (collision.collider.tag == "Obstacle" || Movement.TailUnits.Contains(collision.gameObject))
        {
            GameLost.Lost(); return;
        }
    }
Exemplo n.º 9
0
 private void Update()
 {
     playerDead = player.isDead;
     if (quota <= 0 && !playerDead)
     {
         QuotaMet?.Invoke();
         if (!hasQuotaCollectionSoundPlayed)
         {
             quotaCollectionSound.Play();
             hasQuotaCollectionSoundPlayed = true;
         }
         quotaText.color = green;
     }
     if (playerDead)
     {
         GameLost?.Invoke();
         quotaText.text     = "You Lose! Pause (ESC/P) to restart!";
         button.enabled     = true;
         quotaImage.enabled = true;
         quotaText.color    = red;
     }
 }
Exemplo n.º 10
0
    private void OnPirateReachedGold(PirateBehaviour pirate)
    {
        if (m_remainingLives < 0)
        {
            return;
        }

        m_remainingLives--;
        if (m_remainingLives == 0)
        {
            // Game is lost! All ye abandon all hope.
            Debug.Log("The game is over.");
            GameLost?.Invoke();
            m_chestExplosion.Play();
            StartCoroutine(DoGameOverSequence());
        }

        // Pivot the chest open, change the bar sprite

        float life_t = 1.0f - ((float)m_remainingLives / (float)NumLives);

        m_chestPivot.localRotation = Quaternion.Euler(Vector3.Lerp(Vector3.zero, m_openChestRotation, life_t));
        m_barImg.sprite            = m_stateSprites[m_remainingLives];
    }
Exemplo n.º 11
0
 public static void LoseGame() => GameLost?.Invoke();
Exemplo n.º 12
0
 protected virtual void OnGameLost()
 {
     GameLost?.Invoke(this, EventArgs.Empty);
 }
 private void OnGameLost(EventData eventData)
 {
     GameLost?.Invoke(eventData);
 }