Skip to content

RitalShilli3/java-space-invaders

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

19 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ Java Space Invaders โ€” Refactored with Design Patterns

A modern refactoring of the classic Java Space Invaders arcade game, enhanced using Creational, Structural, and Behavioral Software Design Patterns as part of the CCSW 413 โ€” Software Design Patterns course at the University of Jeddah.

This project improves the original gameโ€™s architecture by making it modular, extensible, memory-efficient, and easier to maintain, while preserving the original gameplay experience.


๐ŸŽฎ Project Overview

This application is based on the iconic Space Invaders (1978) game.
The player controls a cannon and defends Earth from waves of alien invaders.

To elevate the code quality and architecture, we applied the following design patterns across three phases:


1. Creational Design Patterns

Prototype

  • Used for cloning Alien objects instead of repeatedly instantiating new ones.
  • Reduces redundancy and simplifies creation of multiple similar aliens.

Factory Method

  • Introduced a BoardFactory to handle creation of game elements (player, aliens, bullets).
  • Decouples object creation from the game logic.

Singleton

  • Implemented SpriteManager to cache and reuse sprite images.
  • Ensures each sprite is loaded once โ†’ memory and performance optimization.

2. Structural Design Patterns

Decorator

  • Created AlienDecorator and StrongAlien to add HP and extra behavior to aliens.
  • Allows dynamic addition of features without modifying the original Alien class.

Flyweight

  • Introduced AlienType and AlienTypeFactory to share intrinsic alien data (appearance, base stats).
  • Reduces memory usage significantly when rendering many aliens.

3. Behavioral Design Patterns

Observer

  • Implemented a game Status Bar showing:
    • Score
    • Aliens defeated
    • Remaining time
  • Status bar visually responds to events (low time, win, game over).

State

  • Refactored the game phases into separate states:
    • Main Menu
    • Level 1
    • Level 2
    • Game Won
    • Game Over
  • Each state encapsulates its own behavior โ†’ easier to add new levels.

๐Ÿ—‚ Repository Structure

/src /game

  • Board.java
  • SpaceInvaders.java
  • SpriteManager.java // Singleton
  • GameState classes // State Pattern
  • Observer interfaces // Observer Pattern
  • Factory classes // Factory Method
  • AlienDecorator... // Decorator Pattern
  • AlienTypeFactory... // Flyweight Pattern /report

UML Diagrams

Detailed diagrams for all phases can be found in the project report:

  • Original class diagrams
  • Refactored diagrams (Creational, Structural, Behavioral)

Team Members

  • Hajar Habiburahman
  • Rawan Tallha
  • Rital Shilli

University of Jeddah

College of Computer Science and Engineering
Department of Software Engineering

menu level_2 level_complete GameOver


๐Ÿ“ฅ How to Run

  1. Clone the repository:
    git clone https://github.com/RitalShilli3/java-space-invaders

About

๐Ÿ•น A simple Space Invaders Java 2D game clone

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%