Made a simple text based game

For the discussion of Perl, Python, Ruby, and PHP and other interpreted languages.

Made a simple text based game

Post by Fl0urite on Mon Aug 25, 2014 9:05 pm
([msg=82993]see Made a simple text based game[/msg])

Oh and I'm back btw, haven't been on for a few months.
heres the rundown of what I made
made to be good fun or a good time waster
game features:
simple townsperson goes an a quest to kill goblins and orcs, and recieves a bounter for each orc/goblin killed to get better weapons
and health boosts/potions
the game is rather pointless, but the combat is realistic considering there is armor classes and different weapon types have different bonuses/nerfs
melee has a bonus against ranged (1.25x) but a nerf against magic (0.75x)
ranged has a bonus against magic (1.25x) but a nerf against magic (0.75x)
magic has a bonus against melee (1.25x) but a nerf against ranged attacks (0.75x)
also made to be harder to hack then other rpg games, although it includes another version that is much easier to hack
ofcourse if you do manage to hack it and give yourself a bunch of money there is 1 weapon in paticular that 1 hits everything in the game so far. (adamantium sword).
with the unencoded source you can create your own enemies/weapons/savesfiles
basically just mess around.
here is the encoded source:
Code: Select all
http://pastebin.com/i6jsmGkJ

and the unencoded source
Code: Select all
http://pastebin.com/mA8rEXfC
Fl0urite
New User
New User
 
Posts: 11
Joined: Wed Feb 12, 2014 5:01 am
Blog: View Blog (0)


Re: Made a simple text based game

Post by cyberdrain on Tue Aug 26, 2014 11:13 am
([msg=83002]see Re: Made a simple text based game[/msg])

Wow, don't take this the wrong way, but it's almost unreadable (and that's hard for Python sources). Too many globals, no dictionaries, almost no functions. And that's a pity, because it seems like a fun game to test things out on. Decoding the source wasn't that hard, just change exec to print and remove the parentheses. Next time you might want to only distribute the pyc file, though I don't think that will help much. Some things I noticed:
- You don't seem to use any lists or dictionaries, which might help quite a lot with this project (though you might still be learning about them);
- You're not using classes or functions to their full potential;
- At the risk of sounding like centip3de: what's with all the globals? Pass them in or move them into classes;
- There's no empty lines at all, not even between functions or if statements (this would improve readability quite a bit);
- You do use your own implementation of a list into a string, which is interesting (why though?).

So yeah, lists:
Code: Select all
weaponType=playerWeapon.split(':')
playerWeapon="magic:air strike:5:50"
would become
Code: Select all
weaponType = playerWeapon[0]
playerWeapon = ["magic", "air strike", 5, 50]

Dictionaries:
Code: Select all
if weaponType=='melee':
    action='swung'

elif weaponType=='ranged':
    action='shot'

elif weaponType=='magic':
    action='cast'
would become
Code: Select all
action = weaponTypeActions['melee']
weaponTypeActions = {'melee': 'swung', 'ranged': 'shot', 'magic': 'cast'}


Still, I have to admit it is a whole lot better than my first attempt.
Free your mind / Think clearly
User avatar
cyberdrain
Expert
Expert
 
Posts: 2160
Joined: Sun Nov 27, 2011 1:58 pm
Blog: View Blog (0)


Re: Made a simple text based game

Post by Fl0urite on Tue Mar 10, 2015 4:27 pm
([msg=87133]see Re: Made a simple text based game[/msg])

cyberdrain wrote:Wow, don't take this the wrong way, but it's almost unreadable (and that's hard for Python sources). Too many globals, no dictionaries, almost no functions. And that's a pity, because it seems like a fun game to test things out on. Decoding the source wasn't that hard, just change exec to print and remove the parentheses. Next time you might want to only distribute the pyc file, though I don't think that will help much. Some things I noticed:
- You don't seem to use any lists or dictionaries, which might help quite a lot with this project (though you might still be learning about them);
- You're not using classes or functions to their full potential;
- At the risk of sounding like centip3de: what's with all the globals? Pass them in or move them into classes;
- There's no empty lines at all, not even between functions or if statements (this would improve readability quite a bit);
- You do use your own implementation of a list into a string, which is interesting (why though?).

So yeah, lists:
Code: Select all
weaponType=playerWeapon.split(':')
playerWeapon="magic:air strike:5:50"
would become
Code: Select all
weaponType = playerWeapon[0]
playerWeapon = ["magic", "air strike", 5, 50]

Dictionaries:
Code: Select all
if weaponType=='melee':
    action='swung'

elif weaponType=='ranged':
    action='shot'

elif weaponType=='magic':
    action='cast'
would become
Code: Select all
action = weaponTypeActions['melee']
weaponTypeActions = {'melee': 'swung', 'ranged': 'shot', 'magic': 'cast'}


Still, I have to admit it is a whole lot better than my first attempt.


I am not using lists for a good reason: the game is being saved to a file, and that file simply loads the variables into the game.
Fl0urite
New User
New User
 
Posts: 11
Joined: Wed Feb 12, 2014 5:01 am
Blog: View Blog (0)


Re: Made a simple text based game

Post by cyberdrain on Tue Mar 10, 2015 5:03 pm
([msg=87137]see Re: Made a simple text based game[/msg])

Fl0urite wrote:I am not using lists for a good reason: the game is being saved to a file, and that file simply loads the variables into the game.

A list is nothing but a list of variables, so you could modify it a bit to make that work. Dictionaries is a bit harder, but could work similarly. So you haven't moved on to other projects by now?
Free your mind / Think clearly
User avatar
cyberdrain
Expert
Expert
 
Posts: 2160
Joined: Sun Nov 27, 2011 1:58 pm
Blog: View Blog (0)


Re: Made a simple text based game

Post by Fl0urite on Thu Mar 12, 2015 8:41 pm
([msg=87160]see Re: Made a simple text based game[/msg])

cyberdrain wrote:
Fl0urite wrote:I am not using lists for a good reason: the game is being saved to a file, and that file simply loads the variables into the game.

A list is nothing but a list of variables, so you could modify it a bit to make that work. Dictionaries is a bit harder, but could work similarly. So you haven't moved on to other projects by now?

Yes ofcourse, I simply wanted to clear that up :)
Fl0urite
New User
New User
 
Posts: 11
Joined: Wed Feb 12, 2014 5:01 am
Blog: View Blog (0)


Re: Made a simple text based game

Post by cyberdrain on Fri Mar 13, 2015 7:46 am
([msg=87164]see Re: Made a simple text based game[/msg])

Ah, thanks for that :D
Free your mind / Think clearly
User avatar
cyberdrain
Expert
Expert
 
Posts: 2160
Joined: Sun Nov 27, 2011 1:58 pm
Blog: View Blog (0)


Re: Made a simple text based game

Post by Ayr3s on Sat Jun 13, 2015 11:00 pm
([msg=88526]see Re: Made a simple text based game[/msg])

you could try using json to save dictionaries to the save file. :)
User avatar
Ayr3s
New User
New User
 
Posts: 29
Joined: Mon Feb 02, 2015 2:34 pm
Blog: View Blog (0)



Return to Interpreted Languages

Who is online

Users browsing this forum: No registered users and 0 guests