Hi there. I've been spending the last week or so with my first baby-steps in Objective-C. I'm not a complete novice to programming, but haven't programmed any serious stuff for almost 20 years (wow, how time flies!)
I'm quite new to the whole Object-oriented side of things and while I've seen the light when it comes to the usefulness though, but struggle with the following:
I've coded a small RPG-style fight between two Objects of the class "Robot". The actual fight is handled inside the object in a fight-method. This method receives a temp-copy of the opposing Robot-object.
Everything seemed to work fine and I decided to create a few "standard" Robots with different variabels for strength, armour, life-force etc.
(Not code, just example
robot1: strength= 100 armour=50 life-force=100
robot2: strength= 50 armour=100 life-force=100
Before initiating the fights my code simply copied each of these objects into my defined objects of the type Robot:
The above works fine as does the fight-method. However, when trying to initiate a fight between two robots of the same type things go awry.
While my understanding was that the above would simply copy the content from robot1 into the respective robots it seems both computerRobot and playerRobot actually becomes*robot1. (This is probably obvious to most of you, but not me).
So, when the computerRobot damages the playerRobot it receives the same damage itself (as does the original robot1 object).
----
Hopefully this make some sense and hopefully some of you geniuses will be able to inform me what basic concept I've missed along the way.
I'm quite new to the whole Object-oriented side of things and while I've seen the light when it comes to the usefulness though, but struggle with the following:
I've coded a small RPG-style fight between two Objects of the class "Robot". The actual fight is handled inside the object in a fight-method. This method receives a temp-copy of the opposing Robot-object.
Everything seemed to work fine and I decided to create a few "standard" Robots with different variabels for strength, armour, life-force etc.
(Not code, just example
robot1: strength= 100 armour=50 life-force=100
robot2: strength= 50 armour=100 life-force=100
Before initiating the fights my code simply copied each of these objects into my defined objects of the type Robot:
Code:
computerRobot = robot1;
playerRobot = robot2;
The above works fine as does the fight-method. However, when trying to initiate a fight between two robots of the same type things go awry.
Code:
computerRobot = robot1;
playerRobot = robot1;
While my understanding was that the above would simply copy the content from robot1 into the respective robots it seems both computerRobot and playerRobot actually becomes*robot1. (This is probably obvious to most of you, but not me).
So, when the computerRobot damages the playerRobot it receives the same damage itself (as does the original robot1 object).
----
Hopefully this make some sense and hopefully some of you geniuses will be able to inform me what basic concept I've missed along the way.