コード例 #1
0
ファイル: Form1.cs プロジェクト: MichalKoval/JigsawPuzzleGame
        // spustenie hry, nastavia sa vsetky potrebne nastavenia a zobrazi sa hracia
        // plocha s puzzle kuskami a oknom s instrukciami(len pri prvom spusteni programu)
        private void button2_Click(object sender, EventArgs e)
        {
            if (gameData.SourcePicture != null)
            {
                textBox1.Visible    = false;
                pictureBox1.Visible = false;
                button1.Visible     = false;
                button2.Visible     = false;
                panel5.Visible      = true; //obsahuje button3==Restart, button4==NewGame

                //
                //nastavime pociatocne data pre hru
                //
                gameData.SourcePicture          = PictureEditor.CropImage(gameData.SourcePicture, gridLayer.StartCutLocation, gridLayer.EndCutLocation);
                gameData.PiecesGridDimensions   = gridLayer.GridDimensions;
                gameData.PiecesCount            = gameData.PiecesGridDimensions.Width * gameData.PiecesGridDimensions.Height;
                gameData.PieceDimensions        = gridLayer.PieceDimensions;
                gameData.PieceSurroundingSize   = (int)Math.Ceiling(gameData.PieceDimensions.Width * 0.163);
                gameData.GameBoard              = this.panel4;
                gameData.GameBoardStartPosition = new Point(50, 50);

                PuzzleGameUtilities.CreatePieces(gameData);
                PuzzleGameUtilities.SetOriginalPiecesLocations(gameData);
                PuzzleGameUtilities.SetPiecesArrangement(gameData);
                PuzzleGameUtilities.SetPiecesImages(gameData);
                PuzzleGameUtilities.SetPiecesOriginalNeighbours(gameData);
                PuzzleGameUtilities.RandomizePiecesLocations(gameData);


                //
                //Pociatocne nastavenia gameboard-u
                //
                gameboard = new Gameboard(this, gameData, panel4.Size);
                //gameboard ako instancia Form nesmie byt nastavena na top level control !!
                gameboard.TopLevel = false;
                panel4.Controls.Add(gameboard);
                gameboard.Visible  = false;
                gameboard.Anchor   = AnchorStyles.None;
                gameboard.Anchor   = (AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right);
                gameboard.Location = new Point(0, 0); //pozicia vo vnutri panel4
                gameboard.Visible  = true;

                if (showGameInstructions)
                {
                    this.panel6.BringToFront();
                    this.panel6.Visible = true;
                    // zabezpecime aby sa to ukazalo iba pri prvom spusteni
                    showGameInstructions = false;
                }
            }
            else
            {
                noPictureLabel.Visible = true;
                // MessageBox.Show("Nebol vybraný obrazok!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: MichalKoval/JigsawPuzzleGame
 // Button = restart hry, vygeneruju sa nove nahodne pozicie pre puzzle kusky
 private void button3_Click(object sender, EventArgs e)
 {
     gameData.bucketOfPieces.Clear();
     // zrusime susedov
     foreach (var piece in gameData.Pieces)
     {
         piece.LeftNeighbor   = null;
         piece.TopNeighbor    = null;
         piece.RightNeighbor  = null;
         piece.BottomNeighbor = null;
     }
     PuzzleGameUtilities.RandomizePiecesLocations(gameData);
     gameboard.ResetBackgroundCapture();
 }