This is a simple implementation of the card game 'War' using JavaScript classes. The game consists of three main classes: Card
, Deck
, and GameOfWar
.
HTML & Javascript
The Card
class represents a single playing card with a suit, rank, and score.
constructor(suit, rank, score)
: Initializes a new card with the given suit, rank, and score.
The Deck
class represents a deck of playing cards.
constructor()
: Initializes an empty array to holdCard
objects and callscreateDeck()
.createDeck()
: Fills thecards
array with 52Card
objects, one for each suit and rank.shuffle()
: Shuffles thecards
array.
The GameOfWar
class represents the game logic.
constructor()
: Initializes player decks and the pile for 'war' scenarios.gameSetup()
: Divides the deck between two players.war()
: Handles the 'war' scenario.play()
: The main game loop.
const myGame = new GameOfWar();
myGame.play();
This will start a new game and run it until one player wins.