Example #1
0
        private IChecker[][] CreateStateCopy(IChecker[][] state)
        {
            IChecker[][]   newState = new IChecker[9][];
            CheckerFactory factory  = CheckerFactory.GetInstance();

            for (int i = 1; i <= 8; i++)
            {
                newState[i] = new IChecker[9];
            }

            for (int i = 1; i <= 8; i++)
            {
                for (int j = 1; j <= 8; j++)
                {
                    if (state[i][j] != null)
                    {
                        if (state[i][j] is BlackChecker)
                        {
                            IChecker black = factory.CreateBlackPhantom(new Coord(i, j), gameField);
                            newState[i][j] = black;
                        }
                        else if (state[i][j] is WhiteChecker)
                        {
                            newState[i][j] = factory.CreateWhitePhantom(new Coord(i, j), gameField);
                        }
                        if (newState[i][j].IsKing)
                        {
                            state[i][j].BecomeKing();
                        }
                    }
                }
            }
            return(newState);
        }
 public static CheckerFactory GetInstance()
 {
     if (instance == null)
     {
         instance = new CheckerFactory();
     }
     return(instance);
 }
Example #3
0
        public GameField(MainWindow mainWindow)
        {
            this.mainWindow = mainWindow;
            this.formGrid   = mainWindow.grid;
            CheckerFactory factory = CheckerFactory.GetInstance();

            grid = new IChecker[9][];
            for (int i = 1; i <= 8; i++)
            {
                grid[i] = new IChecker[9];
            }

            stepsHistory = new List <string>();
            Turn         = Lib.PlayersSide.WHITE; // whites start

            for (int i = 1; i <= 8; i++)          //генерация шашек
            {
                if (i % 2 == 0)
                {
                    factory.CreateWhite(new Coord(7, i), this);
                    factory.CreateBlack(new Coord(3, i), this);
                    factory.CreateBlack(new Coord(1, i), this);
                }
                else
                {
                    factory.CreateBlack(new Coord(2, i), this);
                    factory.CreateWhite(new Coord(6, i), this);
                    factory.CreateWhite(new Coord(8, i), this);
                }
            }

            //factory.CreateBlack(new Coord(5, 2), this);
            //factory.CreateBlack(new Coord(4, 3), this);
            //IChecker checker = factory.CreateWhite(new Coord(2, 3), this);
            //checker.BecomeKing();
        }