A classic two-player card game "War" implemented in Python. Players compete to win all cards through simple comparison and exciting war scenarios.
- Full 52-card deck implementation
- Two-player gameplay
- War scenario handling (ties)
- Manual or auto-play modes
- Round-by-round statistics
- Card counting
- Win tracking
- Colorful card display with suits
- Language: Pure Python
- Libraries:
random,time(standard library) - Complexity: Beginner
No external dependencies required!
python main.py- Deck is shuffled and split evenly (26 cards each)
- Each player plays their top card
- Higher card wins both cards
- Winner adds both cards to bottom of their deck
- Game continues until one player has all cards
- When cards are equal, it's WAR!
- Each player places 3 cards face-down
- Then 1 card face-up
- Higher face-up card wins all cards in play
- If tied again, repeat war process
- Win by collecting all 52 cards
- Or have most cards after max rounds
| Card | Value |
|---|---|
| 2 | 2 |
| 3 | 3 |
| ... | ... |
| 10 | 10 |
| Jack (J) | 11 |
| Queen (Q) | 12 |
| King (K) | 13 |
| Ace (A) | 14 (highest) |
- Press Enter to play each round
- See each card played
- Control game pace
- Good for learning
- Automatic round progression
- Fast gameplay
- Watch the battle unfold
- Good for quick games
- Represents a single playing card
- Properties: rank, suit, value
- Methods:
__str__(),__repr__()
- Represents 52-card deck
- Methods:
build_deck(): Create full deckshuffle(): Randomize orderdeal(): Deal cards
- Represents a game player
- Properties: name, hand, wins
- Methods:
play_card(): Play top cardadd_cards(): Add won cardshas_cards(): Check if has cardscard_count(): Get card count
- Main game controller
- Methods:
setup_game(): Initialize gameplay_round(): Play one roundwar(): Handle tie scenarioshow_results(): Display final results
👋 Welcome to War Card Game!
Enter Player 1 name: Alice
Enter Player 2 name: Bob
==================================================
♠♥♦♣ WAR CARD GAME ♠♥♦♣
==================================================
Shuffling deck...
Dealing cards...
✓ Alice: 26 cards
✓ Bob: 26 cards
Let the war begin!
--- Round 1 ---
Alice: 7♠ (value: 7)
Bob: K♥ (value: 13)
🏆 Bob wins this round!
--- Round 2 ---
Alice: A♦ (value: 14)
Bob: 3♣ (value: 3)
🏆 Alice wins this round!
--- Round 3 ---
Alice: Q♠ (value: 12)
Bob: Q♥ (value: 12)
⚔️ WAR!
🔥 This means WAR! 🔥
Each player places 3 cards face down and 1 face up...
Alice reveals: 9♦
Bob reveals: K♣
🏆 Bob wins the war!
...
- Object-Oriented Programming (OOP)
- Class design and relationships
- List manipulation
- Random number generation
- Game state management
- Control flow
- User input handling
- String formatting
- War is purely a game of chance
- No skill involved in standard rules
- Outcome determined by initial shuffle
- Games can be very long or very short
- Average game: 200-300 rounds
Card (basic unit)
↓
Deck (collection of cards)
↓
Player (holds cards, plays game)
↓
WarGame (orchestrates gameplay)
- Score multipliers for consecutive wins
- Special card powers
- Time limits per round
- Tournament mode
- Save/load game state
- Three-player war
- Different card values
- Bonus cards
- Reverse war (lowest wins)
- GUI with card graphics
- Animation for card plays
- Sound effects
- Online multiplayer
- AI opponent
- Statistics tracking
- Replay system
- Different game variants
- Leaderboard
- War is one of the simplest card games
- Also called "Battle" in some countries
- Purely luck-based, no strategy
- Can theoretically go on forever
- Great for learning card basics
Open source for educational purposes.