Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 44 45 [46] 47 48 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100875 times)

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #675 on: June 25, 2012, 11:52:21 am »

Yeah, Systems.Collections provides several non-standard collections, of which the ArrayList class behaves like a dynamic array. There are also several other classes you may want to look at, such as the HashTable, the Queue and the Stack.
Logged

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #676 on: June 25, 2012, 12:11:42 pm »

Hmm, in your variant you removed declaractions like "itm_copper_sword". What is the best way to assign global variables to values like elements of the "weapons" massive to be able to call them from anywhere? Should I assign them under initialization class or somewhere else?

For example, to call "item_copper_sword" for a loot table instead of an element #0 for the massive weapon?
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #677 on: June 25, 2012, 12:22:52 pm »

There are a few ways. One way would to just have a lot of different variables in a loot table and either make them static or instantiate it and pass it to the functions that need access to the loot table.


Another way would be to make each weapon type an object of it's own and have it inherit of weapon:
Code: [Select]
class CopperSword : Weapon
{
  public string name = "Copper Sword";
  public int mindamage = 3;
  public int maxdamage = 6;
  public int price = 500;
}


This will make CopperSword have all functions and variables that a Weapon would have, but since we've defined the default values for the name, damage and price, it will use them.
Logged

GlyphGryph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #678 on: June 25, 2012, 12:37:56 pm »

Does anyone know of any great "Build a Roguelike" walkthroughs?

Normally I'd love to tackle a problem like this from scratch, but my free time is extremely limited lately, so anything that can save me progress would be nice.

Preferable in a modular way.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #679 on: June 25, 2012, 12:50:55 pm »

Something like this, or were you looking for more detail?
Logged

GlyphGryph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #680 on: June 25, 2012, 12:53:18 pm »

I was actually hoping for something a bit more in depth.

Especially something that comes with a list of all the libraries you should add at each step to make everything easier, heheh.
 All that guide offers is "Don't pick crappy libraries!"

But honestly I've already written my project plan which is almost identical to a large part of that document, so yeah - more in depth.
Logged

anzki4

  • Bay Watcher
  • On the wings of maybe
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #681 on: June 25, 2012, 01:07:34 pm »

I just made (simply for practice) a program in C++ that creates a random sentence using words in four different text files.

However in cleaning it up a bit, I hit a wall:
Code: [Select]
for (int i=0; i<5; i++){
   ifstream myfile;
   myfile.open(*);               //*Here should come a file named "[i].txt"
   //Some stuff in between
   getline(myfile,*);             //*Here should come string named "string[i]"
   myfile.close();
   }
Now the question is; is there a way to do something along those lines. Some searching on the web seemed to turn up nothing relevant.
Logged

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #682 on: June 25, 2012, 01:21:31 pm »

Does anyone know of any great "Build a Roguelike" walkthroughs?

Normally I'd love to tackle a problem like this from scratch, but my free time is extremely limited lately, so anything that can save me progress would be nice.

Preferable in a modular way.
That's what I am trying to make, but I try to learn all basics first and then build everything from scratch. And you are right, I expect this kind of approach to take a lot of time, but I don't mind it because I don't want to "make and forget", I want it to become a long-term project of me :).
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #683 on: June 25, 2012, 01:24:38 pm »

Does anyone know of any great "Build a Roguelike" walkthroughs?

Normally I'd love to tackle a problem like this from scratch, but my free time is extremely limited lately, so anything that can save me progress would be nice.

Preferable in a modular way.

I really like this one:  http://roguebasin.roguelikedevelopment.org/index.php/Complete_Roguelike_Tutorial,_using_python%2Blibtcod,_part_1

It sort of made things "click" for me so I could see how to add on to it and change it to work for me.

Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

GlyphGryph

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #684 on: June 25, 2012, 01:54:21 pm »

That one looks pretty good. Thanks guys. ^_^
Logged

Soadreqm

  • Bay Watcher
  • I'm okay with this. I'm okay with a lot of things.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #685 on: June 26, 2012, 12:29:45 am »

There is also this tutorial, a pretty simple step-by-step guide to making a roguelike in Java.
Logged

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #686 on: June 26, 2012, 01:39:11 am »

There are a few ways. One way would to just have a lot of different variables in a loot table and either make them static or instantiate it and pass it to the functions that need access to the loot table.


Another way would be to make each weapon type an object of it's own and have it inherit of weapon:
Code: [Select]
class CopperSword : Weapon
{
  public string name = "Copper Sword";
  public int mindamage = 3;
  public int maxdamage = 6;
  public int price = 500;
}


This will make CopperSword have all functions and variables that a Weapon would have, but since we've defined the default values for the name, damage and price, it will use them.
Hmm, it does not work. It gives warnings that things like "itm_pipe.bashdamage" hide inherited type "Weapon.bashdamage", and when I try to call for it, it returns base values ("Weapon" for itm_pipe.name).

main.cs : http://pastebin.com/c1G8AQKK
itemtypedef.cs : http://pastebin.com/DmvKSLXJ
itemlistdef.cs : http://pastebin.com/iGnjJJFd
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #687 on: June 26, 2012, 02:15:43 am »

Apparently you cannot declare the same variables in inherited classes without shadowing original ones first. How do you do that?

My current solution is to use constructors:
itemlistdef.cs : http://pastebin.com/SxKnkNzV

But is there a better way to do it so I could just declare variables right inside of the item classes instead of making new constructors like itm_name() ?
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository

Shades

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #688 on: June 26, 2012, 03:06:05 am »

But is there a better way to do it so I could just declare variables right inside of the item classes instead of making new constructors like itm_name() ?

One option would be to have the weapon constructor call a method that does all the setup and then overload this in the subclasses. Although this would effectively just be renaming your item_name() constructors to something like an init() method.

If the only main difference is that the weapons have different stats you'd be better off with a more database/config file style values rather than a class per weapon though.
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

Deon

  • Bay Watcher
  • 💀 💀 💀 💀 💀
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #689 on: June 26, 2012, 06:18:27 am »

I want to be able to assign special effects to weapons later (like spells, abilities etc), so I think it would be better to keep them as class. Am I thinking in a right direction?

By the way, here's my very own first attempt to make a "read from file a map and move around" thing.

Program.cs : http://pastebin.com/1utWHXkG
mapfile.txt : http://pastebin.com/dGC8Jr5C (it should be 25x25 file where 0 = floor, 1 = wall).

Any suggestions if you feel like reading that mess and helping? :)

P.S. While I am away for a while, answer me another question please. I want a basic output functionality like console (with Clear(), Write(), WriteLine() or similar methods) for display, but with color for symbols. Any suggestions how can I get the desired with the least blood (without learning totally new and alien libraries and such)?
« Last Edit: June 26, 2012, 06:21:34 am by Deon »
Logged
▬(ஜ۩۞۩ஜ)▬
✫ DF Wanderer ✫ - the adventure mode crafting and tweaks
✫ Cartographer's Lounge ✫ - a custom worldgen repository
Pages: 1 ... 44 45 [46] 47 48 ... 91