• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • It's time to vote for your favorite Pokémon Battle Revolution protagonist in our new weekly protagonist poll! Click here to cast your vote and let us know which PBR protagonist you like most.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Minigame BlackJack

  • 32
    Posts
    5
    Years
    • Seen today
    Hi this is my version of the game BlackJack, the next version i Try to make a graphics

    Code:
    def blackJack
    
      if Kernel.pbConfirmMessage(_INTL("Quieres probar suerte"))
        if $Trainer.money>0
      params=ChooseNumberParams.new
      params.setMaxDigits(9)
      params.setRange(1,$Trainer.money) 
      params.setInitialValue($Trainer.money) 
      params.setCancelValue(0)
      qty=Kernel.pbMessageChooseNumber(_INTL("Cuanto deseas apostar?"),params) 
        num=rand(14)+1
        numo=rand(21)+1
        Kernel.pbMessage(_INTL("Tu numero es {1}",num))
        
    if Kernel.pbConfirmMessage(_INTL("Quieres otra carta"))
      numot=rand(14)+1
      num=num+numot
      Kernel.pbMessage(_INTL("Tienes un total de {1}",num))
      if num>21
        Kernel.pbMessage(_INTL("Lamentablemente perdiste porque excediste el numero asi que vuelve a intentarlo"))
      else
        num=num
        end
    else
      Kernel.pbMessage(_INTL("Obtuviste {1}",num)) 
    end
    
    if num>numo
        Kernel.pbMessage(_INTL("Obtuviste {1} y tu adversario {2} has ganado",num,numo))
      $Trainer.money=$Trainer.money+qty*2
    
      elsif num==numo
      Kernel.pbMessage(_INTL("Obtuviste {1} y tu adversario {2} ha sido empate",num,numo))
    
       else
        Kernel.pbMessage(_INTL("Obtuviste {1} y tu adversario {2}",num,numo))
      $Trainer.money=$Trainer.money-qty
      
    end
    
    else
        Kernel.pbMessage(_INTL("No tienes dinero necesitas al menos 1 "))
        end
    else
      Kernel.pbMessage(_INTL("Esta bien cuando lo decidas vuelve a hablar conmigo"))
    end
    
    end
     
    English:
    Code:
    def blackJack
    
      if Kernel.pbConfirmMessage(_INTL("Do you want to try your luck?"))
        if $Trainer.money>0
      params=ChooseNumberParams.new
      params.setMaxDigits(9)
      params.setRange(1,$Trainer.money) 
      params.setInitialValue($Trainer.money) 
      params.setCancelValue(0)
      qty=Kernel.pbMessageChooseNumber(_INTL("How much do you want to bet?"),params) 
        num=rand(14)+1
        numo=rand(21)+1
        Kernel.pbMessage(_INTL("Your number is{1}",num))
        
    if Kernel.pbConfirmMessage(_INTL("Do you want another card?"))
      numot=rand(14)+1
      num=num+numot
      Kernel.pbMessage(_INTL("You have a total of {1}",num))
      if num>21
        Kernel.pbMessage(_INTL("Bust!"))
      else
        num=num
        end
    else
      Kernel.pbMessage(_INTL("You got {1}",num)) 
    end
    
    if num>numo
        Kernel.pbMessage(_INTL("You got {1}. Your opponent got {2}. You won!",num,numo))
      $Trainer.money=$Trainer.money+qty*2
    
      elsif num==numo
      Kernel.pbMessage(_INTL("You got {1}. Your opponent got {2}. Draw!",num,numo))
    
       else
        Kernel.pbMessage(_INTL("You got {1}. Your opponent got {2}.",num,numo))
      $Trainer.money=$Trainer.money-qty
      
    end
    
    else
        Kernel.pbMessage(_INTL("You don't have enough money!"))
        end
    else
      Kernel.pbMessage(_INTL("Talk to me if you ever want to play"))
    end
    
    end
     
    Last edited:
    It's a cool feature, I hope to see graphics soon! :)

    Some comments on the code itself:
    Code:
        num=rand(14)+1
        numo=rand(21)+1
      numot=rand(14)+1
    I think these generates the value of two and three cards? But the distribution is wrong, dealing 2 or 3 cards doesn't give a uniform distribution in the range 1..14 or 1..21. You can see this if you consider a six-sided dice, 7 is more likely than 2, because there's 1+6, 2+5, 3+4, 4+3, 5+2, 6+1, so 6 ways to get a 7, but only 1+1 to get 2.

    This line does nothing, because num is already equal to num (by definition!):
    Code:
        num=num

    And other than that, I think you should try to indent things better. I'd expect to see matching if/elsif/else/end with the same amount of whitespace to the left, and the code inside with more whitespace (in fact, this example should have whitespace to the left of everything, because it's inside a def, and inside some ifs too). For example:
    Code:
    if num>numo
      Kernel.pbMessage(_INTL("You got {1}. Your opponent got {2}. You won!",num,numo))
      $Trainer.money=$Trainer.money+qty*2
    elsif num==numo
      Kernel.pbMessage(_INTL("You got {1}. Your opponent got {2}. Draw!",num,numo))
    else
      Kernel.pbMessage(_INTL("You got {1}. Your opponent got {2}.",num,numo))
      $Trainer.money=$Trainer.money-qty
    end
     
    Back
    Top