Esempio n. 1
0
        private async void GameOver(string message)
        {
            var gameOverDialog = new MessageDialog(message + "\nYou got score : " + score);

            gameOverDialog.Commands.Add(new UICommand {
                Label = "New Game?", Id = 0
            });
            gameOverDialog.Commands.Add(new UICommand {
                Label = "Exit", Id = 1
            });
            var f = await gameOverDialog.ShowAsync();

            if ((int)f.Id == 0)
            {
                testing1        = null;
                bagging         = null;
                testing1        = new TetrisGridArray();
                bagging         = new TetrisBag();
                shapeCreate     = new TetrisShapes(bagging.GetCurrent(), testing1, false);
                waitingGameOver = false;
                score           = 0;
                rows            = 0;
                level           = 1;
            }
            else if ((int)f.Id == 1)
            {
                redrawTimer.Dispose();
                gravityTimer2.Dispose();
                CoreApplication.Exit();
            }
        }
Esempio n. 2
0
        public MainPage()
        {
            this.InitializeComponent();
            testing1 = new TetrisGridArray();
            bagging  = new TetrisBag();

            shapeCreate = new TetrisShapes(bagging.GetCurrent(), testing1, false);
            testing1.DrawArray(Gamedraw);
            var autoEvent = new AutoResetEvent(false);

            gravityTimer2 = new Timer(gravityCallBack, autoEvent, 1000, 500);
            redrawTimer   = new Timer(redrawGrid, autoEvent, 150, 100);

            Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
        }
Esempio n. 3
0
 private async void NewShape()
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         shapeCreate = null;
         try
         {
             shapeCreate = new TetrisShapes(bagging.GetNext(), testing1, false);
         }
         catch (Exception ex)
         {
             waitingGameOver = true;
             GameOver(ex.Message);
         }
     });
 }
Esempio n. 4
0
 internal void MoveLeft(TetrisShapes trackingShape)
 {
     for (int i = 1; i < ArrayWidth - 1; i++)
     {
         for (int j = ArrayHeight - 2; j > 0; j--)
         {
             if (cubeArray[j, i] != null && cubeArray[j, i].locked == false)
             {
                 if (cubeArray[j, i - 1] != null)
                 {
                     return;
                 }
             }
         }
         for (int j = ArrayHeight - 2; j > 0; j--)
         {
             if (cubeArray[j, i] != null && cubeArray[j, i].locked == false)
             {
                 MoveCube(i - 1, i - 2, j - 1, j - 1);
             }
         }
     }
     trackingShape.coreShapeX -= 1;
 }
Esempio n. 5
0
 internal void MoveRight(TetrisShapes trackingShape)
 {
     for (int i = ArrayWidth - 2; i > 0; i--)
     {
         for (int j = ArrayHeight - 2; j > 0; j--)
         {
             if (cubeArray[j, i] != null && cubeArray[j, i].locked == false)
             {
                 if (cubeArray[j, i + 1] != null)
                 {
                     return;
                 }
             }
         }
         for (int j = ArrayHeight - 2; j > 0; j--)
         {
             if (cubeArray[j, i] != null && cubeArray[j, i].locked == false)
             {
                 MoveCube(i - 1, i, j - 1, j - 1);
             }
         }
     }
     trackingShape.coreShapeX += 1;
 }
Esempio n. 6
0
        public bool TetrisGravity(TetrisShapes lockedShape)
        {
            if (!lockedShape.lockedShape)
            {
                for (int i = ArrayHeight - 2; i > 0; i--)
                {
                    for (int j = 1; j < ArrayWidth - 1; j++)
                    {
                        if (cubeArray[i, j] != null && cubeArray[i, j].locked == false)
                        {
                            if (cubeArray[i + 1, j] != null)
                            {
                                lockedShape.lockedShape = true;
                            }
                            else if (cubeArray[i, j + 1] != null && cubeArray[i - 1, j + 1] != null && !cubeArray[i - 1, j + 1].locked && cubeArray[i, j + 1].locked)
                            {
                                lockedShape.lockedShape = true;
                            }
                            else if (cubeArray[i, j - 1] != null && cubeArray[i - 1, j - 1] != null && !cubeArray[i - 1, j - 1].locked && cubeArray[i, j - 1].locked)
                            {
                                lockedShape.lockedShape = true;
                            }
                            else if (i > 1 && cubeArray[i - 1, j + 1] != null && cubeArray[i - 2, j + 1] != null && !cubeArray[i - 2, j + 1].locked && cubeArray[i - 1, j + 1].locked)
                            {
                                lockedShape.lockedShape = true;
                            }
                            else if (i > 1 && cubeArray[i - 1, j - 1] != null && cubeArray[i - 2, j - 1] != null && !cubeArray[i - 2, j - 1].locked && cubeArray[i - 1, j - 1].locked)
                            {
                                lockedShape.lockedShape = true;
                            }
                            else if (j < ArrayWidth - 2 && cubeArray[i, j + 2] != null && cubeArray[i - 1, j + 2] != null && !cubeArray[i - 1, j + 2].locked && cubeArray[i, j + 2].locked)
                            {
                                lockedShape.lockedShape = true;
                            }
                            else if (j > 1 && cubeArray[i, j - 2] != null && cubeArray[i - 1, j - 2] != null && !cubeArray[i - 1, j - 2].locked && cubeArray[i, j - 2].locked)
                            {
                                lockedShape.lockedShape = true;
                            }
                        }
                        if (lockedShape.lockedShape)
                        {
                            for (int f = ArrayHeight - 2; f > 0; f--)
                            {
                                for (int k = 1; k < ArrayWidth - 1; k++)
                                {
                                    if (cubeArray[f, k] != null)
                                    {
                                        cubeArray[f, k].locked = true;
                                    }
                                }
                            }
                            return(true);
                        }
                    }

                    for (int j = 1; j < ArrayWidth - 1; j++)
                    {
                        if (cubeArray[i, j] != null && cubeArray[i, j].locked == false)
                        {
                            MoveCube(j - 1, j - 1, i - 1, i);
                        }
                    }
                }
            }
            lockedShape.coreShapeY += 1;
            return(false);
        }