loopConfused's Profile User Rating: -----

Reputation: 2 Apprentice
Group:
New Members
Active Posts:
10 (0.02 per day)
Joined:
18-January 13
Profile Views:
993
Last Active:
User is offline Feb 05 2013 09:35 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   loopConfused has not set their status

Posts I've Made

  1. In Topic: Histogram random number

    Posted 4 Feb 2013

    This is what I have so far. But Is there a way I can order these in 1-10 all the way up to 91-100 doing an if statement?
    Please and thanks for the understanding.
    histogram = array.new(10, 0)
    for i in 1..200
      num = 1 + rand(100)
      histogram[(num/10).ceil-1]+= 1
      end
    puts "Range #    " + "Found    " + "Chart"
    
  2. In Topic: Rock, paper, sicssiors game assistance

    Posted 29 Jan 2013

    update found my error.
  3. In Topic: Rock, paper, sicssiors game assistance

    Posted 29 Jan 2013

    Here is the new code that I've been working on.
    puts "Would you like to play a Game?"
      puts "Yes/No"
      puts "If you want to quit the game at anytime just type quit."
        player_input = gets.chomp.downcase
        #
         while true #loops forever
    
          if player_input == 'yes'
            puts "Welcome to Rock, Paper, Scissors!"
            puts "Press r for Rock"
            puts "Press s for Scissors"
            puts "Press p for Paper"
            computer = "rsp"[rand(3)].chr
            player = gets.chomp.downcase
            case [player, computer]
              when ['p','r'], ['s','p'], ['r','s']
                puts "You Win!";
              when ['r','r'], ['s','s'], ['p','p']
                puts "You Tied!";
              else
                puts "You Lose!";
            end
            puts "The computer chose: #{computer.upcase}"
          else player_input == "no"
          puts "You no come play. :(/>"
            exit
          end
          break if player_input = "quit"
         end
    

    The problem I'm having is make the loop exit. I have tried
    [code}break if user_input == quit
    #and
    while user_input != "quit"
    #and
    [/code]
  4. In Topic: Rock, paper, sicssiors game assistance

    Posted 29 Jan 2013

    So this is what my code looks like right now, but I can not play the game. what is missing from it.
    puts "Would you like to play a Game?"
    puts "Yes/No"
    
    player_input = gets.chomp.downcase
    
    class  RockPaperScissors
      def play_round
        while true
          game.play_round
          if player_input == 'yes'
            puts "Welcome to Rock, Paper, Scissors!"
            puts "Press r for Rock"
            puts "Press s for Scissors"
            puts "Press p for Paper"
            computer = "rsp"[rand(3)].chr
            player = $stdin.gets.chomp.downcase
            case [player, computer]
              when ['p','r'], ['s','p'], ['r','s']
                puts "You Win!"
              when ['r','r'], ['s','s'], ['p','p']
                puts "You Tied!"
              else
                puts "You Lose!"
            end
            puts "The computer chose: #{computer.upcase}"
    
          else player_input = "no"
          puts "You no come play. :(/>"
          end
        end
      end
    end
    
    
  5. In Topic: Rock, paper, sicssiors game assistance

    Posted 29 Jan 2013

    [quote name='NotarySojac' date='28 January 2013 - 02:10 PM' timestamp='1359407416' post='1792350']

    View PostloopConfused, on 28 January 2013 - 12:33 PM, said:

    for the x amount of times a player can play I should have said infinite amount of time until the player tells the game that they want to quite. sorry for the miss typing


    Here's the absolute cheapest way to terminate the console game:

    1) Tell the player at the start of the game "Type QUIT at anytime to exit"
    2) Add a condition where you do STDIN.gets to look for "QUIT" and terminate the application upon finding that code.

    But, before you do that, think about wrapping all your code into a class so it can be instantiated as an object (or atleast wrap it up into a method so you can loop over it multiple times cleanly, with out having to worry about introducing another layer of nest`age).

    Martyr2 is suggesting that the top level of your code could look like this (which is so nice to look at):
    game = RockPaperScissors.new
    
    while true # loops forever
      game.play_round
    end
    
    


    how would this look like or what would I put into it?

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

loopConfused hasn't added any friends yet.

Comments

loopConfused has no profile comments yet. Why not say hello?