a text-based version of the card game War

I originally programmed the card game "War" in Ruby. I then recreated it in JavaScript.

 

At the top is a "forfeit" button (I discovered this was desperately needed after I spent a while testing the game). Below is a scoreboard that keeps track of how many cards each player has. Finally, there's the "battle" button; the text changes depending on what's transpiring in the game.

When a player wins, a list of the cards the player collects is output to the screen. The cards are added to the bottom of the player's deck in a randomized order to prevent any sort of pattern from forming.

 

When two cards of the same value are played, the players go to war. The "battle" button is updated to say "go to war" when this occurs.

When the players go to war, each places one card face-down and one card face-up.

 

When the game is printing the results to the screen, the "forfeit" and "battle" buttons are grayed out; clicking on them or pressing "Enter" will have no effect.

Sometimes, these games go on forever. When you finally can't take the pain anymore, click the "forfeit" button. A confirmation dialogue will pop up asking if you're sure you want to forfeit.

 

If you're a masochist, you can click "No." Otherwise, click "Yes, I am" and you'll forfeit the game. Forfeiting means Player 2 wins.

Once the first game has been played to completion, the scoreboard will update with the number of wins each player has.

 

If you're a glutton for punishment, you can click "play again." The cards will be collected, shuffled, and dealt to each player.

The game continues on. Forever.

Copyright © 2019 Jennifer Gryczkowski. All rights reserved.