repl.it
@Zavexeon/

Rock Paper Scissors!

Ruby

No description

fork
loading
Files
  • main.rb
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
##
#Created by a Zavexeon
#inspired by davidpython3's game, which is coded in Python 3
#Keep in mind the computer makes it's choice first

def clear
  def send_msg(msg)
    $stdout.__orig_write(JSON.dump(msg) + "\n")
  end

  def clear()
    send_msg({"command": "clearConsole"})
  end
  sleep 0.1
  clear
end

cheat = 0
#colors for text
class String
  def green; "\e[32m#{self}\e[0m" end
  def red; "\e[31m#{self}\e[0m" end
  def brown; "\e[33m#{self}\e[0m" end
  def cyan; "\e[36m#{self}\e[0m" end
  def magenta; "\e[35m#{self}\e[0m" end
  def blue; "\e[34m#{self}\e[0m" end
  def italic; "\e[3m#{self}\e[23m" end
  def underline; "\e[4m#{self}\e[25m" end
  def blink; "\e[5m#{self}\e[25m" end
  def reverse_color; "\e[7m#{self}\e[27m" end
end

puts "Rock Paper Scissors!
".italic.blink
puts "Created by #{"Zavexeon".magenta}.
"

puts "
#{"Instructions:".underline.blue} 
Type in the option you would like to throw! If it is mispelled or is not a valid option it will take you to the next game, no penalty! 

Press enter to play!"

gets

wrecord = 0
lrecord = 0
trecord = 0
gnumber = 1
cheaton = ""
punc = "!"

loop do
  sleep(1)

  rock = "rock"
  paper = "paper"
  scissors = "scissors"

  #chooses computers choice
  com = [rock, paper, scissors].sample

  if cheat + 1 == 2
    puts "
    Cheat: The computer will choose #{com.cyan}."
    cheaton = ", you wascally wabbit"
    punc = "?"
  end

  won = "---------
You won#{punc}
---------".green

  lost = "---------
You lost!
---------".red

clear
  print "
Game ##{gnumber}
Type in rock, paper, or scissors#{cheaton}:"

  #gets human input
  human = gets.chomp.downcase

  if human == "kyleisawesome"
    cheat = 1
  end

  if human == com
    puts "---------
You tied!
---------".brown
    trecord += 1
  elsif human == "rock"
    if com == "scissors"
      puts won
      wrecord += 1
    else
      puts lost
      lrecord += 1
    end
  elsif human == "paper"
    if com == "rock"
      puts won
      wrecord += 1
    else
      puts lost
      lrecord += 1
    end
  elsif human == "scissors"
    if com == "paper"
      puts won
      wrecord += 1
    else
      puts lost
      lrecord += 1
    end
  end
  puts "The computer chose #{com.cyan}.
  "
  puts "You have won #{wrecord} times!".green
  puts "You have lost #{lrecord} times!".red
  puts "You have tied #{trecord} times!".brown
  
  puts "\nPress enter to continue!"
  gets
  gnumber += 1
end
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]