Class: Kidomath

Inherits:
Object
  • Object
show all
Defined in:
lib/kidomath.rb

Class Method Summary collapse

Class Method Details

.ask(level = 1) ⇒ Object



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
# File 'lib/kidomath.rb', line 27

def self.ask(level=1)
  operations = ['+','-','*','/']
  case level
  when 1
    rand1 = 1 + rand(10)
    rand2 = 1 + rand(10)
    randop = operations[rand(operations.length)].chomp
    if rand1 > rand2
      res = rand1.send(randop,rand2)
      print "#{rand1} #{randop} #{rand2} = "
    else
          res = rand2.send(randop,rand1)
          print "#{rand2} #{randop} #{rand1} = "
    end
    kid_said = gets.to_i
    if res == kid_said
        print "Correct answer, here are the gems for you :) keep it up! "
        Cadbury.gems(res)
        print "\n"
    else
        puts "Sorry the anwser is #{res} :("
    end
  when 2
    rand1 = 1 + rand(100)
    rand2 = 1 + rand(100)
    randop = operations[rand(operations.length)].chomp
    res = rand1.send(randop,rand2)
    print "#{rand1} #{randop} #{rand2} = "
    kid_said = gets.to_i
    if res == kid_said
        print "Correct answer, here are the gems for you :) keep it up! "
        Cadbury.gems(10)
        print "\n"
    else
        puts "Sorry the anwser is #{res} :("
    end
   when 3
     rand1 = 1 + rand(200)
     rand2 = 1 + rand(200)
     randop = operations[rand(operations.length)].chomp
     res = rand1.send(randop,rand2)
     print "#{rand1} #{randop} #{rand2} = "
     kid_said = gets.to_i
     if res == kid_said
         print "Correct answer, here are the gems for you :) keep it up! "
         Cadbury.gems(10)
         print "\n"
     else
         puts "Sorry the anwser is #{res} :("
     end
  end
end

.levelObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/kidomath.rb', line 5

def self.level
 print <<'HEREDOC'
Welcome to kido math!.red
At which level are you in?
 1. Learner.
 2. Intermediate.
 3. Expert.

Please Enter your level : 
HEREDOC
self.parseopt()
end

.parseoptObject



18
19
20
21
22
23
24
25
# File 'lib/kidomath.rb', line 18

def self.parseopt
  choice = gets.chomp.to_i
  if (1..3) === choice
      choice
  else
          self.level()
  end
end

.startObject



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/kidomath.rb', line 80

def self.start
 level = self.level()
 self.ask(level)
 print "Want to play more? Type 'Yes or No' : "
 more = gets
 if more.chomp.casecmp("Yes") == 0
     self.start()
 else
     puts "Bye!!! :o)"
     exit
 end

end