Unity/수업내용(C#)
[3.9] 논리연산
ljw4104
2021. 3. 9. 13:08
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study00
{
class Program
{
static void Main(string[] args)
{
string heroName = "홍길동";
float sight = 5.4f;
float attackRange = 3.3f;
float heroX = default, heroY = default;
string monsterName = "고블린";
float monsterX = 4f, monsterY = 3f;
double a = Math.Pow(monsterX - heroX, 2);
double b = Math.Pow(monsterY - heroY, 2);
double distance = Math.Sqrt(a + b);
Console.WriteLine(distance <= sight);
Console.WriteLine(distance <= attackRange);
bool isAttackAvailable = (distance <= sight) && (distance <= attackRange);
Console.WriteLine("{0}이 {1}을 공격할 수 있는 상태인가? : {2}", heroName, monsterName, isAttackAvailable);
Console.WriteLine(String.Empty);
}
}
}