Esempio n. 1
0
        public void HandleOutput(long output)
        {
            var instruction = (int)output;

            switch (setupState)
            {
            case SetupState.SetX:
                tmpX       = instruction;
                setupState = SetupState.SetY;
                break;

            case SetupState.SetY:
                tmpY       = instruction;
                setupState = SetupState.SetTile;
                break;

            case SetupState.SetTile:
                if (tmpX == -1 && tmpY == 0)
                {
                    UpdateScreen();
                    score = instruction;
                }
                else
                {
                    var tile     = (GameTile)instruction;
                    var position = new Point {
                        X = tmpX, Y = tmpY
                    };

                    if (gameState.ContainsKey(position))
                    {
                        gameState[position] = tile;
                    }
                    else
                    {
                        gameState.Add(position, tile);
                    }

                    if (tile == GameTile.Ball)
                    {
                        ballX = GetBallX();
                    }

                    if (tile == GameTile.Paddle)
                    {
                        padX = GetPadX();
                    }

                    if (ballX >= 0 && padX >= 0)
                    {
                        orientation = padX == ballX ? JoystickOrientation.Neutral : padX > ballX ? JoystickOrientation.Left : JoystickOrientation.Right;
                        UpdateScreen();
                    }
                }

                setupState = SetupState.SetX;

                break;
            }
        }
Esempio n. 2
0
 public Game(IIntCodeComputer computer)
 {
     this.computer = computer;
     computer.AddDelegate(this);
     setupState  = SetupState.SetX;
     gameState   = new Dictionary <Point, GameTile>();
     orientation = JoystickOrientation.Neutral;
 }