Data Structures

Card Game Part 1

This is your first paired programming project. You are required to work on this project with a partner. You must talk to me if you want to work on the project alone or if you want to work in a group of 3. This project is graded separately from your homework.

Purpose: This assignment is meant to apply all that we have talked about so far this semester. You will develop a couple of classes and use the Tkinter library together to develop a complete application for the card game War. This assignment will be completed in two parts. First you will develop and test the set of classes to handle the playing cards and then you will incorporate the game logic for the particular game you will be developing as well as the user interface using the pygame libraries. This page only describes the first phase of the project.

Points: 50

Due Date: Monday, September 15

For this first part of the project you will create 3 classes which are described below and then a simple main function that tests these classes out. You may wish to start with the file cardImageTest.py which is in the OOPIntro folder in the Python Code folder. You will also want to get the cards folder which has a set of free card images that can be used with this project.

Classes to be developed You will create 3 classes: A Card class (already completed and in the cardImageTest.py file), a Deck class, and a hand class. A description of these classes including their instance variables and methods is given below.

Card
suit
rank
cardImage - a file storing an image of that card
__init__ - initializes the instance variables
getSuit, getRank, and getImage are all accessor methods for the instance variables

Deck
deckOfCards - a list of cards in the deck
discardPile - a list of cards which have been discarded
__init__ - creates Card objects for each of the 52 cards (no jokers) and stores them in the deckOfCards list
shuffle - randomly arranges the cards in the deckOfCards list
dealTopCard - removes the first card in deckOfCards and returns it
addToDiscard - takes a Card object as a parameter and adds it to the discardPile list
moveDiscardToDeck - moves the DiscardList to the end of the deckOfCards list

Hand/Player
cardsInHand - list of cards being held
numberCards - the number of cards currently being held
playerName - the name of the player holding these cards
__init__ - sets the player name to the parameter that is given.
addCard - adds a Card object which is given as a parameter to the cardsInHand list
lookAtCard - returns the card in the list at the given position
discardCard - returns the card in the list at the given position and removes it from the list

Testing the classes: Now write a main function that tests your classes out. Your main function should do the following:

GUI Image You should also draw a picture on paper of the GUI you think you will implement. Your GUI needs to be able to display the cards being compared and have a button or some other method of flipping the next cards over for each player. Your GUI should also display the current score (the number of cards each player currently has).

Handing In : If you put your code in separate files then have all your files in one folder with your name(s) on it and copy the folder to the drop folder for this class. If you have all your code in one file, make sure the file name includes your name(s) and copy that file to the drop folder. Turn in the picture of your GUI as well.


Return to the Data Structures Home Page