Welcome to the Robot Configuration Wizard! In this challenge, you will build an interactive command-line interface (CLI) to configure and spawn a robot into the maze.
Your goal is to write a program that asks the user for specific details about a robot (name, position, and color) and then creates that robot in the game. You must ensure the user enters valid information!
how to win?
Create a robot named Robot at position 7, 7 with color #ff0000.
0 and 13 (inclusive).
0 and 13 (inclusive).
#ff0000).
#.0-9, a-f, A-F).game.createRobot() to spawn the robot at the specified location with the given name and color.Enter robot name: Robot
Enter robot X: 7
Enter robot Y: 7
Enter robot color: #ff0000
To win this game you need to create a robot named Robot at position 7, 7 and color #ff0000.
You will need the readline-sync library to get input from the user.
import readline from "readline-sync";
readline.question("Prompt text: ") to get a string.readline.questionInt("Prompt text: ") to get an integer.To ensure the user enters valid data, you can use a do...while loop.
let value: number = 0;
let isValid: boolean = false;
do {
value = readline.questionInt("Enter a number: ");
// Check if the value is valid
if (/* condition */) {
isValid = true;
} else {
console.log("Invalid input. Try again.");
}
} while (!isValid);
A helper string can make checking for valid hex characters easier.
const validHexChars : string = "0123456789abcdefABCDEF";
// You can check if a character exists in this string using .includes()
Don't forget to check if the string starts with # using .startsWith("#") and check the length using .length.
Finally, pass your collected variables to the game:
game.createRobot({
name: robotName,
x: robotX,
y: robotY,
color: robotColor,
});