Skip to content

๐ŸŽฎ A comprehensive C programming exploration through rectangle manipulation with gravity physics, collision detection, and modular architecture. Features unit testing, ASCII visualization, and professional development practices.

License

Notifications You must be signed in to change notification settings

MJ-Sarabando/playingwith_C_rectanglesgame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Playing with C: Rectangles Game

C License: MIT Build Status

A fun exploration of C programming through rectangle manipulation with physics! What started as a university assignment evolved into a comprehensive demonstration of modular programming, physics simulation, and professional development practices.

๐ŸŒŸ Features

  • ๐Ÿ”„ Physics Engine: Automatic gravity system with realistic falling behavior
  • ๐ŸŽฒ Random IDs: Each rectangle gets a unique random identifier (0-9)
  • ๐Ÿ” Collision Detection: Advanced collision detection for overlaps and lateral contacts
  • ๐ŸŽจ Visual Display: ASCII-based graphical representation with filled interiors
  • โšก Real-time Manipulation: Create, move, and delete rectangles with instant feedback
  • ๐Ÿงช Unit Testing: Comprehensive test suite with 100% function coverage
  • ๐Ÿ—๏ธ Modular Architecture: Clean separation of concerns across multiple modules
  • ๐Ÿ“ Boundary Validation: Robust input validation and error handling

๐Ÿš€ Quick Start

Prerequisites

  • GCC compiler (C99 standard or later)
  • Unix-like system (Linux, macOS) or Windows with MinGW

Building & Running

# Clone the repository
git clone https://github.com/yourusername/playingwith_C_rectanglesgame.git
cd playingwith_C_rectanglesgame

# Build the project
make

# Run the program
make run

# Run unit tests
make test

๐Ÿ—๏ธ Architecture

The system follows a modular design pattern with clear separation of responsibilities:

๐Ÿ“ฆ Rectangle System
โ”œโ”€โ”€ ๐ŸŽฎ main.c           # Entry point and program orchestration
โ”œโ”€โ”€ ๐ŸŽฏ controlo.c       # Core logic: physics, collision detection, CRUD operations
โ”œโ”€โ”€ ๐ŸŽจ visualizacao.c   # Display engine and ASCII rendering
โ”œโ”€โ”€ ๐Ÿ” analise.c        # Command parsing and user interaction
โ”œโ”€โ”€ ๐Ÿงช tests.c          # Comprehensive unit test suite
โ””โ”€โ”€ ๐Ÿ“„ retangulos.h     # Public API definitions and data structures

๐Ÿ“‹ Module Responsibilities

Module Purpose Key Functions
Control Physics & State Management add_rectangle(), apply_gravity(), check_collision()
Visualization Rendering & Display display_world(), ASCII art generation
Analysis Command Processing parse_command(), process_commands()
Testing Quality Assurance Unit tests for all core functions

๐ŸŽฎ Usage

Interactive Mode

The program offers three operation modes:

  1. ๐ŸŽฏ Demo Mode: Runs predefined test scenarios
  2. โšก Interactive Mode: Manual command input
  3. ๐Ÿงช Testing Mode: Automated unit test execution

Commands Reference

Command Syntax Description Example
Create create x,y+w,h Creates a rectangle at position (x,y) with width w and height h create 5,10+8,4
Move Right moveright x,y+n Moves rectangle containing point (x,y) right by n positions moveright 7,12+3
Move Left moveleft x,y+n Moves rectangle containing point (x,y) left by n positions moveleft 15,8+2
Delete delete x,y Removes rectangle containing point (x,y) delete 10,5
Exit exit Terminates interactive mode exit

๐Ÿ“ Coordinate System

  • Origin: Bottom-left corner at (1,1)
  • Dimensions: 80ร—25 grid
  • Gravity: Downward (toward y=1)
  • Bounds: All rectangles must fit within the plane boundaries

๐ŸŽจ Visual Representation

Rectangles are displayed with ASCII characters:

xxxxxxxxxxxx
x++++5+++++x  โ† Border with 'x', interior filled with '+', ID displayed
x++++++++++x
x++++++++++x
xxxxxxxxxxxx

โš™๏ธ Advanced Features

๐Ÿงช Unit Testing Framework

The system includes a comprehensive testing suite:

# Run all tests
make test

# Memory leak detection (requires Valgrind)
make memcheck

# Static code analysis (requires cppcheck)
make analyze

Test Coverage:

  • โœ… Random ID generation and uniqueness
  • โœ… Rectangle location algorithms
  • โœ… Collision detection (overlap and lateral)
  • โœ… Boundary condition validation
  • โœ… Edge cases and error handling

๐Ÿ”ง Build System

Professional Makefile with multiple targets:

make debug     # Debug build with symbols
make release   # Optimized production build
make clean     # Clean build artifacts
make install   # System-wide installation
make help      # Show all available commands

๐ŸŽฏ Physics Engine

  • Gravity Simulation: Rectangles automatically fall until they hit the ground or another rectangle
  • Collision Prevention: Movement commands are validated to prevent overlapping
  • Lateral Contact Detection: System alerts when rectangles are touching side-by-side

๐Ÿ”ฌ Technical Specifications

  • Language: ANSI C (C99 standard)
  • Memory Management: Stack-based allocation with bounds checking
  • Maximum Rectangles: 10 concurrent rectangles
  • ID System: Random integers 0-9 with collision avoidance
  • Coordinate Precision: Integer-based positioning
  • Performance: O(nยฒ) collision detection, O(n) gravity application

๐Ÿ“Š Performance Characteristics

Operation Time Complexity Space Complexity
Rectangle Creation O(n) O(1)
Movement O(n) O(1)
Collision Detection O(nยฒ) O(1)
Gravity Application O(nยฒ) O(1)
Display Rendering O(wร—h) O(wร—h)

๐Ÿ› ๏ธ Development

Building from Source

# Development build with debugging
make debug

# Run with memory checking
make memcheck

# Generate documentation (requires Doxygen)
make docs

Code Quality

The project maintains high code quality standards:

  • Static Analysis: cppcheck integration
  • Memory Safety: Valgrind compatibility
  • Modular Design: Clear separation of concerns
  • Comprehensive Testing: Unit tests for all critical functions
  • Documentation: Inline comments and external docs

๐Ÿค Contributing

Contributions are welcome! Please ensure:

  1. All unit tests pass (make test)
  2. Code follows existing style conventions
  3. New features include corresponding tests
  4. Memory leaks are avoided (make memcheck)

๐Ÿ“ Example Session

$ make run
Rectangle Manipulation System
=============================

Choose an option:
1 - Run test example
2 - Interactive mode
3 - Run unit tests
Option: 2

Available commands:
- create x,y+l,h
- moveright x,y+p
- moveleft x,y+p
- delete x,y
- exit

Enter command: create 10,5+8,4
Rectangle created successfully (ID: 7)

Current world state:
xxxxxxxxxxxx
x++++7+++++x
x++++++++++x
xxxxxxxxxxxx

๐Ÿ† Project Highlights

This project demonstrates:

  • โœจ Advanced C Programming: Modular architecture, proper memory management
  • ๐Ÿงช Test-Driven Development: Comprehensive unit testing framework
  • ๐ŸŽฏ Software Engineering: Clean code principles, separation of concerns
  • ๐ŸŽจ User Experience: Intuitive command interface, visual feedback
  • ๐Ÿ”ง Professional Tooling: Modern build system, development workflow

๐Ÿ“š Academic Context

Originally developed as part of a Programming Laboratory course assignment, this project showcases professional-level software development practices including modular design, comprehensive testing, and robust error handling.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘ค Author

Maria Sarabando
Computer Science Student


โญ Star this repository if you found it helpful!

Built with โค๏ธ and lots of โ˜•

About

๐ŸŽฎ A comprehensive C programming exploration through rectangle manipulation with gravity physics, collision detection, and modular architecture. Features unit testing, ASCII visualization, and professional development practices.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published