C# · Chapter 3.3 · Basic level

Game Logic (if-else Dragon Boss Gate!)

गेम लॉजिक (if-else से ड्रैगन बॉस अनलॉक करना!)

In games, the Boss Arena stays locked until your Hero reaches Level 10! Notice how C#'s if-else compares with Python's:
• In Python: if level >= 10: (uses colon : + spaces)
• In C#: if (level >= 10) { ... } else { ... } (condition goes inside round brackets ( ), and actions go inside curly braces { } — no colon!).

हर गेम में बॉस फाइट का दरवाज़ा तभी खुलता है जब प्लेयर का level कम से कम 10 हो जाए! देखो C# का if-else कितना साफ़ है:
• शर्त हमेशा गोल ब्रैकेट (level >= 10) के अंदर आती है।
• काम कर्ली ब्रैकेट { ... } के अंदर लिखा जाता है (यहाँ : नहीं लगता)!

In the classroom you can run and edit this code in your browser, get hints and mark the chapter as done. क्लास में यह code ब्राउज़र में चलाकर बदल सकते हो।

Words and symbols in this chapter

int level = 10;
Sets Hero's current game level (10 unlocks the Boss!).
हीरो का लेवल 10 रखता है (इसे 5 करके देखोगे तो दरवाज़ा बंद रहेगा!)।
if (level >= 10)
Condition inside ( ) — checks if level is 10 or higher.
गोल ब्रैकेट ( ) में शर्त — क्या level 10 या उससे ऊपर है?
{ ... }
Curly braces wrap the commands that run when the condition is true.
{ } के अंदर वे कमांड्स आती हैं जो शर्त सच होने पर चलेंगी।
else { ... }
Runs when level is below 10 ("Keep Training!").
अगर लेवल 10 से कम हो तो else वाला हिस्सा चलता है।

Ready example

int level = 10;

if (level >= 10) {
    Console.WriteLine("Boss Fight Unlocked!");
} else {
    Console.WriteLine("Keep Training!");
}

What you will see: At level = 10, a fierce fire-breathing Dragon Boss bursts onto the 2D Game Stage!

जैसे ही level = 10 के साथ Run करोगे, गेम स्टेज पर आग उगलता विशाल ड्रैगन बॉस प्रकट हो जाएगा!

Line by line

int level = 10;
Try 10 (Dragon appears!) vs 4 (Training mode!).
10 पर ड्रैगन बॉस आएगा, 4 करने पर ट्रेनिंग मोड दिखेगा!
if (level >= 10) {
Checks if player reached Level 10.
चेक करता है कि क्या प्लेयर लेवल 10 पर पहुँच गया।
Console.WriteLine("Boss Fight Unlocked!");
Unlocks the Dragon Boss on the 2D Game Stage!
गेम एरीना में विशाल ड्रैगन बॉस को सामने लाता है!

Common mistake

✗ Wrong

if level >= 10 {
    Console.WriteLine("Boss");
}

✓ Right

if (level >= 10) {
    Console.WriteLine("Boss");
}

Unlike Python, C# requires round brackets ( ... ) around every if condition!

Python से अलग, C# में if की शर्त को हमेशा गोल ब्रैकेट ( ... ) के अंदर बंद करना पड़ता है!

Your task

Set int level = 10; and write if (level >= 10) to print "Boss Fight Unlocked!"!

int level = 10; बनाओ और if (level >= 10) लगाकर "Boss Fight Unlocked!" प्रिंट करो!

  1. Write int level = 10;.
    int level = 10; लिखो।
  2. Write if (level >= 10) { Console.WriteLine("Boss Fight Unlocked!"); }.
    if (level >= 10) के { } में Console.WriteLine("Boss Fight Unlocked!"); लिखो।
  3. Click ▶ Run & Preview to summon the Dragon Boss!
    ▶ Run & Preview दबाकर ड्रैगन बॉस को अनलॉक करो!
Starter code for the task
int level = 3;
Console.WriteLine("Current level: " + level);

// TODO 1: upar level ko 10 (ya usse zyada) karo
// TODO 2: if (level >= 10) { Console.WriteLine("Boss Fight Unlocked!"); } likho
// TODO 3: else { Console.WriteLine("Keep Training!"); } bhi jodo

Do this task in the classroom: your code is checked automatically and you get hints if something is missing.

Recap

Quick quiz

How do you write an if check in C#?

C# में if की शर्त लिखने का सही तरीका क्या है?

  1. if level >= 10:
  2. if (level >= 10) { ... }
  3. if [level >= 10] { ... }
  4. when (level >= 10)
Show the answer

Answer: B (if (level >= 10) { ... })

C# wraps the condition in ( ) and the block body inside { }!

C# में शर्त ( ) के अंदर और कोड ब्लॉक { } के अंदर लिखा जाता है!

Practice problems for this chapter

Solve them in the Practice Zone, where each answer is checked automatically and two hints are available.