Beispiel #1
0
    //used to update colour based on the fishing rate.
    public void UpdateColour()
    {
        switch (FishRate)
        {
        case 1:
            GridSquare.GetComponent <Image>().color = new Color(204f / 255f, 204f / 255f, 255f / 255f);
            break;

        case 2:
            GridSquare.GetComponent <Image>().color = new Color(153f / 255f, 153f / 255f, 255f / 255f);
            break;

        case 3:
            GridSquare.GetComponent <Image>().color = new Color(102f / 255f, 102f / 255f, 255f / 255f);
            break;

        case 4:
            GridSquare.GetComponent <Image>().color = new Color(0f / 255f, 0f / 255f, 255f / 255f);
            break;

        default:
            GridSquare.GetComponent <Image>().color = new Color(255f / 255f, 255f / 255f, 255f / 255f);
            break;
        }
    }
Beispiel #2
0
    public void LoadPuzzle(int r, int c, int[,] puzzle)
    {
        this.row    = r;
        this.column = c;
        this.puzzle = puzzle;

        Debug.Log(row + ", " + column);

        //gridTransform .GetComponent<RectTransform >().sizeDelta =

        squareSize = (int)(1000 / r / 1.5f);
        fontSize   = squareSize / 2;
        if (fontSize < 25)
        {
            fontSize = 25;
        }

        currentGrid = new int[column, row];

        //生成方块
        squares = new GridSquare[column, row];
        for (int i = 0; i < row; i++)
        {
            for (int j = 0; j < column; j++)
            {
                GameObject obj = Instantiate(squarePrefab, gridTransform);
                obj.name = "(" + i + ", " + j + ")";

                GridSquare square = obj.GetComponent <GridSquare>();
                square.SetPosition(i, j);
                Vector2 pos = new Vector2(squareSize / 2 + squareSize * j, (row - i) * squareSize - squareSize / 2);
                square.GetComponent <RectTransform>().anchoredPosition = pos;
                //square.GetComponent<RectTransform>().sizeDelta = new Vector2(squareSize*0.9f, squareSize*0.9f);
                squares[i, j] = square;

                SetSquare(square, 0);
                square.SetSize(squareSize);
                //square.image.color = (puzzle[i, j] == 0) ? Color.white : Color.black;
            }
        }

        //生成文字
        //列
        columnText = new List <Text>();
        for (int i = 0; i < column; i++)
        {
            List <int> result = ReadPuzzle(this.puzzle, true, i);
            for (int a = 0; a < result.Count; a++)
            {
                GameObject obj = Instantiate(textPrefab, gridTransform);
                //文字大小
                obj.GetComponent <RectTransform>().sizeDelta = new Vector2(squareSize, squareSize);

                //文字位置
                Vector2 pos = new Vector2(i * squareSize + squareSize / 2, (row) * squareSize + (result.Count - a) * squareSize - squareSize / 2);
                obj.GetComponent <RectTransform>().anchoredPosition = pos;

                //字体
                Text t = obj.GetComponentInChildren <Text>();
                t.text     = result[a] + "";
                t.fontSize = this.fontSize;

                columnText.Add(t);
            }
        }
        //行
        rowText = new List <Text>();
        for (int i = 0; i < row; i++)
        {
            List <int> result = ReadPuzzle(this.puzzle, false, i);
            for (int a = 0; a < result.Count; a++)
            {
                GameObject obj = Instantiate(textPrefab, gridTransform);
                //文字大小
                obj.GetComponent <RectTransform>().sizeDelta = new Vector2(squareSize, squareSize);

                //文字位置
                Vector2 pos = new Vector2(-(result.Count - a) * squareSize + squareSize / 2, (row - i) * squareSize - squareSize / 2);
                obj.GetComponent <RectTransform>().anchoredPosition = pos;

                //字体
                Text t = obj.GetComponentInChildren <Text>();
                t.text     = result[a] + "";
                t.fontSize = this.fontSize;

                rowText.Add(t);
            }
        }

        gridTransform.gameObject.GetComponent <RectTransform>().anchoredPosition = new Vector2(-squareSize * row / 2, -500);
    }
Beispiel #3
0
    public void FindTriggerSquares(bool omnidirectional)
    {
        foreach (var trigger in triggers)
        {
            if (trigger.x_pos != grid.end_x && trigger.y_pos != grid.end_y && !running)
            {
                trigger.GetComponent <Renderer>().material.color = Color.green;
            }
            trigger.isTrigger = false;
        }
        triggers.Clear();
        bool skip_n = false;
        bool skip_e = false;
        bool skip_w = false;
        bool skip_s = false;

        for (int i = 1; i <= range; i++)
        {
            GridSquare square = null;
            if (facing == 'n' || (omnidirectional && !skip_n))
            {
                if (y_pos + i > 19)
                {
                    skip_n = true;
                    if (!omnidirectional)
                    {
                        break;
                    }
                }
                else
                {
                    square = grid.squares[x_pos, y_pos + i];
                    if (square.getItem() == "empty" || square.getItem() == "pit" || square.getItem() == "spikes")
                    {
                        if (square.x_pos != grid.end_x || square.y_pos != grid.end_y)
                        {
                            square.GetComponent <Renderer>().material.color = Color.yellow;
                        }
                        triggers.Add(square);
                        square.isTrigger = true;
                    }
                    else
                    {
                        skip_n = true;
                        if (!omnidirectional)
                        {
                            break;
                        }
                    }
                }
            }
            if (facing == 'e' || (omnidirectional && !skip_e))
            {
                if (x_pos + i > 19)
                {
                    skip_e = true;
                    if (!omnidirectional)
                    {
                        break;
                    }
                }
                else
                {
                    square = grid.squares[x_pos + i, y_pos];
                    if (square.getItem() == "empty" || square.getItem() == "pit" || square.getItem() == "spikes")
                    {
                        if (square.x_pos != grid.end_x || square.y_pos != grid.end_y)
                        {
                            square.GetComponent <Renderer>().material.color = Color.yellow;
                        }
                        triggers.Add(square);
                        square.isTrigger = true;
                    }
                    else
                    {
                        skip_e = true;
                        if (!omnidirectional)
                        {
                            break;
                        }
                    }
                }
            }
            if (facing == 's' || (omnidirectional && !skip_s))
            {
                if (y_pos - i < 0)
                {
                    skip_s = true;
                    if (!omnidirectional)
                    {
                        break;
                    }
                }
                else
                {
                    square = grid.squares[x_pos, y_pos - i];
                    if (square.getItem() == "empty" || square.getItem() == "pit" || square.getItem() == "spikes")
                    {
                        if (square.x_pos != grid.end_x || square.y_pos != grid.end_y)
                        {
                            square.GetComponent <Renderer>().material.color = Color.yellow;
                        }
                        triggers.Add(square);
                        square.isTrigger = true;
                    }
                    else
                    {
                        skip_s = true;
                        if (!omnidirectional)
                        {
                            break;
                        }
                    }
                }
            }
            if (facing == 'w' || (omnidirectional && !skip_w))
            {
                if (x_pos - i < 0)
                {
                    skip_w = true;
                    if (!omnidirectional)
                    {
                        break;
                    }
                }
                else
                {
                    square = grid.squares[x_pos - i, y_pos];
                    if (square.getItem() == "empty" || square.getItem() == "pit" || square.getItem() == "spikes")
                    {
                        if (square.x_pos != grid.end_x || square.y_pos != grid.end_y)
                        {
                            square.GetComponent <Renderer>().material.color = Color.yellow;
                        }
                        triggers.Add(square);
                        square.isTrigger = true;
                    }
                    else
                    {
                        skip_w = true;
                        if (!omnidirectional)
                        {
                            break;
                        }
                    }
                }
            }

            /*if (square.getItem() == "empty" || square.getItem() == "pit" || square.getItem() == "spikes") {
             *  square.GetComponent<Renderer>().material.color = Color.yellow;
             *  triggers.Add(square);
             * } else {
             *  break;
             * }*/
        }
    }
Beispiel #4
0
    public static void ToggleGridSquareHalo(GridSquare gridSquare, bool toggle)
    {
        Behaviour halo = (Behaviour)gridSquare.GetComponent("Halo");

        halo.enabled = toggle; // false
    }