Beispiel #1
0
        public void rotate(Drawing dr, Block currentBlock, Collissions col, bool bottom, bool landed)
        {
            if (!bottom && !landed)                                                                            //pokud blok nedopadl
            {
                bool left  = col.checkLeft(currentBlock, dr.Grid, dr.BaseGrid);
                bool right = col.checkRight(currentBlock, dr.columns, dr.Grid, dr.BaseGrid);
                if (currentBlock.Type == "line")
                {
                    nearLeft  = col.checkNearLeft(currentBlock.StartColumn, currentBlock.ActualOrientation);
                    nearRight = col.checkNearRight(currentBlock.StartColumn, currentBlock.ActualOrientation, dr.columns);
                }
                currentBlock.rotateBlock(left, right, nearLeft, nearRight, true);//pokus o rotaci
                bool outOfRange = dr.TryUpdateGrid(currentBlock);
                if (!outOfRange)
                {
                    collission = col.checkRotation(currentBlock, dr);
                }
                currentBlock.StartColumn = currentBlock.OrigStartColumn;                              //návrat do původní pozice v ose x

                if (!collission && !outOfRange)
                {
                    currentBlock.rotateBlock(left, right, nearLeft, nearRight, false);//rotace
                    dr.updateGrid(currentBlock);
                    dr.drawGrids();
                }
            }
        }
Beispiel #2
0
        public void moveRight(Drawing dr, Block currentBlock, Collissions col, bool bottom)
        {
            bool right = (col.checkRight(currentBlock, dr.columns, dr.Grid, dr.BaseGrid));

            if (!right && !bottom)
            {
                currentBlock.StartColumn++;
                dr.updateGrid(currentBlock);
                dr.drawGrids();
            }
        }
Beispiel #3
0
        public void moveLeft(Drawing dr, Block currentBlock, Collissions col, bool bottom)
        {
            bool left = (col.checkLeft(currentBlock, dr.Grid, dr.BaseGrid));

            if (!left && !bottom)
            {
                currentBlock.StartColumn--;
                dr.updateGrid(currentBlock);
                dr.drawGrids();
            }
        }
Beispiel #4
0
        public Game(Drawing dr)                          //konstruktor
        {
            this.dr            = dr;
            Visib              = Visibility.Hidden;
            PauseButtonContent = "Pause";
            TimeLabelContent   = "Time";
            score              = 0;
            ScoreLabelContent  = string.Format("Score:\n{0:n0}", score);
            ImageBrush background = new ImageBrush();

            Background = background;


            NotifyAll();


            col = new Collissions();                                    //instance třídy kolizí
            mov = new Movements();                                      //instance třídy pro pohyby bloku
            dr.createEmptyGrids();                                      //metoda inicializace všech potřebných polí, výmaz Canvasu
            timer1.Tick    += timer1_Tick;                              //event handler intervalu časovače hry
            timer2.Tick    += Timer2_Tick;                              //a stopek
            timer2.Interval = TimeSpan.FromMilliseconds(999);


            //čtení HiScore ze souboru
            path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\CSharpTetris";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            try
            {
                using (StreamReader sr = new StreamReader(path + @"\his"))
                {
                    hiScoreStr = sr.ReadLine();
                    hiScoreInt = Convert.ToInt32(hiScoreStr);
                }
            }
            catch
            {
            }
            HiScoreLabelContent = String.Format("HiScore:\n{0:n0}", hiScoreInt);
            notify("HiScoreLabelContent");
        }