Ejemplo n.º 1
0
    void PlacedChess(Vector2Int pos, ref ColoredChess cType, ref int[,] chessboard)
    {
        ColoredChess next = new ColoredChess();

        next.InitChess(pos, ref cType);
        foreach (KeyValuePair <Vector2Int, int> p in next.GetChessPosAndColor())
        {
            chessboard[p.Key.x, p.Key.y] = p.Value;
        }
    }
Ejemplo n.º 2
0
    //public void InitChess(List<Vector2Int> pos, List<int> color)
    //{
    //    m_shape = shape;
    //    m_direction = direction;
    //    m_color = color;
    //    m_pos.Clear();
    //    m_pos.Add(pos);
    //    List<Vector2Int> temp = CalcAttachChessOffset(CalcAttachChessId(shape, direction), pos);
    //    m_pos.AddRange(temp);
    //}

    public void InitChess(Vector2Int pos, ref ColoredChess chess)
    {
        m_shape     = chess.m_shape;
        m_direction = chess.m_direction;
        m_color     = new List <int>(chess.m_color);
        m_pos       = new List <Vector2Int>();
        m_pos.Add(pos);
        List <Vector2Int> temp = CalcAttachChessOffset(CalcAttachChessId(m_shape, m_direction), pos);

        m_pos.AddRange(temp);
    }
Ejemplo n.º 3
0
    void OnNextTurn()
    {
        //落子成功,更换下棋顺序
        m_chessTurn = (m_chessTurn == Game_Turn.turn_P1) ? Game_Turn.turn_P2 : Game_Turn.turn_P1;

        m_nextChess = new ColoredChess();
        m_nextChess.NewRandomChess(new Vector2Int(0, 0));

        for (int x = 0; x < x_len_chessboard_next; x++)
        {
            for (int y = 0; y < y_len_chessboard_next; y++)
            {
                m_chessState_next[x, y] = 0;
            }
        }
        PlacedChess(new Vector2Int(1, 1), ref m_nextChess, ref m_chessState_next);
    }
Ejemplo n.º 4
0
    bool CheckPlacedEnable(Vector2Int pos, ref ColoredChess cType, ref int[,] chessState)
    {
        ColoredChess next = new ColoredChess();

        next.InitChess(pos, ref cType);
        foreach (Vector2Int p in next.m_pos)
        {
            if (p.x >= x_len || p.x < 0)
            {
                return(false);
            }
            if (p.y >= y_len || p.y < 0)
            {
                return(false);
            }
            if (chessState[p.x, p.y] != 0)
            {
                return(false);
            }
        }
        return(true);
    }
Ejemplo n.º 5
0
    void OnGUI()
    {
        //绘制棋子
        for (int i = 0; i < x_len; i++)
        {
            for (int j = 0; j < y_len; j++)
            {
                Texture2D tempT = GetChessColorTexture(m_chessState[i, j]);
                if (m_chessState[i, j] != 0)
                {
                    GUI.DrawTexture(new Rect(m_chessPos[i, j].x - m_gridWidth / 2, Screen.height - m_chessPos[i, j].y - m_gridHeight / 2, m_gridWidth, m_gridHeight), tempT);
                }
            }
        }
        //绘制下一步棋子
        for (int i = 0; i < x_len_chessboard_next; i++)
        {
            for (int j = 0; j < y_len_chessboard_next; j++)
            {
                Texture2D tempT = GetChessColorTexture(m_chessState_next[i, j]);

                Vector2[,] tempV = m_chessPos_P1_next;
                if (m_chessTurn == Game_Turn.turn_P1)
                {
                    tempV = m_chessPos_P1_next;
                }
                else if (m_chessTurn == Game_Turn.turn_P2)
                {
                    tempV = m_chessPos_P2_next;
                }

                if (m_chessState_next[i, j] != 0)
                {
                    GUI.DrawTexture(new Rect(tempV[i, j].x - m_gridWidth / 2, Screen.height - tempV[i, j].y - m_gridHeight / 2, m_gridWidth, m_gridHeight), tempT);
                }
            }
        }
        //绘制鼠标上的棋子
        if (CheckPlacedEnable(m_chessPos_current, ref m_nextChess, ref m_chessState))
        {
            ColoredChess next = new ColoredChess();
            next.InitChess(m_chessPos_current, ref m_nextChess);
            foreach (KeyValuePair <Vector2Int, int> p in next.GetChessPosAndColor())
            {
                int i = p.Key.x;
                int j = p.Key.y;

                Texture2D tempT = GetChessColorTexture(p.Value);

                GUI.DrawTexture(new Rect(m_chessPos[i, j].x - m_gridWidth / 2, Screen.height - m_chessPos[i, j].y - m_gridHeight / 2, m_gridWidth, m_gridHeight), tempT);
            }
        }

        // 分数
        //GUI.DrawTexture(new Rect(V3_P1_PointPos.x - m_gridWidth / 2, Screen.height - V3_P1_PointPos.y - m_gridHeight / 2, m_gridWidth, m_gridHeight), T_chess_red);
        //GUI.DrawTexture(new Rect(V3_P2_PointPos.x - m_gridWidth / 2, Screen.height - V3_P2_PointPos.y - m_gridHeight / 2, m_gridWidth, m_gridHeight), T_chess_red);

        GUIStyle style = new GUIStyle();

        style.normal.background = null;                 //这是设置背景填充的
        style.normal.textColor  = new Color(230, 0, 0); //字体颜色
        style.fontSize          = 72;                   //字体大小

        string score = m_playerScore[(int)Game_Turn.turn_P1].ToString();

        GUI.Label(new Rect(V3_P1_PointPos.x + m_gridWidth, Screen.height - V3_P1_PointPos.y - m_gridHeight / 2, m_gridWidth, m_gridHeight), score, style);
        score = m_playerScore[(int)Game_Turn.turn_P2].ToString();
        GUI.Label(new Rect(V3_P2_PointPos.x + m_gridWidth, Screen.height - V3_P2_PointPos.y - m_gridHeight / 2, m_gridWidth, m_gridHeight), score, style);

        //根据获胜状态,弹出相应的胜利图片
        if (!m_isPlaying)
        {
            if (m_winner == 0)
            {
                GUI.DrawTexture(new Rect(Screen.width * 0.3f, Screen.height * 0.45f, Screen.width * 0.3f, Screen.height * 0.15f), T_Draw);
            }
            if (m_winner == 1)
            {
                GUI.DrawTexture(new Rect(Screen.width * 0.3f, Screen.height * 0.45f, Screen.width * 0.3f, Screen.height * 0.15f), T_P1_Win);
            }
            if (m_winner == 2)
            {
                GUI.DrawTexture(new Rect(Screen.width * 0.3f, Screen.height * 0.45f, Screen.width * 0.3f, Screen.height * 0.15f), T_P2_Win);
            }
        }
    }