Programming, computers, etc. [Serious]
- Anonymously Famous
- JKL; Assassin

- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
So, someone is doing some programming homework, which is to define a function. You can literally define this function in one line of code (and still have it be readable). I'm trying really hard to help this person without giving her the answer or a link to lmgtfy.
BOTTOM TEXT
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- atomtengeralattjaro
- Site Admin

- Posts: 35622
- Joined: Wed May 23, 2007 3:43 pm
- Location: green
- Contact:
Re: Programming, computers, etc. [Serious]
i just found out about the netduino. It's a pretty little electronics platform (like the Arduino) that you can program in .NET (micro framework). pretty cool.

Re: Programming, computers, etc. [Serious]
What does it do?
And also, is it possible for an object to use variables from another object from a different class in C#?
And also, is it possible for an object to use variables from another object from a different class in C#?
assdef wrote:I've seen a number of Cocks in my days.
- atomtengeralattjaro
- Site Admin

- Posts: 35622
- Joined: Wed May 23, 2007 3:43 pm
- Location: green
- Contact:
Re: Programming, computers, etc. [Serious]
a.) it does what you program it to do
it has analog and digital inputs and outputs, and you can hook anything on those.
b.) only the so-called Properties are visible to other classes in C#. You can encapsulate any class-level variable into a Property, thus making it accessible from "outside" the class. When defining a Property, you can specify if you want the variable to be read-only, or writeable as well from the outside.
(Properties are really just special methods, (they are like getter/setter methods in Java) so you can add any other functionality to them as well, for example you can check for the validity of the value before setting it, and so on.)
b.) only the so-called Properties are visible to other classes in C#. You can encapsulate any class-level variable into a Property, thus making it accessible from "outside" the class. When defining a Property, you can specify if you want the variable to be read-only, or writeable as well from the outside.
(Properties are really just special methods, (they are like getter/setter methods in Java) so you can add any other functionality to them as well, for example you can check for the validity of the value before setting it, and so on.)

Re: Programming, computers, etc. [Serious]
a. ) Oh, right, of course! That's nice, otherwise you'd have to learn that specific platform's assembly, right? Neat.
II. ) Ah, I see, I see, thanks a lot!
edit:
3. ) Just over 400 lines and it's turned into a clusterfuck already
But hey, at least I got a little pretty (not really) thing out of it. o and c open and close the door, respectively, and the numpad moves you.
II. ) Ah, I see, I see, thanks a lot!
edit:
3. ) Just over 400 lines and it's turned into a clusterfuck already
But hey, at least I got a little pretty (not really) thing out of it. o and c open and close the door, respectively, and the numpad moves you.
- Attachments
-
- goty.rar
- goty all years
- (3.44 KiB) Downloaded 64 times
assdef wrote:I've seen a number of Cocks in my days.
- atomtengeralattjaro
- Site Admin

- Posts: 35622
- Joined: Wed May 23, 2007 3:43 pm
- Location: green
- Contact:
Re: Programming, computers, etc. [Serious]
oh, oldschool! neat.
i could just walk through the door though.. and it turned into a slash.
i could just walk through the door though.. and it turned into a slash.

Re: Programming, computers, etc. [Serious]
Yeah, it's kind of roguelike style, so I made it so that you automatically open the door when trying to walk into it as usual
But yeah, I think most of them don't automatically walk into the tile after the door is open...
But yeah, I think most of them don't automatically walk into the tile after the door is open...
assdef wrote:I've seen a number of Cocks in my days.
Re: Programming, computers, etc. [Serious]
Bah. I prefer the Nintendu 64.atomtengeralattjaro wrote:i just found out about the netduino. It's a pretty little electronics platform (like the Arduino) that you can program in .NET (micro framework). pretty cool.

Re: Programming, computers, etc. [Serious]
So is it possible to declare structs in a function so that they're available to the entire class, like such
?
Otherwise I'd have to declare them all in the beginning of the class and I imagine that could be messy if I have a large number of creatures...
Also, is there a way for a mob to add itself to the list when it's created? The constructor seems to have some accessibility problems...
Code: Select all
public class Game
{
Map world;
public List<Mob> moblist = new List<Mob>();
public Game()
{
world = new Map(48, 20);
LoadCreatures();
Mob randomrat = new Mob(3, 3, crRat);
moblist.Add(randomrat);
}
public bool GameLoop()
{
world.DrawMap();
foreach (Mob mob in moblist)
mob.DrawCreature();
Console.ReadLine();
return true;
}
public void LoadCreatures()
{
Creature crRat = new Creature(10, 3, 2, 5, "Rat", "A small rodent.", 'r', ConsoleColor.Gray);
}
}
Otherwise I'd have to declare them all in the beginning of the class and I imagine that could be messy if I have a large number of creatures...
Also, is there a way for a mob to add itself to the list when it's created? The constructor seems to have some accessibility problems...
assdef wrote:I've seen a number of Cocks in my days.
- Anonymously Famous
- JKL; Assassin

- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
If I'm understanding what you're asking correctly, you want to use the object that you initiated in "LoadCreatures()" and use it in something else.
I don't think that you can do that exactly. However, you could do something like this (pseudocode):
I don't think that you can do that exactly. However, you could do something like this (pseudocode):
Code: Select all
...
public Game()
{
world = new Map(48, 20);
someSortOfNamedListType localMonsterList = LoadCreatures();
Mob randomrat = new Mob(3, 3, localMonsterList["crRat"]);
moblist.Add(randomrat);
}
...
public someSortOfNamedListType LoadCreatures()
{
someSortOfNamedListType returnValue = new someSortOfNamedListType();
Creature crRat = new Creature(10, 3, 2, 5, "Rat", "A small rodent.", 'r', ConsoleColor.Gray);
returnValue.add("crRat", crRat);
}
}
BOTTOM TEXT
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- atomtengeralattjaro
- Site Admin

- Posts: 35622
- Joined: Wed May 23, 2007 3:43 pm
- Location: green
- Contact:
Re: Programming, computers, etc. [Serious]
um..? why don't you just add the mob to the list right after creating it?
or, more simply:
since you've declared the moblist as a class variable, you can access it from anywhere in the Game class.
If you really want the mob to add itself to the list, you need to either make the list publicly accessible (with a property), or pass it on to the creature constructor as a ref parameter (by address, instead of by value). But I don't think you need that.
Code: Select all
public void LoadCreatures()
{
Creature crRat = new Creature(10, 3, 2, 5, "Rat", "A small rodent.", 'r', ConsoleColor.Gray);
moblist.Add(crRat);
}
Code: Select all
public void LoadCreatures()
{
moblist.Add(new Creature(10, 3, 2, 5, "Rat", "A small rodent.", 'r', ConsoleColor.Gray));
}
If you really want the mob to add itself to the list, you need to either make the list publicly accessible (with a property), or pass it on to the creature constructor as a ref parameter (by address, instead of by value). But I don't think you need that.

Re: Programming, computers, etc. [Serious]
Well, you can't see that in the code I provided, but Creature is a struct, and Mob is a class that gets its properties from the Creature struct, so that I can create various instances of monsters (mobs) by just providing the x and y position and the Creature template. The thing is, if I try to do that and declare all the creatures in a function which is then placed into the constructor of Game, the IDE tells me that crRat doesn't exist in the current context, probably because it's deleted after the function ends, so I'd like to know if I can make it a Game member directly.
The list of mobs is so I can draw everyone on the screen without having to account for each instance in the main game loop, and it's really just more about practicity, so I don't have to worry about adding a mob to the list each time I create one, but I guess it's a problem that can be avoided with a bit less laziness too
Pardon me if this doesn't make any sense, I'm kind of just building my own logic, might be going a completely impractical way, I'm just a newbie
The list of mobs is so I can draw everyone on the screen without having to account for each instance in the main game loop, and it's really just more about practicity, so I don't have to worry about adding a mob to the list each time I create one, but I guess it's a problem that can be avoided with a bit less laziness too
Pardon me if this doesn't make any sense, I'm kind of just building my own logic, might be going a completely impractical way, I'm just a newbie
assdef wrote:I've seen a number of Cocks in my days.
- atomtengeralattjaro
- Site Admin

- Posts: 35622
- Joined: Wed May 23, 2007 3:43 pm
- Location: green
- Contact:
Re: Programming, computers, etc. [Serious]
why is it a struct? structs are really just simple classes, as far as i'm concerned
for example, the integer or the string are structs, but the Game and the Creature are (should be) classes.
Either way, I don't understand your question:
(it should be "private" though, as to conform with OOP standards, but technically you can leave it to be "public" for the moment, if you want.)
Either way, I don't understand your question:
in the code you've posted, it is already a member in Game:I'd like to know if I can make it a Game member directly
Code: Select all
public class Game
{
Map world;
public List<Mob> moblist = new List<Mob>();
(...)

Re: Programming, computers, etc. [Serious]
Nevermind, I managed to get around it 
And I make almost everything public so I don't have to worry much about what can see what, is that too bad?
And I make almost everything public so I don't have to worry much about what can see what, is that too bad?
assdef wrote:I've seen a number of Cocks in my days.
- atomtengeralattjaro
- Site Admin

- Posts: 35622
- Joined: Wed May 23, 2007 3:43 pm
- Location: green
- Contact:
Re: Programming, computers, etc. [Serious]
As long as you don't delve into more complicated things, and coding reusable classes and class libraries, it's not so bad. But I found that following the OOP rules even when it's not necessary helps getting used to it on the long run.
Oh, and it came to me that I was not entirely thorough about structs, they are essentially value types, as opposed to classes, which are reference types. I'm not sure when it would be practical to use a self-defined struct, I haven't used any so far.
Oh, and it came to me that I was not entirely thorough about structs, they are essentially value types, as opposed to classes, which are reference types. I'm not sure when it would be practical to use a self-defined struct, I haven't used any so far.

Re: Programming, computers, etc. [Serious]
Okay, so I think I'm getting better at this, and I rewrote the game adding new features and making more horrible, horrible decisions which totally ruin easy extensibility 
I'm abandoning it now, to learn more and try again later, and hopefully it'll be better. The game now features a nice gui (which turned out really great, I have it in a separate class file and will totally be reusing it) and rats that chase you around for no raisin and totally disregard the walls they get stuck at
I'm abandoning it now, to learn more and try again later, and hopefully it'll be better. The game now features a nice gui (which turned out really great, I have it in a separate class file and will totally be reusing it) and rats that chase you around for no raisin and totally disregard the walls they get stuck at
- Attachments
-
- Projects.rar
- gotyay + source
- (54.98 KiB) Downloaded 46 times
assdef wrote:I've seen a number of Cocks in my days.
- Anonymously Famous
- JKL; Assassin

- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
Sounds like it's going to be fun.
The other day I decided that it was time to start learning a new language. I chose Unicon. It's related to the Icon language (which I also don't know). It seems pretty powerful so far, but it doesn't yet support Unicode.
I plan on eventually writing my own Unicode library for Unicon as an exercise in the language.
Some features:
Generators (Python also has these)
No booleans. That's strange. Either an expression succeeds (True) or it fails (False).
For example, you can do this, which adds up all of the numbers that you type in, until you just hit enter:
The other day I decided that it was time to start learning a new language. I chose Unicon. It's related to the Icon language (which I also don't know). It seems pretty powerful so far, but it doesn't yet support Unicode.
I plan on eventually writing my own Unicode library for Unicon as an exercise in the language.
Some features:
Generators (Python also has these)
No booleans. That's strange. Either an expression succeeds (True) or it fails (False).
For example, you can do this, which adds up all of the numbers that you type in, until you just hit enter:
Code: Select all
procedure main()
i := 0
write("I'll add your numbers. Just hit enter when you're done:")
while i +:= integer(read()) #This will fail when the program can't convert the number to an integer, and fall out of the while loop.
write("The total is: ", i)
endBOTTOM TEXT
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
- atomtengeralattjaro
- Site Admin

- Posts: 35622
- Joined: Wed May 23, 2007 3:43 pm
- Location: green
- Contact:
Re: Programming, computers, etc. [Serious]
Today (and yesterday) I fiddled around in java, trying to wrap my head around how is one supposed to fire and handle asynchronous events in the Sun world. (or Oracle world? let's call it Suracle..)
I already knew that there are no delegates (method references) in java, because.. well, Sun felt they look ugly and non-object-oriented. I couldn't find a proper argument, but if I did, I probably still wouldn't be deeply moved. Delegates are cool, it's silly to leave them out of the party.
So, I needed to implement an Observer pattern. That is, have a class that can have multiple kinds of events that it can fire anytime, and it shouldn't care/know about who might be interested, and have other classes that subscribe to these events and get notified when they occur, while also getting type-safe specific data about the event. (I realize this might be hard to understand for someone who has never heard about events or the observer pattern, and at the same time unnecessary for someone who already knows, but meh, i wanted to be thorough
)
So, there is actually an Observer class and and Observable interface in java, since an ancient version, but it's not type-safe, and it only allows for one kind of event per class. And that plainly sucks. So I went on and wrote my own event library, that can be used quite similarly to the .NET approach, but without delegates. I also made it asynchronous, because that's cool and that's what I needed.
(edit: about the old Java components, actually Observer is the interface and Observable is the class, of course I mixed them up. Shining example of why it is important to distinguish between the two, a'la .NET: start the names of interfaces with a nice big letter I.)
I already knew that there are no delegates (method references) in java, because.. well, Sun felt they look ugly and non-object-oriented. I couldn't find a proper argument, but if I did, I probably still wouldn't be deeply moved. Delegates are cool, it's silly to leave them out of the party.
So, I needed to implement an Observer pattern. That is, have a class that can have multiple kinds of events that it can fire anytime, and it shouldn't care/know about who might be interested, and have other classes that subscribe to these events and get notified when they occur, while also getting type-safe specific data about the event. (I realize this might be hard to understand for someone who has never heard about events or the observer pattern, and at the same time unnecessary for someone who already knows, but meh, i wanted to be thorough
So, there is actually an Observer class and and Observable interface in java, since an ancient version, but it's not type-safe, and it only allows for one kind of event per class. And that plainly sucks. So I went on and wrote my own event library, that can be used quite similarly to the .NET approach, but without delegates. I also made it asynchronous, because that's cool and that's what I needed.
(edit: about the old Java components, actually Observer is the interface and Observable is the class, of course I mixed them up. Shining example of why it is important to distinguish between the two, a'la .NET: start the names of interfaces with a nice big letter I.)

- Anonymously Famous
- JKL; Assassin

- Posts: 11413
- Joined: Thu Mar 03, 2011 6:52 pm
- Location: Area ???, under Bermuda Triangle
Re: Programming, computers, etc. [Serious]
Looks like you had some fun.
BOTTOM TEXT
Proud poster of the 300kth post in GeneralThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Re: Programming, computers, etc. [Serious]
People just build libraries like it ain't a thing 
But today I made my first real-ish game in xna, a shooter
But today I made my first real-ish game in xna, a shooter
assdef wrote:I've seen a number of Cocks in my days.

