Jump to content
  • Advertisement
Sign in to follow this  
sharpe

Seeking Beginner Advice for Text-Only Dungeon Game in C# and Python

This topic is 2511 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Greetings and thanks for taking the time to read my first post here on GameDev.net.

Straight to the point: I'm 30 years old and have no programming experience other than basic HTML in notepad back in the late-90's, early-2000's. I'm seeking to make a Rogue-like single player dungeon exploration game. I'm much less concerned about implementing 2D graphics than I am about making my own turn-based combat engine and random dungeon room generator. The first version of the game could be text-only or ASCII.

I've ran part way through one online tutorial for Python and have enjoyed the experience so far.

In reply to the question posed in the FAQ: "[Do] you want to make games or learn to program," the answer is that I want to learn to program. I thoroughly enjoyed programming in either C++, C, or C# -- whatever programming class it was that I took in school some 10 years ago and never used again -- just as I enjoyed coding basic Web pages back in the day. I don't recall anything I learned from the class other than that I couldn't stand re-making the same business/accounting programs again that we made in all the other languages, such as Visual Basic. Instead, I used the text book to help me figure out how to use the random number generator to make a gladiator-like text-only game. Once I started going off in my own direction, the class became excruciatingly tedious in its slow pace and focus on repetition.

Now, I didn't come lightly to the conclusion that I wanted to program rather than just make games. Some time ago, I started making simple games with RPG Maker VX, which is a front end for a form of Ruby. Long story short, I felt confined by it. I didn't want to learn Ruby just to make games with RPG Maker. Instead, I decided I wanted to learn to program using a language that would support my designs in the long term. So, I chose Python.

To be honest, though, I actually am the type of person who rarely finishes what he starts. I have a short attention span. I'm not very intelligent and math is my weakest subject. I'm unmotivated and I procrastinate. I am more of the creative type, which, as I understand it, is the opposite of the type who do well at programming.

But, I digress.

Programming is fun, in my opinion, so even if I quit before finishing a full-fledged game -- as I probably will -- I'll have fun while I learn and work on my project.

Enough about boring ol' me and on to my request for advice.

So far, after a quick Google search, I learned that the following code will allow my game to generate random numbers in Python 2.7.2:

from random import randint
a = randint (0,0)


So, with that knowledge in mind, I made my first "game" (please don't laugh):

loop = 1

while loop != 0:
print "Guess a number between 1 and 10 or guess 0 to end program."

number = input()

from random import randint
target = randint (1,10)

if number <= 0:
print "End of line."
loop = 0
break

if number == target:
print "You guessed correctly!"

else:
print "You guessed wrong. The correct number was", target


Even as simple as that is, I'm sure it's full of problems or aspects that that can be improved.

I've not yet learned anything about functions or classes; I made it half way through the Loop section of the tutorial I'm following.

After I make it through the tutorial, I would like to learn:

  1. How to go about the process of making a save file for a game;
  2. How to make my game in Python, but save it so that it can be played on a Windows-based PC;
  3. How I should go about structuring a simple text-only dungeon game with monsters and rooms and treasure;
  4. How I should go about coding a Rogue-like random dungeon room generator.

To save my little game above, I tried using py2exe but my understanding of Python isn't great enough yet to be able to follow the instructions. This is the part I had trouble with:

Importing setup and py2exe to setup.py and call setup() function with the name of entry point script as argument. Now it is time to run the script and create the executable. To build the executable, run "python setup.py py2exe" on the command prompt. You can see lots of output on the console. In the end you can see the output as in the picture below. [/quote]

As I didn't try very hard, I'll probably figure it out myself. For that matter, I've not searched for an answer to my first question either, and the third and fourth are too advanced for me to tackle right now.

However, for the random dungeon generation, for now, I'm considering a text-only game where the size of the room isn't important; it's abstract.

Instead, I am considering a five-by-five-room (or larger) dungeon grid something like this:

-- -- -- -- --
| 1| 2| 2| 2| 3|
-- -- -- -- --
| 4| 5| 5| 5| 6|
-- -- -- -- --
| 4| 5| 5| 5| 6|
-- -- -- -- --
| 4| 5| 5| 5| 6|
-- -- -- -- --
| 7| 8| 8| 8| 9|
-- -- -- -- --

1 = May have doors going right and down.
2 = May have doors going left, down, right.
3 = May have doors going left and down.
4 = May have doors going up, right, and down.
5 = May have doors going in all directions.
6 = May have doors going up, left, and down.
7 = May have doors going up and right.
8 = May have doors going left, up, and right.
9 = May have doors going left and up.


Not all of the rooms should to be accessible, but there must be a path from the entrance to the exit. I guess I should have the game first decide how many rooms there are, then what the path of doors is from the entrance to the exit (up, left, left, left, down, etc), and lastly have it branch off any other possible rooms from existing rooms with doors. I dunno.

After the game decides where the entrance and exits are and what rooms exist, it populates the rooms with doors, monsters, treasure, traps, etc.

I have a long and detailed plan for the game, but here is neither the time nor the place...


Well, thanks again for taking the time to read this. It was really more of an introduction post than a search for advice or answers, but if you feel like giving a complete newbie some help, know that it will be appreciated!

-Sharpe

Share this post


Link to post
Share on other sites
Advertisement
Python is superb for game development, particular for games that don't require precision timing (for that you need to go the C route).

I am myself creating a graphical RPG game at the moment and finding development in Python so fast, it's a bit scary.

My advice would be to learn the data structures in Python: lists, tuples, sets and also dictionaries. These are SO useful in game programming. Also learn a bit of OOP concepts, how to create classes and inherit from classes etc. Learn the scope of variables because this can be a little tricky for those coming from statically typed programming backgrounds. Python is strongly typed, though, so you shouldn't face the issue of accidental implicit data-type conversions which might lead to weird bugs.

Another specific bit of advice: avoid from ... import .... because this can lead to inadverdant namespace pollution. Python recommends always import ....

If you find it too long to type the modulename.method etc., you can do this

import module as M

where module is the module and M is the short form you choose.

Python is a great language, though people find the forced indentation a little strange or even painful at first.

Share this post


Link to post
Share on other sites
Thanks for the advice, Vharis!

I haven't made it to the lists an tuples section of the tut yet, but I'll pay close attention there. I'm sorry I don't yet understand your advice against "from ... import ..." and importing modules, but I'm sure I will when the time comes.

Good luck on your game, BTW. It looks great!

Also, I found this blog and it looks like it will be of great use to me (and maybe you too, VH) when I become more advanced: http://breinygames.blogspot.com/

It has a Rogue-like 2D random dungeon generator for Python that looks really, really good.

Share this post


Link to post
Share on other sites
Greetings Sharpe! Welcome to the forums!

I am also a -to certain extent- aged hobbyist developer, from the other side of the Atlantic, liking RPGs and Python.

Old-timer RPGs rock! Nice that there are people trying to reimplement those games even nowadays! I haven't played with an exact roguelike, but similar ones I enjoyed from the 80s. Perhaps you remember The Bard's Tale series from those times, I think these may be called the next stage of pure ASCII roguelikes, or am I wrong? Even today I have a savegame from this series, and sometimes I do some progress through the dark dungeons of Skara Brae.:)

Unfortunately not having any technical advice to you in thy RPG game programming endeavour as I have only created a simple platformer - a Lode Runner clone - in Python. Pygame is very good for arcade games, too, so I would consider using some graphics instead of ASCII in your game.

However I would suggest some Python books, which I found most entertaining and useful in learning, both are available as free pdf downloads:
Invent your own computer games with Python and
Think like a computer scientist

Happy coding, learning!
Keep us / me informed about your project.

Share this post


Link to post
Share on other sites

Thanks for the advice, Vharis!

I haven't made it to the lists an tuples section of the tut yet, but I'll pay close attention there. I'm sorry I don't yet understand your advice against "from ... import ..." and importing modules, but I'm sure I will when the time comes.

Good luck on your game, BTW. It looks great!

Also, I found this blog and it looks like it will be of great use to me (and maybe you too, VH) when I become more advanced: http://breinygames.blogspot.com/

It has a Rogue-like 2D random dungeon generator for Python that looks really, really good.


Namespace is an important concept in programming because it defines the "Scope" of variables. Some basic intro can be found in wikipedia:

http://en.wikipedia.org/wiki/Namespace
http://en.wikipedia.org/wiki/Global_variable
http://en.wikipedia.org/wiki/Scope_%28programming%29

Lot of technical jargon there, but once you grasp the basic concept, it's really easy to figure out.

Share this post


Link to post
Share on other sites
Thanks, guys, for the replies! :)

Elodman, I'm picking up what you're putting down!

Unfortunately, I didn't get a computer until 1995, a Packard Bell P75. My friend, who had a 486 DX2, didn't have the Internet yet (of course) and we were too young to have the money to buy games. We had the shareware version of Doom and we played the heck out of that until we went together and bought Doom 2 (I had a screaming-fast non-MMX P166 32MB RAM by then). We weren't much for RPGs on the computer, though I loved NES classics like Dragon Warrior and Final Fantasy and Crystalis, etc. So, I missed most of those great classics that I'm sure I would have loved.

We played a lot of table-top role playing, a.k.a, Dungeons and Dragons, though, then moved to GURPS when I was in the eighth grade.

I actually picked up that book first and liked it, but I liked the tutorial I liked a little better. Plus, I started to get worried about the whole 3.2 Vs. 2.7 thing. I went with 2.7 after a fair bit of reading.

Share this post


Link to post
Share on other sites
For an in-depth tutorial making a roguelike game using Python, you can look try here: http://roguebasin.roguelikedevelopment.org/index.php/Complete_Roguelike_Tutorial,_using_python%2Blibtcod

I have not done much with Python, and I've only glanced at the above tutorial, but it seems to go through just about everything for a simple roguelike game, including dungeon generation, items, exploration, monsters, etc.

Share this post


Link to post
Share on other sites
[size="1"]EDIT: Found it!!! I needed "global roll" without quotes in my roll functions!!! Man, I've been working on that for an hour. I'll edit my code for other newbies like me. :) The game appears to work.



I guess I'm missing something when dealing with variables and functions.

I define the variable "roll" as 747 right up front. I'm not exactly sure why I have to do that, but I know I do. Otherwise, when I run the program, it says "roll" isn't "global."

That's not my concern.

My concern is that it keeps reverting back to 747 after I have a function change it. I guess functions can only change the global variable inside themselves?

After the user chooses which monster to fight, the game calls the combat() function.

The combat() function calls the 20-sided dice rolling function called roll_1d20.

The roll_1d20 function sets the roll variable to a number between 1 and 20 and prints it. It works.

However, for the combat function the roll function is still 747 no matter what the roll_1d20 function says.

Help, please?

from random import randint

roll = 747

def roll_1d20():
global roll
roll = randint (1,20)
print "You rolled", roll, "on a 20-sided dice.\n"

def roll_1d10():
global roll
roll = randint (1,10)
print "You rolled", roll, "on a 10-sided dice.\n"

def combat():
roll_1d20()
if roll <= 9:
print "You missed!\n"
print "The monster strikes and kills you!"
elif roll >= 10:
print "You struck!\n"
roll_1d10()
print "You rolled a", roll, "for damage.\n"
print "You win!"

print "\n\nWelcome to the Sorcerer's Arena!"
game = 1
while game != 0:

print "\nWhich monster would you like to fight?\n"
print "1. Goblin"
print "2. Orc\n"
print "Enter 0 to quit.\n"

monster_choice = input()

if monster_choice == 0:
break

else:
print "\nYou enter the arena, sword in one hand, shield in the other.\n"

if monster_choice == 1:
print "The goblin stands before you, clutching a spear in both hands.\n"

elif monster_choice == 2:
print "The towering orc stands before you, battle axe raised above its head.\n"

combat()




Share this post


Link to post
Share on other sites
Crap. I hate bumping my topic, but I don't want a completely different question to get lost in a super long post. Plus, I'm afraid I'll figure it out like last time right after I post... But, I've been at this for nearly a half hour.

Now I'm having problems seeding a random number -- for player damage, in this case, but I need to know for generating numbers for other things too.


import random

playerST = 14 #The player's strength (ST)
playerWeapon = "sword" #The player's weapon

if playerST == 14:
playerDam = random.randint(2,12) #The basic "damage roll" for player strength of 14.
if playerWeapon == "sword":
playerWeaponDam = 3 #The sword adds 3 points to the basic damage roll.
playerSwDamType = "cut" #Ignore. Not yet used.
playerThDamType = "imp" #Ignore. Not yet used.

def player_dam():
a = playerDam + playerWeaponDam #The player's damage roll is the basic damage plus the weapon damage.
print playerDam #Printed to see what's going on.
print playerWeaponDam #Printed to see what's going on.
print a #Printed to show the actual damage inflicted.

player_dam()
player_dam()
player_dam()


Each time the program runs the player_dam() function, it outputs the same numbers.

The weapon damage is 3, which is meant to be added to the player's strength (playerST variable). The playerST variable is meant to reseed for a different number (between 2 and 12) every time. So, the damage with the sword should be 5-15.

I Googled it and found someone who said to use "random.seed(); random.randint()" just like that. But, IDLE doesn't like it.


import random

playerST = 14
playerWeapon = "sword"

if playerST == 14:
playerDam = random.seed(); random.randint(2,12)
if playerWeapon == "sword":
playerWeaponDam = 3
playerSwDamType = "cut"
playerThDamType = "imp"

def player_dam():
a = playerDam + playerWeaponDam
print playerDam
print playerWeaponDam
print a

player_dam()
player_dam()
player_dam()


This is the error I get:


Traceback (most recent call last):
File "C:\Python27\testing.py", line 19, in <module>
player_dam()
File "C:\Python27\testing.py", line 14, in player_dam
a = playerDam + playerWeaponDam
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'


random.seed() does seem to work and I've tried putting it in every place I can think to do, but I can't seem to get it to re-seed with a new number every time...

So, I either get the exact same damage every time, or it doesn't work at all... :(

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!