스토리지

[3.9] 논리연산 본문

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);
        }
    }
}

 

'Unity > 수업내용(C#)' 카테고리의 다른 글

[3.9] for 반복문  (0) 2021.03.09
[3.9] 반복문 및 조건문 응용  (0) 2021.03.09
[3.9] 여러가지 짬뽕  (0) 2021.03.09
[3.9] 전위.후위 연산자  (0) 2021.03.09
[3.9] 복항 할당식  (0) 2021.03.09
Comments