Skip to content

Latest commit

ย 

History

History
82 lines (68 loc) ยท 3.3 KB

File metadata and controls

82 lines (68 loc) ยท 3.3 KB

The Last King (Vแป‹ Vua Cuแป‘i Cรนng)

A historical strategy card game built with Flutter, inspired by Reigns. Guide your dynasty through turbulent times by making binary choices that affect the balance of your kingdom.

๐ŸŒŸ Features

  • Swipe Mechanic: Tinder-like card swiping (Left/Right) to make decisions (flutter_card_swiper).
  • Resource Management: Balance four key pillars of the kingdom:
    • ๐Ÿ’ฐ Money (Tiแปn)
    • ๐Ÿ‘ฅ People (Dรขn)
    • ๐Ÿ›ก๏ธ Army (Quรขn)
    • ๐Ÿ”ฏ Religion (ฤแบกo)
  • Dynamic visual effects: Confetti blasts on resource changes (confetti).
  • Persistent High Scores: Track your longest reign using local storage (shared_preferences).
  • Monetization:
    • Banner Ads: Always visible at the bottom of the screen.
    • Interstitial Ads: Randomly triggered after 2-9 swipes.

๐Ÿ—๏ธ Architecture

The project follows a clean architecture pattern utilizing Riverpod for state management.

File Structure

lib/
โ”œโ”€โ”€ data/
โ”‚   โ””โ”€โ”€ scenarios_data.dart       # Hardcoded content (Questions/Events)
โ”œโ”€โ”€ models/
โ”‚   โ””โ”€โ”€ scenario.dart             # Data models (Scenario, Choice, Effect)
โ”œโ”€โ”€ providers/
โ”‚   โ””โ”€โ”€ game_provider.dart        # Game Logic & State Management (Riverpod)
โ”œโ”€โ”€ screens/
โ”‚   โ””โ”€โ”€ game_screen.dart          # Main UI: Card Stack, Stats, and Ads
โ”œโ”€โ”€ services/
โ”‚   โ””โ”€โ”€ shared_preference_service.dart # Local Storage Abstraction
โ”œโ”€โ”€ utils/
โ”‚   โ””โ”€โ”€ ad_helper.dart            # AdMob Unit IDs & Test Mode Configuration
โ”œโ”€โ”€ widgets/
โ”‚   โ”œโ”€โ”€ resource_bar.dart         # Animated Stat Bar
โ”‚   โ””โ”€โ”€ scenario_card.dart        # Swipeable Card UI
โ””โ”€โ”€ main.dart                     # App Entry & dependency overrides

State Management (GameNotifier)

The GameProvider manages the GameState, which includes:

  • Resources: Values clamped between 0 and 100.
  • Game Over Logic: Checks if any resource hits 0.
  • Swipe Tracking: Counts swipes to determine when to show Interstitial Ads.
  • High Score: Auto-updates when the current reign exceeds the stored record.

๐ŸŽฎ Game Logic

  1. Core Loop:
    • Player reads a scenario.
    • Swiping Left or Right triggers different effects on resources.
    • If any resource depletes to 0, the game ends (Dynasty Falls).
  2. Ads Logic:
    • Banner: Loaded immediately on start.
    • Interstitial: A threshold is randomized between 2 and 9 swipes. When the user swipes enough times to hit this threshold, a full-screen ad is shown, and the counter resets with a new random threshold.
  3. Storage:
    • "Years Reigned" (Score) is saved to SharedPreferences only if it beats the previous high score.

๐Ÿ› ๏ธ Tech Stack

  • Framework: Flutter (Dart)
  • State Management: flutter_riverpod
  • UI Components: flutter_card_swiper, confetti
  • Ads: google_mobile_ads
  • Fonts: google_fonts

๐Ÿš€ Getting Started

  1. Prerequisites: Flutter SDK installed.
  2. Install Dependencies:
    flutter pub get
  3. Run the App:
    • iOS Simulator: flutter run -d <device_id>
    • Android Emulator: flutter run -d <emulator_id>

Note: AdMob IDs are configured for Test Mode in lib/utils/ad_helper.dart.