21點遊戲,命令列的,面像過程的寫法。Ruby

來源:互聯網
上載者:User

標籤:ar   new   user   ad   rom   遊戲   ef   線程   

21點遊戲,命令列的,面像過程的寫法。
ruby 的寫法以後再試試。

# this is game 21 point# 操作命令符 空沒有操作,n下一步,抽牌;w亮牌結束;l認輸$ope = ''$prompt = '>'$x1 = 0$x2 = 0$x3 = 0$pc = 0$u1 = 0$u2 = 0$u3 = 0$over = ''def out_main(a = 0, b=0, c=0, pc = 0, us1=0, us2=0, us3=0)  puts "21 point Game          "  puts "        -- wide288 author"  puts  puts "  PC is keys           "  if pc == 0    puts "  *  *  *              "  else    puts "  %d  %d  %d              "% [a, b, c]  end  puts  puts "  user is keys         "  puts " %d %d %d              " % [us1, us2, us3]  puts Time.new  puts " n 抽牌; w 亮牌; l 認輸; x 退出;"end#主線程運行def main()  while $ope != 'x'    system 'clear'    out_main($x1, $x2, $x3, $pc, $u1, $u2, $u3)    if 'w' != $ope      print $prompt      $ope = STDIN.gets.chomp()    end    if 'x' == $ope      break    end    if 'l' == $ope      puts "I throw up."      break    end    if 'n' == $ope      number = rand(1..10)      if 0 != number        puts number        if $x1 == 0          $x1 = number        elsif $x2 == 0          $x2 = number        elsif $x3 == 0          $x3 = number        end      end      number = rand(1..9)      if 0 != number        puts number        if $u1 == 0          $u1 = number        elsif $u2 == 0          $u2 = number        elsif $u3 == 0          $u3 = number        end      end    end    if 'w' == $ope      #system "clear"      $pc = 1      pcsum = 21 - ($x1+$x2+$x3)      usersum = 21 - ($u1+$u2+$u3)      puts "%d %d %d pc sum is - 21 =  %d" % [$x1, $x2, $x3, pcsum]      puts "%d %d %d user sum is - 21 = %d" % [$u1, $u2, $u3, usersum]      if usersum >= pcsum        puts "pc win"      else        puts "User Win!!!"      end      #out_main($x1, $x2, $x3, $pc, $u1, $u2, $u3)      break    end  endend# main thread runmain()

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.