import java.util.function.IntConsumer;

import java.util.*;

public class GameEngine
{
    public GameEngine (Vector<String> instructions, boolean debug)
    {
        _computer = new Intcode(instructions, INITIAL_INPUT, debug);
        _debug = debug;
        _theScreen = new Screen(_debug);
        _paddlePosition = null;
        _ballPosition = null;
        _stick = new Joystick();
    }

    public final boolean playGame ()
    {
        /*
         * Initialise the screen. Run the game instructions
         * once.
         */

         // Replace entry 0 with 2 (unlimited lives)

        _computer.changeInstruction(0, "2");

        int[] output = getOutput(INITIAL_INPUT);

        if (_debug)
            System.out.println("Tile information: <"+output[0]+", "+output[1]+"> and "+TileId.idToString(output[2]));

        Tile theTile = new Tile(new Coordinate(output[0], output[1]), output[2]);

        _theScreen.updateTile(theTile);

        if(theTile.getId() == TileId.BALL)
            _ballPosition = theTile.getPosition();
        else
        {
            if (theTile.getId() == TileId.PADDLE)
                _paddlePosition = theTile.getPosition();
        }

        /*
         * Where is the joystick?
         */

        if (_ballPosition.getX() > _paddlePosition.getX())
            _stick.setPosition(Joystick.TILTED_RIGHT);
        else
        {
            if (_ballPosition.getX() < _paddlePosition.getX())
                _stick.setPosition(Joystick.TILTED_LEFT);
        }

        while (!_computer.hasHalted())
        {
            output = getOutput(_stick.getPosition());

            if (_debug)
                System.out.println("Tile information: <"+output[0]+", "+output[1]+"> and "+TileId.idToString(output[2]));

            if ((output[0] == -1) && (output[1] == 0))
            {
                // update score

                _theScreen.getSegmentDisplay().setScore(output[2]);
            }
            else
            {
                theTile = new Tile(new Coordinate(output[0], output[1]), output[2]);

                _theScreen.updateTile(theTile);

                if(theTile.getId() == TileId.BALL)
                {
                    _ballPosition = theTile.getPosition();

                    if (_ballPosition.getX() > _paddlePosition.getX())
                        _stick.setPosition(Joystick.TILTED_RIGHT);
                    else
                    {
                        if (_ballPosition.getX() < _paddlePosition.getX())
                            _stick.setPosition(Joystick.TILTED_LEFT);
                        else
                            _stick.setPosition(Joystick.NEUTRAL_POSITION);
                    }
                }
                else
                {
                    if (theTile.getId() == TileId.PADDLE)
                        _paddlePosition = theTile.getPosition();
                }
            }
        }

        return true;
    }

    public final int getNumberOfBlocks ()
    {
        return _theScreen.numberOfBlocks();
    }

    private final int[] getOutput (int input)
    {
        int[] values = new int[3];

        while (!_computer.hasPaused() && !_computer.hasOutput())
        {
            _computer.singleStepExecution(input);
        }

        if (!_computer.hasPaused())
        {
            values[0] = Integer.parseInt(_computer.getOutput());

            while (!_computer.hasPaused() && !_computer.hasOutput())
            {
                _computer.singleStepExecution(input);
            }

            if (!_computer.hasPaused())
            {
                values[1] = Integer.parseInt(_computer.getOutput());

                while (!_computer.hasPaused() && !_computer.hasOutput())
                {
                    _computer.singleStepExecution(input);
                }

                values[2] = Integer.parseInt(_computer.getOutput());
            }
            else
            {
                System.out.println("Error - computer halted after outputing x value!");
            }
        }

        return values;
    }

    private Intcode _computer;
    private boolean _debug;
    private Screen _theScreen;
    private Coordinate _paddlePosition;
    private Coordinate _ballPosition;
    private Joystick _stick;

    private static final int INITIAL_INPUT = 0; // nothing specified in the overview
}
@@ -814,32 +814,113 @@
 g(output%5B2%5D));%0A%0A
+        System.out.println(%22**initial %22+output%5B0%5D+%22 %22+output%5B1%5D+%22 %22+output%5B2%5D);%0A%0A
         Tile the
@@ -977,32 +977,32 @@
 %5D), output%5B2%5D);%0A
-
 %0A        _theScr
@@ -1581,32 +1581,267 @@
 FT);%0A        %7D%0A%0A
+        System.out.println(%22**initial joystick %22+_stick);%0A%0A        /*%0A         * Now let's play the game!%0A         */%0A%0A        System.out.println(%22%5Cn%5CnPLAYING%22);%0A%0A        //_computer = new Intcode(instructions, INITIAL_INPUT, debug);%0A%0A
         while (!
@@ -2067,32 +2067,123 @@
 g(output%5B2%5D));%0A%0A
+            System.out.println(%22**gaming values %22+output%5B0%5D+%22 %22+output%5B1%5D+%22 %22+output%5B2%5D);%0A%0A
             if (
@@ -2335,16 +2335,100 @@
 put%5B2%5D);
+%0A%0A                System.out.println(%22**score now %22+_theScreen.getSegmentDisplay());
 %0A       
@@ -3176,32 +3176,102 @@
                %7D
+%0A%0A                    System.out.println(%22**gaming joystick %22+_stick);
 %0A               
@@ -3459,32 +3459,32 @@
 %7D%0A            %7D%0A
-
         %7D%0A%0A     
@@ -3470,32 +3470,104 @@
    %7D%0A        %7D%0A%0A
+        System.out.println(%22**score %22+_theScreen.getSegmentDisplay());%0A%0A
         return t

Update GameEngine.java