Skip to content

Commit

Permalink
Adding BrickOutGame class
Browse files Browse the repository at this point in the history
  • Loading branch information
pburrows committed Oct 29, 2023
1 parent e674da4 commit f5fcfaf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
7 changes: 7 additions & 0 deletions csharp/BrickOut.Maui/BrickOut.GameLogic/BrickOutGame.cs
@@ -0,0 +1,7 @@
namespace BrickOut.GameLogic;

public class BrickOutGame
{
public GameBoard GameBoard { get; set; } = GameBoard.NewGame();

}
Expand Up @@ -88,7 +88,3 @@ public void SetLocation(int x, int y)
Location = new Point(x, y);
}
}

public class BrickOutGame
{
}
40 changes: 20 additions & 20 deletions csharp/BrickOut.Maui/BrickOut.Wpf/MainWindow.xaml.cs
Expand Up @@ -25,10 +25,10 @@ namespace BrickOut.Wpf
/// </summary>
public partial class MainWindow : Window
{
public GameBoard CurrentGame { get; set; } = GameBoard.NewGame();
public DispatcherTimer refreshTimer;
public Rectangle paddleRectangle;
public Rectangle ballRectangle;
private BrickOutGame currentGame { get; set; } = new(); // GameBoard.NewGame();
private DispatcherTimer refreshTimer;
private Rectangle paddleRectangle;
private Rectangle ballRectangle;

public MainWindow()
{
Expand All @@ -55,7 +55,7 @@ private void RefreshTimerOnTick(object? sender, EventArgs e)
private void GameCanvasOnMouseMove(object sender, MouseEventArgs e)
{
var position = e.GetPosition(GameCanvas);
CurrentGame.Paddle.SetLocation((int)position.X, 0);
currentGame.GameBoard.Paddle.SetLocation((int)position.X, 0);
}

private List<Color> BrickColors = new()
Expand All @@ -76,25 +76,25 @@ private void UpdateGameBoard()
return;
}

Canvas.SetLeft(paddleRectangle, CurrentGame.Paddle.Location.X);
Canvas.SetLeft(paddleRectangle, currentGame.GameBoard.Paddle.Location.X);

UpdateBallPosition();
}

private void UpdateBallPosition()
{
var newX = CurrentGame.Ball.Location.X + CurrentGame.Ball.VelocityX;
var newY = CurrentGame.Ball.Location.Y + CurrentGame.Ball.VelocityY;
CurrentGame.Ball.SetLocation(newX, newY);
Canvas.SetLeft(ballRectangle, CurrentGame.Ball.Location.X);
Canvas.SetTop(ballRectangle, CurrentGame.Ball.Location.Y);
var newX = currentGame.GameBoard.Ball.Location.X + currentGame.GameBoard.Ball.VelocityX;
var newY = currentGame.GameBoard.Ball.Location.Y + currentGame.GameBoard.Ball.VelocityY;
currentGame.GameBoard.Ball.SetLocation(newX, newY);
Canvas.SetLeft(ballRectangle, currentGame.GameBoard.Ball.Location.X);
Canvas.SetTop(ballRectangle, currentGame.GameBoard.Ball.Location.Y);
}

private void DrawGameBoard()
{
GameCanvas.Children.Clear();

foreach (var brick in CurrentGame.Bricks)
foreach (var brick in currentGame.GameBoard.Bricks)
{
AddRectangleToCanvas(
GetNextBrickColorBrush(),
Expand All @@ -106,17 +106,17 @@ private void DrawGameBoard()

paddleRectangle = AddRectangleToCanvas(
new SolidColorBrush(Colors.Red),
CurrentGame.Paddle.Location.X,
CurrentGame.Paddle.Location.Y,
CurrentGame.Paddle.Shape.Width,
CurrentGame.Paddle.Shape.Height);
currentGame.GameBoard.Paddle.Location.X,
currentGame.GameBoard.Paddle.Location.Y,
currentGame.GameBoard.Paddle.Shape.Width,
currentGame.GameBoard.Paddle.Shape.Height);

ballRectangle = AddRectangleToCanvas(
new SolidColorBrush(Colors.Green),
CurrentGame.Ball.Location.X,
CurrentGame.Ball.Location.Y,
CurrentGame.Ball.Shape.Width,
CurrentGame.Ball.Shape.Height);
currentGame.GameBoard.Ball.Location.X,
currentGame.GameBoard.Ball.Location.Y,
currentGame.GameBoard.Ball.Shape.Width,
currentGame.GameBoard.Ball.Shape.Height);
}

private Rectangle AddRectangleToCanvas(SolidColorBrush brush, int x, int y, int width, int height)
Expand Down

0 comments on commit f5fcfaf

Please sign in to comment.