From: "Sebastjan H." Date: 2012-07-14T04:10:56+09:00 Subject: Re: learning by doing part 2 - tc game Sebastjan H. wrote in post #1068570: > I've done quite some reprogramming according to the advises above and I > need help yet again. > > 1. I haven't uploaded the new files yet as google docs isn't really the > best solution for this. Which brings me to a sub-question: What > repository is best (I mean most user friendly for a beginner). I am > using Bazaar offline and I've had some difficulties using the Launchpad. > > 2. Launchpad requires me to state the license. If I have a project like > this (consisting of several files), where do I state the license and is > this entirely up to me as the author? > > 3. And for the big one: > > I am using a hash with beast names and types: > -------------------------------------------------------------------- > possible_cards = {"derimor" => "dragon", "barador" => "dragon", > "teragon" => "dragon", "gali" => "dragon", etc..... > > -------------------------------------------------------------------- > > I also get the user input for the number of each type: > > -------------------------------------------------------------------- > ## Select the number of dragons > def select_number_of_dragons() > puts "Select the number of dragons (max. 5)" > @dragons_qty = gets.chomp.to_i > if @dragons_qty < 1 or @dragons_qty > 5 > puts "The number of dragons is invalid. Enter a number between 1 and > 5." > return select_number_of_dragons() > end > return @dragons_qty > end > -------------------------------------------------------------------- > > Now I would like to have as many beasts/spells from the hash generated > as user specified. If dragon_qty is 4 then the first (or maybe also > random) 4 dragons from the hash are to be generated. > > I've tried the iterating with loop "for i in 0..dragon_qty" but that > actually multiplies each dragon by dragon_qty:( > > thank you. > > kind regards, > seba I've also tried something with until: ------------------------------------------------------------------- begin possible_cards.each do |name, type| if type == "dragon" deck_dragons << name end end end until deck_dragons.length.to_i == @dragons_qty.to_i ------------------------------------------------------------------- ... but it doesn't work either -- Posted via http://www.ruby-forum.com/.