Esempio n. 1
0
        public void SetRandomChess(int x, int y, int color)
        {
            //set an adjacent random chess
            //the minimum index for both x and y is 0, and the maximum is 14
            int        i         = x - 1;
            int        j         = y - 1;
            List <int> positions = new List <int>();

            for (int m = i; m < i + 3; m++)
            {
                for (int n = j; n < j + 3; n++)
                {
                    try
                    {
                        if (gameBoard.Grid[m, n] == GoBangBoard.None)
                        {
                            positions.Add(n * 15 + m);
                        }
                    }
                    catch
                    {
                        continue; //do no_op
                    }
                }
            }

            RandomSelect randomselect = new RandomSelect(positions);

            try
            {
                int positionCode = randomselect.getRandomSelectNumber();

                int setX = positionCode % 15;
                int setY = positionCode / 15;

                gameBoard.Grid[setX, setY] = color;

                if (gameBoard.NextIndex == 0)  //
                {
                    gameBoard.NextIndex = 1;
                }
                else
                {
                    gameBoard.NextIndex = 0;
                }

                service.SendToRoom(this, string.Format("SetChess,{0},{1},{2}", setX, setY, color));
                if (gameBoard.IsWin(setX, setY))
                {
                    ShowWin(color);
                }
                else
                {
                    service.SendToRoom(this, string.Format("NextChess,{0}", gameBoard.NextIndex));
                    round++;
                }
            }
            catch
            {
                service.SendToRoom(this, string.Format("NextChess,{0}", gameBoard.NextIndex));
                round++;
            }
        }
Esempio n. 2
0
        //public void SetIllusionSpellTimeCollapse()
        //{
        //    //illusionSpellTimer--;
        //    //for (int i = 0; i < IllusionSpellList.Count; i++)
        //    //{
        //    foreach (IllusionSpell item in IllusionSpellList)
        //    {
        //        if (item.illusionSpellTimer>0)
        //        {
        //            item.illusionSpellTimer--;
        //            service.SendToRoom(this, string.Format("IllusionSpellTimeCollapse,{0}",item.side));
        //        }

        //    }

        //    //}

        //}

        //public void SetIllusionSpellRelease(int IllusionSpellReleaseX, int IllusionSpellReleaseY,int side)
        //{
        //    IllusionSpell illusionSpell = new IllusionSpell(side);  //
        //    for (int i = 0; i < IllusionSpellList.Count; i++)
        //    {
        //        if (IllusionSpellList[i].side == side)
        //        {
        //            illusionSpell = IllusionSpellList[i];
        //        }
        //    }
        //    gameBoard.Grid[IllusionSpellReleaseX, IllusionSpellReleaseY] = illusionSpell.preIllusionState ;
        //    service.SendToRoom(this, string.Format("SetIllusionSpellRelease,{0},{1},{2},{3}", IllusionSpellReleaseX, IllusionSpellReleaseY, illusionSpell.preIllusionState, side));
        //    Thread.Sleep(50);
        //    if ((gameBoard.IsWin(IllusionSpellReleaseX, IllusionSpellReleaseY))&&(hasShowWinWithIllusionSpell == false))
        //    {
        //        hasShowWinWithIllusionSpell = true; //This sentence must be put up front before the next one(ShowWin(preIllusionState);)
        //        ShowWin(preIllusionState);

        //    }
        //    //else
        //    //{
        //    //    service.SendToRoom(this, string.Format("NextChess,{0}", gameBoard.NextIndex));
        //    //}
        //}

        public void SetDivisionSpell(int x, int y, int color)
        {
            List <int> positions = new List <int>();

            for (int m = 0; m <= gameBoard.Grid.GetUpperBound(0); m++)
            {
                for (int n = 0; n <= gameBoard.Grid.GetUpperBound(1); n++)
                {
                    try
                    {
                        if (gameBoard.Grid[m, n] == GoBangBoard.None)
                        {
                            positions.Add(n * 15 + m);
                        }
                    }
                    catch
                    {
                        continue; //do no_op
                    }
                }
            }

            RandomSelect randomselect = new RandomSelect(positions);  //???

            try
            {
                int positionCode = randomselect.getRandomSelectNumber();
                //  Thread.Sleep(100);
                positions.Remove(positionCode);  //////////////////

                int setX1 = positionCode % 15;
                int setY1 = positionCode / 15;

                gameBoard.Grid[setX1, setY1] = color;


                RandomSelect randomselect2 = new RandomSelect(positions);

                try
                {
                    int positionCode2 = randomselect2.getRandomSelectNumber();
                    //  Thread.Sleep(100);
                    positions.Remove(positionCode2);

                    int setX2 = positionCode2 % 15;
                    int setY2 = positionCode2 / 15;

                    gameBoard.Grid[setX2, setY2] = color;

                    ////////////
                    try
                    {
                        int positionCode3 = randomselect2.getRandomSelectNumber();
                        positions.Remove(positionCode3);
                        int setX3 = positionCode3 % 15;
                        int setY3 = positionCode3 / 15;
                        gameBoard.Grid[setX3, setY3] = color;

                        try
                        {
                            int positionCode4 = randomselect2.getRandomSelectNumber();
                            positions.Remove(positionCode4);
                            int setX4 = positionCode4 % 15;
                            int setY4 = positionCode4 / 15;
                            gameBoard.Grid[setX4, setY4] = color;

                            gameBoard.Grid[x, y] = GoBangBoard.None;

                            if (gameBoard.NextIndex == 0)  //
                            {
                                gameBoard.NextIndex = 1;
                            }
                            else
                            {
                                gameBoard.NextIndex = 0;
                            }

                            service.SendToRoom(this, string.Format("TriggerBoom,{0},{1},{2},{3}", x, y, GoBangBoard.None, color)); // is equavalent to trigger a boom
                            service.SendToRoom(this, string.Format("SetChess,{0},{1},{2}", setX1, setY1, color));
                            service.SendToRoom(this, string.Format("SetChess,{0},{1},{2}", setX2, setY2, color));
                            service.SendToRoom(this, string.Format("SetChess,{0},{1},{2}", setX3, setY3, color));
                            service.SendToRoom(this, string.Format("SetChess,{0},{1},{2}", setX4, setY4, color));
                            if (gameBoard.IsWin(setX1, setY1))
                            {
                                ShowWin(color);
                            }
                            else if (gameBoard.IsWin(setX2, setY2))
                            {
                                ShowWin(color);
                            }
                            else
                            {
                                service.SendToRoom(this, string.Format("NextChess,{0}", gameBoard.NextIndex));
                            }
                        }
                        catch
                        {
                            service.SendToRoom(this, string.Format("NextChess,{0}", gameBoard.NextIndex)); //No empty cell
                            round++;
                        }
                    }
                    catch
                    {
                        service.SendToRoom(this, string.Format("NextChess,{0}", gameBoard.NextIndex)); //No empty cell
                        round++;
                    }
                }
                catch
                {
                    service.SendToRoom(this, string.Format("NextChess,{0}", gameBoard.NextIndex)); //No empty cell
                    round++;
                }
            }
            catch
            {
                service.SendToRoom(this, string.Format("NextChess,{0}", gameBoard.NextIndex)); //No empty cell
                round++;
            }
        }