frankcollins3 / fcc-mcsft-cSharp

FreeCodeCamp & Microsoft C# course:
1 stars 0 forks source link

cleaning game logic up: [9:17am] #13

Closed frankcollins3 closed 1 year ago

frankcollins3 commented 1 year ago

attempting to do: game solved [x]; game makes 100% sense[];

error: Screen Shot 2023-09-08 at 9 05 33 AM this above problem ^ was solved with this below approach v with a condition that checks if health isn't zero yet: Screen Shot 2023-09-08 at 9 15 10 AM

new err since fixing that error of monster coming back from dead for final attack (which seems gamey in itself anyways): the monsters health bar is down to: 👎 -5 after being hit for: 6 // health went from 1 to - 5 which should be 1 to 0 Screen Shot 2023-09-08 at 9 11 04 AM

proposed approach: something like this that ternary: truthy declares the new health to be 0 if the health went below zero falsy performs the attack as it originally did which works as intended by decrementing healthbar by randomly generated val

Screen Shot 2023-09-08 at 9 16 53 AM

frankcollins3 commented 1 year ago

ternary value: monsterHealth = (monsterHealth -= attackStr < 0) ? 0 : -= attackStr;

looks like -= cant be used in that comparison expression: Screen Shot 2023-09-08 at 9 19 50 AM [9:20am]

frankcollins3 commented 1 year ago

was pretty close. chatGPT showed me that the falsy block must redeclare the original expression. Screen Shot 2023-09-08 at 9 25 00 AM

I believe what I was trying to do would've worked in JS/JSX-react-code

Screen Shot 2023-09-08 at 9 25 16 AM

the monsters health bar is down to: 2 after being hit for: 4 👍 the monsters health bar is down to: 0 after being hit for: 6 // 2 doesn't become - 4 👍 the hero is not attacked after the monster is dead [9:26am]

frankcollins3 commented 1 year ago

their answer: Screen Shot 2023-09-08 at 9 28 13 AM

my answer: Screen Shot 2023-09-08 at 9 28 33 AM [9:29am]