Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Recipe maker
- Main idea:
- + dislay menu with user options
- +,i create recipe
- +,i view recipes
- +,i exit
- To-do
- + funs
- +,i makeRecipe() --ipt[Str: recipe_name, Str: {Ingredients}]
- +,i viewRecipes() --print recipes from userRecipes map
- +,i showMenu() --display menu and options
- +,i sleepText() --displat text and sleep for x time
- +,i main() --call displat manu
- + global vars
- +,i var userRecipes() --Map<String, String>
- +,i var ingredients() --list
- */
- const val time: Long = 50L
- var recipeCounter: Int = 0
- var userRecipes = mutableMapOf("Test recipe 1" to "soup, egg, oatmeal, meat")
- var serverIngredients = listOf(
- "Water 💧",
- "Milk 🥛",
- "Meat 🥩",
- "Vegetables 🥦",
- "Fruits 🍎",
- "Cereal 🥣",
- "Eggs 🥚",
- "Tomato 🍅",
- "Pineapple 🍍",
- "Pickle 🥒",
- "Avocado 🥑",
- "Oil 🛢",
- "Cherry 🍒",
- "Turtle 🐢"
- ) //list must be uneven number for it to work while printing
- fun main() {
- showMenu()
- }
- fun showMenu() {
- var response: Int = 0
- do {
- print("🥞----RECIPE-CREATOR----🥞\n\n")
- sleepText(time, "1) Make Recipe ✍"); sleepText(time, "2) View Recipes 📋"); sleepText(time, "0) Exit ❌")
- print("\nType here 👉 ")
- response = Integer.valueOf(readLine())
- if (response == 0) {
- break;
- } else if (response == 1) {
- makeRecipe()
- } else if (response == 2) {
- viewRecipes()
- } else {
- println("Sorry, the command $response was not recognized, please try again down below")
- showMenu()
- }
- } while(response != 0)
- }
- fun makeRecipe() {
- var recipeName: String?
- var recipeIngredients: String?
- print("\n\tFirst of all, what is going to be the name of your recipe?: ")
- recipeName = readLine() ?: "Default recipe name #$recipeCounter"
- println("\n")
- // possibly add "are you sure?" part here
- var n1: Int = 1
- var n2: Int = 2
- var runnedIndexes = mutableListOf(-1)
- for((index, value) in serverIngredients.withIndex()) {
- var indexN1: Int = index + n1
- var indexN2: Int = index + n2
- if (serverIngredients.size / 2 == index) {
- break
- } else {
- if (index == 0) {
- sleepText(time, "\t$index) $value\t\t\t$indexN1) " + serverIngredients[indexN1])
- } else {
- sleepText(time, "\t$indexN1) " + serverIngredients[index + n1] + "\t\t\t$indexN2) " + serverIngredients[index + n2])
- ++n1; ++n2;
- }
- }
- // println("----$index-$indexPlusOne----")
- /*
- 0i 0 1 +0 +0
- 1i 2 3 +1 +2
- 2i 4 5 +2 +3
- 3i 6 7 +3 +4
- 4i 8 9 +4 +5
- 5i 10 11 +5 +6
- */
- }
- print("\n\tChoose all the ingredients you want from the above list (type them here): ")
- recipeIngredients = readLine() ?: "None"
- do {
- print("\tConfirm your recipe [y/n]: ")
- print("Type here 👉 ")
- var response: String? = readLine()
- if (response.equals("yes") || response.equals("y")) {
- userRecipes.put("$recipeName", "$recipeIngredients")
- println("\n\t------------------------------------------------\n\tGreat, your recipe has been added successfully! 😁\n\t------------------------------------------------\n")
- ++recipeCounter;
- break;
- } else if (response.equals("no") || response.equals("n")) {
- println("Okay then! let's try again..."); makeRecipe(); break
- } else {
- println("You typed '$response', you must type either 'yes' or 'no'"); Thread.sleep(1000L)
- }
- } while (!response.equals("yes") || !response.equals("y"))
- }
- fun sleepText(time: Long, str: String) {
- println(str); Thread.sleep(time)
- }
- fun viewRecipes() {
- if (userRecipes.isEmpty()) {
- println("Ups... It seems that there are no recipes in here! why not create a new one shall we?")
- } else {
- var index: Byte = 1
- for ((key, value) in userRecipes) {
- print("--------------------\n🔷 #$index\n\tRecipe Name: $key:\n\tIngredients: $value\n------------------------\n\n")
- ++index
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement