From: "Sebastjan H." Date: 2012-07-18T21:02:06+09:00 Subject: Re: learning by doing part 2 - tc game I need (hopefully) one final help for this game:) I am trying to program the battle turn and I just wanted to know whether there is any better or more elegant solution other than branching so much: ------------------------------------------------------------- ## Here it needs to branch according to card attributes: spells don't have attacks. if card.type == "armor_spell" player_hp = player_hp + card.armor elsif card.type == "healing_spell" player_hp = player_hp + card.heal elsif card.type == "debuff_spell" if ai_card.type == "dragon" or ai_card.type == "dire wolf" ai_card.attack = ai_card.attack - card.debuff end elsif card.type == "dragon" or card.type == "dire wolf" if ai_card.type == "dragon" or ai_card.type == "dire wolf" player_hp = player_hp + card.armor - ai_card.attack puts "#{ai_card.name} strikes with " + ai_card.attack.to_s puts "\n" end if ai_card.type == "armor_spell" ai_hp = ai_hp + ai_card.armor elsif ai_card.type == "healing_spell" ai_hp = ai_hp + ai_card.heal elsif ai_card.type == "debuff_spell" if card.type == "dragon" or card.type == "dire wolf" card.attack = card.attack - ai_card.debuff end elsif ai_card.type == "dragon" or ai_card.type == "dire wolf" ai_hp = ai_hp + ai_card.armor - card.attack puts "#{card.name} strikes with: " + card.attack.to_s end @deck.delete(card) @ai_deck.delete(ai_card) puts "Player health is #{player_hp}." puts "Ai health is #{ai_hp}." ------------------------------------------------------------- thank you very much. Best regards, seba -- Posted via http://www.ruby-forum.com/.