Hands-On Learning with the Blackjack App
Exercise 1: Understanding the Card System
Difficulty: Beginner
Time: 30 minutes
Goal: Understand how cards are represented and displayed
Step 1: Examine the Card Model
- Open
app/src/main/java/ca/medontime/blackjack/domain/model/Card.kt - Read through the
Carddata class - Understand the
SuitandRankenums
Questions to Answer:
- What properties does a
Cardhave? - How does
getValue()calculate card values? - What does
getImageResourceName()return?
Step 2: Check the Card Images
- Open
app/src/main/res/drawable/folder - Look at the card image files
- Notice the naming pattern:
card_a_of_clubs,card_7_of_hearts, etc.
Step 3: Trace Card Display
- In
HomeFragment.kt, find thesetCardImage()function - Follow how a card goes from data to displayed image
- Understand the
getCardResourceId()function
Challenge:
- What happens if a card image is missing?
- How could you add a new suit (like "Stars")?
Exercise 2: Following the Hit Button Flow
Difficulty: Beginner
Time: 45 minutes
Goal: Understand user interaction flow
Step 1: Find the Hit Button
- Open
app/src/main/res/layout/fragment_home.xml - Find the Hit button definition
- Notice its ID:
android:id="@+id/hit_button"
Step 2: Find the Click Listener
- Open
HomeFragment.kt - Find
setupClickListeners()function - Look at the Hit button click listener
Step 3: Trace the Flow
- Follow the call to
gameViewModel.playerHit() - Open
GameViewModel.ktand findplayerHit()function - See how it calls
gameUseCase.playerHit()
Step 4: Understand UI Updates
- In
HomeFragment.kt, findobserveGameState() - See how the UI updates when game state changes
- Look at
updateUI()function
Questions to Answer:
- What happens when you click Hit?
- How does the app know to show a new card?
- What prevents invalid actions (like hitting when busted)?
Challenge:
- Add a "Double Down" button that doubles the bet and hits once
- Add sound effects when cards are dealt
Exercise 3: Understanding Statistics
Difficulty: Intermediate
Time: 60 minutes
Goal: Learn about data persistence and filtering
Step 1: Examine Statistics Model
- Open
GameStatistics.kt - Understand what data is tracked
- Look at the calculation methods
Step 2: Check Data Persistence
- Open
GameStatisticsDataSource.kt - See how statistics are saved/loaded
- Understand DataStore usage
Step 3: Understand Filtering
- Open
StatisticsViewModel.kt - Look at
updateTimePeriod()function - See how statistics are filtered for different time periods
Step 4: UI Updates
- Open
DashboardFragment.kt - Find
updateTimePeriodButtons()function - See how button colors change
Questions to Answer:
- How are statistics stored?
- How does filtering work?
- Why do the numbers change when you switch time periods?
Challenge:
- Add a "Reset Statistics" confirmation dialog
- Add more statistics (average bet, longest winning streak)
Exercise 4: Layout Analysis
Difficulty: Beginner
Time: 45 minutes
Goal: Understand Android layouts
Step 1: Examine Main Layout
- Open
fragment_home.xml - Identify the root layout (ConstraintLayout)
- Understand the overall structure
Step 2: Understand Card Layout
- Find the dealer and player card sections
- See how cards are arranged horizontally
- Notice the overlap with
android:layout_marginEnd="-20dp"
Step 3: ScrollView Usage
- Find the ScrollView
- Understand why it's needed
- See how it's constrained
Step 4: Button Layout
- Find the game controls section
- See how buttons are arranged
- Understand the bottom margin for navigation
Questions to Answer:
- Why use ConstraintLayout vs LinearLayout?
- How do the cards overlap?
- What makes the layout scrollable?
Challenge:
- Add a "New Game" button
- Change the card overlap amount
- Add animations when cards are dealt
Exercise 5: Adding a New Feature
Difficulty: Intermediate
Time: 90 minutes
Goal: Practice adding features to an existing app
Feature: Add Card Counting Display
Show the current count of cards remaining in the deck.
Step 1: Update the Game Model
- Add a
cardsRemainingproperty to theGameclass - Update the
BlackJackGameUseCaseto track remaining cards
Step 2: Update the UI
- Add a TextView to
fragment_home.xmlto display the count - Update
HomeFragment.ktto show the count - Make sure it updates when cards are dealt
Step 3: Add Logic
- Calculate remaining cards in the use case
- Update the count when cards are dealt
- Handle deck reshuffling when needed
Challenge Extensions:
- Add a "Shuffle" button
- Show card counting statistics
- Add deck visualization
Exercise 6: Understanding Navigation
Difficulty: Beginner
Time: 30 minutes
Goal: Learn Android navigation
Step 1: Examine Navigation Graph
- Open
app/src/main/res/navigation/mobile_navigation.xml - See how fragments are connected
- Understand the navigation structure
Step 2: Check Bottom Navigation
- Open
app/src/main/res/menu/bottom_nav_menu.xml - See the menu items
- Understand how they map to fragments
Step 3: MainActivity Setup
- Open
MainActivity.kt - See how navigation is configured
- Understand the AppBarConfiguration
Questions to Answer:
- How does navigation between screens work?
- What happens when you tap a bottom navigation item?
- How could you add a new screen?
Challenge:
- Add a "Settings" screen
- Add navigation between game and settings
- Implement back button handling
Exercise 7: Error Handling
Difficulty: Intermediate
Time: 60 minutes
Goal: Learn proper error handling
Step 1: Find Error Handling Examples
- Look at
getCardResourceId()inHomeFragment.kt - See how it handles missing resources
- Understand the fallback mechanism
Step 2: Add Error Handling
- Add try-catch blocks around risky operations
- Provide user-friendly error messages
- Log errors for debugging
Step 3: Test Error Scenarios
- Remove a card image file
- See how the app handles it
- Test with invalid data
Questions to Answer:
- What happens when an error occurs?
- How can you prevent crashes?
- What information should you log?
Challenge:
- Add network error handling
- Implement retry mechanisms
- Add error reporting
Exercise 8: Performance Optimization
Difficulty: Advanced
Time: 120 minutes
Goal: Learn performance best practices
Step 1: Identify Performance Issues
- Look for memory leaks
- Check for inefficient operations
- Find unnecessary UI updates
Step 2: Optimize Image Loading
- Implement image caching
- Use appropriate image sizes
- Lazy load images
Step 3: Optimize Data Operations
- Use background threads for heavy operations
- Implement data caching
- Minimize database operations
Questions to Answer:
- What causes performance issues?
- How can you measure performance?
- What are common optimization techniques?
Challenge:
- Add performance monitoring
- Implement lazy loading
- Optimize memory usage
Exercise 9: Testing
Difficulty: Intermediate
Time: 90 minutes
Goal: Learn Android testing
Step 1: Write Unit Tests
- Test the
Cardclass methods - Test the
Handclass calculations - Test the game logic
Step 2: Write Integration Tests
- Test ViewModel functionality
- Test data persistence
- Test navigation
Step 3: Write UI Tests
- Test button clicks
- Test navigation
- Test error scenarios
Questions to Answer:
- What should you test?
- How do you test UI components?
- What's the difference between unit and integration tests?
Challenge:
- Add test coverage reporting
- Implement automated testing
- Add performance tests
Exercise 10: Customization Project
Difficulty: Advanced
Time: 180 minutes
Goal: Apply all learned concepts
Project: Create a Custom Card Game
Using the Blackjack app as a foundation, create a simple card game like "War" or "Go Fish".
Requirements:
- New Game Logic: Implement different game rules
- Custom UI: Modify the layout for the new game
- Statistics: Track game-specific statistics
- Navigation: Add the new game to navigation
- Testing: Write tests for the new features
Deliverables:
- Working custom card game
- Updated UI and navigation
- Game-specific statistics
- Unit tests for game logic
- Documentation of changes
Evaluation Criteria:
- Code quality and organization
- UI/UX design
- Functionality completeness
- Test coverage
- Documentation quality
Learning Progression
Beginner Level (Exercises 1-4)
- Understand basic Android concepts
- Learn Kotlin syntax
- Familiarize with project structure
- Practice reading and understanding code
Intermediate Level (Exercises 5-7)
- Add new features
- Implement error handling
- Understand navigation
- Practice debugging
Advanced Level (Exercises 8-10)
- Performance optimization
- Testing strategies
- Complete project development
- Best practices implementation
Tips for Success
- Start Small: Begin with simple modifications
- Read Documentation: Use official Android docs
- Experiment: Try breaking things and fixing them
- Ask Questions: Don't hesitate to seek help
- Practice Regularly: Consistent practice is key
- Build Projects: Apply what you learn in real projects
Resources
- Official Android Documentation: developer.android.com
- Kotlin Documentation: kotlinlang.org
- Android Developers YouTube: Official Google channel
- Stack Overflow: Community help
- GitHub: Open source examples
Remember: The best way to learn Android development is by building apps. Use these exercises as stepping stones to create your own projects!