Jump to content

  • Log In with Google      Sign In   
  • Create Account

laztrezort

Member Since 20 May 2009
Offline Last Active Jun 18 2013 06:20 PM
-----

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

Posted by laztrezort on 28 October 2011 - 10:28 PM

Also

I try and try for hours, but rarely figure my own answer out without help from someone on here, so I'll take all the help I can get!


Don't get discouraged if problems sometimes seem insurmountable. Some might be (no matter how experienced!), but most just take a lot of blunt force, stubborn perseverance. I've gotten lost for weeks on seemingly little details of this or that. An important skill for any programmer, I believe, is a keen ability to research - of course, research will get much easier as you learn specifics of what to search or ask for.

Good luck!


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

Posted by laztrezort on 28 October 2011 - 10:04 PM

Not to keep begging for more and more, but might you possibly have any thoughts on my damage functions and how I'm handling them with Character member values instead of Weapon member values? Around my third edit of that last big post... If not, you've already been so helpful and generous with your time.


The way I understand it, you have the intuition that WeaponSwingDamage, WeaponThrustDamage, SwingDamageType, and ThrustDamageType could go away from the Character class, and you should be able to get those values directly from the whatever weapon the character has equipped?

There are a couple of ways to go about this, but there are also a couple complications :)

Suppose you do remove those fields from Character and add something like this:

public class Character
{
...
 	int CurrentWeaponIndex;
...
 	public void SwingDamageRoll(Character target)
 	{
      	// instead of keeping a seperate field for the weapon stats, just index directly into the player's weapon list
      	// to get the currently selected weapon.  We store the stats in local variables - this isn't technically necessary, but
      	// it will help keep things readable.
      	int weaponSwingDamage = weaponList[CurrentWeaponIndex].swingDamageType;
      	// do the same for thrustDamage, swingDamageType, etc.
      	...
      	// note that now I'm using the local variable we set above
      	basicDamage = Math.Max(((damageRoll + weaponSwingDamage) - target.Armor), 0);
 	}
 	
}

You will need to rewrite your Equip method accordingly - set the player.CurrentWeaponIndex to the selected weapon #. You will also need to change ThrustDamageRoll method (and whatever other details I may be missing). Hopefully you understand the idea, though?

Also, a little more work, but may result in cleaner code:

It seems to me that damage rolls can be a method of Weapon, instead of Character. If you make these Weapon methods, this would have the added advantage that the Character class never has to even know about damages or damage type. All it needs to do is something like this:

int injury = weaponList[currentWeaponIndex].CalculateThrustDamage(int targetArmor); // or whatever you want to call this method



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

Posted by laztrezort on 28 October 2011 - 09:19 PM


Maybe this will be clearer :)

Where you had this before:

  foreach (Weapon thing in player.weaponList)
        {
                EquipWeapon(player, thing);
                Console.WriteLine("\n{0} equipped!", thing.Name);
        }

You could instead do something like this:

int itemIndex = 0;
Weapon itemToEquip = weaponList[itemIndex];
EquipWeapon(player, itemToEquip);
Console.WriteLine("\n{0} equipped!",itemToEquip.Name);

Which would equip only the first item in the List (since we set itemIndex to 0). Lists and arrays use 0-based indexing, which just means that item indexes start at 0, not at 1 like you might be tempted to think.


HEY!!! Now we're getting somewhere!!! I just had to add player.weaponList because the list is in the Character class and that function is in Main(), but yeah, that worked!!!

Thanks so much!!! :D


Cool! Do you (at least sorta) understand the code above? Also, do you see how you will need to somehow ask the player for which weapon # they want to equip, and use that instead of "itemIndex" above?


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

Posted by laztrezort on 28 October 2011 - 09:07 PM

Maybe this will be clearer :)

Where you had this before:
  foreach (Weapon thing in player.weaponList)
        {
                EquipWeapon(player, thing);
                Console.WriteLine("\n{0} equipped!", thing.Name);
        }

You could instead do something like this:

int itemIndex = 0;
Weapon itemToEquip = weaponList[itemIndex];
EquipWeapon(player, itemToEquip);
Console.WriteLine("\n{0} equipped!",itemToEquip.Name);

Which would equip only the first item in the List (since we set itemIndex to 0). Lists and arrays use 0-based indexing, which just means that item indexes start at 0, not at 1 like you might be tempted to think.


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

Posted by laztrezort on 28 October 2011 - 08:58 PM

Not seeing the whole code, but I suspect you have this line:

Weapon aWeapon = weaponList[0];

Somewhere inside the class definition, not inside an actual method. The compiler thinks you are trying to define a field (a data member of the Character class) called "aWeapon", and then trying to set this field to the first element of the weaponList array (which isn't created until the class is constructed). This is why it is complaining.

Sorry if this isn't making sense, it's late here too :D

And sorry about the array thing, I though perhaps you had used them already!


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

Posted by laztrezort on 28 October 2011 - 08:14 PM

I can add things to a list, and I'm sure I can remove things as well with a little reading and effort (pulpfists's Goblin Brawl does this), but how in the world do I pick something out of a list to do something with it?

If players have two weapons in player.weaponList, how do I get my equipWeapon() function to work?


Sorry if this is off base (I haven't been following your code very closely up to this point), but getting items out of a List, you can index into just like an array:

List<Weapon> weapons;
// create and use the weapons list
Weapon aWeapon = weapons[0]; // "aWeapon" now references the same instance as the first item in the List (element 0), just like an array
Weapon aWeapon2 = weapons[1]; // this is the second item.  If you go outside the bounds of the List, you will get an error, just like with an array

You will need to know (keep track of somehow) witch index of the list you want to use. In this case, it looks like you can ask the player which weapon they choose (enter a number, for example, and use that as the index into the List).


#4877931 Can someone give me the exact definition/usage of Stack/Heap and Reference Ty...

Posted by laztrezort on 28 October 2011 - 12:08 PM

I think a source of much of the confusion is the stack in C++, where the programmer had much more implicit control. In C# to be honest, I don't really know why they even made the distinguishment. They should have probably ignored the concept completely and made it something only the compiler developers were really aware of. Worst case scenario, for those few edge cases where the developer needed to optimize for stack usage, it could have been exposed as an attribute. Actually, there is already the stackalloc method, so even this wouldn't be need.


Yes, this tripped me at first when moving from C++ (along with a few other memory related details) - the best thing for me (from a practical viewpoint) was to just forget about the hows and whys of memory in .net and trust the framework to take care of it all. I still get a twinge of, er, guilt maybe?, every now and then when tossing around a ton of instanced objects. Old habits, I suppose.

Not to say these things aren't important to know, and some of the wonderful replies here have filled in the rough spots of my understanding.


#4876536 Super efficient tile engine design?

Posted by laztrezort on 24 October 2011 - 06:12 PM

By large number of tiles, I assume you mean size of map dimensions (not the number of different textures)?

I'm not sure why anyone would bother trying to write a "super efficient" tile engine these days. Just make a tile engine, and if you run into memory issues, partition the world into "chunks" and stream the chunks from disk as needed. A modern computer can handle very large amounts of memory very quickly, so I think the more difficult task would be the actual generation of these large maps.

In general, efficiency is probably the last thing you should be worrying about at this stage. Follow Nick's tutorial (or any of the other many tile engine tutorials available) and get something working first.


#4873050 Using XNA RenderTargets

Posted by laztrezort on 15 October 2011 - 11:42 PM

Rendertarget usage can get a bit tricky, if you haven't already you should probably read this and this. If you were more specific (e.g. show some code) you may get some more specific help.


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

Posted by laztrezort on 14 October 2011 - 05:40 PM

I'm going to work through the beginner examples rather than just reading them. It's humbling, and I'd much rather pick up in C# where I was in Python, but I realize that's just not happening.


You may already have some good learning resources lined up, but there was a thread not too long back which may have some beginner-friendly challenge ideas for you to try, here. It seems like there was another one around at about the same time, but I can't seem to find it...


#4870646 [C#] Checking the amount of items in a List?

Posted by laztrezort on 08 October 2011 - 06:36 PM

Its not a neat solution, for the first item just write it, then for subsequent items write a comma then write the item. Maybe:

bool first = true;
foreach (string items in mInventory.List)
{
    if(first)
    {
        Console.WriteLine(" \"{0}\"", items);
        first = false;
    }
    else
    {
        Console.WriteLine(", \"{0}\"", items);
    }    
}


To add more solutions to the mix, Jon Skeet wrote a smart enumerable class that supports IsFirst and IsLast queries (among a couple others), which can be found here if looking for a general purpose way of doing the above. However, for the specific OP, String.Join might be the most simple.


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

Posted by laztrezort on 05 October 2011 - 10:23 PM

WindowsError: [Error 193] %1 is not a valid Win32 application


I don't know python very well, but this error message makes we wonder if there is a 32/64 bit incompatibility issue. From the tutorial link:

(Note for Windows 7 64-bits users: install the 32-bits version, since the 64-bits version of Python seems to cause problems with libtcod.)


It looks like libtcod is not compatible with 64 bit Python, maybe this is the problem?


#4869630 XNA Sprite performance problem with Matrix's

Posted by laztrezort on 05 October 2011 - 08:28 PM

I don't know of anything that you could be doing with Matrix calculations that would affect performance so drastically (unless you are doing it 10000+ times a frame). You can try posting some more code, there's probably something else affecting performance here.


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

Posted by laztrezort on 02 October 2011 - 12:04 AM

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.


#4865001 XNA C# Help with HUD

Posted by laztrezort on 22 September 2011 - 09:09 PM

You need to set the HUD.player member to the Player parameter you pass to it, like so:

public HUD(Game game, GameStateManager manager, Player player)
        	: base(game, manager)
    	{
              this.player = player;
    	}

This way, the HUD.player references the same Player object as the one you create in your GamePlayState object. This way they are the same object (the same chunk of memory), so anything you do to HUD.player will be the same as doing it to the Player instance you pass into the HUD constructor (and vice versa).

Sorry if I'm not explaining it well enough - you would probably do better to read up on classes (reference types) and structs (value types) and what their differences are. While you are at it, look into pass-by-reference and pass-by-value, since despite the similar names these are different concepts, and are important to understand up-front.




PARTNERS