Пример #1
0
        }//close CheckAnyJump

        /// <summary>
        /// makes the piece jump if there is a valid square to jump to
        /// </summary>
        /// <param name="enemyRow">row of location of enenmy</param>
        /// <param name="targetRow">row of location to jump to</param>
        /// <param name="enemyCol">column of location of enenmy</param>
        /// <param name="targetCol">column of location to jump to</param>
        /// <param name="current">current locaiton of piece</param>
        /// <param name="enemy">color of enemy</param>
        /// <param name="jumpMore">result of CheckAnyJump to find any more valid jumps</param>
        /// <returns></returns>
        private bool MakeJump(int enemyRow, int targetRow, int enemyCol, int targetCol,
                              BoardSquare current, SquareColor enemy, out bool jumpMore)
        {
            if (enemyRow < 1 || targetRow < 1 || enemyCol < 1 || targetCol < 1 ||
                enemyRow > 8 || targetRow > 8 || enemyCol > 8 || targetCol > 8)
            {
                jumpMore = false;
                return(false);
            }
            BoardSquare targetTemp;
            BoardSquare enemyTemp;

            if (CheckCapture(_board[enemyRow], enemyCol, enemy, out enemyTemp) &&
                CheckCapture(_board[targetRow], targetCol, SquareColor.None, out targetTemp))
            {
                if (enemyTemp.Color == SquareColor.Red)
                {
                    _redCount--;
                }
                else
                {
                    _blackCount--;
                }
                enemyTemp.Color = SquareColor.None;
                targetTemp.King = current.King;
                jumpMore        = (CheckAnyJump(targetTemp, enemy));
                return(true);
            }
            jumpMore = false;
            return(false);
        }// close MakeJump
    private void SetInitialState()
    {
        for (int i = 0; i < 5; i++)
        {
            _colors[3 * i]       = _colorCandidates[i];
            _colors[(3 * i) + 1] = _colorCandidates[i];
            _colors[(3 * i) + 2] = _colorCandidates[i];
        }

        _firstStageColor = _colorCandidates[Rnd.Range(0, _colorCandidates.Length)];
        _colors[15]      = _firstStageColor;
        _colors.Shuffle();

        _allowedPresses   = new HashSet <int>();
        _currentColor     = _firstStageColor;
        _startingPosition = -1;
        _lastPress        = -1;

        for (int i = 0; i < 16; i++)
        {
            if (_colors[i] == _firstStageColor)
            {
                _allowedPresses.Add(i);
            }
        }

        Log("Initial state: {0}", _colors.Select(c => c.ToString()[0]).JoinString(" "));
        Scaffold.StartSquareColorsCoroutine(_colors, delay: true);
        Log("First color to press is {0}.", _firstStageColor);
    }
Пример #3
0
        private List <Square> GetColorableSquare(SquareColor putColor, Func <Square, Square> nextSquare)
        {
            SquareColor findColor = putColor.TurnColor();
            var         list      = new List <Square>();
            Square      v         = nextSquare(this);

            if (v != null && v.Color == findColor)
            {
                while (v != null)
                {
                    if (v.Color == putColor)
                    {
                        return(list);
                    }
                    else if (v.Color == SquareColor.Null)
                    {
                        list.Clear();
                        return(list);
                    }
                    list.Add(v);
                    v = nextSquare(v);
                }
                list.Clear();
            }
            return(list);
        }
Пример #4
0
    private void SetInitialState()
    {
        SetAllBlack();

        // Decide which color is the “neutral” color (the remaining four are the “live” ones)
        var colors = _usefulColors.ToArray().Shuffle();

        _rememberedColors    = colors.Subarray(0, 4);                                      // this array will be reordered as the player presses them
        _rememberedPositions = Enumerable.Range(0, 16).ToArray().Shuffle().Subarray(0, 4); // will be re-populated as the player presses them
        _neutralColor        = colors[4];
        _stage       = 0;
        _subprogress = 0;

        for (int i = 0; i < 16; i++)
        {
            _colors[i] = _neutralColor;
        }
        for (int i = 0; i < 4; i++)
        {
            _colors[_rememberedPositions[i]] = _rememberedColors[i];
        }

        Debug.LogFormat("[Discolored Squares #{0}] Initial colors are: {1}", _moduleId, _rememberedColors.Select((c, cIx) => string.Format("{0} at {1}", c, coord(_rememberedPositions[cIx]))).Join(", "));
        StartSettingSquareColors(delay: true);
    }
    private void SetInitialState()
    {
tryAgain:
        var counts = new int[5];

        for (int i = 0; i < 16; i++)
        {
            _colors[i] = (SquareColor)Rnd.Range(1, 6);
            counts[(int)_colors[i] - 1]++;
        }
        var minCount      = counts.Where(c => c > 0).Min();
        var minCountColor = (SquareColor)(Array.IndexOf(counts, minCount) + 1);

        if (counts.Count(c => c == minCount) > 1)
        {
            goto tryAgain;
        }

        _firstStageColor = minCountColor;
        _lastStage       = minCountColor;
        _expectedPresses = new HashSet <int>();
        _allowedPresses  = new HashSet <int>();
        for (int i = 0; i < 16; i++)
        {
            if (_colors[i] == minCountColor)
            {
                _allowedPresses.Add(i);
                _expectedPresses.Add(i);
            }
        }
        Scaffold.StartSquareColorsCoroutine(_colors, SquaresToRecolor.NonwhiteOnly, delay: true);
        Log("First stage color is {0}. Count: {1}.", _firstStageColor, minCount);
        LogDebug("Colors: {0}", _colors.JoinString(", "));
    }
    private void SetInitialState()
    {
        for (int i = 0; i < 5; i++)
        {
            _colors[3 * i]       = (SquareColor)i;
            _colors[(3 * i) + 1] = (SquareColor)i;
            _colors[(3 * i) + 2] = (SquareColor)i;
        }

        _firstStageColor = (SquareColor)Rnd.Range(0, 5);
        _colors[15]      = _firstStageColor;

        Shuffle(_colors);

        _allowedPresses   = new HashSet <int>();
        _currentColor     = _firstStageColor;
        _startingPosition = -1;
        _lastPress        = -1;

        for (int i = 0; i < 16; i++)
        {
            if (_colors[i] == _firstStageColor)
            {
                _allowedPresses.Add(i);
            }
        }

        Debug.LogFormat(@"[VaricoloredSquares #{0}] Initial state: {1}", _moduleId, string.Join(" ", _colors.Select(c => "RBGYM"[(int)c].ToString()).ToArray()));

        _activeCoroutine = StartCoroutine(SetSquareColors(delay: true));
        Debug.LogFormat(@"[VaricoloredSquares #{0}] First color to press is {1}.", _moduleId, _firstStageColor);
    }
Пример #7
0
    static void InitializeCubeColors(SquareColor[,] danceCube)
    {
        // Set counter to 0
        int counter = 0;

        // Iterate through the cube, setting the appropriate color
        for (int squareRow = 0; squareRow < danceCube.GetLength(0); squareRow++)
        {
            for (int squareCol = 0; squareCol < danceCube.GetLength(1); squareCol++)
            {
                if (counter % 2 == 0)
                {
                    danceCube[squareRow, squareCol] = SquareColor.RED;
                }
                else
                {
                    danceCube[squareRow, squareCol] = SquareColor.BLUE;
                }

                counter++;
            }
        }

        // Set the middle square color to Green
        danceCube[1, 1] = SquareColor.GREEN;
    }
Пример #8
0
        private Texture2D GetSquareTexture(SquareColor color)
        {
            Texture2D squareTexture;

            switch (color)
            {
            case SquareColor.Empty: return(null);

            case SquareColor.Red: squareTexture = _squareRed; break;

            case SquareColor.Blue: squareTexture = _squareBlue; break;

            case SquareColor.Green: squareTexture = _squareGreen; break;

            case SquareColor.Yellow: squareTexture = _squareYellow; break;

            case SquareColor.Orange: squareTexture = _squareOrange; break;

            case SquareColor.Violet: squareTexture = _squareViolet; break;

            case SquareColor.LightBlue: squareTexture = _squareLightBlue; break;

            default: throw new Exception("Unknown SquareColor");
            }
            return(squareTexture);
        }
Пример #9
0
 public static bool Send(Objects.Client client, uint creatureId, SquareColor color)
 {
     CreatureSquarePacket p = new CreatureSquarePacket(client);
     p.CreatureId = creatureId;
     p.Color = color;
     return p.Send();
 }
Пример #10
0
 /// <summary>
 /// Create a square with the specified file and rank.
 /// </summary>
 /// <param name="file"><see cref="File"/></param>
 /// <param name="rank"><see cref="Rank"/></param>
 public Square(File file, int rank)
 {
     _file = file;
     _rank = rank;
     _color = (rank + (int) file) % 2 == 0
         ? SquareColor.Dark
         : SquareColor.Light;
 }
Пример #11
0
 /// <summary>
 /// Create a square with the specified file and rank.
 /// </summary>
 /// <param name="file"><see cref="File"/></param>
 /// <param name="rank"><see cref="Rank"/></param>
 public Square(File file, int rank)
 {
     _file  = file;
     _rank  = rank;
     _color = (rank + (int)file) % 2 == 0
         ? SquareColor.Dark
         : SquareColor.Light;
 }
Пример #12
0
        private void InitializeSquares(ref Point topOfSpacePoint, int x, int y, SquareColor color)
        {
            Square p = new Square(topOfSpacePoint, false, color, true);

            topOfSpacePoint.Y = topOfSpacePoint.Y + 50;

            arrayAvail[x, y] = p;
        }
Пример #13
0
        public static bool Send(Objects.Client client, uint creatureId, SquareColor color)
        {
            CreatureSquarePacket p = new CreatureSquarePacket(client);

            p.CreatureId = creatureId;
            p.Color      = color;
            return(p.Send());
        }
Пример #14
0
    //assigning defaults
    public override void SetOrigin()
    {
        base.SetOrigin();

        originPosition      = transform.position;
        originColor         = color;
        originFaceDirection = faceDirection;
    }
Пример #15
0
        }//close CheckCapture

        /// <summary>
        /// returns if row of cells given by cell contains a piece in the
        /// targetColor in the targetCol. out is set to square in column
        /// </summary>
        /// <param name="cell">given board cell</param>
        /// <param name="targetCol">given column</param>
        /// <param name="targetColor">given color</param>
        /// <returns></returns>
        private bool CheckCapture(LinkedListCell <BoardSquare> cell, int targetCol,
                                  SquareColor targetColor)
        {
            while (cell.Data.Column != targetCol)
            {
                cell = cell.Next;
            }
            return(cell.Data.Color == targetColor);
        }//close CheckCapture
Пример #16
0
 public void CreateFigureSquare(int x, int y, SquareColor color)     // координаты в матрице
 {
     y -= 4;
     if (x < 0 || x >= MatrixSizeX || y < 0 || y >= MatrixSizeY)
     {
         return;
     }
     CreateSquare(_figureObject, x, y, color);
 }
Пример #17
0
        public Square(Point point, bool queenOnSquare, SquareColor squareColor, bool squareAvailable)
        {
            Rectangle myRect = new Rectangle(point.X, point.Y, 50, 50); //TODO: take another look at this.

            this.QueenOnSquare   = queenOnSquare;
            this.SquareColor     = squareColor;
            this.x               = point.X;
            this.y               = point.Y;
            this.SquareAvailable = squareAvailable;
        }
Пример #18
0
    //reset to defaults
    public override void Initialize()
    {
        base.Initialize();

        transform.position = originPosition;
        color         = originColor;
        faceDirection = originFaceDirection;

        move = false;
    }
Пример #19
0
 private void Write(SquareColor color)
 {
     if (color == SquareColor.Black)
     {
         Write("●");
     }
     else if (color == SquareColor.White)
     {
         Write("○");
     }
 }
Пример #20
0
 private SquareColor changeColorOfSquare(SquareColor temp)
 {
     if (temp == SquareColor.Black)
     {
         return(SquareColor.White);
     }
     else
     {
         return(SquareColor.Black);
     }
 }
Пример #21
0
        public void PutColor(int x, int y, SquareColor putColor)
        {
            var    list = GetTurnableSquare(x, y, putColor);
            Square s    = Square[x, y];

            foreach (var v in list)
            {
                v.Color = putColor;
            }
            s.Color = putColor;
        }
Пример #22
0
 private static Image DrawSquare(SquareColor color, PlayerColor player = 0, Type piece = null)
 {
     var image = new Bitmap(100, 100);
     using (var g = Graphics.FromImage(image))
     {
         g.FillRectangle(new SolidBrush(color.ToColor()), 0, 0, 100, 100);
         if (piece != null)
             g.DrawImage(Images.GetPieceImage(player, piece), 0, 0, 100, 100);
     }
     return image;
 }
Пример #23
0
 public static SquareColor TurnColor(this SquareColor color)
 {
     if (color == SquareColor.Black)
     {
         return(SquareColor.White);
     }
     else if (color == SquareColor.White)
     {
         return(SquareColor.Black);
     }
     return(color);
 }
Пример #24
0
        public List <Square> GetColorableSquare(SquareColor putColor)
        {
            var list = new List <Square>();

            foreach (Square s in Square)
            {
                if (s.Color != SquareColor.Null)
                {
                    continue;
                }
                if (s.GetLeftOverColorableSquare(putColor).Count > 0)
                {
                    list.Add(s);
                    continue;
                }
                if (s.GetOverColorableSquare(putColor).Count > 0)
                {
                    list.Add(s);
                    continue;
                }
                if (s.GetRightOverColorableSquare(putColor).Count > 0)
                {
                    list.Add(s);
                    continue;
                }
                if (s.GetRightColorableSquare(putColor).Count > 0)
                {
                    list.Add(s);
                    continue;
                }
                if (s.GetRightUnderColorableSquare(putColor).Count > 0)
                {
                    list.Add(s);
                    continue;
                }
                if (s.GetUnderColorableSquare(putColor).Count > 0)
                {
                    list.Add(s);
                    continue;
                }
                if (s.GetLeftUnderColorableSquare(putColor).Count > 0)
                {
                    list.Add(s);
                    continue;
                }
                if (s.GetLeftColorableSquare(putColor).Count > 0)
                {
                    list.Add(s);
                    continue;
                }
            }
            return(list);
        }
Пример #25
0
    private void Awake()
    {
        //get references
        triangle   = transform.Find("Triangle");
        squareTop  = transform.Find("SquareTop").GetComponent <SpriteRenderer>();
        squareSide = transform.Find("SquareSide").GetComponent <SpriteRenderer>();
        indicator  = transform.Find("Indicator").GetComponent <SpriteRenderer>();

        transform.name = "Square";
        Color          = Color;
        Direction      = Direction;
    }
Пример #26
0
        public static SquareColor[,] Select(this SquareColor[,] matrix, ReturnElemetAndIndex callback)
        {
            var newMatrix = new SquareColor[matrix.GetLength(0), matrix.GetLength(1)];

            for (int i = 0; i < matrix.GetLength(0); ++i)
            {
                for (int j = 0; j < matrix.GetLength(1); ++j)
                {
                    newMatrix[i, j] = callback(i, j, matrix[i, j]);
                }
            }
            return(newMatrix);
        }
Пример #27
0
 public void SetButtonColor(int ix, SquareColor color)
 {
     if (color == SquareColor.Black)
     {
         SetButtonBlack(ix);
     }
     else
     {
         _buttonRenderers[ix].sharedMaterial = IsColorblind ? MaterialsCB[(int)color] ?? Materials[(int)color] : Materials[(int)color];
         Lights[ix].color = _lightColors[(int)color];
         Lights[ix].gameObject.SetActive(true);
     }
 }
Пример #28
0
        }//close CheckCapture

        /// <summary>
        /// checks if a jump is possible given location of the enemy
        /// </summary>
        /// <param name="enemyRow">row of location of enenmy</param>
        /// <param name="targetRow">row of location to jump to</param>
        /// <param name="enemyCol">column of location of enenmy</param>
        /// <param name="targetCol">column of location to jump to</param>
        /// <param name="current">current locaiton of piece</param>
        /// <param name="enemy">color of enemy</param>
        /// <returns></returns>
        private bool CheckJump(int enemyRow, int targetRow, int enemyCol, int targetCol,
                               BoardSquare current, SquareColor enemy)
        {
            if (enemyRow < 1 || targetRow < 1 || enemyCol < 1 || targetCol < 1 ||
                enemyRow > 8 || targetRow > 8 || enemyCol > 8 || targetCol > 8)
            {
                return(false);
            }
            else
            {
                return(CheckCapture(_board[enemyRow], enemyCol, enemy) &&
                       (CheckCapture(_board[targetRow], targetCol, SquareColor.None)));
            }
        }//close CheckJump
Пример #29
0
        }// close MakeJump

        /// <summary>
        /// returns true if the piece at current BoardSquare
        /// can jump over an enemy to the target square
        /// </summary>
        /// <param name="current">current location of piece</param>
        /// <param name="target">target square to jump to</param>
        /// <param name="enemy">color of enemy</param>
        /// <param name="jumpMore">returns if piece can jump again</param>
        /// <returns></returns>
        private bool Jump(BoardSquare current, BoardSquare target,
                          SquareColor enemy, out bool jumpMore)
        {
            int rowNum = 0;
            int colNum = 0;

            if (current.King)
            {
                if (current.Row - target.Row == 2)
                {
                    rowNum = current.Row - 1;
                }
                else
                {
                    rowNum = current.Row + 1;
                }
            }//close if
            else if (Math.Abs(current.Row - target.Row) == 2)
            {
                if (enemy == SquareColor.Red)
                {
                    rowNum = current.Row - 1;
                }
                else
                {
                    rowNum = current.Row + 1;
                }
            }//close else if
            else
            {
                jumpMore = true;
                return(false);
            }//close else

            if (current.Column - target.Column == -2)
            {
                colNum = current.Column + 1;
            }
            else if (current.Column - target.Column == 2)
            {
                colNum = current.Column - 1;
            }
            else
            {
                jumpMore = true;
                return(false);
            }
            return(MakeJump(rowNum, target.Row, colNum, target.Column, current, enemy, out jumpMore));
        }//close Jump
Пример #30
0
        public override bool ParseMessage(NetworkMessage msg, PacketDestination destination)
        {
            int position = msg.Position;

            if (msg.GetByte() != (byte)IncomingPacketType.CreatureSquare)
                return false;

            Destination = destination;
            Type = IncomingPacketType.CreatureSquare;

            CreatureId = msg.GetUInt32();
            Color = (SquareColor)msg.GetByte();

            return true;
        }
Пример #31
0
        public List <Square> GetTurnableSquare(int x, int y, SquareColor putColor)
        {
            var    list = new List <Square>();
            Square s    = Square[x, y];

            list.AddRange(s.GetLeftOverColorableSquare(putColor));
            list.AddRange(s.GetOverColorableSquare(putColor));
            list.AddRange(s.GetRightOverColorableSquare(putColor));
            list.AddRange(s.GetRightColorableSquare(putColor));
            list.AddRange(s.GetRightUnderColorableSquare(putColor));
            list.AddRange(s.GetUnderColorableSquare(putColor));
            list.AddRange(s.GetLeftUnderColorableSquare(putColor));
            list.AddRange(s.GetLeftColorableSquare(putColor));
            return(list);
        }
Пример #32
0
    private void SetInitialState()
    {
tryAgain:
        var counts = new Dictionary <SquareColor, int>();

        foreach (var c in _colorsInUse)
        {
            counts[c] = 1;
        }
        var indexes = Enumerable.Range(0, 16).ToList().Shuffle().Take(_colorsInUse.Length).ToArray();

        for (var i = 0; i < _colorsInUse.Length; i++)
        {
            _colors[indexes[i]] = _colorsInUse[i];
        }
        for (int i = 0; i < 16; i++)
        {
            if (!indexes.Contains(i))
            {
                _colors[i] = _colorsInUse.PickRandom();
                counts[_colors[i]]++;
            }
        }
        var minCount = _colorsInUse.Min(c => counts[c]);

        if (counts.Count(kvp => kvp.Value == minCount) > 1)
        {
            goto tryAgain;
        }

        var minCountColor = _colorsInUse.First(c => counts[c] == minCount);

        _firstStageColor = minCountColor;
        _lastStage       = minCountColor;
        _expectedPresses = new HashSet <int>();
        _allowedPresses  = new HashSet <int>();
        for (int i = 0; i < 16; i++)
        {
            if (_colors[i] == minCountColor)
            {
                _allowedPresses.Add(i);
                _expectedPresses.Add(i);
            }
        }
        StartSquareColorsCoroutine(_colors, SquaresToRecolor.NonwhiteOnly, delay: true);
        Log("First stage color is {0}. Count: {1}.", _firstStageColor, minCount);
        LogDebug("Colors: {0}", _colors.JoinString(", "));
    }
Пример #33
0
        private void ReadTypes()
        {
            string[] lines = File.ReadAllLines("Figures.txt");

            int j = 0;

            SquareColor[,] matrix = new SquareColor[4, 4];;
            foreach (var line in lines)
            {
                string[] elements = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (elements.Length == 0)
                {
                    continue;
                }
                if (elements.Length != 4)
                {
                    throw new Exception("Wrong format of Figures.txt");
                }


                for (int i = 0; i < elements.Length; ++i)
                {
                    int color = 0;
                    if (!int.TryParse(elements[i], out color))
                    {
                        throw new Exception("Wrong format of Figures.txt");
                    }
                    matrix[i, j] = (SquareColor)color;
                }

                j++;
                if (j > 3)
                {
                    _types.Add(matrix);
                    j      = 0;
                    matrix = new SquareColor[4, 4];
                }
            }

            if (j != 0)
            {
                throw new Exception("Wrong format of Figures.txt");
            }
            if (_types.Count == 0)
            {
                throw new Exception("Wrong format of Figures.txt");
            }
        }
Пример #34
0
        /// <summary>
        /// Create board(squares and checkers).
        /// </summary>
        /// <param name="userColor"></param>
        public void PrepareBoard(UserColor userColor)
        {
            for (int i = 0; i < _boardSize; i++)
            {
                for (int j = 0; j < _boardSize; j++)
                {
                    var         position    = new Position(i, j);
                    var         id          = j * _boardSize + i;
                    SquareColor squareColor = (i + j) % 2 == 0 ? SquareColor.White : SquareColor.Black;

                    Square square = new Square(id, position, squareColor);
                    _boardSquares[i, j]     = square;
                    _squaresData[square.Id] = square;
                }
            }

            int c = 0, index = 0;

            while (c < 2)
            {
                if (_boardSquares[index / _boardSize, index % _boardSize].Color == SquareColor.Black)
                {
                    var     checkerColor = userColor == UserColor.White ? CheckerColor.Black : CheckerColor.White;
                    Checker checker      = new Checker(index, _squaresData[index], checkerColor);
                    _checkersData[index] = checker;
                    _squaresData[index].SetChecker(checker);
                    c++;
                }
                index++;
            }

            c     = 0;
            index = _boardSize * _boardSize - 1;
            while (c < 2)
            {
                if (_boardSquares[index / _boardSize, index % _boardSize].Color == SquareColor.Black)
                {
                    var     checkerColor = userColor == UserColor.White ? CheckerColor.White : CheckerColor.Black;
                    Checker checker      = new Checker(index, _squaresData[index], checkerColor);
                    checker.IsSuperChecker = true;
                    _checkersData[index]   = checker;
                    _squaresData[index].SetChecker(checker);
                    c++;
                }
                index--;
            }
            BoardController.Instance.OnBoardPrepared(_squaresData.Values.ToList(), _checkersData.Values.ToList());
        }
Пример #35
0
        public static bool Any(this SquareColor[,] matrix, CheckElemetAndIndex callback)
        {
            var newMatrix = new SquareColor[matrix.GetLength(0), matrix.GetLength(1)];

            for (int i = 0; i < matrix.GetLength(0); ++i)
            {
                for (int j = 0; j < matrix.GetLength(1); ++j)
                {
                    if (callback(i, j, matrix[i, j]))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #36
0
 public Image this[SquareColor color]
 {
     get
     {
         return color == SquareColor.White ? this.WhiteSquare : this.BlackSquare;
     }
 }
Пример #37
0
 public void SetSquare(SquareColor color)
 {
     this.square = color;
 }
Пример #38
0
        private void DrawSquare(CairoContextEx gr, double x, double y, SquareColor []colours, int index)
        {
            gr.Save ();
            for (int column = 0; column < columns; column++) {
                for (int row = 0; row < rows; row++) {

                    // if you want 2 schemes (primary or secundary colors)
                    Color c = palette.Cairo(ColorPalette.Id.First+ color_sheme*3 + (int)colours[index+(columns * row) + column]);
                    gr.Rectangle (x + row * rect_w, y + column * rect_h, rect_w, rect_h);
                    gr.FillGradient (x + row * rect_w, y + column * rect_h, rect_w, rect_h, c);
                }
            }
            gr.Restore ();
            for (int column = 0; column < columns; column++) {
                for (int row = 0; row < rows; row++) {
                    gr.Rectangle (x + row * rect_w, y + column * rect_h, rect_w, rect_h);
                    gr.Stroke ();
                }
            }
        }
Пример #39
0
        private void Randomize(SquareColor []colours, int source, int target)
        {
            int elements = 4 + random.Next (2);
            bool done = false;

            while (done == false) {
                for (int i = 0; i < squares; i++) {
                    colours[i + target] = colours[i + source];
                }

                for (int i = 0; i < elements; i++) {
                    colours[target + random.Next (squares)] = (SquareColor) random.Next ((int) SquareColor.Length);
                }

                // Is not valid if it is already present
                bool equals = true;
                for (int answer = 0; answer < answers; answer++) {
                    if (answer * squares == target)
                        continue;

                    equals = true;
                    for (int i = 0; i < squares; i++) {
                        if (colours[i + target] != colours[i + (answer * squares)]) {
                            equals = false;
                            break;
                        }
                    }

                    if (equals == true)
                        break;
                }

                if (equals == false)
                    done = true;
            }
        }