-
Notifications
You must be signed in to change notification settings - Fork 0
/
readMe.txt
25 lines (13 loc) · 5.33 KB
/
readMe.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Card Game Creator (https://www.youtube.com/watch?v=6fehXX7UiDY)
Hello, and welcome to my 15-112 Fundamentals of Computer Programming term project!
My project was designed to solve two basic problems: 1) most computer card games are casino card games, and there is not enough representation of trick-based card games, and 2) all computer card games have a fixed set of rules, so users cannot add twists to the rules to make the game more enjoyable.
To solve this problem, I decided to make a card game which, by itself, has minimal rules. By itself, it only follows the basic rule of a trick-based game: players must play the same suit as the first card in a trick (or collection of cards played in the center in which each player has played one card,) and the trick goes to the person who played the highest card of the leading suit. If a player does not have the leading suit, he/she may play any card.
Starting with these barebones rules, I began adding parameters, to allow the user to create more complex card games. On the UI level, this is done through a drag and drop interface, where the user can drag and drop a list of possible options to a rules area. Once they let go, they will be presented with a pop up dialog asking for more details. There are two preset games, Hearts and 29, to give the user an idea of how to use the drag and drop interface. Further, the user can save his/her own preset and load it by name, to allow users to program and store their own card games. Once the user is done, he/she can press 'Start Game' to begin playing!
When playing the game, the screen displays one player's hand at a time. As the user hovers over a card it will highlight the card, and when the user clicks it will animate the motion of the card to the center. That users cards will then disappear, and a popup will appear instructing the user to pass the computer to the next player. This is to prevent players from seeing cards other than their own. Further, depending on the game, there may be a pass or bidding phase at the beginning.
The audience of this game is both card game fanatics, like myself, and people who have not had much experience with card games. Card Game fanatics would make use of the drag and drop feature, for it would give them maximal freedom in creating a card game. For first-time card-gamers, the drag and drop interface would be relatively difficult to understand. After all, how can you create a card game if you are not familiar with them? However, a first-time card-gamer would enjoy playing the preset games, and potentially creating his/her own card games using those as examples.
For the computational part of my game, I made each major screen of the game a separate class. Therefore, I have a Menu class, which inherits from the EventBasedAnimationClass, a DefineRulesMenu class, which gets the canvas and root passed to it by the Menu class, and a CardGame class, which gets the canvas and root passed to it by the DefineRulesMenu class. Other than the Menu class, the other two classes have a "done" attribute, which indicates whether the view is active or has been finished (when the user clicks a button to a previous screen.) Meanwhile, the superview (the previous view) has a method running on another thread to check whether the subview is done. If so, it removes the subview and returns to drawing itself.
I also have a CardGameDialog class, which configures the various popup dialogs that appear throughout the game, a Button class, which configures the buttons used throughout the game, and a DragAndDrop class. The DragAndDrop class inherits from the Button class, with the exception that it can be dragged, and only registers a click when it is dropped.
For gameplay, I have a Card class, a Player class, and a Rules class. The Card class keeps track of the suit and value of the card, which player the card belongs to, etc. It know how to draw itself and check whether the user clicked inside it. The Player class keeps track of the players bids, points, hand, the tricks the player has received, the player's name and number, etc. Lastly, the rules class keeps track of which rules the user turned on and off, and keeps track of which cards are legal to play, which bids are legal, which player receives the trick, etc.
When the user actually starts playing the game, when a player plays a card and when a player receives a trick the cards' motion is animated. I implemented this using a callback queue. A callback queue is a 2D list, with each inner list including a time interval, a callback function, the number of times to repeat, and an end function. I created a custom callback queue to make my code cleaner (by not repeatedly calling canvas.after in my animation functions) and to enable an end function, which is called once the animation is over. This framework is ideal for a card game, because the gameplay is paused during the animation, and only AFTER the animation is complete does the game move to the next player.
Lastly, the rules for the preset games (Hearts and 29) are saved as .txt files in the same directory as the game. When the user saves a custom preset, the game converts the user's inputs (the specific text the user entered into the popup dialogs) into a single, human-readable .txt file. When the user loads a preset, Python parses the file, if it exists, and adds the specified attributes into the rules dictionary.
Enjoy!