Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Card Game - War

Description

A classic two-player card game "War" implemented in Python. Players compete to win all cards through simple comparison and exciting war scenarios.

Features

  • 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

Stack

  • Language: Pure Python
  • Libraries: random, time (standard library)
  • Complexity: Beginner

Installation & Usage

No external dependencies required!

python main.py

Game Rules

Basic Rules

  1. Deck is shuffled and split evenly (26 cards each)
  2. Each player plays their top card
  3. Higher card wins both cards
  4. Winner adds both cards to bottom of their deck
  5. Game continues until one player has all cards

War (Tie) Rules

  1. When cards are equal, it's WAR!
  2. Each player places 3 cards face-down
  3. Then 1 card face-up
  4. Higher face-up card wins all cards in play
  5. If tied again, repeat war process

Winning

  • Win by collecting all 52 cards
  • Or have most cards after max rounds

Card Values

Card Value
2 2
3 3
... ...
10 10
Jack (J) 11
Queen (Q) 12
King (K) 13
Ace (A) 14 (highest)

Game Modes

Manual Mode

  • Press Enter to play each round
  • See each card played
  • Control game pace
  • Good for learning

Auto-Play Mode

  • Automatic round progression
  • Fast gameplay
  • Watch the battle unfold
  • Good for quick games

Classes

Card

  • Represents a single playing card
  • Properties: rank, suit, value
  • Methods: __str__(), __repr__()

Deck

  • Represents 52-card deck
  • Methods:
    • build_deck(): Create full deck
    • shuffle(): Randomize order
    • deal(): Deal cards

Player

  • Represents a game player
  • Properties: name, hand, wins
  • Methods:
    • play_card(): Play top card
    • add_cards(): Add won cards
    • has_cards(): Check if has cards
    • card_count(): Get card count

WarGame

  • Main game controller
  • Methods:
    • setup_game(): Initialize game
    • play_round(): Play one round
    • war(): Handle tie scenario
    • show_results(): Display final results

Example Game Session

👋 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!

...

Learning Outcomes

  • Object-Oriented Programming (OOP)
  • Class design and relationships
  • List manipulation
  • Random number generation
  • Game state management
  • Control flow
  • User input handling
  • String formatting

Strategy Tips

  • 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

Code Structure

Card (basic unit)
  ↓
Deck (collection of cards)
  ↓
Player (holds cards, plays game)
  ↓
WarGame (orchestrates gameplay)

Customization Ideas

Add Features

  • Score multipliers for consecutive wins
  • Special card powers
  • Time limits per round
  • Tournament mode
  • Save/load game state

Variations

  • Three-player war
  • Different card values
  • Bonus cards
  • Reverse war (lowest wins)

Future Enhancements

  • GUI with card graphics
  • Animation for card plays
  • Sound effects
  • Online multiplayer
  • AI opponent
  • Statistics tracking
  • Replay system
  • Different game variants
  • Leaderboard

Fun Facts

  • 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

License

Open source for educational purposes.