آموزش برنامه نویسی با سی شارپ C# قسمت 6 – دستورات شرطی - بخش 1 از 2 جمعه 8 نوامبر 2024
زمان مطالعه: 2 دقیقه
زمان ویدیو:
8m2s
لینک یوتیوب
لینک آپارات
bool isDead = false ;
float health = 100f ;
int hits = 0 ;
float enemyDamage = 3.6f ;
hits = hits + 1 ;
health = health - enemyDamage;
Console.WriteLine(health);
health += enemyDamage; // health = health + enemyDamage;
health *= enemyDamage; // health = health * enemyDamage;
health /= enemyDamage; // health = health / enemyDamage;
Console.WriteLine($"Health: {health} | Dead: {isDead} | Hits: {hits}." );
// take damage
hits = hits + 1 ; // hits++;
health = health - enemyDamage; // health -= enemyDamage;
Console.WriteLine($"Health: {health} | Dead: {isDead} | Hits: {hits}." );
Console.WriteLine($"Health: {health} | Dead: {isDead} | Hits: {hits}." );
// take damage
hits = hits + 1 ; // hits++;
health = health - enemyDamage;
Console.WriteLine($"Health: {health} | Dead: {isDead} | Hits: {hits}." );
// take damage
hits = hits + 1 ; // hits++;
health = health - enemyDamage;
Console.WriteLine($"Health: {health} | Dead: {isDead} | Hits: {hits}." );
// take damage
hits = hits + 1 ; // hits++;
health = health - 90 ;
Console.WriteLine($"Health: {health} | Dead: {isDead} | Hits: {hits}." );
if (condition)
{
// do something
}
int hits = 1 ;
if (hits == 0 )
{
Console.WriteLine("No Hit" );
}
int hits = 1 ;
if (hits >= 0 )
{
Console.WriteLine("Greater Than Or Equal" );
}
if (hits <= 0 )
{
Console.WriteLine("Less Than Or Equal" );
}
if (health <= 0 )
{
health = 0 ;
isDead = true ;
}
bool isDead = false ;
float health = 100f ;
int hits = 0 ;
float enemyDamage = 3.6f ;
// Take Damage
hits++;
health -= enemyDamage;
if (health <= 0 )
{
health = 0 ;
isDead = true ;
}
Console.WriteLine($"Health: {health} | Dead: {isDead} | Hits: {hits}." );
// Take Damage
hits++;
health -= enemyDamage;
if (health <= 0 )
{
health = 0 ;
isDead = true ;
}
Console.WriteLine($"Health: {health} | Dead: {isDead} | Hits: {hits}." );
// Take Damage
hits++;
health -= enemyDamage * 30 ;
if (health <= 0 )
{
health = 0 ;
isDead = true ;
}
Console.WriteLine($"Health: {health} | Dead: {isDead} | Hits: {hits}." );