Ejemplo n.º 1
0
 public MainWindow()
 {
     dispatchTimer.Tick    += new EventHandler(dispatchTimer_tick);
     dispatchTimer.Interval = new TimeSpan(0, 0, 0, 0, 300);
     currentBlocks          = new List <Block>();
     setBlockCoords         = new List <Point>();
     currentBlockCoords     = new List <Point>();
     setBlocks = new List <Block>();
     InitializeComponent();
     CURRENT_TYPE = ShapeFactory.GetRandomNr(1, 6);
     createShape();
     NEXT_TYPE = ShapeFactory.GetRandomNr(1, 6);
     setNextShape();
     dispatchTimer.Start();
     colCounter = new List <int>();
     PlaySound();
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Instantiates an instance of the Game class from a Location point, a random, and a BlockType enum.
 /// </summary>
 /// <param name="location">The location of the gaming grid.</param>
 /// <param name="random">A random to use for the game's functions that use random.</param>
 /// <param name="BlockType">The type of blocks that will be generated in the game.</param>
 public Game(Point location, Random random, BlockType BlockType)
 {
     this.Location = location;
     this.random   = random;
     this.gridPile = new Pile();
     gridSize      = new Size(
         (Block.BlockLength * gridWidth)
         , (Block.BlockLength * gridHeight));
     Boundaries           = new Rectangle(Location, gridSize);
     shapeGenerationPoint = new Point((Boundaries.Left) + BlocksOver(4), Boundaries.Top - BlocksOver(1));
     shapeFactory         = new ShapeFactory();
     dropShapes           = new List <Shape>();
     linesToClear         = new List <List <Block> >();
     GenerateBackgroundBlockGrid();
     lockDelay      = new TimedEffect(500, TimeUnit.Milliseconds);
     this.BlockType = BlockType;
 } // end constructor method Game
Ejemplo n.º 3
0
        private void setNextShape()
        {
            //List<int> colValShape1 = new List<int>();
            //List<int> rowValShape1 = new List<int>();
            //colValShape1.Add(3); colValShape1.Add(3); colValShape1.Add(3); colValShape1.Add(3);
            //rowValShape1.Add(1); rowValShape1.Add(2); rowValShape1.Add(3); rowValShape1.Add(4);
            nextBlockGrid.Children.Clear();
            Block currBlock = ShapeFactory.SetupType(NEXT_TYPE);
            var   cols      = currBlock.nextCols;
            var   rows      = currBlock.nextRows;

            for (int i = 0; i < 4; i++)
            {
                Rectangle testRect = ShapeFactory.CreateRectangle(currBlock.color);
                nextBlockGrid.Children.Add(testRect);
                Grid.SetColumn(testRect, cols[i]);
                Grid.SetRow(testRect, rows[i]);
            }
        }
Ejemplo n.º 4
0
        public void Init()
        {
            map          = new Shape[MAP_HEIGHT, MAP_WIDTH];
            score        = 0;
            linesRemoved = 0;
            currentShape = ShapeFactory.GenerateShape(3, 0);
            nextShape    = ShapeFactory.GenerateShape(3, 0);
            SetInterval(400);
            label1.Text = "" + score;
            label2.Text = "" + linesRemoved;

            gameTimer.Interval = Interval;
            gameTimer.Tick    += new EventHandler(Update);
            gameTimer.Start();

            typeof(Panel).InvokeMember("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, gamePanel, new object[] { true });
            typeof(Panel).InvokeMember("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, nextFigurePanel, new object[] { true });

            Invalidate();
        }
Ejemplo n.º 5
0
        public void rotatePiece()
        {
            var currentRow = currentBlocks[0].rows;
            var currentCol = currentBlocks[0].cols;

            if (currentBlocks[0].Blocktype.Equals("Type"))
            {
                return;
            }

            currentBlocks.RemoveAt(0);
            removeShape();
            //Type3 Type3Rotate = new Type3();
            Block RotateBlock = ShapeFactory.SetupType(CURRENT_TYPE);

            RotateBlock.RotateType(rotation, currentRow, currentCol);

            for (int i = 0; i < 4; i++)
            {
                /*
                 * Rectangle newRect = new Rectangle()
                 * {
                 *  Width = 20,
                 *  Height = 20,
                 *  RadiusX = 2,
                 *  RadiusY = 2,
                 *  Stroke = Brushes.Black,
                 *  Fill = Brushes.Gold,
                 *  StrokeThickness = 1,
                 *
                 * };
                 * newRect.Name = MOVING;
                 */
                Rectangle newRect = ShapeFactory.CreateRectangle(RotateBlock.color);

                tetrisGrid.Children.Add(newRect);
                Grid.SetColumn(newRect, RotateBlock.cols[i]);
                Grid.SetRow(newRect, RotateBlock.rows[i]);
            }
            currentBlocks.Add(RotateBlock);
        }
Ejemplo n.º 6
0
        private void createShape()
        {
            //Type3 test1 = new Type3();
            //Type3 test2 = new Type3();
            //var cols = test2.cols;
            //var rows = test2.rows;

            Block newBlock = ShapeFactory.SetupType(CURRENT_TYPE);
            var   cols     = newBlock.cols;
            var   rows     = newBlock.rows;

            for (int i = 0; i < 4; i++)
            {
                /*
                 * Rectangle newRect = new Rectangle()
                 * {
                 *  Width = 20,
                 *  Height = 20,
                 *  RadiusX = 2,
                 *  RadiusY = 2,
                 *  Stroke = Brushes.Black,
                 *  Fill = Brushes.Gold,
                 *  StrokeThickness = 1,
                 *
                 * };
                 * newRect.Name = MOVING;
                 */
                Rectangle newRect = ShapeFactory.CreateRectangle(newBlock.color);
                tetrisGrid.Children.Add(newRect);
                Grid.SetColumn(newRect, cols[i]);
                Grid.SetRow(newRect, rows[i]);
            }
            currentBlocks.Add(newBlock);

            rotationEnabled = true;
            rotation        = 0;
        }
Ejemplo n.º 7
0
        public void Update(GameTime gameTime)
        {
            switch (State)
            {
            case eLevelState.Playing:
                ActiveShape.Update(gameTime);
                if (ActiveShape.IsDisposed)
                {
                    ActiveShape = NextShape;
                    NextShape   = ShapeFactory.CreateRandom(GameMode);
                    if (ActiveShape.CollidesWithOtherBlocks())
                    {
                        LoseLife();
                    }
                }

                // Upgrade level when applicable
                if (Score >= LevelUpLookup[LevelNr])
                {
                    LevelNr++;
                    FallDelayInMS -= LevelDelayDecrementer;
                    Engine.Instance.Audio.PlaySound("levelUp");
                }

                if (Engine.Instance.KB.KeyIsReleased(Keys.Escape))
                {
                    State = eLevelState.QuitConfirm;
                }
                if (Engine.Instance.KB.KeyIsReleased(Keys.B))
                {
                    SetRandomBG();
                }
                break;

            case eLevelState.CountingDown:
                CountDown.Update(gameTime);
                if (CountDown.IsInterval)
                {
                    if (CountDown.TimeLeftSec > 0)
                    {
                        Engine.Instance.Audio.PlaySound("countdown");
                    }
                    else
                    {
                        Engine.Instance.Audio.PlaySound("countdownFinished");
                        State = eLevelState.Playing;
                    }
                }
                break;

            case eLevelState.QuitConfirm:
                if (Engine.Instance.KB.KeyIsReleased(Keys.Y))
                {
                    Engine.Instance.ActiveState = new MainMenu();
                }
                else if (Engine.Instance.KB.KeyIsReleased(Keys.N))
                {
                    State = eLevelState.Playing;
                }
                break;

            default:
                throw new CaseStatementMissingException();
            }
        }
Ejemplo n.º 8
0
 private void NextShpae()
 {
     currentShape = nextShape;
     nextShape    = ShapeFactory.GenerateShape(3, 0);
 }