Example #1
0
        public void fixFigure(Figure figure)
        {
            HashSet <int> indexRow = new HashSet <int>();

            for (int i = 0; i < Figure.Length; i++)
            {
                var p = figure.getPosition(i);

                indexRow.Add(p.Y);

                this.Grid.setElement(p, figure.label);
            }

            SortedSet <int> deleteIndexRow = new SortedSet <int>();

            // only verify specify row of the figure
            foreach (var index in indexRow)
            {
                if (this.Grid.verifyRow(index))
                {
                    deleteIndexRow.Add(index);
                }
            }

            foreach (var index in deleteIndexRow.Reverse())
            {
                Grid.removeLine(index);
                this.score++;
            }

            this.currentFigure = FigureController.createFigure(this.Grid.dimension.X / 2, this.Grid.dimension.Y - 2);
        }
Example #2
0
        private void reset()
        {
            this.score = 0;
            this.Grid.init();
            this.currentFigure = FigureController.createFigure(this.Grid.dimension.X / 2, this.Grid.dimension.Y - 2);

            this.nextFigure = currentFigure;
        }
Example #3
0
        public void update()
        {
            // collision
            if (CollisionController.isCollision(this.Grid, this.nextFigure))
            {
                this.nextFigure = this.currentFigure;
            }

            this.currentFigure = this.nextFigure;

            this.nextFigure = FigureController.down(this.nextFigure);

            if (CollisionController.isCollision(this.Grid, this.nextFigure))
            {
                this.fixFigure(this.currentFigure);
                return;
            }

            this.currentFigure = this.nextFigure;
        }
Example #4
0
        private void load()
        {
            try
            {
                string[] lines = File.read(nameFile);

                this.render.render("load the game? (y/n)");
                if (this.inputHandler.confirmationInput())
                {
                    this.score = int.Parse(lines[0]);
                    this.Grid.init(lines);
                }
            }
            catch (System.Exception)
            {
                this.render.render("no load file");
            }

            this.currentFigure = FigureController.createFigure(this.Grid.dimension.X / 2, this.Grid.dimension.Y - 2);

            this.nextFigure = currentFigure;
        }
Example #5
0
        public void handlerEvent()
        {
            // input event
            switch (this.inputHandler.getInput())
            {
            case Action.Left:
                this.nextFigure = FigureController.left(this.currentFigure);
                break;

            case Action.Right:
                this.nextFigure = FigureController.rigth(this.currentFigure);
                break;

            case Action.RotateClockwise:
                this.nextFigure = FigureController.rotateInv(this.currentFigure);
                break;

            case Action.RotateCounterClockwise:
                this.nextFigure = FigureController.rotate(this.currentFigure);
                break;

            case Action.Save:
                this.save();
                this.on = false;
                return;

            case Action.Exit:
                this.on = false;
                return;

            case Action.Reset:
                this.reset();
                break;

            default:
                this.nextFigure = this.currentFigure;
                break;
            }
        }