예제 #1
0
        public void DrawGameBoard()
        {
            string GetBoardCellString(GridPoint gridPoint)
            {
                var  point         = new GameGridCell(gridPoint.X, gridPoint.Y);
                bool isCellPresent = GridCells.TryGetValue(point, out var cell);

                if (isCellPresent)
                {
                    return(cell.DrawCell());
                }
                return(" ");
            }

            if (ClearConsoleWhenDrawingBoard)
            {
                Console.Clear();
            }
            GridHelper.DrawGrid2D(
                gridPoints: GridCells.Select(gc => new GridPoint(gc.X, gc.Y)).ToList(),
                GetPointString: GetBoardCellString);
            Console.WriteLine($"     Blocks Remaining: {NumberOfBlocksRemaining}");
            Console.WriteLine($"     Score: {Score}");
            Console.WriteLine($"     Time index: {_timeIndex}");
            Console.WriteLine();
        }
예제 #2
0
        private void RefreshGridCells()
        {
            // The software draws tiles to the screen with output instructions:
            // every three output instructions specify the x position
            // (distance from the left), y position (distance from the top),
            // and tile id.
            // The arcade cabinet also has a segment display capable of showing
            // a single number that represents the player's current score.
            // When three output instructions specify X=-1, Y=0, the third
            // output instruction is not a tile; the value instead specifies
            // the new score to show in the segment display. For example, a
            // sequence of output values like -1,0,12345 would show 12345 as
            // the player's current score.
            for (int outputIndex = 0; outputIndex < OutputListener.Values.Count; outputIndex += 3)
            {
                var x         = OutputListener.Values[outputIndex];
                var y         = OutputListener.Values[outputIndex + 1];
                var param3Val = OutputListener.Values[outputIndex + 2];
                if (x == -1 && y == 0)
                {
                    Score = (long)param3Val;
                }
                else
                {
                    var gridCell = new GameGridCell((int)x, (int)y, (GameCellType)(int)param3Val);
                    if (GridCells.Contains(gridCell))
                    {
                        GridCells.Remove(gridCell);
                    }
                    GridCells.Add(gridCell);
                    if (GameCellType.Ball.Equals(gridCell.Type))
                    {
                        Last3BallPositions[2] = Last3BallPositions[1];
                        Last3BallPositions[1] = Last3BallPositions[0];
                        Last3BallPositions[0] = gridCell;
                    }
                }
            }
            // Check if this is a ball/paddle contact
            var dX = Math.Abs(Ball.X - HorizontalPaddle.X);
            var dY = Math.Abs(Ball.Y - HorizontalPaddle.Y);

            if (dX <= 1 && dY == 1)
            {
                BallPaddleContactTurns.Add(_timeIndex);
            }
        }