-
Notifications
You must be signed in to change notification settings - Fork 0
/
BreakoutModel.cs
94 lines (76 loc) · 1.88 KB
/
BreakoutModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System.Drawing;
namespace BrickOut.GameLogic;
public class GameBoard
{
public int Height { get; set; } = 640;
public int Width { get; set; } = 480;
public List<Brick> Bricks { get; set; } = new();
public Ball Ball { get; set; }
public Paddle Paddle { get; set; }
public static GameBoard NewGame()
{
var board = new GameBoard();
board.Paddle = new Paddle(0, 635);
board.Ball = new Ball(20, 630);
// create bricks
for (var row = 0; row < 6; row++)
{
int y = row * 10;
// 24 columns == 480 width / 20 pixel wide bricks
for (var col = 0; col < 24; col++)
{
int x = col * 20;
board.Bricks.Add(new Brick(x, y));
}
}
return board;
}
}
public interface DisplayItem
{
public Size Shape { get; set; }
public Point Location { get; set; }
}
public class Brick : DisplayItem
{
public Size Shape { get; set; }
public Point Location { get; set; }
public Brick(int x, int y)
{
Shape = new Size(20, 10);
Location = new Point(x, y);
}
}
public class Ball : DisplayItem
{
public Size Shape { get; set; }
public Point Location { get; set; }
public int VelocityX { get; set; } = 8;
public int VelocityY { get; set; } = -8;
public Ball(int x, int y)
{
Shape = new Size(5, 5);
Location = new Point(x, y);
}
public void SetLocation(int x, int y)
{
Location = new Point(x, y);
}
}
public class Paddle : DisplayItem
{
public Size Shape { get; set; }
public Point Location { get; set; }
public Paddle(int x, int y)
{
Shape = new Size(40, 5);
Location = new Point(x, y);
}
public void SetLocation(int x, int y)
{
Location = new Point(x, y);
}
}
public class BrickOutGame
{
}