Login Register






[Game] Town Major v1.2 filter_list
Author
Message
[Game] Town Major v1.2 #1
After being back in Python programming for like 3 days I started programming a little game. Altough it took me more then 10 hours to create it. But I learned a lot from it. Hope you like it!

[Image: townmajor.png]

Goal
The game itself is quite simple. You start in a little town with some resources and you have to build it up. After 30 days your score will be calculated and I added some events that occur on a specific day. Any comments, tips & feedback are appriciated.

Version 1.2
Code:
CHANGELOG [*] Fixed bugs [*] Added another event [*] You can now level your town by reaching a certain amount of residents

Download

Source code -> DOWNLOAD
[Image: Signature.png]

Chek Out My Tutorials
| Set Up A Pentest Lab | How To Make Bitcoins |

Reply

RE: [Game] Town Major v1.0 #2
Well done. Those are the kind of games I actually expected for the HC CLI Game Compilation. Maybe I should do a second one.
I played a while and ran into two issues. Buying houses only costs 15 coins instead of 150.
After a while I pressed the wrong button and the game crashed:

Code:
Choose an option: 2 ============================================= 21374 COINS Shopping Menu ------------- 1) Buy House 150 Coins 2) Buy Factory 250 Coins 3) Sell Goods 13 Coins 4) Back to menu Choose an option: Traceback (most recent call last): File "home.py", line 263, in <module> day() File "home.py", line 69, in day menu() File "home.py", line 87, in menu shop() File "home.py", line 146, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 152, in shop menu() File "home.py", line 85, in menu stats() File "home.py", line 110, in stats menu() File "home.py", line 87, in menu shop() File "home.py", line 146, in shop shop() File "home.py", line 152, in shop menu() File "home.py", line 89, in menu end_day() File "home.py", line 163, in end_day day() File "home.py", line 69, in day menu() File "home.py", line 87, in menu shop() File "home.py", line 152, in shop menu() File "home.py", line 85, in menu stats() File "home.py", line 110, in stats menu() File "home.py", line 89, in menu end_day() File "home.py", line 163, in end_day day() File "home.py", line 69, in day menu() File "home.py", line 85, in menu stats() File "home.py", line 110, in stats menu() File "home.py", line 87, in menu shop() File "home.py", line 150, in shop shop () File "home.py", line 150, in shop shop () File "home.py", line 150, in shop shop () File "home.py", line 150, in shop shop () File "home.py", line 150, in shop shop () File "home.py", line 150, in shop shop () File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 150, in shop shop () File "home.py", line 150, in shop shop () File "home.py", line 150, in shop shop () File "home.py", line 150, in shop shop () File "home.py", line 152, in shop menu() File "home.py", line 85, in menu stats() File "home.py", line 110, in stats menu() File "home.py", line 89, in menu end_day() File "home.py", line 163, in end_day day() File "home.py", line 69, in day menu() File "home.py", line 89, in menu end_day() File "home.py", line 163, in end_day day() File "home.py", line 69, in day menu() File "home.py", line 89, in menu end_day() File "home.py", line 163, in end_day day() File "home.py", line 69, in day menu() File "home.py", line 87, in menu shop() File "home.py", line 146, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 150, in shop shop () File "home.py", line 152, in shop menu() File "home.py", line 89, in menu end_day() File "home.py", line 163, in end_day day() File "home.py", line 69, in day menu() File "home.py", line 85, in menu stats() File "home.py", line 110, in stats menu() File "home.py", line 87, in menu shop() File "home.py", line 137, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 132, in shop shop() File "home.py", line 150, in shop shop () File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 150, in shop shop () File "home.py", line 152, in shop menu() File "home.py", line 89, in menu end_day() File "home.py", line 163, in end_day day() File "home.py", line 69, in day menu() File "home.py", line 85, in menu stats() File "home.py", line 110, in stats menu() File "home.py", line 87, in menu shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 150, in shop shop () File "home.py", line 146, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 152, in shop menu() File "home.py", line 85, in menu stats() File "home.py", line 110, in stats menu() File "home.py", line 89, in menu end_day() File "home.py", line 163, in end_day day() File "home.py", line 69, in day menu() File "home.py", line 89, in menu end_day() File "home.py", line 163, in end_day day() File "home.py", line 69, in day menu() File "home.py", line 87, in menu shop() File "home.py", line 150, in shop shop () File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 150, in shop shop () File "home.py", line 152, in shop menu() File "home.py", line 89, in menu end_day() File "home.py", line 163, in end_day day() File "home.py", line 69, in day menu() File "home.py", line 89, in menu end_day() File "home.py", line 163, in end_day day() File "home.py", line 69, in day menu() File "home.py", line 89, in menu end_day() File "home.py", line 163, in end_day day() File "home.py", line 69, in day menu() File "home.py", line 87, in menu shop() File "home.py", line 150, in shop shop () File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 154, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 154, in shop shop() File "home.py", line 150, in shop shop () File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 137, in shop shop() File "home.py", line 154, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 146, in shop shop() File "home.py", line 128, in shop choice = input("\nChoose an option: ") File "<string>", line 0 ^ SyntaxError: unexpected EOF while parsing [1]+ Fertig gedit home.py deque@decra:~/Dokumente/python$

I supposed this happened because I pressed enter without giving an option. I entered the same options so quickly that this is probably the reason for it.

Other than that you can maybe brush the statistics a bit. The production value has too many digits:

Code:
Population: 25 120 Coins Production: 0.30000000000000004 10 Goods

Can I add this to the Game Compilation? See: http://www.hackcommunity.com/Thread-Cont...-line-game
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: [Game] Town Major v1.0 #3
@Deque
Thanks for the feedback I will work on it!

The game crashed in the menu because the 'input' command asks for an integer and it was a string I think.
The buy house bug is fixed but it was just a copy paste mistake to pastebin (my bad Confused)

I rounded the Production value with the "{0:.2f}".format(Production) command
altough I don't know why 0.1 + 0.1 + 0.1 = 0.0000000000000004.

And ofcourse you can add it to the Game Compilation I thought it closed last weekend Confused
[Image: Signature.png]

Chek Out My Tutorials
| Set Up A Pentest Lab | How To Make Bitcoins |

Reply

RE: [Game] Town Major v1.0 #4
Well done! Definitely well done. As Deque said, doesn't bear wrong key inputs
Code:
def menu(): print " =============================================" print "\n\n MENU" print " ------" print " 1) Statistics" print " 2) Shop" print " 3) End day" print " 4) Quit Game" choice = input("\nChoose an option: ") if (choice==1): stats() elif (choice==2): shop() elif (choice==3): end_day() elif (choice==4): quit_game() else: menu()

I'm not a Python coder, so I may be wrong, but I think that this way
Code:
def menu(): print " =============================================" print "\n\n MENU" print " ------" print " 1) Statistics" print " 2) Shop" print " 3) End day" print " 4) Quit Game" choice = input("\nChoose an option: ") if (choice==1): stats() elif (choice==2): shop() elif (choice==3): end_day() elif (choice==4): quit_game() menu()
may work, may not it?

Also, how about clearing screen before next step? Like before menu:
Code:
cls = lambda: os.system('cls') def menu(): cls() print " =============================================" print "\n\n MENU" print " ------" print " 1) Statistics" print " 2) Shop" print " 3) End day" print " 4) Quit Game" choice = input("\nChoose an option: ") if (choice==1): stats() elif (choice==2): shop() elif (choice==3): end_day() elif (choice==4): quit_game() menu()

This way, screen will be cleaned everytime you reach menu, before displaying the menu function.
Also, how about storing player's info in a file and reading from it whenever the user runs the game? Else, everytime we would have to input starting data (username, town's name...)
Does the days thing work without saving to file how many days are going by? I mean, I see in the code, if Date == 1, etc... But where it does it read Date from? Does it set date to 1 automatically at the first run? (As I said, I'm not a Python coder, forgive me) And does it also update date automatically, without you moving a finger? Because would think about having a file where I have the value of the current day, and when it, running sees that it's passed 30 days, would end.
This would do, but actually, it would be more sense-full to set a value, like 1, and update on next use, also checking if date changed.
So, if I use it 10 times today, it would still be 1, but if I don't use it for a week, I won't find it at 8 without having done a thing.
But maybe I'm just wrong, please, let me know.
My Bitcoin address: 1AtxVsSSG2Z8JfjNy9KNFDUN6haeKr7LiP
Give me money by visiting www.google.com here: http://coin-ads.com/6Ol83U

If you want a Bitcoin URL shortener/advertiser, please, use this referral: http://coin-ads.com/register.php?refid=noize

Reply

RE: [Game] Town Major v1.0 #5
@noize
Thanks for the feedback!

I tried to fix the wrong input bug with the code but it still returns an error Sad

For the clear screen command, I started python programming 3 days ago and I never heard of that command so I will keep it in mind the next time I code something. And I maybe recode this game with it. But doesn't "cls" only work on windows?

I also have no idea how to store data in a file right now.. I still have a long way to go Sad

Oh and to answer your question about the days. 1 is assigned to the variable Date when Date is declared (Line 244). The date stays 1 until the user chooses to End the day in the menu. When the user choose to end the day, Date will be incremented by 1.
[Image: Signature.png]

Chek Out My Tutorials
| Set Up A Pentest Lab | How To Make Bitcoins |

Reply

RE: [Game] Town Major v1.0 #6
(04-06-2013, 11:56 AM)Dapaus Wrote: @noize
Thanks for the feedback!

I tried to fix the wrong input bug with the code but it still returns an error Sad

For the clear screen command, I started python programming 3 days ago and I never heard of that command so I will keep it in mind the next time I code something. And I maybe recode this game with it. But doesn't "cls" only work on windows?

I also have no idea how to store data in a file right now.. I still have a long way to go Sad

Oh and to answer your question about the days. 1 is assigned to the variable Date when Date is declared (Line 244). The date stays 1 until the user chooses to End the day in the menu. When the user choose to end the day, Date will be incremented by 1.

First, starting by the date thing, that's cool to make the user end the day when he wants to, but don't variables remain for the session only? I mean, when closing the file and then reopening it, wouldn't date go back to 1?
In batch, I know I could do something like

Code:
@echo off set date=1 :: HERE GOES MY FILE :: HERE I DO THINGS set day=%date% :: WHEN USER CHOOSES TO END THE DAY echo @echo off > copyfile echo set date=2 >> copyfile for /f "skip=2 delims=" %%i in ('type %0 >> copyfile') do echo %%i >> copyfile ren %0 something cls & call copyfile & del something /f /q > nul

But it would be MUCH better to print a value like "3", which is the day to a file and read everytime from it.
If you'd like to, I could help you to print over and read from files in Python for Windows, but I'm not able to do so in other OS's.
Also, yes "cls" works in Windows only.
With Linux I think should work this way:

Code:
cls = lambda: os.system('cls') clear = lambda: os.system('clear') def menu(): cls() clear() print " =============================================" print "\n\n MENU" print " ------" print " 1) Statistics" print " 2) Shop" print " 3) End day" print " 4) Quit Game" choice = input("\nChoose an option: ") if (choice==1): stats() elif (choice==2): shop() elif (choice==3): end_day() elif (choice==4): quit_game() menu()

Please, note that the above shouldn't work in Linux only, but in Windows too.
My Bitcoin address: 1AtxVsSSG2Z8JfjNy9KNFDUN6haeKr7LiP
Give me money by visiting www.google.com here: http://coin-ads.com/6Ol83U

If you want a Bitcoin URL shortener/advertiser, please, use this referral: http://coin-ads.com/register.php?refid=noize

Reply

RE: [Game] Town Major v1.0 #7
Quote:The game crashed in the menu because the 'input' command asks for an integer and it was a string I think.

The game really shouldn't crash because of a wrong userinput. You can do something like this to prevent crashing:


Code:
choice = raw_input("Choose an option: ") if choice.isdigit(): #make sure that user input is an integer option = int(choice) #savely convert to int

(04-06-2013, 11:17 AM)Dapaus Wrote: I rounded the Production value with the "{0:.2f}".format(Production) command
altough I don't know why 0.1 + 0.1 + 0.1 = 0.0000000000000004.

That's because 0.1 (dec) converted to binary is 0.00011001100110011001100110011001100110011001100110011001100110...
It has an endless amount of digits after the dot and the computer can't save the number without rounding it.

It is better to calculate with integers instead and only converting them to float when necessary. I.e. you could calculate (1 + 1 + 1) / 10 = 0.3
instead of (0.1 + 0.1 + 0.1) = 0.3000000000000004

Quote:And ofcourse you can add it to the Game Compilation I thought it closed last weekend Confused

Yes, it is closed, because I am working on publishing the compilation. It seems I accidentally opened it again.
I am just a bit disappointed with the current entries. Most of them are not really innovative. Yours is an entirely new game, so it would be a great contribution for the compilation.

(04-06-2013, 12:13 PM)noize Wrote: First, starting by the date thing, that's cool to make the user end the day when he wants to, but don't variables remain for the session only? I mean, when closing the file and then reopening it, wouldn't date go back to 1?

It's not only the date Dapaus would have to save into a file. You would need a whole savegame implementation with all the variables in it.
30 days is not that much that you really need a savegame, though. It's only a nice to have.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: [Game] Town Major v1.0 #8
Wow impressive, You actually did good Smile
@DaPaus Consider using a while loop for your menu like

Code:
start = True while start: ###menu items####
When user presses enter (No Input), start becomes False and the program exits.
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply

RE: [Game] Town Major v1.0 #9
Great game! I like it!

Just I bumped into a little problem:
Code:
MENU ------ 1) Statistics 2) Shop 3) End day 4) Quit Game Choose an option: 3 ============================================= It becomes night and everyone goes to bed and waits for a new day to come... PRESS ENTER TO CONTINUE Traceback (most recent call last): File "C:\Users\1llusion\Desktop\Town.py", line 258, in <module> day() File "C:\Users\1llusion\Desktop\Town.py", line 63, in day menu() File "C:\Users\1llusion\Desktop\Town.py", line 81, in menu shop() File "C:\Users\1llusion\Desktop\Town.py", line 141, in shop shop() File "C:\Users\1llusion\Desktop\Town.py", line 141, in shop shop() File "C:\Users\1llusion\Desktop\Town.py", line 136, in shop shop() File "C:\Users\1llusion\Desktop\Town.py", line 136, in shop shop() File "C:\Users\1llusion\Desktop\Town.py", line 127, in shop shop() File "C:\Users\1llusion\Desktop\Town.py", line 147, in shop menu() File "C:\Users\1llusion\Desktop\Town.py", line 83, in menu end_day() File "C:\Users\1llusion\Desktop\Town.py", line 158, in end_day day() File "C:\Users\1llusion\Desktop\Town.py", line 63, in day menu() File "C:\Users\1llusion\Desktop\Town.py", line 81, in menu shop() File "C:\Users\1llusion\Desktop\Town.py", line 147, in shop menu() File "C:\Users\1llusion\Desktop\Town.py", line 83, in menu end_day() File "C:\Users\1llusion\Desktop\Town.py", line 158, in end_day day() File "C:\Users\1llusion\Desktop\Town.py", line 63, in day menu() File "C:\Users\1llusion\Desktop\Town.py", line 79, in menu stats() File "C:\Users\1llusion\Desktop\Town.py", line 105, in stats menu() File "C:\Users\1llusion\Desktop\Town.py", line 81, in menu shop() File "C:\Users\1llusion\Desktop\Town.py", line 132, in shop shop() File "C:\Users\1llusion\Desktop\Town.py", line 147, in shop menu() File "C:\Users\1llusion\Desktop\Town.py", line 83, in menu end_day() File "C:\Users\1llusion\Desktop\Town.py", line 158, in end_day day() File "C:\Users\1llusion\Desktop\Town.py", line 51, in day Goods = Goods + round(Population * Production) TypeError: a float is required C:\Users\1llusion\Desktop>

System: Windows 64bit.
Staff will never ever ask you for your personal information.
We know everything about you anyway.

Reply

RE: [Game] Town Major v1.2 #10
So I spend 2 hours rewriting the code. And I think most bugs are fixed. I also added some more events and now you can level your city from "Settlement" to "Metropolis". Thanks for the feedback everyone.


@noize: I didn't add a save function because I think it isn't needed. It's quite a short game!
But I fixed the clear screen function with the following piece of code:
Code:
if sys.platform in ("linux", "linux2"): clear = lambda: os.system("clear") else: clear = lambda: os.system("cls") clear()


@Deque: Thanks for clearing those problems out. I rewrote the code with those tips in mind! And thanks for adding it to your Game Compilation

@Ex094: Thanks for the tip but I didn't use it in the new version because I don't want my program to quit if the user accidentaly press the wrong button.

@1llusion: Thanks for reporting the bug. It should be fixed now.
[Image: Signature.png]

Chek Out My Tutorials
| Set Up A Pentest Lab | How To Make Bitcoins |

Reply