21: Point game, command line, and face image process. Ruby
Source: Internet
Author: User
Blackjack game, command line, face image process.
Try ruby in the future.
# this is game 21 point
# Operation command symbol No operation, n next step, draw cards; w show card ends;
$ 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 draw cards; w show cards; l admit defeat; x quit;"
end
#Main thread running
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
end
end
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.