Example #1
0
 public vicPiece Start(MyBoard board, int index)
 {
     vicPiece vic = new vicPiece();
     vic.index = -1;
     vic.nType = 0;
     //KT bomb
     if (board.arrSquares[_startIndex].bomb != 0 &&
         board.arrSquares[_startIndex].bomb != nType && Buff != 2) //Co bomb k fai cua doi minh
     {
         board.arrSquares[_startIndex].shield = 0;
         board.arrSquares[_startIndex].shadow = 0;
         InCage();
         board.arrSquares[_startIndex].bomb = 0;
         SoundPlayer sound1 = new SoundPlayer(@"Resources\Audio\ExClose.wav");
         sound1.LoadAsync();
         sound1.Play();
         sound1.Dispose();
         Started = false;
         Ended = false;
         return vic;
     }
     if (board.arrSquares[_startIndex].shadow != 1)
     {
         vic.nType = board.arrSquares[_startIndex].status;
         vic.index = board.arrSquares[_startIndex].curIndex;
     }
     _curPoint = start;
     _curIndex = _startIndex;
     board.arrSquares[_curIndex].status = nType;
     board.arrSquares[_curIndex].curIndex = index;
     SoundPlayer sound = new SoundPlayer(@"Resources\Audio\Start.wav");
     sound.LoadAsync();
     sound.Play();
     sound.Dispose();
     return vic;
 }
Example #2
0
        public vicPiece MoveSteponStep(MyBoard board, int index)
        {
            vicPiece vic = new vicPiece();
            vic.index = -1;
            vic.nType = 0;
            IsChoice = true;

            board.arrSquares[curIndex].status = 0;
            board.arrSquares[curIndex].curIndex = -1;
            board.arrSquares[curIndex].shadow = 0;
            board.arrSquares[curIndex].shield = 0;

            curIndex = (curIndex + 1) % 56;
            if (board.arrSquares[_curIndex].bomb != 0 &&
               board.arrSquares[_curIndex].bomb != nType && Buff != 6 && Buff != 2) //Co bomb k fai cua doi minh
            {
                board.arrSquares[_startIndex].shield = 0;
                board.arrSquares[_startIndex].shadow = 0;
                board.arrSquares[_curIndex].bomb = 0;
                InCage();
                vic.nType = -2;
                SoundPlayer sound1 = new SoundPlayer(@"Resources\Audio\ExClose.wav");
                sound1.LoadAsync();
                sound1.Play();
                Started = false;
                Ended = false;
                sound1.Dispose();
                return vic;
            }
            if (board.arrSquares[_curIndex].shadow != 1 && board.arrSquares[_curIndex].status != nType)
            {
                vic.nType = board.arrSquares[_curIndex].status;
                vic.index = board.arrSquares[_curIndex].curIndex;
            }
            if (board.arrSquares[curIndex].status == nType) // nguoi doi minh
                curIndex = (curIndex + 1) % 56;
            _curPoint = board.arrSquares[curIndex].square;
            board.arrSquares[_curIndex].status = nType;
            board.arrSquares[_curIndex].curIndex = index;
            if (curIndex == _endIndex)
                _ended = true;
            return vic;
        }
 private void Process(int t, int index)
 {
     for (int i = 0; i < cage[turn].nPieces; i++)
         if (cage[turn].Pieces[i].IsChoice)
             cage[turn].Pieces[i].IsChoice = false;
     SoundPlayer sound = new SoundPlayer(@"Resources\Audio\move.wav");
     sound.LoadAsync();
     sound.Play();
     sound.Dispose();
     int count = 0;
     while (count < go)
     {
         count++;
         vic = cage[t].Pieces[index].MoveSteponStep(board, index);
         if (vic.nType == -2)
         {
             this.Invoke(new AntiCrossThreadNoArgument(Refresh));
             break;
         }
         if (!this.InvokeRequired)
         {
             Refresh();
         }
         else
         {
             this.Invoke(new AntiCrossThreadNoArgument(Refresh));
         }
     }
 }
        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
        //+++++++++++++++++++++++++++ Computer AI +++++++++++++++++++++++++++++++++++++++++++++++++++//
        private void comAI()
        {
            go = Shaking();
            changeTurn(go);
            //Kiểm tra sử dụng Hổ báo
            if (hasProp)
            {
                isCrossUsed();
            }
            if (cage[turn].CanAction(go))
            {
                if (hasProp)
                {
                    isActiveProp();
                }
                int pieceindex;
                if ((cage[turn].Cross || cage[turn].SpeedUp || cage[turn].GetTurn) && cage[turn].PriP != -2)
                {
                    pieceindex = cage[turn].PriP + 10;
                    if (cage[turn].Pieces[pieceindex - 10].moveFail(go, board))
                    {
                        pieceindex = cage[turn].CheckPieceAI(go);
                    }
                    cage[turn].PriP = -2;
                }
                else
                {
                    pieceindex = cage[turn].CheckPieceAI(go);
                }
                if (pieceindex >= 10 && pieceindex <= 13)
                {
                    if (cage[turn].SpeedUp)
                        go = SpeedUp(turn, pieceindex - 10, go);
                    Process(turn, pieceindex - 10);

                }
                else
                {
                    if (pieceindex >= 20)
                    {
                        vic = cage[turn].Action_AI(go, pieceindex - 20);
                        this.Invoke(new AntiCrossThreadNoArgument(Refresh));
                        if (win)
                            goto exit;
                    }
                    if (pieceindex < 10)
                    {
                        vic = cage[turn].Action_AI(go, pieceindex);
                        this.Invoke(new AntiCrossThreadNoArgument(Refresh));
                    }
                }
            }
            if (turn == nextturn)
            {
                comAI();
            }
            else
            {
                if (!cage[turn].GetTurn)
                {
                    pString.Image = imglstString.Images[nextturn];
                    if (!pString.InvokeRequired)
                        pString.Visible = true;
                    else
                        pString.Invoke(new AntiCrossThread2Argument(SetVisible), pString, true);
                    //Refresh();
                    //Xóa đạo cụ chủ động nếu có xài
                    if (cage[turn].Cross)
                    {
                        cage[turn].Cross = false;
                        cage[turn].clearbuff(board);
                    }
                    if (cage[turn].SpeedUp)
                    {
                        cage[turn].SpeedUp = false;
                        cage[turn].clearbuff(board);//bug
                    }

                    if (cage[nextturn].Hide) //Xóa đạo cụ của địch
                    {
                        for (int i = 0; i < cage[nextturn].nPieces; i++)
                        {
                            MyPieces p = cage[nextturn].Pieces[i];
                            if (p.Started && !p.Ended)
                            {
                                int t = board.arrSquares[p.curIndex % 56].status;
                                if (t != nextturn + 1)
                                {
                                    if (t != 0)
                                    {
                                        int team = board.arrSquares[p.curIndex % 56].status - 1;
                                        int index = board.arrSquares[p.curIndex % 56].curIndex;
                                        cage[team].Update(index);
                                        SoundPlayer sound = new SoundPlayer(@"Resources\Audio\Kick.wav");
                                        sound.LoadAsync();
                                        sound.Play();
                                        sound.Dispose();
                                        this.Invoke(new AntiCrossThreadNoArgument(Refresh));
                                        //Thread.Sleep(300);
                                    }
                                    board.arrSquares[p.curIndex % 56].status = nextturn + 1;
                                    board.arrSquares[p.curIndex % 56].curIndex = i;
                                }
                            }
                        }
                        cage[nextturn].Hide = false;
                        cage[nextturn].clearbuff(board);
                    }
                    if (cage[nextturn].Shield) // Xóa đạo cụ của địch
                    {
                        cage[nextturn].Shield = false;
                        cage[nextturn].clearbuff(board);
                    }

                    for (int i = 0; i < cage[turn].nPieces; i++)
                    {
                        if (cage[turn].Pieces[i].IsChoice)
                            cage[turn].Pieces[i].IsChoice = false;
                    }
                    this.Invoke(new AntiCrossThreadNoArgument(Refresh));
                    if (cage[turn].Useprop)
                        cage[turn].Useprop = false;
                    //KT dùng passiveprop sau khi kết thúc lượt đi
                    if (hasProp)
                    {
                        isPassiveProp();
                    }
                    //Thread.Sleep(200);
                    pString.Invoke(new AntiCrossThread2Argument(SetVisible), pString, false);
                    pShake.Invoke(new AntiCrossThread3Argument(SetImage), pShake, imglstShake.Images[nextturn], 1);
                    btnShake.Invoke(new AntiCrossThread3Argument(SetImage), btnShake, imglstShake.Images[nextturn], 0);
                    turn = nextturn;
                    if (cage[nextturn].isPlayer)
                    {
                        pShake.Invoke(new AntiCrossThread2Argument(SetVisible), pShake, false);
                        btnShake.Invoke(new AntiCrossThread2Argument(SetVisible), btnShake, true);
                    }
                    else
                    {
                        comAI();
                    }
                }
                else
                {
                    MessageBox.Show("Tiếp tục 1 lượt nữa.");
                    cage[turn].GetTurn = false;
                    nextturn = turn;
                    //Refresh();
                    comAI();
                }
            }
            exit:
            if (win && !first)
            {
                first = true;
                Congratulation(turn);
                this.Invoke(new AntiCrossThreadNoArgument(frmMenu.Show));
                this.Invoke(new AntiCrossThreadNoArgument(Dispose));
            }
        }
 private void RacingHorses_MouseUp(object sender, MouseEventArgs e)
 {
     if (isClick == true)
     {
         for (int i = 0; i < cage[turn].nPieces; i++)
             if (cage[turn].Pieces[i].isChoice(e.X, e.Y))
                 if (cage[turn].IsAction(i, go))
                 {
                     isClick = false;
                     cage[turn].Pieces[i].IsChoice = true;
                     if (cage[turn].Pieces[i].Started && !cage[turn].Pieces[i].Ended)
                     {
                         if (cage[turn].SpeedUp)
                             go = SpeedUp(turn, i, go);
                         Process(turn, i);
                     }
                     else
                     {
                         vic = cage[turn].Action(go, i);
                         Refresh();
                         if (win)
                             break;
                     }
                     playerProcess();
                     break;
                 }
                 else
                     break;
     }
     if (win)
     {
         Congratulation(turn);
         this.Dispose();
         frmMenu.Show();
     }
 }
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
        private void RacingHorses_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 4; i++)
            {
                AiProps[i] = new MyProps();
            }

            pShake.Image = imglstShake.Images[0];
            pShake.Visible = false;
            imgarr = imglstArrow;
            pString.Visible = false;
            btnBuff[0] = btnHide;
            btnBuff[1] = btnShield;
            btnBuff[2] = btnGetTurn;
            btnBuff[3] = btnBomb;
            btnBuff[4] = btnSpeedup;
            btnBuff[5] = btnCross;
            cage = new MyCage[nCage];
            board = new MyBoard();
            for (int i = 0; i < 4; i++)
            {
                bool b = false;
                for (int t = 0; t < teamchoose.Count; t++)
                {
                    if (i == teamchoose[t])
                        b = true;
                }
                cage[i] = new MyCage(i + 1, 4, board, b);
            }
            dice = new MyDice();
            turn = 0;
            nextturn = 0;
            vic = new vicPiece();
            vic.index = -1;
            vic.nType = 0;
            if (!hasProp)
                board.props = false;
            btnShake.Visible = false;
            if (cage[0].isPlayer)
            {
                btnShake.Visible = true;
            }
            else
            {
                pShake.Visible = true;
                thread_AI = new Thread(Thread_AI);
                thread_AI.Start();
            }
        }