Exemplo n.º 1
0
 public bool Clicked(ref NetworkMessage.Result result)     //Try to reveal the cell and return whether it was valid click or not
 {
     if (checkStatus == Status.HIDDEN)
     {
         checkStatus = Status.CLICKED;
         if (surroundingArea == 0)
         {
             if (isMine)
             {
                 //Game over
                 Debug.Log("Game Over");
                 checkStatus = Status.MINE;
             }
             else
             {
                 //Debug.Log("Area");
                 GridManager.instance.RevealAreaAt(index, ref result);
             }
         }
         NetworkMessage.CellResult cr = new NetworkMessage.CellResult();
         cr.index       = index;
         cr.status      = checkStatus;
         cr.surrounding = surroundingArea;
         result.result.Add(cr);
         return(true);
     }
     return(false);
 }
Exemplo n.º 2
0
 public void ReflectResult(NetworkMessage.Result result)
 {
     foreach (NetworkMessage.CellResult cr in result.result)
     {
         grid[cr.index.x, cr.index.y].Reflect(cr);
     }
     CheckGrid();
 }
Exemplo n.º 3
0
 /*
  * GridManager is the only function that has access to the cells.
  * Other classes don't have any reference to the cells(grid)
  * These functions will be called by GameManager which is triggered by Player class.
  * //*/
 public bool ClickAt(int x, int y, ref NetworkMessage.Result result)
 {
     if (grid[x, y].isMine && grid[x, y].checkStatus != Cell.Status.FLAGGED)
     {
         isLose = true;
     }
     return(grid[x, y].Clicked(ref result));
 }
Exemplo n.º 4
0
 //This function is called in cell's Reveal function.
 //Cell class can't affect other cells so a cell calls this function to reveal other cells
 public void RevealAreaAt(int x, int y, ref NetworkMessage.Result result)
 {
     for (int i = x - 1; i <= x + 1; i++)
     {
         for (int j = y - 1; j <= y + 1; j++)
         {
             if (i < 0 || i > width - 1 || j < 0 || j > height - 1 || (i == x && j == y))
             {
                 continue;
             }
             grid[i, j].Clicked(ref result);
         }
     }
 }
Exemplo n.º 5
0
    public bool Flagged(ref NetworkMessage.Result result)     //Try to put/remove falg on the cell and return whether it was valid click or not
    {
        //TODO mine number should be managed my grid manager
        if (checkStatus == Status.HIDDEN)
        {
            checkStatus = Status.FLAGGED;
            goto Clickable;
        }
        else if (checkStatus == Status.FLAGGED)
        {
            checkStatus = Status.HIDDEN;
            goto Clickable;
        }
        return(false);

Clickable:
        NetworkMessage.CellResult cr = new NetworkMessage.CellResult();
        cr.index  = index;
        cr.status = checkStatus;
        result.result.Add(cr);
        return(true);
    }
Exemplo n.º 6
0
 public void RevealAreaAt(Vector2Int index, ref NetworkMessage.Result result)
 {
     RevealAreaAt(index.x, index.y, ref result);
 }
Exemplo n.º 7
0
 public bool FlagAt(Vector2Int index, ref NetworkMessage.Result result)
 {
     return(FlagAt(index.x, index.y, ref result));
 }
Exemplo n.º 8
0
 public bool FlagAt(int x, int y, ref NetworkMessage.Result result)
 {
     return(grid[x, y].Flagged(ref result));
 }