Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/08-Milestone Project - 2/00-Milestone-2-Warmup-Project.ipynb
Views: 648
Warmup Project Exercise
Simple War Game
Before we launch in to the OOP Milestone 2 Project, let's walk through together on using OOP for a more robust and complex application, such as a game. We will use Python OOP to simulate a simplified version of the game war. Two players will each start off with half the deck, then they each remove a card, compare which card has the highest value, and the player with the higher card wins both cards. In the event of a time
Single Card Class
Creating a Card Class with outside variables
Here we will use some outside variables that we know don't change regardless of the situation, such as a deck of cards. Regardless of what round,match, or game we're playing, we'll still need the same deck of cards.
Create an example card
Deck Class
Using a class within another class
We just created a single card, but how can we create an entire Deck of cards? Let's explore doing this with a class that utilizes the Card class.
A Deck will be made up of multiple Cards. Which mean's we will actually use the Card class within the __init__ of the Deck class.
Create a Deck
Player Class
Let's create a Player Class, a player should be able to hold instances of Cards, they should also be able to remove and add them from their hand. We want the Player class to be flexible enough to add one card, or many cards so we'll use a simple if check to keep it all in the same method.
We'll keep this all in mind as we create the methods for the Player class.