Eat. Sleep. Code: The Computer Programming Thread, Ver. 010

I believe a masters is pretty nice to have, an IT internship would probably be worthless experience, you’d prolly be better off getting a job as a test than that(and even that’s not great). Web design is probably slightly more useful assuming you are actually implementing the website and not just deciding where things go. Any sort of job/internship is useful in the way that it shows “hey this person is not retarded and can be trusted to do things” capacity.

looking good king come a long way since the beginning of the thread!

Any advice for getting code xp? I really want to get into a programming field.

Sent from my SPH-D700 using Tapatalk 2

If you’re new to programming, try this site: http://www.codecademy.com/

Congrats on getting stuff done. There is a submission process for the WP7 phone marketplace, and it takes about 2-3 days presuming nothing is wrong, so make sure you get it in a good deal before the 15th.

You might like scientific programming, such as:
www.sagemath.org

If I’m making a RPG in C++ and I want to have items (healing items, equipment, damage items, accessories, loot and so on) with several different parameters, what is the best way to implement that in code?

Do I do an individual .cpp and .h file for each item?
Do I make a map for each item type then fill it up with the variables that define them?
Do I do it through lists?

I mean I could probably do it with the first option, but that seems ridiculous and extremely inefficient on my time (though I honestly don’t know if it would run better that way).

Or, what is the best way to code for a large amount of staticly defined, similar objects that have different variables.

Make one super class and use that to instantiate all your items. Then have a separate class to manage them all. Alternatively (and probably the better route), you could learn how to use XML and use XML files to create all your items. All your code would have to do is read the files you give it.

eh, perhaps I should have been more specific. I have taken two classes in Java programming, and next semester I will be taking a Programming Languages course and AI course, while the following semester will be a data and file structures course, and then I’ll graduate. Yay me.

Is simply having these classes and a degree enough to get a job with hands on coding? Typically?

I get the jist of that, but I mean, as a more specific example, say I want to include swords. They’ll have six variables attached to them-- ATK, DEF, WEIGHT, SPEED, CRIT – and I want 100 different types of swords (wooden sword, iron sword, gold sword) with their own static stats.

In the code, where would I store the values for each of the individual weapons to be retrieved when a sword comes into existence?

My experience so far is very basic from online tutorials and the C++ for dummies. XML might be useful, but I refuse to believe that that would be the default option for managing something like this.

I’m looking at some of my old code from last year where I made a RPG combat system. What I did is I made a super class called Item, and then had subclasses for each item type (Weapon, Armor). In my Main class, I created an array of pointers for each item type (e.g. Weapon* pWeapon[]). I defined all of the items in Main as well. I put all of the definitions in a function so that I can just call the function in main().

Example of what I did

Spoiler

Item class



/* Item.h
Class that can be used to create all types of items. */
 
#include <string>
using namespace std;
 
#ifndef ITEM_H
#define ITEM_H
 
//item effect ID's
#define NONE  -1
#define RESTORE_HP  0
#define RESTORE_MP  1
#define ALTER_ATP  2
#define ALTER_MAG  3
#define AILMENT_POISON4
 
class Item
{
 
public:
Item();
virtual ~Item() {};
void virtual UseEffect(int effectID);//the item's ability when used
void virtual SetDetail(string detail) { m_Detail = detail; }//returns description
string GetDetail(){ return m_Detail; }
int GetPrice(){ return m_Price; }//Price
void SetPrice(int price){ m_Price = price; }
void SetName(string name){ m_Name = name; }
string GetName(){ return m_Name; }
int GetQty(){ return m_Qty; }//quantity
int GetID(){ return m_ID; }
void SetID(int ID){ m_ID = ID; }
//void ItemDB();//contains items
protected:
string m_Name;
string m_Detail;//item description
int m_Price;
int m_Qty;//item quantity
int m_ID;//ID# of item's effects
 
 
};
#endif


Weapon class



/* Weapon.h
Items that consists of weapons. Deals damage to enemies.*/
 
#include "Item.h"
 
#ifndef WEAPON_H
#define WEAPON_H
 
class Weapon : public Item
{
public:
Weapon(string name, int ATP, int MAG, int price, int effectID = -1);
virtual ~Weapon() {};
//void virtual UseEffect(int effectID);//the item's ability when used (if applicable)
int GetATP(){ return m_ATP; }//returns total attack power
void SetATP(int amount){ m_ATP = amount; }//sets ATP + equipped weapon + misc. bonuses
 
int GetMAG(){ return m_MAG; }//returns total magic power
void SetMAG(int amount){ m_MAG = amount; }//sets MAG + equipped weapon + misc. bonuses
 
int GetRES(){ return m_RES; }//returns total resistance
void SetRES(int amount){ m_RES = amount; }//sets RES + equipped armor + misc. bonuses
 
int GetDFP(){ return m_DFP; }//returns total Defense Power
void SetDFP(int amount){ m_DFP = amount; }//sets DFP + armor bonus + misc.
 
int GetSPD(){ return m_SPD; }//returns total Speed
void SetSPD(int amount){ m_SPD = amount; }//sets SPD + misc.
protected:
int m_ATP;
int m_DFP;
int m_SPD;
int m_MAG;
int m_RES;
};
#endif


Main



 
const int MAX_ITEMS = 10;
Weapon* pWeapon[MAX_ITEMS];
Armor* pArmor[MAX_ITEMS];
 
void ItemDB()
{
//Weapon(string name, int ATP, int MAG, int price, int effectID)
pWeapon[0] = new Weapon("Light Blade", 20, 0, 200);
pWeapon[1] = new Weapon("Falcon Axe", 35, 0, 700);
pWeapon[2] = new Weapon("Taser Knuckles", 49, 0, 1600);
pWeapon[3] = new Weapon("Handgun", 15, 0, 200);
pWeapon[4] = new Weapon("Laser", 27, 0, 650);
pWeapon[5] = new Weapon("Snipe King", 36, 0, 1160);
pWeapon[6] = new Weapon("Techer's Staff", 10, 15, 200);
pWeapon[7] = new Weapon("Stardust Rod", 20, 40, 500);
pWeapon[8] = new Weapon("Staff of Ages", 25, 60, 900);
 
//Special weapon with poison effect
pWeapon[9] = new Weapon("Dirty Shank", 20, 0, 2500, AILMENT_POISON);
 
//Armor(string name, int DFP, int RES, int price, int effectID = -1)
pArmor[0] = new Armor("Rookie's Jacket", 5, 0, 200);
pArmor[1] = new Armor("Techer's Robe", 5, 10, 200);
pArmor[2] = new Armor("Hunter's Vest", 12, 4, 800);
pArmor[3] = new Armor("Master Mage Cowl", 15, 25, 200);
 
//special armor; heals wearer every turn
pArmor[4] = new Armor("Bio-Suit", 30, 20, 200);
 
}


If you’re going to be making a lot of items, I would try to create some kind of editor to make things easier.

Yesssssss, the part from the last section was what I was looking for.

The core of ‘programming’ is in the design. This requires understanding of the big O notation, eg, O(n) versus O(n^2) versus O(log n). More Math == more intelligence. The fact is, most people can easily understand this, it’s just a matter of wrapping your head around graphs in cartesian coordinates as a point of comparison.

Real world algorithm design is a trade off between the time you have and the efficiency you know you can obtain. A lot of times you want to be able to know what you want, and then it’s only a matter of finding out if it’s feasible. The other half is being able to debug very large projects efficiently and effectively. This requires an analysis of all sorts of potential problems, from thread dependencies, to memory management, to infinite loops, but it all boils down to being efficient with the tools you are familiar with. For instance Java, I am familiar with Eclipse and I can debug multi threaded and multi-process software in parallel. It’s just a matter of being knowledgeable about your particular problem and then working hard to figure it out. From what I can see, if you got lost on, ‘what is Big O,’ then you’ll have some reading to do. But it also depends on what you’re doing.

Depending on the type of work you’re doing, you’ll have a leg up on a lot of ‘system’ or ‘research’ engineers because you can program more effectively than they can, but they may have more physical system dependent knowledge in their grasp.

My prog II course explained big oh.

So basically, it sounds like your saying I need xp to get a job, while I don’t really have the xp yet?

Sent from my SPH-D700 using Tapatalk 2

while not xml specifically(though it is VERY common), having things defined in some sort of arbitrary file and then loaded in is basically the default way to do something like items. You seem 'em all the time, .ini files are really common and often where they are stored. The advantage to this is that you can change items without recompiling, you can create/edit items and save them off to be loaded in later, and people who can’t code can edit them much better.

you should be able to find something eventually, but not having xp is a HUGE handicap(which is why I recommend getting internships if at all possible), knowing people also makes it much easier. The most important thing you can do if you don’t have experience is to make GOOD samples of non trivial problems. Either implementing hard algorithms, designing your own algorithm, making you rown architecture etc…

You do have experience from your courses. Internships are the correct answer to getting more experience. Just have some confidence and keep trying, you will find something.

From your courses you can find non-trivial projects which you find fun to explain and talk about. Part of an interview should be explaining some prior work, as many engineers and scientists spend a lot of time making presentation slides, it’s good to be prepared with a good example. It is tedious, but it doesn’t take that long and shows you are willing to do such work.

Some examples from some of my courses:

  1. Parallel processing examples using SIMD and/or MIMD computers to solve well known algorithms in different ways. I think it’s really interesting to find the limitations and potential speed ups of parallel algorithms in a very rigorous way. This one was in C/MPI and assembly.
  2. From Graph Theory class, our Professor came up with a game to keep a complicated system of ‘pipes’ flowing. It was a very simple underlying algorithm at each step, e.g. O(n^3), but there were a lot of pipes and you had a time limit to respond. The limits are like a real world, dynamic control system problem, and show how I can handle constrained work. This one was in Python.
  3. From AI class, we made agents to compete against each other in competitive games about once every two weeks. I would definitely find that fun to explain how I kicked almost everyone else’s ass at every game. Also, it was in LISP which I had never used before or since ;p.

Thanks dude.

Sent from my SPH-D700 using Tapatalk 2

How bad would it be if Sun wins this?

So, I’m learning Xcode at work. Things were going smoothly up until now.

I have a screen with different images, and I want to be able to move them individually. The problem is, I want to call the touch events from the images’ own class, and not the class I’ve instantiated them in. The two classes are HelloViewController and SpriteViewController. In HelloViewController, I made a mutable array of SpriteViewControllers, which are the images to be moved. In both classes, I have a touchesEnded() method; the method in HelloViewController works, but not the one in SpriteViewController. I’m thinking that I have to override the method, and I thought it was done using the “super” keyword in the sprite class, but I have the same problem. I tried removing the methods in the Hello class, but that didn’t work. This doesn’t appear to be as straightforward as it is in other C languages. Can anyone help with this?

tl;dr: I have two methods called touchesEnded(), each one in their own class. Can call one but not the other. Help?

I don’t know xcode, but typically theres some sort of event.preventDefault() or similar that lets the system know you’ve handled the event and not to bubble it up further on the handling chain

Super just calls the same named method of the parent class doesn’t it? So if you’re calling super, you’re calling that other function specifically?

Yeah, I think I might’ve misunderstood how super works, and forgot how overriding works, apparently. I managed to get everything to work, but maybe I was wrong on how touch events work? I was under the impression that once you have a touchesMoved/touchesBegan/touchesEnded method somewhere in your code, you didn’t have to call it explicitly and it was basically always on. It worked that way for the one class, but not for the other one.