logo

Design and Development of a Breakout Game in C#

   

Added on  2023-06-13

27 Pages3183 Words447 Views
Introduction
This project entails the design and development of a version of the Atari2600 classic “breakout” game.
This is a simple classic arcade game, developed in 1976 by a company called Atari Inc; inspired by a
1972 Atari arcade Pong game that had been developed by Steve Jobs and Steve Wozniak1. The game
contains layers of bricks, which are broken by a bouncing ball. The ball is reflected to the bricks by a
moveable paddle platform at the bottom; which is moved by a player horizontally to bounce the ball
upwards.
Design of the Game
Figure 1.0 Game control flow chart diagram
The game follows a simple design where when the application is started; it first initializes the
Graphical user interface components, then lays out layers of bricks, before waiting for a player to
start playing the game. When the game is started, various listeners keep check of the ball’s
position and the bricks. When a brick is hit by the ball, the brick is removed from the view, and
the ball reflected back. A function handles the change of direction of the ball. This function also
handles the ball when it hits the paddle platform as well as when it hits the walls of the play area.
Brick removal calls the method to increment the player’s score, which is automatically updated
on the GUI.
The application was developed in C#, to ensure that the application User interface is as robust
and lightweight as possible; the user interface was defined in xml and called in C#.
1. Thomasson, Michael. "Atari VCS 2600." Encyclopedia of Video Games: MZ 2 (2012): 52.

To make it easy to control the game’s logic, a number of classes were developed, each
representing a single object; such as Ball, Paddle and Brick. Each of these objects interacts with
one another to and are the foundation of the game.
The programs main functions and algorithms are contained in the PongBrickGame namespace.
The main form that makes the GUI is empty and is drawn at runtime.
Figure 1.0 Main Form of the application,
We use the graphics drawing functionalities to draw the playfield, the bricks, paddle and the ball
at runtime. Since each object is modeled in a class of its own, it’s an easier approach.

Figure 2: Game GUI when the Game is started
Figure 3.0 GUI when the game is being played

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace PongBrickGame
{
/// <summary>
/// This class simply paints the
/// FORM to create the Games's
/// graphical user interface
/// </summary>
public class Game
{
protected Image image = null;
public Point startPosition = new Point(50, 50);
protected Rectangle playFieldBounds = new Rectangle(0,0, 10, 10);
protected Rectangle moveableBounds = new Rectangle();
public Game(string fileName)
{
image = Image.FromFile(fileName);
playFieldBounds.Width = image.Width;
playFieldBounds.Height = image.Height;
}
public int Width
{
get
{
return playFieldBounds.Width;
}
}
public int Height
{
get
{
return playFieldBounds.Height;
}
}
public virtual int GetWidth()
{
return playFieldBounds.Width;
}
public Image GetImage()
{
return image;
}
public virtual Rectangle GetBounds()
{
return moveableBounds;
}
public void UpdateBounds()

{
moveableBounds = playFieldBounds;
moveableBounds.Offset(startPosition);
}
public virtual void Draw(Graphics g)
{
UpdateBounds();
g.DrawImage(image, moveableBounds, 0, 0, playFieldBounds.Width,
playFieldBounds.Height, GraphicsUnit.Pixel);
}
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Threading;
namespace PongBrickGame
{
/// <summary>
/// The main Class of this application.

/// It forms the whole game
/// </summary>
public class BrickBreaker : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
private const int noOfBricksRows = 8;
private const int noOfTiles = 3;
private int totalBrickOnTheForm = 0;
private int noOfBalls = 0;
private Ball ball = new Ball();
private Paddle playerPaddle = new Paddle();
private System.Windows.Forms.Timer timer1;
private RowOfBricks[] rows = new RowOfBricks[noOfBricksRows];
private Score playerScore = null;
private Thread gameThread = null;
[DllImport("winmm.dll")]
public static extern long PlaySound(String lpszName, long hModule, long dwFlags);
/// <summary>
/// The main constructor of the application
/// calls the InitializeComponents() function
/// which greates the GUI
/// </summary>
public BrickBreaker()
{
InitializeComponent();

End of preview

Want to access all the pages? Upload your documents or become a member.