Exemple #1
0
    public void ClickSquare(int x, int y)
    {
        if (computer || gameOver)
        {
            return;
        }
        int sq = CoordXY(x, y);

        sq = situation.Filped ? SquareFilp(sq) : sq;
        int pc = situation.CurrentBoard[sq];

        //选中自己的棋子
        if ((pc & SideTag(situation.SdPlayer)) != 0)
        {
            sqSelected = sq;
            drawSelectHandle(true, x, y);
            SoundManager.MyInstance.PlayEffect(SoundManager.AUDIO_CLICK);
        }
        else if (sqSelected != 0)
        {
            int mv = Move(sqSelected, sq);
            if (situation.LegalMove(mv))
            {
                if (situation.MakeMove(mv))
                {
                    mvLast = mv;
                    DrawPiece(sqSelected, sq);
                    sqSelected = 0;
                    //检测重复局面
                    int repValue = situation.RepStatus(3);
                    if (situation.IsMate())
                    {
                        //分出胜负
                        Debug.Log("you win");
                        gameOver = true;
                    }
                    else if (repValue > 0)
                    {
                        //repValue是对电脑来说的分值
                        repValue = situation.RepValue(repValue);
                        int    soundId = 0;
                        string message = "";
                        if (repValue > WIN_VALUE)
                        {
                            soundId = SoundManager.AUDIO_LOSS;
                            message = "长打作负,请不要气馁!";
                        }
                        else if (repValue < -WIN_VALUE)
                        {
                            soundId = SoundManager.AUDIO_WIN;
                            message = "电脑长打作负,祝贺你取得胜利!";
                        }
                        else
                        {
                            soundId = SoundManager.AUDIO_DRAW;
                            message = "双方不变作和,辛苦了!";
                        }
                        SoundManager.MyInstance.PlayEffect(soundId);
                        Debug.Log(message);
                        gameOver = true;
                    }
                    else if (situation.MoveNum > 100)
                    {
                        SoundManager.MyInstance.PlayEffect(SoundManager.AUDIO_DRAW);
                        Debug.Log("超过自然限着作和,辛苦了!");
                        gameOver = true;
                    }
                    else
                    {
                        //将军或者吃子
                        int soundId = situation.Checked() ? SoundManager.AUDIO_ENEMY_CHECK : (pc != 0 ? SoundManager.AUDIO_CAPTURE : SoundManager.AUDIO_MOVE);
                        SoundManager.MyInstance.PlayEffect(soundId);
                        if (situation.Captured())
                        {
                            situation.SetIrrev();
                        }
                        //电脑走棋
                        computer = true;
                    }
                }
                else
                {
                    //被将军
                    SoundManager.MyInstance.PlayEffect(SoundManager.AUDIO_CHECK);
                }
            }
            else
            {
                //不合法的棋
                SoundManager.MyInstance.PlayEffect(SoundManager.AUDIO_ILLEGAL);
            }
        }
    }