Python Hi-Lo GUI Card Game
- War Card Game Python 3
- War Card Game In Python
- War Card Game Python
- War Card Game Python Code
- War Card Game In Python
Whenever cards are 'won', they should be shuffled together and placed on the bottom of the winner's deck. Wars occur when the initial cards are identical. Each player deals three cards face down and picks one of those three at random to decide the war. If it's another tie, the process is repeated. I need a simply war card game finished in python. Its 80% done and all i need is just the finishing touches. I need to make a menu, comment and a very light pseudo code if there is no pseudo code not a big deal. What would be important is for it to be done before 12 est tonight. Can i get some help? Question: Use Python 3: War Card Game.(note Please Use The SKELETON CODE Provided).Drag The Picture To Webpage Box To Expand. Skeleton Code For Program: # War Game Import Random Class CircularQueue: # Constructor, Which Creates A New Empty Queue: Def init(self, Capacity): If Type(capacity)!= Int Or Capacity. Python war card game oop. GitHub Gist: instantly share code, notes, and snippets.
Project – Hi-Lo
Project Hi-Lo has been updated many times since this post. I will leave this here for the record and so that you can see the evolution of the game.
Please be aware that I had only been learning to program in Python for about 8 weeks when I first wrote this and the code is quite poor. The code is vastly improved in the next two updates though.
See: Python GUI Card Game V2. for latest update, May 2021.
War Card Game Python 3
You might also be interested in another completed card project of mine: Python Video Poker Machine
A Short Intro
I enjoy card games of all sorts, so naturally I wanted to have a go at writing some card games in Python.
As I did not have a clue where to start, or how hard it would be, I settled on the simplest (playable) single player card game I could think of. It was “Hi-Lo“, well my version of it anyway.
Simply put, the player has to guess if the next card to be turned over is either higher or lower than the previously revealed card, what could be simpler? Maybe the game Snap!, but that’s not a single player game.
The Playing Card Images
But before any significant game design I needed images of a deck of playing cards. I didn’t want to steal someone else’s work, so I got my trusty pack of cards out and started scanning and editing. Oh dear, it turned out to be a lot trickier than I thought it would be!
After three hours of messing about, the sample cards that I had made just didn’t look right. A few were a bit wonky as well. I decided to abandon making my own, far too much work, and far too messy if you don’t know what you are doing.
Google. Help!
After traversing the “Interwebs”, I found a royalty free image, of a deck of “Classic” playing cards on Pixabay. There are several other packs of cards on there of varying quality, but I found the one shown below to nearly suit my needs.
I was going to post a direct link to the image on Pixabay so that you could see that it is royalty free, with no attribution required, and can even be used commercially, but I can’t find the blooming thing now, I think it has been removed.
Tricky Cards
I decided that I’m going to cut the cards up individually by hand using Photoshop Elements.
I cut out all the Club cards, Ace to King, making very sure they were all exactly the same size in pixels, 69X94, after putting a two pixel thick black border around each card.
I had to do the border again as when I had cut each card out I used the inside border as a guide. In all, It took about 30 minutes.
By now I had a bit more of an idea of how the game might look and work. I realised that I needed a Joker, I wanted to use it as a wild card, and I also needed an image of the back of a card, neither of which were included the card pack image. I eventually found the images that I wanted, and edited them to size. See above.
Proof Of Concept
In other words, am I capable of programming it or not? Over the course of several hours I finally came up with this working outline for the game.
I used the button-image code produced by WAC (now called Tk Assistant and updated significantly) for the card displays.
On reflection, maybe I should have used labels instead? The cards do not need to be clicked on at any stage, so yes, maybe if there is an advantage to using labels over buttons, but I am not sure about this really.
It almost worked. I was totally shocked at how quickly this simple game could become a complicated mess of variables, with a ton of scoping problems.
Python Variable Scope Gotcha’s
This is mainly due to me not fully understanding the crazy concept of variables of the same name potentially having different values for different scopes, as well as “Global” not really meaning what it appears to mean, well, only sometimes, jez!
I read a few tutorials and watched some videos on variable scope, but I’m still not fully understanding something.
Update: What had me so confused back then was that if you are not going to change the value of the variable, just read it for example, inside a function then you don’t need it to be a global.
I Must Be Doing Something Very Wrong!
The code to create the proof of concept version ran to over 250 lines of code, contained 7 functions, and used four global variables, really? This can’t be right I thought.
I restarted the project from scratch several times, but I was still not happy. I decided to use the often quoted programmers adage of breaking the problem down into smaller chunks. I went for just two cards. This simplified a lot of the tasks I had been struggling with, but not all.
I eventually got it all working, mainly through trial and error, and then I started adding features like, score, high-score, Next card, and a message area.
Global Hell
There were still a lot of small bugs in this version, and the code was starting to bloat again, 200+ lines, and to my distress I had to use even more Global statements than before, six in fact.
I did eventually iron out the bugs though, and I slimmed down bits of the code.
“Every time you use a Global statement, God kills a kitten in heaven!”.
Eventually Hi-Lo V0.7 (below) started to take shape, and you know what? I was starting to like how it looked. I think I prefer this two card version to the five card one that I had first envisioned for the game, it’s kind of cute and compact.
By the end of the day I had version 0.13 running as a playable game. Around 200 lines of code, 7 global variables (ouch!), and 14 functions. I will learn from this. I will now go and study variable scope some more, and then I will get back to adding some ideas that I have for improvements to the game, see below.
HI-LO Potential Improvements
Here is a list of some potential ideas that I am considering for improvements to the game:
- Use Window’s built in sounds
- Use a Joker as a wild card
- save high-score in a text file
- Add the rest of the cards images, or at least one red set
- When a pair come up message that a pair is good enough
- Print the odds of getting next turn correct (will need maths help for that)
- Background music?
- Game over message box, offer quit or new game.
- Improve GUI look.
- New high-score message when achieved
- Log of games played, date, time, points, high-score
- A “change card” option every 10 turns?
- Tick box options of “Use Joker”, “Pairs Lose”, “Extra Life every 10”
- Start with 3 lives to enhance length of game.
- Add my usual Shambles drop-down menu.
- Linux compatible code.
And The Point?
The whole point of this exercise, for me at least, is to find out about writing GUI based card games in Python.
I am certainly a lot wiser about that now, and it has also shown me that I must really knuckle down and learn variable scope properly, rather than just luck it out by sprinkling global statements everywhere and seeing if it works or not, that’s simply not good enough!
You might be interested in my future post: How To Avoid Global Variables
Related posts:
Post Updated March 2020
Previous post: Python Code Snippets #8
Next Post: GUI Card Game Completed
Latest versionReleased:
A simple python module that implements a few classes need to construct a card game
Project description
Python-Card-Game
A simple python module that implements a few classes need to contruct a card game
War Card Game In Python
Card game using pygame. Uses a custom card engine to help with GUI
- Free software: ISC license
- Documentation: https://Python-Card-Game.readthedocs.org.
Setup
use the requirements document in CardEngine and run the following
War Card Game Python
$ pip install cat pycardgame.req
let me know if you have issues getting your python configuredMine is: Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32 We don’t want python-3000
Credits
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
For Fun
Checkout markdown developed by daringfireball.
Project details
Release historyRelease notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size Python-Card-Game-0.1.0.tar.gz (12.2 kB) | File type Source | Python version None | Upload date | Hashes |
War Card Game Python Code
Hashes for Python-Card-Game-0.1.0.tar.gz
War Card Game In Python
Algorithm | Hash digest |
---|---|
SHA256 | 54dfac9eebf16073efc0fe8d82d8810bc88b40df9c8a626d0fa2167617ff5f38 |
MD5 | aaed899649056a910367d0218fb57e13 |
BLAKE2-256 | 8db28210c419531715ded5ba2468fde3d984cbcd92713bc8840adaad5d98c2a2 |