Skip to content

Commit

Permalink
Add riddles to 1st floor rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
Giora Simchoni committed Sep 6, 2017
1 parent b1c0934 commit 289c444
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 22 deletions.
4 changes: 2 additions & 2 deletions R/classes.R
Expand Up @@ -283,8 +283,8 @@ DarkRoom <- R6::R6Class("DarkRoom",

gameStartScenario <- function() {
message("Welcome to the Castle of R!")
message("\nCastle of R is a text-based adventure.\n\nThe purpose of this game is to test your skills in base R. Let's begin.")
message("\n\nYou're in the Castle lounge, 1st floor.\nYou're sitting in front of Lady R, an elderly and pleasant woman, who is the owner of the Castle of R.\nBehind you there's a window with a lovely view to the gardens of the Castle of R.\nIn front of you, over Lady R's shoulder, you can see a door.")
message("\nCastle of R is a text-based adventure, based on the canonical 'An Introduction to R' book, by Venables, Smith and the R Core Team.\n\nThe purpose of this game is to test your skills in base R. Let's begin.")
message("\n\nYou're in the Castle lounge, 1st floor.\nYou're sitting in front of Lady R, an elderly and pleasant woman, who is the owner of the Castle of R.\nBehind you there's a window with a lovely view to the gardens of the Castle of R.\nIn front of you, over Lady R's shoulder, you can see a door, towards the north.")
message("Lady R is asking for your name.")
playerName <- readline()
message(paste0("\"Pleased to meet you ", playerName, ". Would like some tea?\""))
Expand Down
1 change: 0 additions & 1 deletion R/react.R
Expand Up @@ -69,7 +69,6 @@ react <- function(game, ...){
game$mode <- "door"
game$riddle <- game$currentRoom$door[[game$door_idx]]$getRiddle(game$currentRoom$name)
if (!is.na(game$riddle$prepare)) {
cat(game$riddle$prepare)
eval(parse(text = game$riddle$prepare))
}
game$riddle$askQuestion()
Expand Down
14 changes: 7 additions & 7 deletions inst/extdata/CastleOfR_Doors.txt
@@ -1,11 +1,11 @@
name direction_1to2 room1 room2 question1 solution1 val1 hint1 prepare1 cleanup1 question2 solution2 val2 hint2 prepare2 cleanup2
d_lounge_intro north lounge intro What is 2 to the power of ((555 / 444 * 333 + (222 - 111))*4 - 2103)? (Use R!) 2 ^ ((555 / 444 * 333 + (222 - 111))*4 - 2103) 64 2 ^ 3 = 8 NA NA Ask for help on the solution() function using help() function. help(solution) NA ?help NA NA
d_intro_simple east intro simple A variable named x has been defined in your workspace. Please remove it. rm(x) NA rm "x <<- ""a""" "tryCatch(rm(x, envir = globalenv()), warning = function(w) {invisible()})" what is 1 + 1? 1+1 2 two� NA NA
d_simple_objectsRoom east simple objectsRoom what is 0 + 0? 0+0 0 zero� NA NA what is 1 + 1? 1+1 2 two� NA NA
d_simple_darkRoom1 south simple darkRoom1 what is 0 + 0? 0+0 0 zero� NA NA NA NA NA NA NA NA
d_objectsRoom_factors south objectsRoom factors what is 0 + 0? 0+0 0 zero� NA NA what is 1 + 1? 1+1 2 two� NA NA
d_factors_darkRoom1 west factors darkRoom1 what is 0 + 0? 0+0 0 zero� NA NA NA NA NA NA NA NA
d_factors_arrays up factors arrays what is 0 + 0? 0+0 0 zero� NA NA what is 1 + 1? 1+1 2 two� NA NA
d_lounge_intro north lounge intro "What is [2 to the power of 3], times [10 minus 2]? (Use R!)" (2 ^ 3) * (10 - 2) 64 2 ^ 3 = 8 NA NA Ask for help on the solution() function using help() function. help(solution) NA ?help NA NA
d_intro_simple east intro simple A variable named x has been defined in your workspace. Please remove it. rm(x) NA rm "x <<- ""a""" "tryCatch(rm(x, envir = globalenv()), warning = function(w) {invisible()})" "Create the sequence [2, 4, 6, 8, 10, 12, 14, 16, 18, 20] without typing all elements." "seq(2, 20, 2)" NA ?seq NA NA
d_simple_objectsRoom east simple objectsRoom A vector named x has been defined in your workspace. Put a missing value in the 2nd element of x. x[2] <- NA NA ?`NA` x <<- 1:5 "tryCatch(rm(x, envir = globalenv()), warning = function(w) {invisible()})" What is the class of variable DF? class(DF) NA The answer is in the question. "DF <<- data.frame(x = 1:3, y = 4:6)" "tryCatch(rm(DF, envir = globalenv()), warning = function(w) {invisible()})"
d_simple_darkRoom1 south simple darkRoom1 "Concatenate the strings ""tea"" and ""cup"" using the paste0 function" "paste0(""tea"", ""cup"")" NA ?paste0 NA NA NA NA NA NA NA NA
d_objectsRoom_factors south objectsRoom factors How do you get the value of pi in R? pi NA You just did. NA NA Get the min and max of vector n with a single function. range(n) NA ?range "n <<- sample(1:10, 5)" "tryCatch(rm(n, envir = globalenv()), warning = function(w) {invisible()})"
d_factors_darkRoom1 west factors darkRoom1 "Turn the character vector a into a factor. Assign it to variable b. Don't use ""as""." b <- factor(a) NA The answer is in the question. "a <<- c(rep(""a"", 3), rep(""b"", 4), rep(""c"", 5))" "tryCatch(rm(a, b, envir = globalenv()), warning = function(w) {invisible()})" NA NA NA NA NA NA
d_factors_arrays up factors arrays The variable height holds the height of 10 men. The variable countries holds a factor representing in which country each man resides. Find the minimum height for each country. "tapply(height, countries, min)" NA ?tapply "height <<- sample(160:200, 10); countries <<- gl(2, 5, labels = c(""Albania"", ""Turkey""))" "tryCatch(rm(height, countries, envir = globalenv()), warning = function(w) {invisible()})" what is 1 + 1? 1+1 2 two� NA NA
d_arrays_lists west arrays lists what is 0 + 0? 0+0 0 zero� NA NA what is 1 + 1? 1+1 2 two� NA NA
d_arrays_darkRoom2 north arrays darkRoom2 what is 0 + 0? 0+0 0 zero� NA NA NA NA NA NA NA NA
d_lists_timeRoom2 west lists timeRoom2 what is 0 + 0? 0+0 0 zero� NA NA NA NA NA NA NA NA
Expand Down
12 changes: 6 additions & 6 deletions inst/extdata/CastleOfR_Objects.txt
Expand Up @@ -2,12 +2,12 @@ name room objName location type points question solution val hint tip floorMapsI
o_intro_1 intro pen on the floor power 3 Ask for help on the hint() function using the ? operator. `?`(hint) NA "?""?""" NA 0 NA NA
o_intro_2 intro box on a chair pwd 0 "How do you create the vector [1, 2, 3]?" "c(1, 2, 3)" "c(1, 2, 3)" c NA 0 NA NA
o_simple_3 simple bottle on a bed tip 0 Assign 7 to the a variable named x. x <- 7 NA Arrow "If you want to know how long before Lady R will get here, try ?timeLeft." 0 NA NA
o_simple_4 simple book on a stand power 3 A vector named x has been defined in your workspace. How do you get the square root of all elements in x? sqrt(x) "c(2, 3, 4)" 7 chars answer NA 0 "x <<- c(4, 9, 16)" "rm(x, envir = globalenv())"
o_objectsRoom_5 objectsRoom tissue on the floor power 3 what is 0 + 0? 0 + 0 0 zero� NA 0 NA NA
o_objectsRoom_6 objectsRoom picture on the wall map 0 what is 0 + 0? 0 + 0 0 zero� NA 1 NA NA
o_objectsRoom_7 objectsRoom can in an open box tip 0 what is 0 + 0? 0 + 0 0 zero� "If you lock a door after you've opened it, it will take Lady R longer to get you. Try ?lockDoor." 0 NA NA
o_factors_8 factors coin in a dustbin pwd 0 what is 0 + 0? 0 + 0 0 zero� NA 0 NA NA
o_factors_9 factors brush on a shelf power 3 what is 0 + 0? 0 + 0 0 zero� NA 0 NA NA
o_simple_4 simple book on a stand power 3 A vector named x has been defined in your workspace. How do you get the square root of all elements in x? sqrt(x) NA 7 chars answer NA 0 "x <<- c(4, 9, 16)" "tryCatch(rm(x, envir = globalenv()), warning = function(w) {invisible()})"
o_objectsRoom_5 objectsRoom tissue on the floor power 3 Find out the length of a variable named z. length(z) NA The answer is in the question. NA 0 z <<- 1:999 "tryCatch(rm(z, envir = globalenv()), warning = function(w) {invisible()})"
o_objectsRoom_6 objectsRoom picture on the wall map 0 The vector digits contains the digits 1 to 9 as characters. Convert them to numeric. as.numeric(digits) NA ?as.numeric NA 1 digits <<- as.character(1:9) "tryCatch(rm(digits, envir = globalenv()), warning = function(w) {invisible()})"
o_objectsRoom_7 objectsRoom can in an open box tip 0 Find out if the variable p contains a string is.character(p) NA p "If you lock a door after you've opened it, it will take Lady R longer to get you. Try ?lockDoor." 0 "p <<- ""is.character(p)""" "tryCatch(rm(p, envir = globalenv()), warning = function(w) {invisible()})"
o_factors_8 factors coin in a dustbin pwd 0 What is the mean of vector v? mean(v) NA The answer is in the question. NA 0 v <<- runif(10) "tryCatch(rm(v, envir = globalenv()), warning = function(w) {invisible()})"
o_factors_9 factors brush on a shelf power 3 fac is a factor vector. What are its levels? levels(fac) NA The answer is in the question. NA 0 "fac <<- gl(3, 4, labels = c(""dont"", ""go"", ""west""))" "tryCatch(rm(fac, envir = globalenv()), warning = function(w) {invisible()})"
o_arrays_10 arrays credit card attached to one of the doors power 3 what is 0 + 0? 0 + 0 0 zero� NA 0 NA NA
o_arrays_11 arrays umbrella hung on the wall tip 0 what is 0 + 0? 0 + 0 0 zero� If you forgot the question try ?whatWasTheQuestion. 0 NA NA
o_lists_12 lists button on the floor pwd 0 what is 0 + 0? 0 + 0 0 zero� NA 0 NA NA
Expand Down
2 changes: 1 addition & 1 deletion inst/extdata/CastleOfR_Rooms.txt
@@ -1,6 +1,6 @@
name title floor comment
intro The Intro Room 1 "If you want to take an object and put it in your satchel, try ?takeObject."
simple The Simple Manipulations Room 1 NA
simple The Simple Manipulations Room 1 "If you don't know the answer to a question, try ?hint and ?solution."
objectsRoom The Objects Room 1 NA
factors The Factors Room 1 NA
arrays The Arrays Room 2 NA
Expand Down
10 changes: 5 additions & 5 deletions inst/extdata/CastleOfR_TimeRoomsRiddles.txt
@@ -1,9 +1,9 @@
name room question solution val hint prepare cleanup
r_timeRoom2_1 timeRoom2 what is 0 + 0? 0+0 0 zero.. NA NA
r_timeRoom2_2 timeRoom2 How do you list all current objects? ls() NA Unix NA NA
r_timeRoom2_3 timeRoom2 what is 0 + 0? 0+0 0 zero.. NA NA
r_timeRoom2_4 timeRoom2 what is 0 + 0? 0+0 0 zero.. NA NA
r_timeRoom2_5 timeRoom2 what is 0 + 0? 0+0 0 zero.. NA NA
r_timeRoom2_1 timeRoom2 "Create a vector of length 5 containing all twos, assign it to a variable named y" "y <- rep(2, 5)" NA Repeat two 5 times. NA "tryCatch(rm(y, envir = globalenv()), warning = function(w) {invisible()})"
r_timeRoom2_2 timeRoom2 How do you list all current objects? ls() NA Unix "a <<- ""a""; b <<- ""b""; c <<- ""c""" "rm(list = ls(), envir = global.env())"
r_timeRoom2_3 timeRoom2 Check which elements of a vector named x are greater than -1. x > -1 NA Result should be a logical vector containing only TRUE/FALSE "x <<- c(34, -1, -10, 22, -5)" "tryCatch(rm(x, envir = globalenv()), warning = function(w) {invisible()})"
r_timeRoom2_4 timeRoom2 There are missing values in a vector named z. Put zeros in there. z[is.na(z)] <- 0 NA ?is.na "z <<- c(""a"", NA, 1, TRUE, NA)" "tryCatch(rm(z, envir = globalenv()), warning = function(w) {invisible()})"
r_timeRoom2_5 timeRoom2 "What is the sum of vector v, omitting missing values?" "sum(v, na.rm = TRUE)" NA na.rm v <<- runif(5); v[6] <- NA "tryCatch(rm(v, envir = globalenv()), warning = function(w) {invisible()})"
r_timeRoom3_6 timeRoom3 what is 0 + 0? 0+0 0 zero.. NA NA
r_timeRoom3_7 timeRoom3 what is 0 + 0? 0+0 0 zero.. NA NA
r_timeRoom3_8 timeRoom3 what is 0 + 0? 0+0 0 zero.. NA NA
Expand Down

0 comments on commit 289c444

Please sign in to comment.