Class: Player

Inherits:
Object
  • Object
show all
Includes:
CryptoCalculator::InstanceMethods, FancyText::InstanceMethods
Defined in:
lib/app/player.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = "", balance = 10000, entry_date = "", past_crypto_list = [], crypto_invested = [], exit_date = "", exited_crypto_data = []) ⇒ Player

Returns a new instance of Player.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/app/player.rb', line 18

def initialize name="", balance = 10000, ="", past_crypto_list=[], crypto_invested=[], exit_date="", exited_crypto_data = []
    @name = name 
    @balance = balance
    @entry_date = 
    @past_crypto_list = past_crypto_list
    @crypto_invested = crypto_invested
    @exit_date = exit_date
    @exited_crypto_data = exited_crypto_data
    @total_balance = total_balance
    save
end

Instance Attribute Details

#balanceObject

Returns the value of attribute balance.



15
16
17
# File 'lib/app/player.rb', line 15

def balance
  @balance
end

#crypto_investedObject

Returns the value of attribute crypto_invested.



15
16
17
# File 'lib/app/player.rb', line 15

def crypto_invested
  @crypto_invested
end

#entry_dateObject

Returns the value of attribute entry_date.



15
16
17
# File 'lib/app/player.rb', line 15

def 
  @entry_date
end

#exit_dateObject

Returns the value of attribute exit_date.



15
16
17
# File 'lib/app/player.rb', line 15

def exit_date
  @exit_date
end

#exited_crypto_dataObject

Returns the value of attribute exited_crypto_data.



15
16
17
# File 'lib/app/player.rb', line 15

def exited_crypto_data
  @exited_crypto_data
end

#nameObject

Returns the value of attribute name.



15
16
17
# File 'lib/app/player.rb', line 15

def name
  @name
end

#past_crypto_listObject

Returns the value of attribute past_crypto_list.



15
16
17
# File 'lib/app/player.rb', line 15

def past_crypto_list
  @past_crypto_list
end

#total_balanceObject

Returns the value of attribute total_balance.



15
16
17
# File 'lib/app/player.rb', line 15

def total_balance
  @total_balance
end

Class Method Details

.allObject



34
35
36
# File 'lib/app/player.rb', line 34

def self.all 
    @@all
end

Instance Method Details

#permission_to_pastObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/app/player.rb', line 67

def permission_to_past
    prompt = TTY::Prompt.new
    choices = {yes: 1, no: 2}
    permission = 
        prompt.select("
        Are You Sure You Want To Go Back To #{@entry_date}?", 
        choices)
    
    puts "\n"
    puts "\n"
    
    if permission == choices[:yes]
        progressbar("Travelling to The Past [:bar]", 
            "

        Successfully Travelled Back to #{@entry_date}!!")

        welcome_to_time_message(@entry_date, "make")
    else
        permission_to_past
    end  
end

#permission_to_scrapeObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/app/player.rb', line 90

def permission_to_scrape 
    prompt = TTY::Prompt.new
    choices = {learn: 1, proceed: 2}
    permission = 
        prompt.select("
        Do You Want To Learn About Any Currency Before Investing ?", 
        choices)

    puts "\n"
    puts "\n"
    

    if permission == choices[:learn]
        real_scrapping
        permission_to_scrape
    else
        InvestedCrypto.select_crypto_to_invest 
    end  
end

#real_scrappingObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/app/player.rb', line 110

def real_scrapping 
    prompt = TTY::Prompt.new
    scrapping_permission = 
        prompt.select("
        Please Select the CryptoCurrency You Want to Learn About: ", 
        SCRAPPING_CHOICES)

    puts "\n"
    puts "\n"

    Scrapper.send(scrapping_permission)
  

end

#saveObject



30
31
32
# File 'lib/app/player.rb', line 30

def save 
    @@all << self
end

#set_entry_dateObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/app/player.rb', line 44

def  
    pastel = Pastel.new
    prompt = TTY::Prompt.new

    random_year = 2018

    slow_motion(random_year)

    puts pastel.cyan.bold"

        The year selected is #{random_year}
        
        "

    entered_date = prompt.ask(
        " 
        Now, Please type any day in format DD-MM:") do |q|
        q.validate(/([0-2][0-9]|(3)[0-1])[-|\/](((0)[0-9])|((1)[0-2]))/, "Invalid Date Format. TRY AGAIN!" )
    end

    @entry_date = "#{entered_date}-#{random_year}"
end

#set_exit_dateObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/app/player.rb', line 125

def set_exit_date
    pastel = Pastel.new 
    prompt = TTY::Prompt.new

    @exit_date = 
        prompt.ask(
            "
            Please type any day after
        #{@entry_date} and before 31-12-2021 in format DD-MM-YYYY: ") do |q|
        q.validate(/([0-2][0-9]|(3)[0-1])[-|\/](((0)[0-9])|((1)[0-2]))[-|\/]\d{4}/, "Invalid Date Format. TRY AGAIN!" )
    end

    puts "\n"
    puts "\n"

    progressbar("Travelling Back To The Future [:bar]", 
            "

        Successfully Travelled Ahead to #{@exit_date}!!")
    
        welcome_to_time_message(@exit_date, "check on")
end

#set_nameObject



38
39
40
41
42
# File 'lib/app/player.rb', line 38

def set_name 
    prompt = TTY::Prompt.new
    @name = prompt.ask("
        Enter Your Player Name: ")
end

#total_balance_messageObject



148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/app/player.rb', line 148

def total_balance_message 
    pastel = Pastel.new
    type_writter("

        The 10,000 AUD you have invested  in #{@entry_date}
        has made the total balance of....

        ")
    slow_motion(pastel.green.bold("#{@total_balance}"))
    type_writter("
        AUD in #{@exit_date}.
        
        ")
end