A modern Blazor WebAssembly application featuring two interactive browser games with gamepad support, responsive design, and Progressive Web App (PWA) capabilities.
Take care of your virtual pet by managing its hunger, happiness, and energy levels. Watch as your pet's mood and appearance change based on how well you care for it.
Controls:
- Feed (A) - Reduce hunger and boost happiness
- Play (B) - Increase happiness (may reduce energy)
- Rest (X) - Restore energy
- Gamepad Support - Xbox/PlayStation controllers
Engage in real-time tank combat with AI enemies. Use dual joystick controls to move and aim, with auto-fire and manual fire modes.
Controls:
- Move Joystick - Control tank movement
- Aim Joystick - Control turret direction
- Fire Button - Manual fire mode
- Auto Toggle - Switch between auto and manual fire
- Restart - Reset the battlefield
- Fullscreen - Toggle fullscreen mode
-
Clone the repository
git clone https://github.com/gergroen/Games.git cd Games -
Install .NET 9.0 SDK (if not already installed)
# Linux/macOS wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh chmod +x dotnet-install.sh ./dotnet-install.sh --channel 9.0 export PATH="$HOME/.dotnet:$PATH" # Windows # Download from https://dotnet.microsoft.com/download/dotnet/9.0
-
Build and run
dotnet build Games.sln dotnet run --project Games
Note: Startup takes 8-12 seconds. Look for "Now listening on: http://[::]:5080"
-
Open in browser
- Navigate to http://localhost:5080 (HTTP) or https://localhost:7042 (HTTPS)
- Start with the Virtual Pet game at
/or try Tank Battle at/tanks
- Frontend Framework: Blazor WebAssembly (.NET 9.0)
- UI Framework: Bootstrap 5 with custom game-specific styling
- Graphics: HTML5 Canvas (Tank Battle game)
- Audio: Web Audio API for game sound effects
- Input: Gamepad API, touch controls, virtual joysticks
- PWA: Service Worker for offline functionality and app installation
- Deployment: Azure Static Web Apps with automated CI/CD
- Chrome 88+
- Firefox 84+
- Safari 14+
- Edge 88+
- iOS Safari 14+
- Chrome Mobile 88+
- Samsung Internet 13+
- Gamepad Support: Xbox and PlayStation controllers on supported browsers
- Touch Controls: Virtual joysticks and touch-optimized buttons
- PWA Installation: Install as a native app on mobile devices
- Offline Support: Play games without an internet connection after initial load
- Responsive Design: Optimized for desktop, tablet, and mobile
- Dynamic Mood System: Pet's appearance changes based on stats
- Real-time Decay: Stats decrease over time, requiring active care
- Visual Feedback: Animated faces show current mood and actions
- Gamepad Integration: Use controller buttons for pet interactions
- Real-time Combat: Smooth 60fps gameplay with physics simulation
- AI Opponents: Smart enemy tanks with collision detection
- Dual Control System: Separate movement and aiming controls
- Visual Effects: Canvas-based graphics with particle effects
- Audio Feedback: Sound effects for firing and combat
Games/
โโโ Games/ # Main Blazor WebAssembly project
โ โโโ Pages/ # Game components (Razor pages)
โ โ โโโ Tamagotchi.razor # Virtual pet game UI
โ โ โโโ Tanks.razor # Tank battle game UI
โ โโโ Services/ # Game logic and state management
โ โ โโโ PetGameService.cs # Virtual pet game logic
โ โ โโโ BattlefieldService.cs # Tank battle game logic
โ โโโ Models/ # Data structures and game entities
โ โ โโโ PetState.cs # Pet game state model
โ โ โโโ GamepadModels.cs # Gamepad input models
โ โ โโโ Tanks/ # Tank game models
โ โโโ wwwroot/ # Static assets and JavaScript
โ โ โโโ js/ # JavaScript interop files
โ โ โโโ css/ # Stylesheets
โ โ โโโ manifest.json # PWA manifest
โ โ โโโ service-worker.js # Service worker for offline support
โ โโโ Layout/ # Application layout components
โโโ .github/workflows/ # Azure Static Web Apps deployment
โโโ README.md # This file
-
Start development server
dotnet watch --project Games
This enables hot reload for rapid development.
-
Code formatting (required before commits)
dotnet format dotnet format --verify-no-changes # Verify formatting -
Build for production
dotnet publish Games -c Release
-
Run E2E tests (validates both games)
./run-e2e-tests.sh # Full testing with graceful degradation ./run-e2e-tests.sh --smoke-only # Fast smoke tests only
- Game Logic: Implement in the appropriate service class (
PetGameService.csorBattlefieldService.cs) - UI Components: Update the corresponding Razor component (
.razorand.razor.csfiles) - Styling: Add styles to component-specific
.razor.cssfiles - JavaScript Interop: Add browser API calls to JavaScript files in
wwwroot/js/
- C# Conventions: Follow standard C# naming and coding conventions
- Nullable Reference Types: Enabled for enhanced type safety
- Implicit Usings: Leveraged to reduce boilerplate code
- Component Isolation: CSS scoped to individual components
- Service Registration: Use dependency injection for game services
The application is automatically deployed to Azure Static Web Apps on every push to the master branch.
- Platform: Azure Static Web Apps
- Build Process: Automated via GitHub Actions
- CDN: Global content delivery network
- HTTPS: Automatic SSL certificate management
- Custom Domains: Supported through Azure configuration
- Source Path:
./Games - Output Path:
wwwroot - API: No backend API (client-side only)
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes following the coding standards
- Format your code (
dotnet format) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Minimal Changes: Make the smallest possible changes to achieve your goal
- Testing: Use
./run-e2e-tests.shfor automated validation of both games - Manual Testing: Manually validate both games after making changes
- Automated Testing: Run E2E tests to ensure no regressions (
dotnet test Games.E2ETests) - Performance: Maintain smooth 60fps gameplay
- Accessibility: Ensure keyboard navigation works properly
- Mobile: Test touch controls on mobile devices
- Code Quality: Run
dotnet formatbefore committing changes
The repository includes comprehensive E2E tests using Playwright:
./run-e2e-tests.sh # Full testing (recommended)
./run-e2e-tests.sh --smoke-only # Fast validation
./run-e2e-tests.sh --help # See all optionsThe test runner automatically:
- Installs .NET 9.0 SDK if needed
- Starts the Games application if not running
- Runs tests with graceful degradation (smoke tests when browsers unavailable)
- Provides clear feedback on results
See Games.E2ETests/README.md for detailed testing documentation.
When adding new features, ensure they include appropriate tests:
- Add E2E tests for user-facing functionality in
Games.E2ETests/ - Follow naming convention:
FeatureName_ShouldExpectedBehavior - Mark browser tests with
[TestCategory("RequiresBrowser")] - Include accessibility testing for interactive elements
- Test mobile viewports for responsive features
- Update documentation in README files when adding new test classes
The Games application includes comprehensive end-to-end (E2E) testing using Microsoft Playwright and MSTest.
๐ Smoke Tests (4 tests)
- Basic application availability and HTTP response validation
- Static asset serving verification (CSS, JS, images)
- Page routing functionality for both games
- No browser installation required
๐ฎ Game Functionality Tests (16 tests)
- Tamagotchi Game (7 tests): Pet interactions, stat displays, gamepad indicators
- Tank Battle Game (9 tests): Canvas rendering, HUD functionality, controls
โฟ Accessibility Tests (6 tests)
- Keyboard navigation and focus management
- ARIA labels and semantic HTML validation
- Screen reader compatibility
- Color contrast and visual accessibility
๐ฑ PWA Tests (5 tests)
- Service Worker registration and offline support
- Web App Manifest validation
- App icon accessibility
- Installation capability verification
โก Performance Tests (6 tests)
- Application load time measurement
- Game interaction responsiveness
- Canvas rendering performance
- Memory usage and resource optimization
Prerequisites:
# Install .NET 9.0 SDK and start the application
dotnet run --project Games # Must be running on localhost:5080Quick smoke tests (no browser required):
cd Games.E2ETests
dotnet test --filter "TestCategory!=RequiresBrowser"Full test suite (requires Playwright browsers):
# Install browsers (first time only)
pwsh bin/Debug/net9.0/playwright.ps1 install --with-deps
# Run all tests
dotnet test --logger "console;verbosity=detailed"Specific test categories:
dotnet test --filter "ClassName=TamagotchiGameTests"
dotnet test --filter "ClassName=TankBattleGameTests"
dotnet test --filter "ClassName=AccessibilityTests"
dotnet test --filter "ClassName=PWATests"
dotnet test --filter "ClassName=PerformanceTests"For detailed testing documentation, see Games.E2ETests/README.md.
- Navigate to
/- verify pet displays with stats - Test all action buttons (Feed, Play, Rest)
- Verify gamepad connection status
- Check responsive design on mobile
- Test keyboard navigation (Tab/Enter/Space)
- Navigate to
/tanks- verify battlefield loads - Test Fire button and Auto toggle
- Verify HUD displays HP correctly
- Test Restart and Fullscreen buttons
- Check virtual joysticks on mobile
- Verify smooth 60fps animation
- Test offline functionality after initial load
- Verify app installation prompt on mobile
- Check service worker updates and caching
- Validate manifest.json and icon accessibility
This project is open source. Please refer to the repository for license details.
Visit the live application: Games on Azure Static Web Apps
Built with โค๏ธ using .NET 9.0 and Blazor WebAssembly