Exemplo n.º 1
0
 public void RecursiveOpen(int x, int y, Minefield mine)
 {
     if (mine.isOpened())
     {
         return;
     }
     else
     {
         if (mine.bombInProximity != 0 || mine.CheckBomb())
         {
             mine.OpenCover();
             return;
         }
         else
         {
             mine.OpenCover();
             if (y + 1 < fieldHeight)
             {
                 RecursiveOpen(x, y + 1, field[x, y + 1].GetComponent <Minefield>());
             }
             if (x + 1 < fieldWidth)
             {
                 RecursiveOpen(x + 1, y, field[x + 1, y].GetComponent <Minefield>());
             }
             if (y - 1 >= 0)
             {
                 RecursiveOpen(x, y - 1, field[x, y - 1].GetComponent <Minefield>());
             }
             if (x - 1 >= 0)
             {
                 RecursiveOpen(x - 1, y, field[x - 1, y].GetComponent <Minefield>());
             }
         }
     }
 }
Exemplo n.º 2
0
    public void BFSOpen(Minefield mine)
    {
        int x, y;
        Queue <Minefield> openQueue = new Queue <Minefield>();
        Minefield         currMine;

        openQueue.Enqueue(mine);
        if (mine.CheckBomb())
        {
            mine.OpenCover();
        }
        while (openQueue.Count > 0)
        {
            currMine = openQueue.Dequeue();
            if (currMine.isOpened() || currMine.CheckBomb())
            {
                continue;
            }

            x = currMine.Coords[0];
            y = currMine.Coords[1];
            if (currMine.bombInProximity != 0)
            {
                currMine.OpenCover();
                continue;
            }

            currMine.OpenCover();
            if (x < fieldWidth && y + 1 < fieldHeight)
            {
                openQueue.Enqueue(field[x, y + 1].GetComponent <Minefield>());
            }
            if (x + 1 < fieldWidth && y < fieldHeight)
            {
                openQueue.Enqueue(field[x + 1, y].GetComponent <Minefield>());
            }
            if (x >= 0 && y - 1 >= 0)
            {
                openQueue.Enqueue(field[x, y - 1].GetComponent <Minefield>());
            }
            if (x - 1 >= 0 && y >= 0)
            {
                openQueue.Enqueue(field[x - 1, y].GetComponent <Minefield>());
            }
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (GameOver)
        {
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    Minefield mine = field[i, j].GetComponent <Minefield>();
                    if (mine.CheckBomb())
                    {
                        field[i, j].GetComponent <Minefield>().OpenCover();
                    }
                }
            }
            canvas.enabled = true;
            soundSource.PlayOneShot(explosion);
            GameOverText.enabled = true;
            smug.enabled         = true;
            restartButton.gameObject.SetActive(true);
            GameOver = false;
            counting = false;
        }


        if (GameWon)
        {
            canvas.enabled = true;
            soundSource.PlayOneShot(win);
            nice.enabled        = true;
            GameWonText.enabled = true;
            restartButton.gameObject.SetActive(true);
            GameWon  = false;
            counting = false;
        }

        if (SceneManager.GetActiveScene().name == "MainGame")
        {
            timeLabel.enabled = true;
            if (counting)
            {
                timer += Time.deltaTime;
            }
            timeLabel.text = Mathf.RoundToInt(timer).ToString();
        }
    }