Be the first to post for 'Conditional Program Flow Using if'!

If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.

1 Like

I decided to make a bonus level for my game. It is inspired by the TV show Mr.Robot!

36 PM

36 PM

45 PM

Really digging this course!

3 Likes

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Hacker : MonoBehaviour {

// Use this for initialization
void Start () {
	ShowMainMenu("Hello my dudes!");
}

void ShowMainMenu (string greeting) {
	Terminal.ClearScreen();
	Terminal.WriteLine(greeting);
	Terminal.WriteLine("H4CK TH3 PL4N3T!!1!");
	Terminal.WriteLine("1 - haxxors the Gym, bro");
	Terminal.WriteLine("2 - hack the school");
	Terminal.WriteLine("3 - HACK THE GIBSON");
	Terminal.WriteLine("Choose wisely.");
}

void OnUserInput(string input) {
	if (input == "menu")
	{
		ShowMainMenu("Returning to main menu:");
	}
	else if (input == "dude")
	{
		Terminal.WriteLine("sweet");
	}
	else if (input == "sweet")
	{
		Terminal.WriteLine("dude");
	}
	else
	{
		Terminal.WriteLine("Invalid input.");
	}
}

}

3 Likes

It was getting late, and I was getting a bit cheeky…

I am not new to coding, but I am new to C#, and I am loving the pacing. Keep it up, @ben!

-Goodge

2 Likes
void OnUserInput(string input)
{
    if (input == "1")
    {
        Terminal.WriteLine("Welcome to the Library!");
    }
    else if (input == "2")
    {
        Terminal.WriteLine("Welcome to the Police Station");
    }
    else if (input == "3")
    {
        Terminal.WriteLine("Welcome to the NASA!");
    }
    else if (input == "Q")
    {
        Terminal.WriteLine("Have a nice Day");
    }
    else if (input == "007")
    {
        Terminal.WriteLine("No, Mr Bond, I expect you to die...");
        greeting = "James Bond";
    }
    else if (input == "menu")
    {
        ShowMainMenu();
    }
    else
    {
        Terminal.WriteLine("Unexpected Crash!!!");
    }
}
1 Like

Took a while to figure this out on my own. End result? WORTH IT!



After typing “self destruct”:

After typing NTCO:

4 Likes

Here’s my menu and Easter Egg. :slight_smile:

void OnUserInput(string input) {

   if (input == "menu")
    {

        ShowMainMenu("Want to choose something else?");

    }

    else if (input == "1")
    {

        Terminal.WriteLine("You want Level 1?");

    }

    else if (input == "2")
    {

        Terminal.WriteLine("You want Level 2?");

    }

   else if (input == "cake")
    {

        Terminal.WriteLine("The cake is a lie");

    }

    else

    {
        Terminal.WriteLine ("I don't get it");
    }
3 Likes

Here is just simple code for this, nothing too fancy.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Hacker : MonoBehaviour {

	// Use this for initialization
	void Start () {
        name = "Hacker";
        ShowMainMenu(name);
    }

    void ShowMainMenu(string name) {
        Terminal.ClearScreen();
        Terminal.WriteLine("Hello, Mr. " + name + '.');
        Terminal.WriteLine("What would you like to hack into?");
        Terminal.WriteLine("Press 1 for your friend's computer");
        Terminal.WriteLine("Press 2 for university");
        Terminal.WriteLine("Press 3 for a bank");
        Terminal.WriteLine("\nBe careful, don't get caught.");
    }
    void OnUserInput(string input)
    {
        print("The user typed " + input);
        if (input == "1")
        {
            Terminal.ClearScreen();
            Terminal.WriteLine("You chose level 1.");
        }

        else if (input == "2")
        {
            Terminal.ClearScreen();
            Terminal.WriteLine("You chose level 2.");
        }

        else if (input == "3")
        {
            Terminal.ClearScreen();
            Terminal.WriteLine("You chose level 3.");
        }
        else if (input == "menu")
            ShowMainMenu(name);

        else
        {
            Terminal.ClearScreen();
            Terminal.WriteLine("Your input is not valid.");
            Terminal.WriteLine("Type 1, 2, 3 or menu.");
        }
    }
}
1 Like

Lots of fun, it remind me of the input statement on c64 long time ago. But I don’t have control over multi input variables here. I see forward to learn and understand a lot more of this. I’ve been wanted to learn this for quite some time. Good course Thanks!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Hacker : MonoBehaviour {

    string username = "JixiPW";

    // Use this for initialization
    void Start ()
    {
        ShowMainMenu();
    }

    void ShowMainMenu()
    {
        SystemStartTxt();
        Terminal.WriteLine("Choose destination level to hack?");
        Terminal.WriteLine(" ");
        Terminal.WriteLine("Level 1 Farm");
        Terminal.WriteLine("Level 2 School");
        Terminal.WriteLine("Level 3 Library");
        Terminal.WriteLine(" ");
        Terminal.WriteLine("Enter your selection:");
    }

    void SystemStartTxt()
    {
        Terminal.ClearScreen();
        Terminal.WriteLine("WM2000 HACKING TERMINAL V1 LOADED");
        UserLogin("Logged in as:");
        Terminal.WriteLine(" ");
    }

    void UserLogin(string login)
    {
        Terminal.WriteLine(login + " " + username);
    }

    void OnUserInput(string input)
    {
        
        if (input == "1")
        {
            Debug.Log("Level 1");
            Debug.Log(input == "1");
            Terminal.ClearScreen();
            SystemStartTxt();
            Terminal.WriteLine("Level 1 Farm");
        }
        else if (input == "2")
        {
            Debug.Log("Level 2");
            Debug.Log(input == "2");
            Terminal.ClearScreen();
            SystemStartTxt();
            Terminal.WriteLine("Level 2 School");
        }
        else if (input == "3")
        {
            Debug.Log("Level 3");
            Debug.Log(input == "3");
            Terminal.ClearScreen();
            SystemStartTxt();
            Terminal.WriteLine("Level 3 Library");
        }
        else if (input == "menu")
        {
            ShowMainMenu();
        }
        else if (input == "007")
        {
            username = "James Bond";
            SystemStartTxt();
            Terminal.WriteLine("Welcome back Mr. Bond.");
        }
        else if (input == "/dance")
        {
            Terminal.WriteLine(username + " start to dance!");
        }
        else if (input == "cls")
        {
            SystemStartTxt();
        }
        else if (input == "help")
        {
            SystemStartTxt();
            Terminal.WriteLine("Help - Type:");
            Terminal.WriteLine("--------------------------");
            Terminal.WriteLine("help    List all commands.");
            Terminal.WriteLine("menu    Main menu.");
            Terminal.WriteLine("cls     Clear screen.");
            Terminal.WriteLine("/dance  Start dance.");
            Terminal.WriteLine("007     Transform to 007.");
            Terminal.WriteLine("--------------------------");
        }
        else
        {
            Terminal.WriteLine("Level not valid!");
            Terminal.WriteLine("Type 'help' to list all commands");
        }
    }
}
2 Likes

I thought I’d go for a HP Lovercraft theme though I did get sidetracked with anime.

2 Likes

I love Portal lol

I just decided to go simple.

public class Hacker : MonoBehaviour {

// Use this for initialization
void Start () {
    ShowMainMenu("Hello Ki. ");
    print("Hello " + "World");
}

void ShowMainMenu(string greeting)
{
    Terminal.ClearScreen();
    Terminal.WriteLine(greeting + "RED ALERT!!");
    Terminal.WriteLine("THE NYX VIRUS HAS BEEN DISPERSED!");
    Terminal.WriteLine("Crack the code, save the world!");
    Terminal.WriteLine("Only a special person can do this...");
    Terminal.WriteLine("What kind of person are you? \n");
    Terminal.WriteLine("1 - Scavenger");
    Terminal.WriteLine("2 - Nomad");
    Terminal.WriteLine("3 - Survivor \n");
    Terminal.WriteLine("You are a: ");
}

void OnUserInput(string input)
{

   if (input == "1") 
    {
        Terminal.WriteLine("You chose level 1.\nWelcome, Scavenger.");
    }
   else if (input == "2")
    {
        Terminal.WriteLine("You chose level 2.\nWelcome, Nomad.");
    }
   else if (input == "3")
    {
        Terminal.WriteLine("You chose level 3.\nWelcome, Survivor.");
    }
   else if (input == "menu" || input == "Menu")
    {
        ShowMainMenu("");
    }
   else if (input == "007")
    {
        Terminal.WriteLine("Welcome back, Mr. Bond.");
    }
   else
    {
        Terminal.WriteLine("You have entered an invalid input.");
    }
}

}

image
image
image

Privacy & Terms