- Introduction
- About the Game
- ER Diagram
- Features
- How to Play
- Contribute
- User Stories
- Test Cases
- Debugging
- Resources
Stop! is a Django-based single-player word game where users compete against the clock to generate words for predefined categories that match a randomly chosen letter. The project demonstrates the use of Django's key features, including models, views, templates, form handling, and database integration.
The primary goal is to highlight Django’s potential for building scalable web applications while delivering an engaging word game experience.
Stop! is a digital adaptation of the classic pen-and-paper game. It challenges players’ vocabulary and creativity by requiring quick thinking under time constraints. The game is perfect for building your vocabulary while competing against yourself.
Here’s the Entity-Relationship Diagram for the game, created using Mermaid:
erDiagram
User {
int id PK
string username
string email
string password
}
Player {
int id PK
int user_id FK
int score
}
Round {
int id PK
char letter
bool is_active
datetime created_at
}
Category {
int id PK
string name
datetime created_at
}
Submission {
int id PK
int player_id FK
int round_id FK
int category_id FK
string word
bool is_valid
string validation_message
bool score_calculated
}
WordSubmission {
int id PK
int player_id FK
string word
string status
string feedback
}
ValidAnswer {
int id PK
int category_id FK
string word
}
User ||--o{ Player : "has"
Player ||--o{ Submission : "makes"
Player ||--o{ WordSubmission : "suggests"
Round ||--o{ Submission : "includes"
Category ||--o{ Submission : "has"
Category ||--o{ ValidAnswer : "contains"
-
Game Rounds:
- Start a round with a randomly generated letter.
- Timer set for 60 seconds to challenge the player.
- Submit words for categories such as "Animal," "Country," and "Food."
-
Word Validation:
- Words are validated in real-time against a database of valid answers.
- Validation checks include:
- Does the word start with the correct letter?
- Is the word valid for the chosen category?
-
Results Page:
- Displays all submissions for the round.
- Shows points earned for valid and unique words.
- Tracks cumulative player scores.
-
Suggest a New Word:
- Players can suggest words for categories.
- Admins can approve/reject suggestions to expand the game’s word database.
- Players earn bonus points for approved suggestions.
-
Responsive Design:
- User-friendly interface styled with Bootstrap.
- Optimized for mobile, tablet, and desktop devices.
-
Dark Mode:
- A toggle to switch between light and dark themes for better accessibility.
The rules are simple:
- Start a round with a randomly chosen letter.
- Fill in categories like "Animal," "Country," and "Food" with words starting with that letter.
- Press "Submit" before the timer runs out.
- See your score and evaluate your performance on the results page!
Players can contribute to the game by suggesting new words:
- Submit words that are missing from the current database.
- Admins review and approve the suggestions.
- Earn bonus points for every approved word.
- As a player, I want to start a new game round with a randomly generated letter and see a timer, so I can compete against myself.
- As a player, I want to submit words for categories like "Animal," "Country," "Food," etc., to earn points.
- As a player, I want to see detailed results after a game round to evaluate my performance.
- As a player, I want to suggest a new word and earn bonus points if it is approved by an admin.
- As an admin, I want to review and validate submissions to ensure they follow the rules of the game.
- As an admin, I want to approve or reject player-submitted words, expanding the database of valid answers.
- As a developer, I want to showcase the use of Django's features (models, views, templates, form handling, and database queries) in building a web application.
- As a professor/reviewer, I want to evaluate the proper use of Django as a framework to structure and manage this application.
Here are test cases to validate the core functionality of the game:
- Test Case 1: Start a new round and verify that a random letter is generated and displayed.
- Test Case 2: Ensure the timer counts down correctly and stops at 0.
- Test Case 3: Verify that categories load dynamically on the game screen.
- Test Case 1: Validate words starting with the correct letter are accepted.
- Test Case 2: Verify that invalid words (e.g., incorrect starting letter or invalid category) are rejected with proper error messages.
- Test Case 3: Ensure duplicate submissions are flagged and do not receive points.
- Test Case 1: Confirm that the player’s score is displayed correctly.
- Test Case 2: Verify that unique valid words receive bonus points.
- Test Case 3: Ensure cumulative player scores update properly in the database.
- Test Case 1: Allow players to suggest words and verify that they appear in the admin’s review panel.
- Test Case 2: Confirm that approved suggestions add to the valid answers database.
- Test Case 3: Verify that players earn bonus points for approved words.
-
Install
coverage
:pip install coverage
-
Run tests with coverage enabled:
coverage run --source='.' manage.py test
-
Generate a coverage report:
coverage report
-
Generate an HTML report:
coverage html
-
Open the report in your browser:
open htmlcov/index.html # Use `start` on Windows
- Views: Ensure all views are tested for valid and invalid inputs.
- Models: Verify model methods behave as expected.
- Forms: Test form validation for edge cases.
- Templates: Test template rendering with different context variables.
-
Logging:
- Use Django’s
logging
module to track word validation results and submission statuses:logger.debug(f"Validating word: {word}, Category: {category_name}")
- Use Django’s
-
Django Debug Toolbar:
- Install and configure the Django Debug Toolbar to monitor database queries and page rendering times:
pip install django-debug-toolbar
- Install and configure the Django Debug Toolbar to monitor database queries and page rendering times:
-
Browser DevTools:
- Inspect the user interface for responsiveness and layout issues.
- Use the Console to debug JavaScript functions (e.g., dark mode toggle).
-
Test Database:
- Use Django’s test database to run isolated tests on models and views:
python manage.py test
- Use Django’s test database to run isolated tests on models and views:
-
Handle Exceptions Gracefully:
- Add
try/except
blocks for database operations to prevent application crashes:try: round = Round.objects.get(id=round_id) except Round.DoesNotExist: return JsonResponse({'error': 'Round not found'}, status=404)
- Add
- Django: Framework for backend logic and database handling.
- Bootstrap: Frontend framework for styling and responsiveness.
- SQLite: Lightweight database for development.
- Mermaid: For generating the ER diagram.