Ejemplo n.º 1
0
        public void EnableLine(LogicLine line, bool flag)
        {
            if (LineTop.Line == line)
            {
                LineTop.Enabled = flag;
            }

            if (LineBottom.Line == line)
            {
                LineBottom.Enabled = flag;
            }

            if (LineLeft.Line == line)
            {
                LineLeft.Enabled = flag;
            }

            if (LineRight.Line == line)
            {
                LineRight.Enabled = flag;
            }

            if (IsComplete)
            {
                if (RectCompleted != null)
                {
                    RectCompleted(this);
                }
            }
        }
        public void EnableLine(Vector2 pos, LogicLine.Positioning positioning, int nextTurn)
        {
            /*int x = pos.X == 0 ? pos.X : pos.X - 1;
             * int y = pos.Y == 0 ? pos.Y : pos.Y - 1;
             * LogicRectangle rect = _gameField[x][y];
             * LogicLine line = rect.GetLine(pos, positioning);*/
            var result = from logicLine in LogicLines
                         where logicLine.Pos == pos && logicLine.LinePositioning == positioning
                         select logicLine;
            LogicLine line = result.First();

            Instance.nextTurn = nextTurn;

            UIController.Instance.NetRequestEnableLine(line);
        }
Ejemplo n.º 3
0
        public void GenerateStates(LogicRectangle[][] gameField)
        {
            //Horizontal cycle
            int            index = 0;
            LogicLine      line;
            LogicRectangle rect;
            LogicRectangle prevRect;

            do
            {
                for (int i = 0; i < gameField[index].Length; i++)
                {
                    rect = gameField[index][i];
                    if (i == 0)
                    {
                        line = new LogicLine(UIController.Instance.GetNewLine());
                        line.SetupUIVLine(new Vector2(index, i), gameField[index].Length);
                        line.RectRight        = rect;
                        rect.LineLeft.Line    = line;
                        rect.LineLeft.Enabled = true;
                        line.EnableLine(true);
                        continue;
                    }
                    prevRect = gameField[index][i - 1];
                    line     = new LogicLine(UIController.Instance.GetNewLine());
                    line.SetupUIVLine(new Vector2(index, i), gameField[index].Length);
                    line.RectLeft              = prevRect;
                    line.RectRight             = rect;
                    prevRect.LineRight.Line    = line;
                    prevRect.LineRight.Enabled = false;
                    rect.LineLeft.Line         = line;
                    rect.LineLeft.Enabled      = false;
                    line.EnableLine(false);

                    if (i == gameField[index].Length - 1)
                    {
                        line = new LogicLine(UIController.Instance.GetNewLine());
                        line.SetupUIVLine(new Vector2(index, ++i), gameField[index].Length);
                        line.RectLeft          = rect;
                        rect.LineRight.Line    = line;
                        rect.LineRight.Enabled = true;
                        line.EnableLine(true);
                    }
                }
                ++index;
            } while (index < gameField.Length);

            //Vertical cycle
            index = 0;
            int  min     = (gameField.Length - sideWidth) / 2;
            int  counter = 0;
            int  xPos    = 0;
            bool down    = false;

            do
            {
                int  j         = xPos;
                int  inCounter = 0;
                int  max       = min + gameField[index].Length - 1;
                bool back      = false;
                bool inFreeze  = false;
                for (int i = min; i <= max; i++)
                {
                    rect = gameField[i][j];
                    if (i == min)
                    {
                        line = new LogicLine(UIController.Instance.GetNewLine());
                        line.SetupUIHLine(new Vector2(i, index));
                        line.RectRight       = rect;
                        rect.LineTop.Line    = line;
                        rect.LineTop.Enabled = true;
                        line.EnableLine(true);
                    }
                    if (i > min && i <= max)
                    {
                        if (!inFreeze && !back)
                        {
                            prevRect = gameField[i - 1][j - 1];
                        }
                        else if (inFreeze && !back)
                        {
                            prevRect = gameField[i - 1][j];
                        }
                        else
                        {
                            prevRect = gameField[i - 1][j + 1];
                        }
                        line = new LogicLine(UIController.Instance.GetNewLine());
                        line.SetupUIHLine(new Vector2(i, index));
                        line.RectLeft               = prevRect;
                        line.RectRight              = rect;
                        prevRect.LineBottom.Line    = line;
                        prevRect.LineBottom.Enabled = false;
                        rect.LineTop.Line           = line;
                        rect.LineTop.Enabled        = false;
                        line.EnableLine(false);
                    }

                    if (i == max)
                    {
                        line = new LogicLine(UIController.Instance.GetNewLine());
                        line.SetupUIHLine(new Vector2(i + 1, index));
                        line.RectLeft           = rect;
                        rect.LineBottom.Line    = line;
                        rect.LineBottom.Enabled = true;
                        line.EnableLine(true);
                    }

                    if (j == index)
                    {
                        ++inCounter; inFreeze = true;
                    }
                    if (j < index && !back)
                    {
                        ++j;
                    }
                    if (inCounter == sideWidth)
                    {
                        back = true; inFreeze = false;
                    }
                    if (back)
                    {
                        --j;
                    }
                }
                if (min == 0)
                {
                    ++counter;
                }
                if (min == 0 && counter < sideWidth)
                {
                    xPos++;
                }
                if (min > 0 && !down)
                {
                    --min;
                }
                if (counter == sideWidth)
                {
                    down = true;
                }
                if (down)
                {
                    ++min;
                }
                if (min > 0 && counter == sideWidth)
                {
                    xPos += 2;
                }

                ++index;
            } while (index < gameField.Length);
        }