Beispiel #1
0
        public Game(Game gameToCopy)
        {
            // Used for Cloning State
            isGameOver   = gameToCopy.isGameOver;
            softGameOver = gameToCopy.softGameOver;

            totalLinesCleared = gameToCopy.totalLinesCleared;

            isTicking = gameToCopy.isTicking;
            gameTick  = 1;
            firstTick = gameToCopy.firstTick;

            this.isActive = false;

            this.StartXPosition = gameToCopy.StartXPosition;
            this.StartYPosition = gameToCopy.StartYPosition;

            this.CurrentPiece = new Piece(gameToCopy.piece.PieceType, gameToCopy.piece.PositionX, gameToCopy.piece.PositionY);

            this.NextPiece = gameToCopy.NextPiece;
            this.Height    = gameToCopy.Height;
            this.Width     = gameToCopy.Width;

            this.deadGrid = new ShapeEnum[this.Width, this.Height];

            for (int x = 0; x < this.deadGrid.GetLength(0); x++)
            {
                for (int y = 0; y < this.deadGrid.GetLength(1); y++)
                {
                    this.deadGrid[x, y] = gameToCopy.deadGrid[x, y];
                }
            }
        }
Beispiel #2
0
 private void ShapeIPiece()
 {
     this.Shape       = new ShapeEnum[1, 4];
     this.Shape[0, 0] = ShapeEnum.Active;
     this.Shape[0, 1] = ShapeEnum.Active;
     this.Shape[0, 2] = ShapeEnum.Active;
     this.Shape[0, 3] = ShapeEnum.Active;
 }
Beispiel #3
0
 private void ShapeOPiece()
 {
     this.Shape       = new ShapeEnum[2, 2];
     this.Shape[0, 0] = ShapeEnum.Active;
     this.Shape[0, 1] = ShapeEnum.Active;
     this.Shape[1, 0] = ShapeEnum.Active;
     this.Shape[1, 1] = ShapeEnum.Active;
 }
Beispiel #4
0
 private void ShapeTPiece()
 {
     this.Shape       = new ShapeEnum[3, 2];
     this.Shape[0, 0] = ShapeEnum.Empty;
     this.Shape[0, 1] = ShapeEnum.Active;
     this.Shape[1, 0] = ShapeEnum.Active;
     this.Shape[1, 1] = ShapeEnum.Active;
     this.Shape[2, 0] = ShapeEnum.Empty;
     this.Shape[2, 1] = ShapeEnum.Active;
 }
Beispiel #5
0
 private void ShapeLPiece()
 {
     this.Shape       = new ShapeEnum[2, 3];
     this.Shape[0, 0] = ShapeEnum.Active;
     this.Shape[0, 1] = ShapeEnum.Active;
     this.Shape[0, 2] = ShapeEnum.Active;
     this.Shape[1, 0] = ShapeEnum.Empty;
     this.Shape[1, 1] = ShapeEnum.Empty;
     this.Shape[1, 2] = ShapeEnum.Active;
 }
Beispiel #6
0
 private ShapeEnum[,] InitialiseEmptyShape(ShapeEnum[,] emptyShape)
 {
     for (int x = 0; x < emptyShape.GetLength(0); x++)
     {
         for (int y = 0; y < emptyShape.GetLength(1); y++)
         {
             emptyShape[x, y] = ShapeEnum.Empty;
         }
     }
     return(emptyShape);
 }
Beispiel #7
0
 private void InitialiseDeadGrid()
 {
     deadGrid = new ShapeEnum[this.Width, this.Height];
     for (int x = 0; x < deadGrid.GetLength(0); x++)
     {
         for (int y = 0; y < deadGrid.GetLength(1); y++)
         {
             deadGrid[x, y] = ShapeEnum.Empty;
         }
     }
 }
Beispiel #8
0
        public GameState(Game state)
        {
            //this.NextPiece = state.NextPiece;
            //this.gameTick = state.gameTick;
            //this.isTicking = state.isTicking;

            this.piece             = state.piece;
            this.deadGrid          = state.deadGrid;
            this.isGameOver        = state.isGameOver;
            this.softGameOver      = state.softGameOver;
            this.isActive          = state.isActive;
            this.TotalLinesCleared = state.TotalLinesCleared;
        }
Beispiel #9
0
        private void clearLines(int[] linesToClear)
        {
            Graphics g = buffer.Graphics;

            g.Clear(Color.Black);

            DrawPiece(game, g);
            RefreshPlayArea(game, g);

            buffer.Render(Graphics.FromHwnd(this.Handle));

            localDeadGrid = game.DeadGrid;
        }
Beispiel #10
0
        private void InitialiseDeadGrid()
        {
            //Building the grid out of a 2d array of ShapeEnums which can be active or inactive
            deadGrid = new ShapeEnum[this.Width, this.Height];

            //Populating the grid with inactive blocks
            for (int x = 0; x < deadGrid.GetLength(0); x++)
            {
                for (int y = 0; y < deadGrid.GetLength(1); y++)
                {
                    deadGrid[x, y] = ShapeEnum.Empty;
                }
            }
        }
Beispiel #11
0
        private void timLinesClearing_Tick(object sender, EventArgs e)
        {
            tickCount++;

            Graphics g = buffer.Graphics;

            g.Clear(Color.Black);
            DrawPiece(game, g);
            RefreshPlayArea(game, g);

            int multiplier = 20;
            int brushSize  = 20;

            var clearBrush = new SolidBrush(Color.DarkSlateBlue);
            var textBrush  = new SolidBrush(Color.GhostWhite);
            var pen        = new Pen(clearBrush, brushSize);

            string textToDraw = GetLineClearText(linesToClear.Count());

            foreach (var item in linesToClear)
            {
                var rect = new Rectangle
                {
                    X      = (xOffset * multiplier) - 1,
                    Y      = (yOffset + item) * multiplier,
                    Height = multiplier,
                    Width  = (tickCount * 100) / 10,
                };
                g.FillRectangle(clearBrush, rect);

                g.DrawString(textToDraw, new Font("Arial", 8), textBrush, (xOffset * multiplier), ((yOffset + item) * multiplier) + 2);
                //g.FillRectangle(brush, new Rectangle(xOffset * multiplier, (yOffset + item) * multiplier, (game.Width + xOffset) * multiplier, 10));
            }


            buffer.Render(Graphics.FromHwnd(this.Handle));
            if (tickCount == 20)
            {
                timLinesClearing.Stop();
                localDeadGrid = game.DeadGrid;
                //gameTimer.Start();
                //game.TriggerGameTick();
                //DrawGame();
            }
        }
Beispiel #12
0
        public void RotateAntiClockwise()
        {
            int origShapeX = Shape.GetLength(0);
            int origShapeY = Shape.GetLength(1);
            var original   = Shape;

            Shape = InitialiseEmptyShape(new ShapeEnum[origShapeY, origShapeX]);

            int newShapeMaxX = Shape.GetUpperBound(0);
            int newShapeMaxY = Shape.GetUpperBound(1);

            for (int y = 0; y < original.GetLength(1); y++)
            {
                for (int x = 0; x < original.GetLength(0); x++)
                {
                    Shape[y, newShapeMaxY - x] = original[x, y];
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// Called once at build time
        /// </summary>
        private void StartNewGame()
        {
            game = new Game(800, 20, 10, 4, true);

            InitaliseAI();

            GameReady           += brain.StartAI;
            game.PieceHitBottom += brain.hitBottom;
            localDeadGrid        = game.DeadGrid;
            game.GameOver       += game_GameOver;

            game.LinesCleared      += game_LinesCleared;
            game.LinesAboutToClear += game_LinesAboutToClear;
            gameTimer.Interval      = 10;
            gameTimer.Start();
            isGameOver = false;
            DrawGame();

            GameReady.Invoke(this, new EventArgs());
        }
Beispiel #14
0
        public void restartGame()
        {
            game = new Game(800, 20, 10, 4, true);

            game.PieceHitBottom += brain.hitBottom;
            localDeadGrid        = game.DeadGrid;
            game.GameOver       += game_GameOver;

            game.LinesCleared      += game_LinesCleared;
            game.LinesAboutToClear += game_LinesAboutToClear;
            gameTimer.Interval      = 1;
            gameTimer.Start();
            isGameOver = false;
            DrawGame();

            brain.SyncAllStates(game);

            GameReady.Invoke(this, new EventArgs());

            //will probably need to link the new game to stateSynced
            //brain.evaluateNextGenome();
        }
Beispiel #15
0
        private void StartNewGame(bool initialising)
        {
            game = new Game(800, 20, 10, 4, true);

            if (initialising)
            {
                InitalisePopulation();
            }

            game.readyForNextMove += this.nextMoveRequired;
            //game.PieceHitBottom += doNothing;

            localDeadGrid  = game.DeadGrid;
            game.GameOver += game_GameOver;

            game.LinesCleared      += game_LinesCleared;
            game.LinesAboutToClear += game_LinesAboutToClear;

            gameTimer.Interval = 10;
            gameTimer.Start();

            DrawGame();
        }
Beispiel #16
0
 void game_LinesAboutToClear(object sender, ShapeEnum[,] e)
 {
     localDeadGrid = e;
 }