ios - Obj-C creating a battle scene? -
this has been problem me week figured i'd post here help. i'm still learning obj-c bear me. ill post code explain i'm trying do:
- (void) resetstats { self.herohplabel.text = [nsstring stringwithformat:@"0"]; self.heroatklabel.text = [nsstring stringwithformat:@"0"]; self.herodeflabel.text = [nsstring stringwithformat:@"0"]; self.herospdlabel.text = [nsstring stringwithformat:@"0"]; self.enemyhplabel.text = [nsstring stringwithformat:@"0"]; self.enemyatklabel.text = [nsstring stringwithformat:@"0"]; self.enemydeflabel.text = [nsstring stringwithformat:@"0"]; self.enemyspdlabel.text = [nsstring stringwithformat:@"0"]; } - (void) setherostats { self.herohplabel.text = [nsstring stringwithformat:@"%i", herohp]; self.heroatklabel.text = [nsstring stringwithformat:@"%i", heroatk]; self.herodeflabel.text = [nsstring stringwithformat:@"%i", herodef]; self.herospdlabel.text = [nsstring stringwithformat:@"%i", herospd]; } - (void) enemy1 { enemyhp = 100; enemyatk = 1; enemydef = 0; enemyspd = 5; int enemy1hp; enemy1hp = enemyhp; self.enemyhplabel.text = [nsstring stringwithformat:@"%i", enemyhp]; self.enemyatklabel.text = [nsstring stringwithformat:@"%i", enemyatk]; self.enemydeflabel.text = [nsstring stringwithformat:@"%i", enemydef]; self.enemyspdlabel.text = [nsstring stringwithformat:@"%i", enemyspd]; enemy1alive = yes; if (enemyhp <= 0) { nslog(@"the enemy dead"); [self resetstats]; } } - (ibaction)fight:(id)sender { if (battleactive == no) { self.fightoutlet.hidden = yes; [self setherostats]; [self enemy1]; battleactive = yes; if (herohp <= 0) { battleactive = no; self.fightoutlet.hidden = no; [self resetstats]; } } else if (battleactive == yes) useless = 0; }
so, explain mess. trying create simple "battle" scene in hero fight enemy 4 different stats. when press "battle button" (the fight action) labels on vc (don't have enough rep post image) update show stats of hero , enemy spawned hp, atk, def, spd.
what i'm trying make if enemy's health 0 or less enemy1 stop running , enemy2 called change of enemy stats accordingly (enemy2 hasn't been made yet because i'm stuck on next part) can't figure out make enemy take damage (for learning reasons , keeping simple i've made button take away 100 hp).
example because i'm confused writing this:
the user presses "battle" button
the stat labels updated accordingly
the user presses button deal damage enemy equal hero's attack minus enemy's defense.
when enemy's health <= 0 enemy stats updated stats of enemy2
this cycle continue until hero's health <=0 (after hero attacks enemy attack unless killed said attack) when hero dies stats reset "0" , can done again.
like said, i'm new , have been stuck on awhile apologize if simple do.
thanks
first should make question more specific, example: monster didn't disappear, game doesn't end etc. didn't read code, think should learn how use classes first instead of functions. **btw, code not working change text of label not actual value of instances ** also, function enemy never work reset enemy's hp every time call function. create class monster , class hero , @ least code can less messy , readable.
Comments
Post a Comment