Programming, computers, etc. [Serious]

All things asdf (and anything else)
User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Wed Jun 20, 2012 1:52 am

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
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
atomtengeralattjaro
Site Admin
Site Admin
Posts: 35622
Joined: Wed May 23, 2007 3:43 pm
Location: green
Contact:

Re: Programming, computers, etc. [Serious]

Post by atomtengeralattjaro » Sat Jul 07, 2012 4:35 pm

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.
Ivokyuftaf6666 wrote:
Sun Oct 20, 2019 5:22 pm
Awesome Site, Delivering Fun
Image

User avatar
Arkannine
ASDF Warlord
ASDF Warlord
Posts: 15521
Joined: Tue Oct 28, 2008 9:21 pm
Location: I'm on a boat

Re: Programming, computers, etc. [Serious]

Post by Arkannine » Mon Jul 09, 2012 4:09 pm

What does it do?

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.

User avatar
atomtengeralattjaro
Site Admin
Site Admin
Posts: 35622
Joined: Wed May 23, 2007 3:43 pm
Location: green
Contact:

Re: Programming, computers, etc. [Serious]

Post by atomtengeralattjaro » Mon Jul 09, 2012 4:42 pm

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.)
Ivokyuftaf6666 wrote:
Sun Oct 20, 2019 5:22 pm
Awesome Site, Delivering Fun
Image

User avatar
Arkannine
ASDF Warlord
ASDF Warlord
Posts: 15521
Joined: Tue Oct 28, 2008 9:21 pm
Location: I'm on a boat

Re: Programming, computers, etc. [Serious]

Post by Arkannine » Mon Jul 09, 2012 4:50 pm

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 :lol:
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 65 times
assdef wrote:I've seen a number of Cocks in my days.

User avatar
atomtengeralattjaro
Site Admin
Site Admin
Posts: 35622
Joined: Wed May 23, 2007 3:43 pm
Location: green
Contact:

Re: Programming, computers, etc. [Serious]

Post by atomtengeralattjaro » Mon Jul 09, 2012 6:25 pm

oh, oldschool! neat.
i could just walk through the door though.. and it turned into a slash.
Ivokyuftaf6666 wrote:
Sun Oct 20, 2019 5:22 pm
Awesome Site, Delivering Fun
Image

User avatar
Arkannine
ASDF Warlord
ASDF Warlord
Posts: 15521
Joined: Tue Oct 28, 2008 9:21 pm
Location: I'm on a boat

Re: Programming, computers, etc. [Serious]

Post by Arkannine » Mon Jul 09, 2012 6:34 pm

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...
assdef wrote:I've seen a number of Cocks in my days.

User avatar
assdef
JKL;'s Nightmare
JKL;'s Nightmare
Posts: 7050
Joined: Sat Jan 02, 2010 9:30 pm

Re: Programming, computers, etc. [Serious]

Post by assdef » Tue Jul 10, 2012 4:40 am

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.
Bah. I prefer the Nintendu 64.
Image

User avatar
Arkannine
ASDF Warlord
ASDF Warlord
Posts: 15521
Joined: Tue Oct 28, 2008 9:21 pm
Location: I'm on a boat

Re: Programming, computers, etc. [Serious]

Post by Arkannine » Wed Jul 11, 2012 5:09 pm

So is it possible to declare structs in a function so that they're available to the entire class, like such

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.

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Wed Jul 11, 2012 6:44 pm

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):

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
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
atomtengeralattjaro
Site Admin
Site Admin
Posts: 35622
Joined: Wed May 23, 2007 3:43 pm
Location: green
Contact:

Re: Programming, computers, etc. [Serious]

Post by atomtengeralattjaro » Wed Jul 11, 2012 7:32 pm

um..? why don't you just add the mob to the list right after creating it?

Code: Select all

public void LoadCreatures()
        {
            Creature crRat = new Creature(10, 3, 2, 5, "Rat", "A small rodent.", 'r', ConsoleColor.Gray);
            moblist.Add(crRat);
        }  
or, more simply:

Code: Select all

public void LoadCreatures()
        {
            moblist.Add(new Creature(10, 3, 2, 5, "Rat", "A small rodent.", 'r', ConsoleColor.Gray));
        }  
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.
Ivokyuftaf6666 wrote:
Sun Oct 20, 2019 5:22 pm
Awesome Site, Delivering Fun
Image

User avatar
Arkannine
ASDF Warlord
ASDF Warlord
Posts: 15521
Joined: Tue Oct 28, 2008 9:21 pm
Location: I'm on a boat

Re: Programming, computers, etc. [Serious]

Post by Arkannine » Wed Jul 11, 2012 8:05 pm

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 :P

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.

User avatar
atomtengeralattjaro
Site Admin
Site Admin
Posts: 35622
Joined: Wed May 23, 2007 3:43 pm
Location: green
Contact:

Re: Programming, computers, etc. [Serious]

Post by atomtengeralattjaro » Wed Jul 11, 2012 9:56 pm

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:
I'd like to know if I can make it a Game member directly
in the code you've posted, it is already a member in Game:

Code: Select all

public class Game
    {
        Map world;
        public List<Mob> moblist = new List<Mob>();
(...)
(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.)
Ivokyuftaf6666 wrote:
Sun Oct 20, 2019 5:22 pm
Awesome Site, Delivering Fun
Image

User avatar
Arkannine
ASDF Warlord
ASDF Warlord
Posts: 15521
Joined: Tue Oct 28, 2008 9:21 pm
Location: I'm on a boat

Re: Programming, computers, etc. [Serious]

Post by Arkannine » Thu Jul 12, 2012 3:18 pm

Nevermind, I managed to get around it :P
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.

User avatar
atomtengeralattjaro
Site Admin
Site Admin
Posts: 35622
Joined: Wed May 23, 2007 3:43 pm
Location: green
Contact:

Re: Programming, computers, etc. [Serious]

Post by atomtengeralattjaro » Thu Jul 12, 2012 5:22 pm

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.
Ivokyuftaf6666 wrote:
Sun Oct 20, 2019 5:22 pm
Awesome Site, Delivering Fun
Image

User avatar
Arkannine
ASDF Warlord
ASDF Warlord
Posts: 15521
Joined: Tue Oct 28, 2008 9:21 pm
Location: I'm on a boat

Re: Programming, computers, etc. [Serious]

Post by Arkannine » Tue Jul 24, 2012 1:55 pm

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 :D
Attachments
Projects.rar
gotyay + source
(54.98 KiB) Downloaded 46 times
assdef wrote:I've seen a number of Cocks in my days.

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Tue Jul 24, 2012 5:44 pm

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:

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)
end
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
atomtengeralattjaro
Site Admin
Site Admin
Posts: 35622
Joined: Wed May 23, 2007 3:43 pm
Location: green
Contact:

Re: Programming, computers, etc. [Serious]

Post by atomtengeralattjaro » Tue Jul 31, 2012 7:06 pm

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 :P )

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.)
Ivokyuftaf6666 wrote:
Sun Oct 20, 2019 5:22 pm
Awesome Site, Delivering Fun
Image

User avatar
Anonymously Famous
JKL; Assassin
JKL; Assassin
Posts: 11413
Joined: Thu Mar 03, 2011 6:52 pm
Location: Area ???, under Bermuda Triangle

Re: Programming, computers, etc. [Serious]

Post by Anonymously Famous » Tue Jul 31, 2012 9:42 pm

Looks like you had some fun.
BOTTOM TEXT
ThingerDudes wrote:The only reasonable amount of Nutella is infinity. Everything else is too little.
Proud poster of the 300kth post in General

User avatar
Arkannine
ASDF Warlord
ASDF Warlord
Posts: 15521
Joined: Tue Oct 28, 2008 9:21 pm
Location: I'm on a boat

Re: Programming, computers, etc. [Serious]

Post by Arkannine » Wed Aug 01, 2012 1:28 pm

People just build libraries like it ain't a thing :P

But today I made my first real-ish game in xna, a shooter :D
Shootah.rar
featuring horrible programmer art!
(27.82 KiB) Downloaded 91 times
assdef wrote:I've seen a number of Cocks in my days.

Post Reply