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;
    }

    public final boolean playGame ()
    {
        int x = 0;
        int y = 0;
        int id = TileId.EMPTY;

        /*
         * Initialise the screen.
         */

        while (!_computer.hasHalted())
        {
            while (!_computer.hasHalted() && !_computer.hasOutput())
            {
                _computer.singleStepExecution(INITIAL_INPUT);
            }

            if (!_computer.hasHalted())
            {
                x = Integer.parseInt(_computer.getOutput());

                while (!_computer.hasHalted() && !_computer.hasOutput())
                {
                    _computer.singleStepExecution(INITIAL_INPUT);
                }

                if (!_computer.hasHalted())
                {
                    y = Integer.parseInt(_computer.getOutput());

                    while (!_computer.hasHalted() && !_computer.hasOutput())
                    {
                        _computer.singleStepExecution(INITIAL_INPUT);
                    }

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

                    return false;
                }

                if (_debug)
                    System.out.println("Tile information: <"+x+", "+y+"> and "+TileId.idToString(id));

                Tile theTile = new Tile(new Coordinate(x, y), id));

                _theScreen.updateTile(theTile);

                if(theTile.getId() == TileId.BALL)
                    _ballPosition = theTile.getPosition();
                else
                {
                    if (theTile.getId() == TileId.PADDLE)
                        _paddlePosition = theTile.getPosition();
                }
            }
            else
            {
                if (_debug)
                    System.out.println("Computer halted.");

                return true;
            }
        }

        return true;
    }

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

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

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

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

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

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

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

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

        retrn values;
    }

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

    private static final int INITIAL_INPUT = 0; // nothing specified in the overview
}
@@ -411,1226 +411,108 @@
     
-int x = 0;%0A        int y = 0;%0A        int id = TileId.EMPTY;%0A%0A        /*%0A         * Initialise the screen.%0A         */%0A%0A        while (!_computer.hasHalted())%0A        %7B%0A            while (!_computer.hasHalted() && !_computer.hasOutput())%0A            %7B%0A                _computer.singleStepExecution(INITIAL_INPUT);%0A            %7D%0A%0A            if (!_computer.hasHalted())%0A            %7B%0A                x = Integer.parseInt(_computer.getOutput());%0A%0A                while (!_computer.hasHalted() && !_computer.hasOutput())%0A                %7B%0A                    _computer.singleStepExecution(INITIAL_INPUT);%0A                %7D%0A%0A                if (!_computer.hasHalted())%0A                %7B%0A                    y = Integer.parseInt(_computer.getOutput());%0A%0A                    while (!_computer.hasHalted() && !_computer.hasOutput())%0A                    %7B%0A                        _computer.singleStepExecution(INITIAL_INPUT);%0A                    %7D%0A%0A                    id = Integer.parseInt(_computer.getOutput());%0A                %7D%0A                else%0A                %7B%0A                    System.out.println(%22Error - computer halted after outputing x value!%22);%0A%0A                    return false;%0A                %7D%0A%0A        
+/*%0A         * Initialise the screen.%0A         */%0A%0A        int%5B%5D output = getOutput(INITIAL_INPUT);%0A%0A
     
@@ -535,32 +535,24 @@
             
-      
-  
 System.out.p
@@ -584,16 +584,32 @@
  %3C%22+
-x+%22, %22+y
+output%5B0%5D+%22, %22+output%5B1%5D
 +%22%3E 
@@ -632,31 +632,30 @@
 oString(
-id));%0A%0A        
+output%5B2%5D));%0A%0A
         
@@ -697,30 +697,44 @@
 ate(
-x, y), id));%0A%0A        
+output%5B0%5D, output%5B1%5D), output%5B2%5D);%0A%0A
     
@@ -766,32 +766,24 @@
 (theTile);%0A%0A
-        
         if(t
@@ -825,24 +825,16 @@
         
-   
-     
 _ballPos
@@ -860,32 +860,24 @@
 Position();%0A
-        
         else
@@ -881,36 +881,26 @@
 lse%0A        
- 
-       %7B%0A  
+%7B%0A
             
@@ -895,30 +895,24 @@
             
-      
 if (theTile.
@@ -937,24 +937,16 @@
 PADDLE)%0A
-        
         
@@ -998,203 +998,8 @@
 ();%0A
-                %7D%0A            %7D%0A            else%0A            %7B%0A                if (_debug)%0A                    System.out.println(%22Computer halted.%22);%0A%0A                return true;%0A            %7D%0A
     
@@ -1163,19 +1163,14 @@
  get
-Information
+Output
  (in
@@ -1241,36 +1241,36 @@
  (!_computer.has
-Halt
+Paus
 ed() && !_comput
@@ -1374,36 +1374,36 @@
  (!_computer.has
-Halt
+Paus
 ed())%0A        %7B%0A
@@ -1493,36 +1493,36 @@
  (!_computer.has
-Halt
+Paus
 ed() && !_comput
@@ -1646,28 +1646,28 @@
 computer.has
-Halt
+Paus
 ed())%0A      
@@ -1785,12 +1785,12 @@
 .has
-Halt
+Paus
 ed()

Update GameEngine.java