Exemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            if (GUILayout.Button("Print"))
            {
                PuzzleGrid grid = target as PuzzleGrid;
                PuzzleGrid.main = grid;
                grid.Print();
            }
            if (GUILayout.Button("Clear"))
            {
                PuzzleGrid grid = target as PuzzleGrid;
                PuzzleGrid.main = grid;
                grid.Clear();
                grid.isFresh = true;
            }

            if (GUILayout.Button("Generate"))
            {
                PuzzleGrid grid = target as PuzzleGrid;
                PuzzleGrid.main = grid;
                grid.tokenSize  = Settings.GetImmediate().tokens.size;
                grid.CreateGrid(grid.generateNonMatchedGrid, false);
            }

            if (GUILayout.Button("Collapse Columns (in loop)"))
            {
                PuzzleGrid grid = target as PuzzleGrid;
                PuzzleGrid.main = grid;
                grid.CollapseColumns(grid.collapseDirection);
            }
        }
Exemplo n.º 2
0
    //生成方格
    public void GenerateGrid(float ipWidth, float ipHeight, int row, int col)
    {
        float margin = grid.GetComponent <RectTransform>().sizeDelta.x / -2;
        //调整长宽
        float WID = ipWidth * col + 2 * margin;
        float HEI = ipHeight * row + 2 * margin;

        GetComponent <RectTransform>().sizeDelta = new Vector2(WID, HEI);
        //计算第一个方格的相对于锚点的坐标
        float x0 = ipWidth / 2;
        float y0 = ipHeight / 2;

        //调整标志框的尺寸
        MarkBox.instance.GetComponent <RectTransform>().sizeDelta = new Vector2(ipWidth, ipHeight);

        puzzleGrids = new PuzzleGrid[col, row];
        for (int y = 0; y < row; y++)
        {
            for (int x = 0; x < col; x++)
            {
                GameObject    pg = Instantiate(puzzleGrid);
                RectTransform rt = pg.GetComponent <RectTransform>();
                rt.sizeDelta        = new Vector2(ipWidth - blank, ipHeight - blank);
                rt.anchoredPosition = new Vector2(x0 + x * ipWidth, y0 + y * ipHeight);
                pg.transform.SetParent(grid.transform, false);
                //调整碰撞体的大小
                pg.GetComponent <BoxCollider2D>().size = new Vector2(ipWidth, ipHeight);
                PuzzleGrid script = pg.GetComponent <PuzzleGrid>();
                script.location   = new Vector2(x, y);
                puzzleGrids[x, y] = script;
            }
        }
    }
Exemplo n.º 3
0
        private void NewPuzzleGrid()
        {
            if (_puzzleGrid != null)
            {
                PuzzleHostingPanel.Children.Remove(_puzzleGrid);
            }
            _puzzleGrid            = new PuzzleGrid();
            _puzzleGrid.PuzzleWon += delegate(object sender, EventArgs e)
            {
                StatusLabel.Content = "Got it!!!";
            };

            _puzzleGrid.MoveMade += new EventHandler <HandledEventArgs>(OnMoveMade);

            _puzzleGrid.IsApplyingStyle = _stylingPuzzle;
            _puzzleGrid.NumRows         = 3;

            _puzzleGrid.ElementToChopUp = _elementToChopUp;
            _puzzleGrid.PuzzleSize      = _puzzleSize;

            _puzzleGrid.ShowNumbers(false);

            _puzzleGrid.ShouldAnimateInteractions = true;

            PuzzleHostingPanel.Children.Add(_puzzleGrid);
            StatusLabel.Content = "New " + _numRows + "x" + _numRows + " game";
        }
Exemplo n.º 4
0
 private void InitPictureGrid(CrossWordTask task)
 {
     _pictureGrid = new PuzzleGrid(task.ColumnsTasks.Length, task.RowsTasks.Length);
     _pictureGrid.MovingEnabled = true;
     PicturePanel.Controls.Clear();
     PicturePanel.Controls.Add(_pictureGrid);
     _pictureGrid.Moved  += PictureMoved;
     _pictureGrid.Scaled += PictureScaled;
     _pictureGrid.HoveredPointChanged += PictureGrid_HoveredPointChanged;
     _pictureGrid.CellChanged         += PictureGrid_CellChanged;
 }
Exemplo n.º 5
0
        public static bool TryDoublePairElimination(this PuzzleGrid puzzle)
        {
            var anyChanges = false;

            foreach (var boxRow in puzzle.BoxRows)
            {
                anyChanges |= boxRow.TryDoublePairElimination();
            }
            foreach (var boxCol in puzzle.BoxCols)
            {
                anyChanges |= boxCol.TryDoublePairElimination();
            }
            return(anyChanges);
        }
Exemplo n.º 6
0
        private void Awake()
        {
            fabAnimator = fab.GetComponent <Animator>();

            progressManager       = GameObject.FindObjectOfType <ProgressManager>();
            transitionsController = GameObject.FindObjectOfType <TransitionsManager>();

            paletteDefault    = GameObject.FindObjectOfType <Palette>();
            puzzleGridDefault = GameObject.FindObjectOfType <PuzzleGrid>();

            paletteWhiteHighlight    = GameObject.FindObjectOfType <UIWhiteHighlight.Palette>();
            puzzleGridWhiteHighlight = GameObject.FindObjectOfType <UIWhiteHighlight.PuzzleGrid>();

            levelGrid = GameObject.FindObjectOfType <LevelGrid>();
        }
Exemplo n.º 7
0
 public static bool TryClosedLoopCandidateElimination(this PuzzleGrid puzzle, byte loopScale)
 {
     if (puzzle.ClosedLoop(
             loopScale: loopScale,
             getUnits: p => p.Rows,
             getOtherUnits: p => p.Cols,
             getIdxInOtherUnit: c => c.ColIdx))
     {
         return(true);
     }
     return(puzzle.ClosedLoop(
                loopScale: loopScale,
                getUnits: p => p.Cols,
                getOtherUnits: p => p.Rows,
                getIdxInOtherUnit: c => c.RowIdx));
 }
Exemplo n.º 8
0
        public override void InitGrid()
        {
            gridEvents = GetComponent <GridEventTrigger>();

            Grid.Apply(c => c.GetComponent <PolyominoCell>().Init());

            puzzleGrid = new PuzzleGrid <Polyominoes.Pentomino.Type>(Grid);

            currentShapeType = Polyominoes.Pentomino.Type.F;
            currentShape     = new ObservedValue <TightShape2>(new TightShape2(Polyominoes.Pentomino.Shapes[currentShapeType]));

            currentShape.OnValueChange += PaintHighlight;
            currentShape.OnValueChange += UpdateCurrentShape;

            UpdateCurrentShape();
        }
Exemplo n.º 9
0
 private void InitializePuzzleBoard()
 {
     _textBlocks.Clear();
     foreach (var control in PuzzleGrid.GetChildren())
     {
         if (control is TextBlock textBlock)
         {
             if (textBlock.Name.Substring(0, 2) != "Cr")
             {
                 continue;
             }
             textBlock.HorizontalAlignment = HorizontalAlignment.Center;
             textBlock.VerticalAlignment   = VerticalAlignment.Center;
             textBlock.Text = textBlock.Name;
             _textBlocks.Add(textBlock);
         }
     }
 }
Exemplo n.º 10
0
        private void DisplayColsTask(CrossWordTask task)
        {
            var cols       = task.ColumnsTasks;
            var gridWidth  = cols.Length;
            var gridHeight = cols.Max(c => c.Length);

            _colsTaskGrid = new PuzzleGrid(gridWidth, gridHeight, showHorizontalMainLines: false);
            for (int x = 0; x < gridWidth; x++)
            {
                var emptyCount = gridHeight - cols[x].Length;
                for (int y = 0; y < cols[x].Length; y++)
                {
                    _colsTaskGrid.GridCells[x, emptyCount + y] = cols[x][y];
                }
            }

            ColsPanel.Controls.Clear();
            ColsPanel.Controls.Add(_colsTaskGrid);
        }
Exemplo n.º 11
0
        private void DisplayRowsTask(CrossWordTask task)
        {
            var rows       = task.RowsTasks;
            var gridWidth  = rows.Max(r => r.Length);
            var gridHeight = rows.Length;

            _rowsTaskGrid = new PuzzleGrid(gridWidth, gridHeight, showVerticalMainLines: false);
            for (int y = 0; y < gridHeight; y++)
            {
                var emptyCount = gridWidth - rows[y].Length;
                for (int x = 0; x < rows[y].Length; x++)
                {
                    _rowsTaskGrid.GridCells[emptyCount + x, y] = rows[y][x];
                }
            }

            RowsPanel.Controls.Clear();
            RowsPanel.Controls.Add(_rowsTaskGrid);
        }
Exemplo n.º 12
0
    public Level ( int seed = 0, PuzzleQuad[] quads = null, byte[] robots = null, string token = null ) {

        if ( seed == 0 ) {
            quads = DefaultQuads.hardest;
            robots = new byte[] { 226, 48, 43, 18 };
            token = "BT";
        }
        else {
            this.rnd = new System.Random ( seed );

        }
        this.grid = CreateGrid ( quads );
        this.tokensPos = this.grid.tokensPos;
        this.robotsPos = PlaceRobots ( robots );
        this.token = ChooseToken ( token );
    }
Exemplo n.º 13
0
    public List <PuzzlePiecePosition> ValidBoardPositions()
    {
        if (_cachedValidBoardPositions != null)
        {
            return(_cachedValidBoardPositions);
        }

        List <PuzzlePiecePosition> validPostions = new List <PuzzlePiecePosition>();
        PuzzleGrid grid = new PuzzleGrid();

        var savedLocalEulerAngles = transform.localEulerAngles;
        var savedLocalPosition    = transform.localPosition;

        // for all 24 rotations rotation
        foreach (var rotation in TwentyFourRotations.rotations)
        {
            transform.localEulerAngles = rotation;
            // for each x position
            for (int x = -(4 - 1); x < (4 + (4 - 1)); x++)
            {
                // for each y position
                for (int y = -(4 - 1); y < (4 + (4 - 1)); y++)
                {
                    // for each z position
                    for (int z = -(4 - 1); z < (4 + (4 - 1)); z++)
                    {
                        // place piece
                        transform.localPosition = new Vector3(x, y, z);
                        var blocks = BlockLocations;
                        if (grid.IsValidBoardPosition(blocks.ToList()))
                        {
                            // eliminate duplicate orientations
                            var shouldAdd = true;
                            var blockSetA = new HashSet <IntVector3>(blocks);
                            foreach (var position in validPostions)
                            {
                                var blockSetB = new HashSet <IntVector3>(position.blockPositions);
                                if (blockSetA.SetEquals(blockSetB))
                                {
                                    shouldAdd = false;
                                    break;
                                }
                            }
                            if (shouldAdd)
                            {
                                validPostions.Add(new PuzzlePiecePosition()
                                {
                                    eulerAngle     = transform.localEulerAngles,
                                    position       = transform.localPosition,
                                    blockPositions = blocks
                                });
                            }
                        }
                    }
                }
            }
        }
        transform.localPosition    = savedLocalPosition;
        transform.localEulerAngles = savedLocalEulerAngles;

        _cachedValidBoardPositions = validPostions;
        return(validPostions);
    }
Exemplo n.º 14
0
 private void Awake()
 {
     palette    = GameObject.FindObjectOfType <Palette>();
     puzzleGrid = GameObject.FindObjectOfType <PuzzleGrid>();
 }
 public BoardRenderer(PuzzleGrid pictureGrid)
 {
     _pictureGrid = pictureGrid;
 }
Exemplo n.º 16
0
    IEnumerator Solve(IEnumerable <PuzzlePiece> unplacedPieces, IEnumerable <PuzzlePiece> placedPieces, PuzzleGrid grid, Action <IEnumerable <PuzzlePiece> > solvedFun)
    {
        if (unplacedPieces.Count() == 0)
        {
            solvedFun(placedPieces);
            yield break;
        }

        var piece = unplacedPieces.First();
        var savedOriginalRotation = piece.transform.localEulerAngles;
        var savedOriginalPosition = piece.transform.localPosition;

        piece.transform.SetParent(CubeContainer.transform, true);
        foreach (var validPosition in piece.ValidBoardPositions())
        {
            if (grid.IsValidMove(validPosition.blockPositions))
            {
                grid.AddPiece(validPosition.blockPositions);
                if (grid.IsPuzzleSolvable())
                {
                    // animate movement only when we found a valid move
                    yield return(StartCoroutine(MovePiece(piece, piece.transform.localPosition, piece.transform.localEulerAngles, validPosition.position,
                                                          validPosition.eulerAngle, moveSpeeds[moveSpeedIndex])));

                    yield return(StartCoroutine(Solve(unplacedPieces.Skip(1), placedPieces.Concat(new PuzzlePiece[] { piece }), grid, solvedFun)));
                }
                grid.RemovePiece(validPosition.blockPositions);
            }
        }

        // Done trying to fit this piece, put piece back in the ring where it came from
        piece.transform.SetParent(PiecesContainer.transform, true);
        yield return(StartCoroutine(MovePiece(piece, piece.transform.localPosition, piece.transform.localEulerAngles,
                                              savedOriginalPosition, savedOriginalRotation, moveSpeeds[moveSpeedIndex])));
    }
Exemplo n.º 17
0
        private void CreatePuzzle()
        {
            this.puzzleHostingPanel.Children.Clear();

            this.puzzleGrid            = new PuzzleGrid();
            this.puzzleGrid.PuzzleWon += delegate(object sender, EventArgs e)
            {
                this.getAnswerBtn.IsEnabled        = false;
                this.nextStepBtn.IsEnabled         = false;
                this.showNumbersCheckBox.IsEnabled = false;

                this.Dispatcher.BeginInvoke(new ThreadStart(() =>
                {
                    ResultWindow win = new ResultWindow();
                    win.State        = ResultState.Pass;
                    win.ShowMessage(MessageWindowCallback);
                }),
                                            DispatcherPriority.ApplicationIdle,
                                            null);
            };

            if (puzzleStream != null)
            {
                puzzleStream.Dispose();
                puzzleStream = null;
            }

            byte[] imageData = PuzzleData.LoadImageData(this.puzzleItem.ImageFile);

            if (this.puzzleStream != null)
            {
                this.puzzleStream.Dispose();
                this.puzzleStream = null;
            }

            this.puzzleStream = new System.IO.MemoryStream(imageData);

            BitmapImage bi = new BitmapImage();

            bi.BeginInit();
            bi.StreamSource = this.puzzleStream;
            bi.EndInit();

            Image image = new Image();

            image.Source = bi;

            image.Width  = puzzleSize.Width;
            image.Height = puzzleSize.Height;

            this.elementToChopUp = image;

            this.puzzleGrid.MoveMade += new EventHandler <HandledEventArgs>(OnMoveMade);

            this.puzzleGrid.IsApplyingStyle = true;
            this.puzzleGrid.NumRows         = PuzzleSetting.Instance.Rows;
            this.puzzleGrid.NumCols         = PuzzleSetting.Instance.Cols;

            this.puzzleGrid.ElementToChopUp = elementToChopUp;
            this.puzzleGrid.PuzzleSize      = puzzleSize;

            this.puzzleGrid.ShowNumbers(this.showNumbersCheckBox.IsChecked.Value);

            this.puzzleGrid.ShouldAnimateInteractions = true;

            this.showNumbersCheckBox.IsEnabled = true;

            puzzleHostingPanel.Children.Add(this.puzzleGrid);
        }
Exemplo n.º 18
0
 private void Awake()
 {
     main = this;
 }