-
Notifications
You must be signed in to change notification settings - Fork 0
/
interact.R
186 lines (151 loc) · 4.08 KB
/
interact.R
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#' Create a New Pet
#'
#' @description Generate and save a new pet's blueprint. The pet begins life as
#' an egg.
#'
#' @param pet_name Character. A name for the new tamRgo pet. Maximum eight
#' characters.
#'
#' @return Nothing.
#'
#' @export
#'
#' @examples \dontrun{lay_egg(name = "KEVIN")}
lay_egg <- function(pet_name) {
bp <- .create_blueprint(pet_name)
.write_blueprint(bp)
message("You have a new egg", appendLF = FALSE); Sys.sleep(1)
message(".", appendLF = FALSE); Sys.sleep(1)
message(".", appendLF = FALSE); Sys.sleep(1)
message(".", appendLF = FALSE); Sys.sleep(1)
message(" it hatched!", appendLF = FALSE)
message("\nSee its stats with get_stats()")
}
#' Print Your Pet's Stats
#'
#' @description Print to the console the characteristics, experience and status
#' of the current pet.
#'
#' @details The output will show the following elements of the blueprint:
#'
#' Section 'characteristics':
#' \describe{
#' \item{name}{Pet's user-provided name.}
#' \item{species}{Randomly-selected pet species.}
#' \item{born}{Date that the pet was created.}
#' \item{age}{Days since born.}
#' \item{level}{Growth stage.}
#' \item{xp}{Experience points.}
#' \item{happy}{Happiness on a scale of 0 to 5.}
#' \item{hungry}{Hunger on a scale of 0 to 5.}
#' \item{dirty}{Dirtiness on a scale of 0 to 5.}
#' }
#'
#' @return Nothing.
#'
#' @export
#'
#' @examples \dontrun{see_stats()}
get_stats <- function() {
bp <- .check_and_update()
message(
"Characteristics",
"\n Name: ", bp$characteristics$name,
"\n Species: ", bp$characteristics$species,
"\n Age: ", bp$characteristics$age,
"\n Level: ", bp$experience$level,
"\nStatus",
"\n Happy: ", rep("\U025A0", bp$status$happy), rep("\U025A1", 5 - bp$status$happy),
"\n Hungry: ", rep("\U025A0", bp$status$hungry), rep("\U025A1", 5 - bp$status$hungry),
"\n Dirty: ", rep("\U025A0", bp$status$dirty), rep("\U025A1", 5 - bp$status$dirty)
)
}
#' See Your Pet
#'
#' @description Print to the console an image of your pet.
#'
#' @return Nothing.
#'
#' @export
#'
#' @examples \dontrun{see_pet()}
see_pet <- function() {
bp <- .check_and_update()
pet_matrix <- .get_pet_matrix(
bp$characteristics$species,
bp$experience$level
)
.draw_pet(pet_matrix)
}
#' Play with Your Pet
#'
#' @description Increase 'happy' status value by 1 (max 5).
#'
#' @return Nothing.
#'
#' @export
#'
#' @examples \dontrun{play()}
play <- function() {
bp <- .check_and_update()
bp$status$happy <- min(bp$status$happy + 1L, 5L)
suppressMessages(.write_blueprint(bp, ask = FALSE))
message("'Happy' status value is now ", bp$status$happy, "/5")
}
#' Feed Your Pet
#'
#' @description Reduce 'hungry' status value by 1 (min 0).
#'
#' @return Nothing.
#'
#' @export
#'
#' @examples \dontrun{feed()}
feed <- function() {
bp <- .check_and_update()
bp$status$hungry <- max(bp$status$hungry - 1L, 0L)
suppressMessages(.write_blueprint(bp, ask = FALSE))
message("'Hungry' status value is now ", bp$status$hungry, "/5")
}
#' Clean Your Pet
#'
#' @description Reduces 'dirty' status value to 0.
#'
#' @return Nothing.
#'
#' @export
#'
#' @examples \dontrun{clean()}
clean <- function() {
bp <- .check_and_update()
bp$status$dirty <- 0L
suppressMessages(.write_blueprint(bp, ask = FALSE))
message("'Dirty' status value is now 0/5")
}
#' Release Your Pet
#'
#' @description Delete the current blueprint.
#'
#' @return Nothing.
#'
#' @export
#'
#' @examples \dontrun{see_stats()}
release <- function() {
bp <- .check_and_update()
answer_a <-
readline(paste0("Really release ", bp$characteristics$name, "? y/n: "))
if (substr(tolower(answer_a), 1, 1) == "y") {
answer_b <- readline("Are you sure? y/n: ")
if (substr(tolower(answer_b), 1, 1) == "y") {
file.remove(
file.path(tools::R_user_dir("tamRgo", which = "data"), "blueprint.rds")
)
message(bp$characteristics$name, " was set free!")
} else {
message(bp$characteristics$name, " was not released.")
}
} else {
message(bp$characteristics$name, " was not released.")
}
}