943,696 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 585
  • Python RSS
Jun 23rd, 2009
0

Re-execute main program

Expand Post »
I have written a poker game in Python and have it fairly well finished. My hang-up now is an option to play again. Most of the game is in a function called playHand() which re-runs as long as you still have money, but if you lose all of your money, or the computer characters all lose theirs, I want to give an option to 'play again'. This would require basically re-running the entire program from the beginning. I have seen others use something like "if name == __main__:" but I'm not sure how that works or if that is what I need. How do I re-start the entire program so you could re-play the game as if you just started it?
Similar Threads
Reputation Points: 10
Solved Threads: 7
Junior Poster in Training
txwooley is offline Offline
84 posts
since Apr 2009
Jun 23rd, 2009
0

Re: Re-execute main program

just move the entry/start point of your game into a function, and then at the end of that function (even after) you can give the use the option to "play again".
Reputation Points: 85
Solved Threads: 64
Practically a Master Poster
sillyboy is offline Offline
686 posts
since Mar 2007
Jun 23rd, 2009
0

Re: Re-execute main program

OK. That almost sounds TOO simple. I kick myself for not thinking of this. Thanks. On the same program but a different topic, this is currently a text based game. I have been teaching myself Python via on-line tutorials for about the last year now and think I might be ready to attempt GUI. Which would be the best for me to use for a Texas Hold 'Em card game? I use exclusively Linux OS and don't care if it runs on Doze or not. Can anyone point me at the best GUI to use and perhaps recommend some on-line tutorials? Thanks for the input, and thanks again for answering my stupid question about main. I feel silly now! I have been trying to figure this out for almost two weeks!
Reputation Points: 10
Solved Threads: 7
Junior Poster in Training
txwooley is offline Offline
84 posts
since Apr 2009
Jun 23rd, 2009
0

Re: Re-execute main program

it's ususally the simple "bugs/fixes" that are the hardest to see because they are simply overlooked. good luck with the GUI, unfortunately i haven't dealt with python GUIs before, but i'm sure somebody around here will be able to help.
Reputation Points: 85
Solved Threads: 64
Practically a Master Poster
sillyboy is offline Offline
686 posts
since Mar 2007
Jun 23rd, 2009
0

Re: Re-execute main program

As for a regular application, I'd go with wxPython for sure. Best GUI toolkit I've used for Python (I can't stand Tkinter at all).
If you want to make it more graphics-rich and not look like a regular program, you can try pygame, but that might be a bit difficult to jump into right away.
Reputation Points: 186
Solved Threads: 77
Posting Pro in Training
shadwickman is offline Offline
495 posts
since Jul 2007
Jun 24th, 2009
0

Re: Re-execute main program

Thanks shadwickman. I thought wxPython was a Windows application. I just get that from the name though. I will look into it. Thanks. I see a tutorial on this site, but can you recommend another on-line or perhaps even a book to purchase for a relatively new python guy?
Reputation Points: 10
Solved Threads: 7
Junior Poster in Training
txwooley is offline Offline
84 posts
since Apr 2009
Jun 24th, 2009
1

Re: Re-execute main program

Which Linux distro are you using? Regardless, if you want a visual editor for wxPython, I'd suggest wxGlade. It generates nice code but it may take a little getting used to using. I mostly just code all my GUIs by hand anyways.
As for good wxPython resources, here's some:

Style Guide - Not too comprehensive, but might offer some standardizing tips.
wxPython by Example - A short tutorial which has good examples for bare-bones apps.
wxPython Cookbook - Contains a lot of information on various aspects of wxPython. Lots of examples.
Widget Examples - Has a number of good application skeletons and examples about individual widgets and their uses.
Documentation - The regular documentation for wxPython.

VERY GOOD Tutorial - I'd recommend giving this a read through and looking at the example code as it's quite large and it covers a lot in an understandable way.

wxGlade Tutorial - If you decide to give wxGlade a go. Make sure to learn pure wxPython coding first so that you can do it by hand. Then use this for large GUIs just to speed things up if you want.

There was another very definitive page with all the widgets and examples and information about them, but I can't seem to find it at the moment. I'll post it later if I do find it. Hope these help for now!
Reputation Points: 186
Solved Threads: 77
Posting Pro in Training
shadwickman is offline Offline
495 posts
since Jul 2007
Jun 24th, 2009
0

Re: Re-execute main program

Hey, thanks again shadwickman. I was introduced to Ubuntu a few years ago and now I wont use anything else. These tutorials are just what I was looking for. Now I have my studying and reading cut out for me for the next few weeks.
Reputation Points: 10
Solved Threads: 7
Junior Poster in Training
txwooley is offline Offline
84 posts
since Apr 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: How can I create a list of randomly generated tuples?
Next Thread in Python Forum Timeline: Recognize the amount of digits in a string





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC