Skip to content

ThreadDotRun/BoardGameConstructionKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎲 BoardGame SQLite: Your Game Board, Persisted!

Welcome to BoardGame SQLite, the ultimate Python library for crafting 2D game boards that stick around like a well-played chess move! 🧩 Whether you’re building a strategy game, a dungeon crawler, or a digital Risk clone, this library lets you manage a board with attributes (think tanks, health points, or sneaky rogues) and saves it all to SQLite—because no one likes losing their game state. With a rock-solid test suite, you’re ready to roll the dice! 🎯

Python SQLite Tests License Build

🌟 Why You’ll Love It

Imagine your game board as a battlefield: every square holds troops, treasures, or traps. BoardGame SQLite is your trusty general, letting you:

  • 🗺️ Command a 2D Board: Set up an n x n grid and assign attributes like unit: tank or health: 5.
  • 💾 Persist Like a Pro: Save your board state to SQLite, in-memory for testing or file-based for epic campaigns.
  • 🧑‍💻 Code with Confidence: 8 unit tests cover every move, from initialization to persistence.
  • 🚀 Get Started Fast: No dependencies, just pure Python magic.

Whether you’re a hobbyist coder or a game dev wizard, this library is your shortcut to building robust game mechanics without sweating the storage details. Let’s dive in! ⚔️

🎮 Quick Start

Prerequisites

  • 🐍 Python 3.6+ (because who’s still on 2.x?)
  • 📦 SQLite (comes with Python’s sqlite3 module)

Installation

  1. Clone this repo like you’re capturing a flag:
    git clone https://github.com/your-username/boardgame-sqlite.git
    cd boardgame-sqlite
  2. That’s it! No pip install nonsense—pure Python standard library goodness.

Play Your First Move

Here’s how to set up a 5x5 board and deploy a tank:

from board_game import BoardGame

# Create a 5x5 board with a file-based SQLite database
game = BoardGame(size=5, db_name="battle.db")

# Deploy a tank at (2, 3)
game.set_position(2, 3, [["unit", "tank"], ["health", 5]])
print(game.get_position(2, 3))  # [['unit', 'tank'], ['health', 5]]

# Heal the tank
game.update_attribute(2, 3, "health", 10)
print(game.get_position(2, 3))  # [['unit', 'tank'], ['health', 10]]

# Clear the position
game.remove_position(2, 3)
print(game.get_position(2, 3))  # None

# Save and close
game.close()

Run this, and your board state is safely tucked away in battle.db. Reload it later, and your tank’s ready for round two! 🛡️

🧪 Test It Like a Boss

The included test suite (TestBoardGame.py) is your quality assurance squad, with 8 tests covering every angle:

  • test_init: Ensures your board starts fresh.
  • test_validate_coord: Keeps moves within bounds.
  • test_set_position: Sets and overwrites attributes.
  • test_get_position: Retrieves your game pieces.
  • test_update_attribute: Updates or adds attributes.
  • test_remove_position: Clears the battlefield.
  • test_get_board_state: Grabs the full board state (safely copied).
  • test_persistence: Confirms SQLite saves your game.

Run the tests:

python3 TestBoardGame.py

Expect a victory lap:

=== Setting up test ===
Testing __init__
  __init__: Size and empty board - PASSED
...
Testing persistence
  persistence: File-based persistence - PASSED
Ran 8 tests in 0.005s
OK

🛠️ Features That Pack a Punch

  • Flexible Board Management 📍: Handle any n x n grid with sparse storage (only occupied positions are stored).
  • SQLite Superpowers 💽: Toggle between in-memory (:memory:) for tests and file-based (e.g., game.db) for persistence.
  • Attribute Awesomeness 🏰: Store key-value pairs (e.g., [['unit', 'soldier'], ['health', 10]]) at any position.
  • Robust Validation 🔍: Coordinate checks prevent off-board shenanigans.
  • Test-Driven Glory 🏆: 100% test coverage ensures your game logic is bulletproof.

📂 What’s in the Box?

boardgame-sqlite/
├── README.md          📜 Your guide to glory
├── board_game.py      🕹️ The BoardGame class with SQLite magic
├── TestBoardGame.py   🧪 Tests (with embedded BoardGame for sandbox compatibility)
├── header.txt         📄 Empty placeholder (future docs?)
├── footer.txt         📄 Empty placeholder (more to come?)
├── additional.txt     📄 Empty placeholder (room for extras)
  • board_game.py: The standalone BoardGame class, ready for production.
  • TestBoardGame.py: Unit tests with an embedded BoardGame class to dodge import issues in sandboxes like Grok.com.
  • header.txt, footer.txt, additional.txt: Empty files, waiting for your creative touch (game rules, metadata, or ASCII art?).

💡 Pro Tips for Devs

  • Extend Attributes: Add complex attributes (e.g., nested lists) by tweaking the JSON serialization in board_game.py.
  • Scale Up: Test with large boards (e.g., size=1000) to stress-test SQLite performance.
  • Add Transactions: Wrap SQLite operations in BEGIN TRANSACTION for atomic updates in multiplayer games.
  • Visualize It: Pair with a library like matplotlib to plot your board state. Want a heatmap of occupied positions? Ping me!
  • Cleanup: The test suite auto-deletes test_board.db, but keep an eye on file-based DBs in production.

🤝 Join the Game

Want to level up this project? Contributions are as welcome as a critical hit! 🎉

  1. Fork the repo.
  2. Create a branch (git checkout -b feature/EpicFeature).
  3. Commit your brilliance (git commit -m 'Add EpicFeature').
  4. Push it (git push origin feature/EpicFeature).
  5. Open a Pull Request and bask in the glory.

Please add tests for new features and ensure existing tests pass. Got ideas? Open an issue!

📜 License

Licensed under the MIT License. Build, share, and conquer!

🙏 Shoutouts

  • 🐍 Python and SQLite for making this a breeze.
  • ☕ Coffee, the true MVP of late-night coding.
  • 🎮 Board game fans everywhere—keep rolling those dice!

🌟 Star this repo to show some love!
📬 Questions? Issues? Hit up the issues page.
🧑‍💻 Built with passion for devs like you. Now, go make some epic games!

About

This framework will allow the developer to leverage a fully functioning back end for their games, with a demo front end of a specifly implemented game (ultimately included)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages