parent
f087f6d7ec
commit
17da96140c
@ -1,11 +1,86 @@
|
||||
# Mock up a game
|
||||
# Mock up a Game: Apply Design Patterns
|
||||
|
||||
## Assignment Overview
|
||||
|
||||
Put your newfound knowledge of design patterns to work by creating a simple game prototype! This assignment will help you practice both architectural patterns (inheritance or composition) and the pub/sub communication system you learned about in the lesson.
|
||||
|
||||
## Instructions
|
||||
|
||||
Using the code samples in the lesson, write a representation of a game you enjoy. It will have to be a simple game, but the goal is to use either the class or the composition pattern and the pub/sub pattern to show how a game might launch. Get creative!
|
||||
Create a simple game representation that demonstrates the design patterns from this lesson. Your game should be functional but doesn't need complex graphics \u2013 focus on the underlying architecture and communication patterns.
|
||||
|
||||
### Requirements
|
||||
|
||||
**Choose Your Architecture Pattern:**
|
||||
- **Option A**: Use class-based inheritance (like the `GameObject` → `Movable` → `Hero` example)
|
||||
- **Option B**: Use composition (like the factory function approach with mixed behaviors)
|
||||
|
||||
**Implement Communication:**
|
||||
- **Include** an `EventEmitter` class for pub/sub messaging
|
||||
- **Set up** at least 2-3 different message types (like `PLAYER_MOVE`, `ENEMY_SPAWN`, `SCORE_UPDATE`)
|
||||
- **Connect** user input (keyboard/mouse) to game events through the event system
|
||||
|
||||
**Game Elements to Include:**
|
||||
- At least one player-controlled character
|
||||
- At least one other game object (enemy, collectible, or environmental element)
|
||||
- Basic interaction between objects (collision, collection, or communication)
|
||||
|
||||
### Suggested Game Ideas
|
||||
|
||||
**Simple Games to Consider:**
|
||||
- **Snake Game** \u2013 Snake segments follow the head, food spawns randomly
|
||||
- **Pong Variation** \u2013 Paddle responds to input, ball bounces off walls
|
||||
- **Collector Game** \u2013 Player moves around collecting items while avoiding obstacles
|
||||
- **Tower Defense Basics** \u2013 Towers detect and shoot at moving enemies
|
||||
|
||||
### Code Structure Guidelines
|
||||
|
||||
```javascript
|
||||
// Example starting structure
|
||||
const Messages = {
|
||||
// Define your game messages here
|
||||
};
|
||||
|
||||
class EventEmitter {
|
||||
// Your event system implementation
|
||||
}
|
||||
|
||||
// Choose either class-based OR composition approach
|
||||
// Class-based example:
|
||||
class GameObject { /* base properties */ }
|
||||
class Player extends GameObject { /* player-specific behavior */ }
|
||||
|
||||
// OR Composition example:
|
||||
const gameObject = { /* base properties */ };
|
||||
const movable = { /* movement behavior */ };
|
||||
function createPlayer() { /* combine behaviors */ }
|
||||
```
|
||||
|
||||
### Testing Your Implementation
|
||||
|
||||
**Verify your code works by:**
|
||||
- **Testing** that objects move or change when events are triggered
|
||||
- **Confirming** that multiple objects can respond to the same event
|
||||
- **Checking** that you can add new behaviors without modifying existing code
|
||||
- **Ensuring** keyboard/mouse input properly triggers game events
|
||||
|
||||
## Submission Guidelines
|
||||
|
||||
**Your submission should include:**
|
||||
1. **JavaScript file(s)** with your game implementation
|
||||
2. **HTML file** to run and test your game (can be simple)
|
||||
3. **Comments** explaining which pattern you chose and why
|
||||
4. **Brief documentation** of your message types and what they do
|
||||
|
||||
## Rubric
|
||||
|
||||
| Criteria | Exemplary | Adequate | Needs Improvement |
|
||||
| -------- | ------------------------------------------------------- | ----------------------------------------------------- | --------------------------------------------------- |
|
||||
| | Three elements are placed on the screen and manipulated | Two elements are placed on the screen and manipulated | One element is placed on the screen and manipulated |
|
||||
| Criteria | Exemplary (3 points) | Adequate (2 points) | Needs Improvement (1 point) |
|
||||
|----------|---------------------|---------------------|------------------------------|
|
||||
| **Architecture Pattern** | Correctly implements either inheritance OR composition with clear class/object hierarchy | Uses chosen pattern with minor issues or inconsistencies | Attempts to use pattern but implementation has significant problems |
|
||||
| **Pub/Sub Implementation** | EventEmitter works correctly with multiple message types and proper event flow | Basic pub/sub system works with some event handling | Event system present but doesn't work reliably |
|
||||
| **Game Functionality** | Three or more interactive elements that communicate through events | Two interactive elements with basic event communication | One element responds to events or basic interaction |
|
||||
| **Code Quality** | Clean, well-commented code with logical organization and modern JavaScript | Generally well-organized code with adequate comments | Code works but lacks organization or clear commenting |
|
||||
|
||||
**Bonus Points:**
|
||||
- **Creative game mechanics** that showcase interesting uses of the patterns
|
||||
- **Multiple input methods** (keyboard AND mouse events)
|
||||
- **Scalable architecture** that would be easy to extend with new features
|
||||
@ -1,11 +1,67 @@
|
||||
# Play with the Canvas API
|
||||
# Assignment: Explore the Canvas API
|
||||
|
||||
## Learning Objectives
|
||||
|
||||
By completing this assignment, you will demonstrate your understanding of Canvas API fundamentals and apply creative problem-solving to build visual elements using JavaScript and HTML5 canvas.
|
||||
|
||||
## Instructions
|
||||
|
||||
Pick one element of the Canvas API and create something interesting around it. Can you create a little galaxy of repeated stars? Can you create an interesting texture of colored lines? You can look at CodePen for inspiration (but don't copy)
|
||||
Choose one aspect of the Canvas API that interests you and create an engaging visual project around it. This assignment encourages you to experiment with the drawing capabilities you've learned while building something uniquely yours.
|
||||
|
||||
### Project Ideas to Inspire You
|
||||
|
||||
**Geometric Patterns:**
|
||||
- **Create** a galaxy of animated twinkling stars using random positioning
|
||||
- **Design** an interesting texture using repeated geometric shapes
|
||||
- **Build** a kaleidoscope effect with rotating, colorful patterns
|
||||
|
||||
**Interactive Elements:**
|
||||
- **Develop** a drawing tool that responds to mouse movements
|
||||
- **Implement** shapes that change color when clicked
|
||||
- **Design** a simple animation loop with moving elements
|
||||
|
||||
**Game-Related Graphics:**
|
||||
- **Craft** a scrolling background for a space game
|
||||
- **Build** particle effects like explosions or magic spells
|
||||
- **Create** animated sprites with multiple frames
|
||||
|
||||
### Development Guidelines
|
||||
|
||||
**Research and Inspiration:**
|
||||
- **Browse** CodePen for creative canvas examples (for inspiration, not copying)
|
||||
- **Study** the [Canvas API documentation](https://developer.mozilla.org/docs/Web/API/Canvas_API) for additional methods
|
||||
- **Experiment** with different drawing functions, colors, and animations
|
||||
|
||||
**Technical Requirements:**
|
||||
- **Use** proper canvas setup with `getContext('2d')`
|
||||
- **Include** meaningful comments explaining your approach
|
||||
- **Test** your code thoroughly to ensure it runs without errors
|
||||
- **Apply** modern JavaScript syntax (const/let, arrow functions)
|
||||
|
||||
**Creative Expression:**
|
||||
- **Focus** on one Canvas API feature but explore it deeply
|
||||
- **Add** your own creative twist to make the project personal
|
||||
- **Consider** how your creation could be part of a larger application
|
||||
|
||||
### Submission Guidelines
|
||||
|
||||
Submit your completed project as a single HTML file with embedded CSS and JavaScript, or as separate files in a folder. Include a brief comment explaining your creative choices and the Canvas API features you explored.
|
||||
|
||||
## Rubric
|
||||
|
||||
| Criteria | Exemplary | Adequate | Needs Improvement |
|
||||
| -------- | --------------------------------------------------------- | ----------------------------------- | --------------------- |
|
||||
| | Code is submitted showing an interesting texture or shape | Code is submitted, but does not run | Code is not submitted |
|
||||
| Criteria | Exemplary | Adequate | Needs Improvement |
|
||||
|----------|-----------|----------|-------------------|
|
||||
| **Technical Implementation** | Canvas API used creatively with multiple features, code runs flawlessly, modern JavaScript syntax applied | Canvas API used correctly, code runs with minor issues, basic implementation | Canvas API attempted but code has errors or doesn't execute |
|
||||
| **Creativity and Design** | Highly original concept with polished visual appeal, demonstrates deep exploration of chosen Canvas feature | Good use of Canvas features with some creative elements, solid visual result | Basic implementation with minimal creativity or visual appeal |
|
||||
| **Code Quality** | Well-organized, commented code following best practices, efficient algorithms | Clean code with some comments, follows basic coding standards | Code lacks organization, minimal comments, inefficient implementation |
|
||||
|
||||
## Reflection Questions
|
||||
|
||||
After completing your project, consider these questions:
|
||||
|
||||
1. **What Canvas API feature did you choose and why?**
|
||||
2. **What challenges did you encounter while building your project?**
|
||||
3. **How could you extend this project into a larger application or game?**
|
||||
4. **What other Canvas API features would you like to explore next?**
|
||||
|
||||
> 💡 **Pro Tip**: Start simple and gradually add complexity. A well-executed simple project is better than an overly ambitious project that doesn't work properly!
|
||||
Loading…
Reference in new issue