From c954a28e9a7f6dfb623777340b0ebdfbb3bdd76f Mon Sep 17 00:00:00 2001 From: Hugo Caille Date: Sun, 7 Jun 2015 20:59:53 +0200 Subject: [PATCH] Code style cleanups --- breakout/breakout/Breakout.cs | 38 ++++++++++------------- breakout/breakout/DefaultLevels.cs | 1 - breakout/breakout/GameComponents/Ball.cs | 14 ++++----- breakout/breakout/GameComponents/Bat.cs | 16 ++-------- breakout/breakout/GameComponents/Bonus.cs | 29 +++++++---------- breakout/breakout/GameComponents/Brick.cs | 31 +----------------- breakout/breakout/GameLevel.cs | 31 +++--------------- breakout/breakout/Textures/BatTextures.cs | 3 -- breakout/breakout/Util/ButtonSprite.cs | 6 +--- breakout/breakout/Util/Circle.cs | 3 -- breakout/breakout/Util/MenuArrow.cs | 4 --- 11 files changed, 43 insertions(+), 133 deletions(-) diff --git a/breakout/breakout/Breakout.cs b/breakout/breakout/Breakout.cs index 20a108e..dcb7de0 100644 --- a/breakout/breakout/Breakout.cs +++ b/breakout/breakout/Breakout.cs @@ -33,10 +33,6 @@ namespace breakout { /// Class Breakout. /// public class Breakout : Game { - /// - /// The graphics - /// - GraphicsDeviceManager graphics; /// /// The sprite batch /// @@ -49,14 +45,16 @@ public class Breakout : Game { /// The sounds /// private Sounds sounds; + /// /// The song start /// - private bool songStart = false; + private bool songStart; + /// /// The Mute song /// - private bool muteSong = false; + private bool muteSong; /// /// The game state @@ -138,9 +136,11 @@ public class Breakout : Game { /// Initializes a new instance of the class. /// public Breakout() { - graphics = new GraphicsDeviceManager(this); - graphics.PreferredBackBufferWidth = 800; - graphics.PreferredBackBufferHeight = 600; + new GraphicsDeviceManager(this) + { + PreferredBackBufferWidth = 800, + PreferredBackBufferHeight = 600 + }; Content.RootDirectory = "Content"; int screenWidth = Window.ClientBounds.Width; @@ -296,9 +296,9 @@ protected override void Update(GameTime gameTime) { } foreach(Brick b in gameLevel.BricksMap){ - if (b.Bonus.Activated == true) + if (b.Bonus.Activated) { - b.Bonus.Update(gameTime, gameLevel.Bat.Hitbox, gameLevel, b); + b.Bonus.Update(gameTime, gameLevel.Bat.Hitbox, gameLevel); } } gameLevel.Bat.HandleInput(keyboardState, previousKeyboardState); @@ -374,8 +374,6 @@ protected override void Update(GameTime gameTime) { case GameState.EXIT: this.Exit(); break; - default: - break; } @@ -576,7 +574,7 @@ protected override void Draw(GameTime gameTime) { foreach (Brick b in gameLevel.BricksMap) { - if (b.Bonus.Activated == true) + if (b.Bonus.Activated) { b.Bonus.Draw(spriteBatch, gameTime); } @@ -598,7 +596,7 @@ protected override void Draw(GameTime gameTime) { foreach (Brick b in gameLevel.BricksMap) { - if (b.Bonus.Activated == true) + if (b.Bonus.Activated) { b.Bonus.Draw(spriteBatch, gameTime); } @@ -624,7 +622,7 @@ protected override void Draw(GameTime gameTime) { foreach (Brick b in gameLevel.BricksMap) { - if (b.Bonus.Activated == true) + if (b.Bonus.Activated) { b.Bonus.Draw(spriteBatch, gameTime); } @@ -647,8 +645,6 @@ protected override void Draw(GameTime gameTime) { exitButton.Draw(spriteBatch, gameTime); menuArrow.Draw(spriteBatch, gameTime); break; - default: - break; } spriteBatch.End(); @@ -698,11 +694,11 @@ private void PutBricksTexture() /// /// Gets the lives. /// - /// The sprite batch. + /// The sprite batch. /// The game time. - private void GetLives(ref SpriteBatch spriteBatch, GameTime gameTime) + private void GetLives(ref SpriteBatch batch, GameTime gameTime) { - livesSprites[gameLevel.Lives].Draw(spriteBatch, gameTime); + livesSprites[gameLevel.Lives].Draw(batch, gameTime); } } diff --git a/breakout/breakout/DefaultLevels.cs b/breakout/breakout/DefaultLevels.cs index 6f1b9ec..0869dc8 100644 --- a/breakout/breakout/DefaultLevels.cs +++ b/breakout/breakout/DefaultLevels.cs @@ -17,7 +17,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net.Configuration; using System.Reflection; using breakout.Util; diff --git a/breakout/breakout/GameComponents/Ball.cs b/breakout/breakout/GameComponents/Ball.cs index 76e27a1..05f75cf 100644 --- a/breakout/breakout/GameComponents/Ball.cs +++ b/breakout/breakout/GameComponents/Ball.cs @@ -54,7 +54,7 @@ public Ball(int screenWidth, int screenHeight) : base(screenWidth, screenHeight) /// /// The ball. public Ball(Ball ball) - : base(ball.screenWidth, ball.screenHeight) { + : base(ball.ScreenWidth, ball.ScreenHeight) { this.Position = ball.Position; this.Texture = ball.Texture; this.Direction = -ball.Direction; @@ -119,12 +119,12 @@ public void Update(GameTime gameTime, Rectangle batHitBox, GameLevel gameLevel, /// The game level. private void BouncingOnTheWalls(GameLevel gameLevel) { if ((Position.Y <= 0 && Direction.Y < 0)) { - this.sm.bump.Play(0.5f, 0.0f, 0.0f); + this.sm.Bump.Play(0.5f, 0.0f, 0.0f); Direction = new Vector2(Direction.X, -Direction.Y); gameLevel.Score -= 10; } - if (Position.X <= 0 && Direction.X < 0 || Position.X > screenWidth - Texture.Height && Direction.X > 0) { - this.sm.bump.Play(0.5f, 0.0f, 0.0f); + if (Position.X <= 0 && Direction.X < 0 || Position.X > ScreenWidth - Texture.Height && Direction.X > 0) { + this.sm.Bump.Play(0.5f, 0.0f, 0.0f); Direction = new Vector2(-Direction.X, Direction.Y); gameLevel.Score -= 10; } @@ -137,7 +137,7 @@ private void BouncingOnTheBat(Rectangle batHitBox) { if ((Direction.Y > 0 && this.hitbox.IntersectsRec(batHitBox))) { Direction = new Vector2(((float)hitbox.X - batHitBox.Center.X) / (batHitBox.Width / 2), -Direction.Y); Direction = Vector2.Normalize(Direction); - this.sm.bump.Play(0.5f, 0.0f, 0.0f); + this.sm.Bump.Play(0.5f, 0.0f, 0.0f); } } @@ -151,9 +151,9 @@ private List GetTouchedBricks(GameLevel gameLevel) { foreach (Brick b in gameLevel.BricksMap) { if (this.hitbox.IntersectsRec(b.Hitbox) && b.Resistance > 0) { if (b.Resistance == 4) { - this.sm.bump.Play(0.5f, 0.0f, 0.0f); + this.sm.Bump.Play(0.5f, 0.0f, 0.0f); } else { - this.sm.bumpBrick.Play(0.5f, 0.0f, 0.0f); + this.sm.BumpBrick.Play(0.5f, 0.0f, 0.0f); } if (b.Bonus.Type != BonusType.NONE && b.Bonus.Activated == false) { diff --git a/breakout/breakout/GameComponents/Bat.cs b/breakout/breakout/GameComponents/Bat.cs index 989bd50..5dfe713 100644 --- a/breakout/breakout/GameComponents/Bat.cs +++ b/breakout/breakout/GameComponents/Bat.cs @@ -37,11 +37,6 @@ public class Bat : MovingSprite { /// private Vector2 acceleration = Vector2.Zero; /// - /// Gets or sets the acceleration. - /// - /// The acceleration. - public Vector2 Acceleration { get { return acceleration; } set { acceleration = value; } } - /// /// Gets the hitbox. /// /// The hitbox. @@ -56,13 +51,6 @@ public Rectangle Hitbox { /// Height of the screen. public Bat(int screenWidth, int screenHeight) : base(screenWidth, screenHeight) { } - /// - /// Initializes this instance and sets a default position at the top right of the screen and a zero direction/speed. - /// - public override void Initialize() { - base.Initialize(); - } - /// /// Loads the content common to every sprite of our game, the texture 2D /// @@ -70,7 +58,7 @@ public override void Initialize() { /// Name of the asset. public override void LoadContent(ContentManager content, string assetName) { base.LoadContent(content, assetName); - Position = new Vector2(screenWidth / 2 - Texture.Width / 2, screenHeight - 10 - Texture.Height / 2); + Position = new Vector2(ScreenWidth / 2 - Texture.Width / 2, ScreenHeight - 10 - Texture.Height / 2); } /// @@ -113,7 +101,7 @@ public override void HandleInput(KeyboardState keyboardState, KeyboardState prev /// /// The game time. public override void Update(GameTime gameTime) { - if ((position.X <= 0 && direction.X < 0) || (position.X >= screenWidth - Texture.Width && direction.X > 0)) { + if ((position.X <= 0 && direction.X < 0) || (position.X >= ScreenWidth - Texture.Width && direction.X > 0)) { speed = 0; acceleration = Vector2.Zero; } diff --git a/breakout/breakout/GameComponents/Bonus.cs b/breakout/breakout/GameComponents/Bonus.cs index c2e36ff..aebafb5 100644 --- a/breakout/breakout/GameComponents/Bonus.cs +++ b/breakout/breakout/GameComponents/Bonus.cs @@ -59,7 +59,7 @@ public BonusType Type /// /// The activated /// - private bool activated = false; + private bool activated; /// /// Gets or sets a value indicating whether this is activated. /// @@ -84,13 +84,6 @@ private Rectangle hitbox get { return new Rectangle((int)Position.X, (int)Position.Y, Texture.Width, Texture.Height); } } - /// - /// Initializes a new instance of the class. - /// - /// Width of the screen. - /// Height of the screen. - public Bonus(int screenWidth, int screenHeight) : base(screenWidth, screenHeight) { } - /// /// Initializes a new instance of the class. /// @@ -122,7 +115,7 @@ public override void LoadContent(ContentManager content, String assetName) /// The bat hit box. /// The game level. /// The brick. - public void Update(GameTime gameTime, Rectangle batHitBox, GameLevel gameLevel, Brick brick) + public void Update(GameTime gameTime, Rectangle batHitBox, GameLevel gameLevel) { Direction = new Vector2(0, 1); if (this.hitbox.Intersects(batHitBox)) @@ -130,14 +123,14 @@ public void Update(GameTime gameTime, Rectangle batHitBox, GameLevel gameLevel, switch (this.Type) { case BonusType.HIGH_SPEED: - this.sm.powerDown.Play(); + this.sm.PowerDown.Play(); foreach (Ball b in gameLevel.Balls) { b.Speed *= 1.5f; } break; case BonusType.HIGH_RESISTANCE: - this.sm.powerDown.Play(); + this.sm.PowerDown.Play(); foreach (Brick b in gameLevel.BricksMap) { if (b.Resistance != 0 && b.Resistance != 4) @@ -148,22 +141,22 @@ public void Update(GameTime gameTime, Rectangle batHitBox, GameLevel gameLevel, } break; case BonusType.BAT_REDUCED: - this.sm.powerDown.Play(); + this.sm.PowerDown.Play(); gameLevel.Bat.Texture = gameLevel.BatTexture.Reduced; break; case BonusType.BAT_EXTENDED: - this.sm.powerUp.Play(); + this.sm.PowerUp.Play(); gameLevel.Bat.Texture = gameLevel.BatTexture.Extended; break; case BonusType.DOWN_LIFE: - this.sm.powerDown.Play(); + this.sm.PowerDown.Play(); if (gameLevel.Lives > 0) { gameLevel.Lives--; } break; case BonusType.LOW_RESISTANCE: - this.sm.powerUp.Play(); + this.sm.PowerUp.Play(); foreach (Brick b in gameLevel.BricksMap) { if (b.Resistance != 0 && b.Resistance != 4) @@ -174,14 +167,14 @@ public void Update(GameTime gameTime, Rectangle batHitBox, GameLevel gameLevel, } break; case BonusType.LOW_SPEED: - this.sm.powerUp.Play(); + this.sm.PowerUp.Play(); foreach (Ball b in gameLevel.Balls) { b.Speed /= 1.5f; } break; case BonusType.UP_LIFE: - this.sm.powerUp.Play(); + this.sm.PowerUp.Play(); if (gameLevel.Lives < 4) { gameLevel.Lives++; @@ -199,7 +192,7 @@ public void Update(GameTime gameTime, Rectangle batHitBox, GameLevel gameLevel, Type = BonusType.NONE; Activated = false; - } else if(Position.Y >= screenHeight/0.6){ + } else if(Position.Y >= ScreenHeight/0.6){ Activated = false; } diff --git a/breakout/breakout/GameComponents/Brick.cs b/breakout/breakout/GameComponents/Brick.cs index 45ad848..5d4c62a 100644 --- a/breakout/breakout/GameComponents/Brick.cs +++ b/breakout/breakout/GameComponents/Brick.cs @@ -29,17 +29,6 @@ namespace breakout.GameComponents /// public class Brick : Sprite { - /// - /// Gets or sets the height. - /// - /// The height. - private int height { get; set; } - /// - /// Gets or sets the width. - /// - /// The width. - private int width { get; set; } - /// /// Gets or sets the bonus. /// @@ -71,23 +60,13 @@ public Rectangle Hitbox /// The w. /// The r. /// The b. - public Brick(int screenWidth, int screenHeight, Vector2 position, int h, int w, int r = 1, BonusType b = BonusType.NONE) : base( screenWidth, screenHeight) + public Brick(int screenWidth, int screenHeight, Vector2 position, int r = 1, BonusType b = BonusType.NONE) : base( screenWidth, screenHeight) { - this.height = h; - this.width = w; this.Position = position; this.Resistance = r; this.Bonus = new Bonus(screenWidth, screenHeight, b); } - /// - /// Initializes this instance and sets a default position at the top right of the screen. - /// - public override void Initialize() - { - base.Initialize(); - } - /// /// Draws the sprite. /// @@ -157,13 +136,5 @@ public int UpdateTexture(BrickTexture textures) } return newScore; } - - /// - /// Updates this instance. - /// - public override void Update() - { - base.Update(); - } } } diff --git a/breakout/breakout/GameLevel.cs b/breakout/breakout/GameLevel.cs index 2b18ceb..1a7ed6f 100644 --- a/breakout/breakout/GameLevel.cs +++ b/breakout/breakout/GameLevel.cs @@ -34,14 +34,6 @@ namespace breakout /// public class GameLevel { - /// - /// The columns - /// - private int columns; - /// - /// The lines - /// - private int lines; /// /// The screen width /// @@ -83,15 +75,6 @@ public int Nb_bricks /// The nb bonus /// private int nbBonus; - /// - /// Gets or sets the nb bonus. - /// - /// The nb bonus. - public int NbBonus - { - get { return nbBonus; } - set { nbBonus = value; } - } /// /// The bat @@ -131,7 +114,7 @@ public List Balls /// /// The score /// - private int score = 0; + private int score; /// /// Gets or sets the score. /// @@ -209,14 +192,12 @@ public List BricksMap public GameLevel(int screenWidth, int screenHeight, GameFile level, int lines, int columns, List balls, Bat bat) { this.screenWidth = screenWidth; - this.screenHeight = (int)(0.6 * (double)screenHeight); + this.screenHeight = (int)(0.6 * screenHeight); this.levelFile = level; this.Balls = balls; this.Bat = bat; - this.lines = lines; - this.columns = columns; this.BricksMap = new List(); - this.nb_bricks = this.lines * this.columns; + this.nb_bricks = lines * columns; } /// @@ -251,7 +232,6 @@ public void CreateBackground(GraphicsDevice device) public void CreateSong() { byte[] songBytes = Convert.FromBase64String((string)this.levelFile.Data.Music["file"]); - string mime = (string) this.levelFile.Data.Music["type"]; string temp = Path.GetTempFileName(); File.WriteAllBytes(temp, songBytes); @@ -297,7 +277,6 @@ public void Update(bool restart, GameFile file) /// public void InitializeBonus() { - int index = 0; foreach (Brick brick in this.BricksMap) { if (brick.Bonus.Type != BonusType.NONE) @@ -314,7 +293,6 @@ public void InitializeBonus() { brick.Bonus.Name = "malus"; } - index++; } } } @@ -350,7 +328,7 @@ private void LoadLevel() var line = (double) brick["line"]; var column = (double) brick["column"]; var resistance = (double) brick["resistance"]; - this.BricksMap.Add(new Brick(this.screenWidth, this.screenHeight, new Vector2(x + (int) column * margin_w, y + (int) line * margin_h), 20, 50, (int) resistance)); + this.BricksMap.Add(new Brick(this.screenWidth, this.screenHeight, new Vector2(x + (int) column * margin_w, y + (int) line * margin_h), (int) resistance)); } } @@ -379,7 +357,6 @@ private void SetBonus() { Random rnd = new Random(); Random x_rnd = new Random(); - Random y_rnd = new Random(); for (int i = 0; i < this.nbBonus; i++) { diff --git a/breakout/breakout/Textures/BatTextures.cs b/breakout/breakout/Textures/BatTextures.cs index 38fadeb..0036d2b 100644 --- a/breakout/breakout/Textures/BatTextures.cs +++ b/breakout/breakout/Textures/BatTextures.cs @@ -36,7 +36,6 @@ public class BatTextures public Texture2D Reduced { get { return reduced; } - set { reduced = value; } } /// @@ -50,7 +49,6 @@ public Texture2D Reduced public Texture2D Regular { get { return regular; } - set { regular = value; } } /// @@ -64,7 +62,6 @@ public Texture2D Regular public Texture2D Extended { get { return extended; } - set { extended = value; } } diff --git a/breakout/breakout/Util/ButtonSprite.cs b/breakout/breakout/Util/ButtonSprite.cs index 6484dd1..c156ee5 100644 --- a/breakout/breakout/Util/ButtonSprite.cs +++ b/breakout/breakout/Util/ButtonSprite.cs @@ -35,7 +35,7 @@ public class ButtonSprite : Sprite { /// Gets or sets the name. /// /// The name. - public String Name { get { return name; } set { name = value; } } + public String Name { get { return name; } } /// /// Gets the hitbox. @@ -89,11 +89,7 @@ public void Update(MouseState mouseState, MouseState previousMouseState, ref Gam case "next": gameState = GameState.NEXT_LEVEL; break; - default: - break; } - - } } diff --git a/breakout/breakout/Util/Circle.cs b/breakout/breakout/Util/Circle.cs index 39bc470..e447d2b 100644 --- a/breakout/breakout/Util/Circle.cs +++ b/breakout/breakout/Util/Circle.cs @@ -36,7 +36,6 @@ public class Circle { /// The x. public int X { get { return x; } - set { x = value; } } /// @@ -49,7 +48,6 @@ public int X { /// The y. public int Y { get { return y; } - set { y = value; } } /// @@ -62,7 +60,6 @@ public int Y { /// The radius. public double Radius { get { return radius; } - set { radius = value; } } /// diff --git a/breakout/breakout/Util/MenuArrow.cs b/breakout/breakout/Util/MenuArrow.cs index 6f3212a..c0269e2 100644 --- a/breakout/breakout/Util/MenuArrow.cs +++ b/breakout/breakout/Util/MenuArrow.cs @@ -65,7 +65,6 @@ public ButtonSprite CurrentButtonSelected { /// The button group. public List ButtonGroup { get { return buttonGroup; } - set { buttonGroup = value; } } /// @@ -129,10 +128,7 @@ public void Update(KeyboardState keyboardState, KeyboardState previousKeyboardSt case "next": gameState = GameState.NEXT_LEVEL; break; - default: - break; } - } }