깃이란?

깃다운로드 검색

윈도우면 윈도우 클릭

https://git-scm.com/downloads

 

Git - Downloads

Downloads macOS Windows Linux/Unix Older releases are available and the Git source repository is on GitHub. GUI Clients Git comes with built-in GUI tools (git-gui, gitk), but there are several third-party tools for users looking for a platform-specific exp

git-scm.com

 

버전에 맞춰 설치하면 되지만 일반적으로 이럴 것이다.

 

그 후 다른 옵션은 건들지 않고 Next만 누르면 설치가 된다

 

깃이 설치가 완료되면 깃허브를 들어가서 회원가입 or 로그인

 

https://github.com/

 

GitHub: Let’s build from here

GitHub is where over 100 million developers shape the future of software, together. Contribute to the open source community, manage your Git repositories, review code like a pro, track bugs and fea...

github.com

 

그후 레포지토리를 관리해주는 SourceTree를 설치할 것이다.

 

소스 트리 다운 로드

https://www.sourcetreeapp.com/

 

Sourcetree | Free Git GUI for Mac and Windows

A Git GUI that offers a visual representation of your repositories. Sourcetree is a free Git client for Windows and Mac.

www.sourcetreeapp.com

 

여기는 건너뛰

가끔 이렇게 깃이 설치된 경로를 못찾거나 하는 경우에 생기는 것 같은데

저기에 체크박스가 있으면 체크박스 선택 후 

고급옵션 => 기본적으로 줄 끝을 자동으로 처리하도록설정을 체크

 

 

이렇게 하면 기본적으로 Git, SourceTree 설치가 완료된다.

 

SourceTree를 사용하면 cmd창에서

git add. / git commit -m ""  같은 문구를 보기 편한 UI 버튼으로 만들어주기에

보기에 편하여 사용하는 Tool 이다. 

 

추 후

깃에 올릴때는
본인이 만든 Assets, Packages, ProjectSettings만 복사 한다 나머지 ignore + .vsconfig
깃 레포지 링크를 복사해서 sourcetree에 넣고

새폴더를 만들어 저장위치를 지정하고 클론
생성된 로컬 레포지에 들어가서 새폴더 생성
sourcetree에서 스테이지에 올리면 -> git add. 상태
그리고 메세지를 입력하여 커밋하면 로컬 레퍼지토리로 넘어간다. -> git commit -m " "
그 다음 단계는 푸시 => git push

'산대특 > 게임 알고리즘' 카테고리의 다른 글

ClimbCloud  (2) 2024.02.01
C# 대리자, 람다함수  (1) 2024.01.31
CatEscape 게임  (2) 2024.01.30
멤버 변수와 지역 변수  (0) 2024.01.29
유니티 실행 시 인터페이스  (0) 2024.01.25

우선 textures에 새로운 사진들을 첨부한후

Texture Type을 Sprite(2D and UI)로 변경후 Apply 

 

배경을 덮은 후 

캐릭터를 가져오는데 뒤에 가려져서 보이지 않으면

다음과 같이 Order in Layer을 1로 변경하면 앞에 배치된다.

 

캐릭터에 적용 할 c# script의 제목으로 PlayerController로 저장후

이동과 이동시 콘솔에 찍히도록 코드를 작성

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

public class PlayerController : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            Debug.Log("왼쪽으로 2유닛만큼 이동");
            this.transform.Translate(-2, 0, 0);
        }
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            Debug.Log("오른쪽으로 2유닛만큼 이동");
            this.transform.Translate(2, 0, 0);
        }
    }
}

 

그 후 화살표가 땅에 닿으면 사라지게 작성

아래 콘솔을 보면 arrow의 좌표가 찍히다가 사라지는 것을 알 수 있다.

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Windows.Speech;

public class ArrowController : MonoBehaviour
{
    [SerializeField] private float speed = 1f;
    void Start()
    {

    }

    void Update()
    {
        // 화살표가 내려오면서 Console에 찍히도록 
        Vector3 movement = Vector3.down * speed * Time.deltaTime; // 방향 * 속도 * 시간
        this.transform.Translate(movement);
        Debug.LogFormat("y: {0}", this.transform.position.y);
        
        if(this.transform.position.y <= -3.56)
        {
            Destroy(this.gameObject);
        }
    }
}

 

그리고 이제 충돌하면 사라지게 만들 것인데

그러기 위해 두 텍스쳐간의 radius (캐릭터를 중심으로한 테두리 원이라 생각하면 편하다.)을 보이는 선을 지정해주고

두 텍스쳐간의 거리가 두텍스쳐간의 radius의 합보다 가까워 지면 arrow가 사라지게 할 것이다.

https://docs.unity3d.com/ScriptReference/Gizmos.DrawWireSphere.html

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

public class PlayerController : MonoBehaviour
{
    public float radius = 1f; // radius를 개발자가 인스펙터에서 바꿀수 있도록 선언
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            Debug.Log("왼쪽으로 2유닛만큼 이동");
            this.transform.Translate(-2, 0, 0);
        }
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            Debug.Log("오른쪽으로 2유닛만큼 이동");
            this.transform.Translate(2, 0, 0);
        }
    }
    private void OnDrawGizmos()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawWireSphere(this.transform.position, this.radius);
    }

}

 

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Windows.Speech;

public class ArrowController : MonoBehaviour
{
    [SerializeField] private float speed = 1f;
    [SerializeField] private float radius = 1f;

    private GameObject playerGo;
    void Start()
    {
        this.playerGo = GameObject.Find("player");
    }

    void Update()
    {
        // 화살표가 내려오면서 Console에 찍히도록 
        Vector3 movement = Vector3.down * speed * Time.deltaTime; // 방향 * 속도 * 시간
        this.transform.Translate(movement);
        Debug.LogFormat("y: {0}", this.transform.position.y);
        
        if(this.transform.position.y <= -3.56)
        {
            Destroy(this.gameObject);
        }
        // 두 텍스쳐(arrow, player) 간의 거리
        Vector2 p1 = this.transform.position;
        Vector2 p2 = this.playerGo.transform.position;
        Vector2 dir = p1 - p2; // 방향
        float distance = dir.magnitude; // 거리 
        // float distance = Vector2.Distane(p1,p2); // => 거리만 알고 싶을 때

        // 두 radius 간의 거리
        float r1 = this.radius;
        PlayerController controller = this.playerGo.GetComponent<PlayerController>();
        float r2 = controller.radius;// 여기서 보호 수준 때문에 PlayController.cs 의 radius를 퍼블릭으로 변경
        float sumRadius = r1 + r2;

        // 두 텍스쳐간의 거리가 두텍스쳐간의 radius의 합보다 가까워 지면 arrow가 충돌이라 인지하고 arrow를 사라지게 할 것이다.
        if(distance < sumRadius)
        {
            Debug.LogFormat("충돌함: {0}, {1}", distance, sumRadius);
            Destroy(this.gameObject) ;
        }
    }
    private void OnDrawGizmos()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawWireSphere(this.transform.position, this.radius);
    }

}

 


 

프리팹

프리팹 : 게임 오브젝트를 파일화 시킨것 (에셋)

https://docs.unity3d.com/kr/2018.4/Manual/Prefabs.html

 

프리팹 - Unity 매뉴얼

Unity의 프리팹 시스템을 이용하면 게임 오브젝트를 생성, 설정 및 저장할 수 있으며, 해당 게임 오브젝트의 모든 컴포넌트, 프로퍼티 값, 자식 게임 오브젝트를 재사용 가능한 에셋으로 만들 수

docs.unity3d.com

 

아래와 같이 하이어라이키에 있는 arrow를 새폴더(Prefabs)를 만들어 넣어주었고,

그러면 하이어라이키에 있는 arrow는 삭제해도 된다.

 

그 후 c# script를 만들어서 아래와 같은 선언

 

그러고 나서 생성된 gameObject의 arrowPrefab에 Prefabs에 있는 arrow를 할당

 

클론한 arrow가 떨어지게 한다.

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

public class ArrowGenerator : MonoBehaviour
{
    //프리팹 에셋을 가지고 프리팹 인스턴스를 만든다 
    [SerializeField] private GameObject arrowPrefab;

    void Start()
    {
        GameObject go = Instantiate(this.arrowPrefab);  //프리팹 인스턴스 
        //위치는 프리팹 에셋에 설정된 위치 
        //위치를 재설정 
        Debug.LogFormat("go: {0}", go);
    }

    void Update()
    {

    }
}

 

델타를 선언한후 3이될때마다 새로운 arrow 출력

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

public class ArrowGenerator : MonoBehaviour
{
    //프리팹 에셋을 가지고 프리팹 인스턴스를 만든다 
    [SerializeField] private GameObject arrowPrefab;
    private float delta;
    void Start()
    {
       
    }

    void Update()
    {
        delta += Time.deltaTime;
        Debug.Log(delta);
        if (delta >= 3)
        {
            GameObject go = Instantiate(this.arrowPrefab);  //프리팹 인스턴스 
                                                            //위치는 프리팹 에셋에 설정된 위치 
                                                            //위치를 재설정 
            delta = 0;
        }
    }
}

 

 

이제 기즈모의 테두리를 볼 필요 없으니 기즈모 부분만 주석처리하고

화살표 떨어지는것의 방향 Vector3는 구조체 이므로 x좌표만 랜덤으로 지정하였다.

(y, z는 기존에 ArrowController에서 0으로 지정하였기에 좌표만 찍어주면 된다.)

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

public class ArrowGenerator : MonoBehaviour
{
    //프리팹 에셋을 가지고 프리팹 인스턴스를 만든다 
    [SerializeField] private GameObject arrowPrefab;
    private float delta;
    void Start()
    {
       
    }

    void Update()
    {
        delta += Time.deltaTime;  //이전 프레임과 현재 프레임 사이 시간 
        //Debug.Log(delta);
        if (delta > 3)  //3초보다 크다면 
        {
            GameObject go = Object.Instantiate(this.arrowPrefab); // 생성
            float randX = Random.Range(-9.7f, 9.7f); // 화살표가 화면 상에 떨어질 범위
            go.transform.position = new Vector3(randX, go.transform.position.y, go.transform.position.z); // x축 위치만 랜덤하게
            delta = 0;  //경과 시간을 초기화 
        }
    }
}


이제 체력바를 만들어줄건데

하이어라이키에 우클릭후 ui-canvas 로 만들어주고

저렇게 두군데를 canvas scaler에 있는 scale with screen size, expand를 해줘야

각각의 다른 매체에서 열 때 화면 사이즈 최적화가 된다.

 

 

이렇게 캔버스 안에 이미지를 넣어주고 적절하게 크기 조절 후 배치

※캔버스가 너무 커서 이미지가 scene에 잘 안보일수 있으므로

하이라이키에 있는 이미지를 더블클릭해서 위치 찾기

 

그후 보기와 같이 이미지 타입과

fill origin은 기호에 맞게 설정한후

fill amount 수치를 바꾸면 원안에 파란색 게이지가 변함을 확인할 수 있다.

새로운 하이어라이키와 script 생성 후 오브젝트로 넣는다.

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; // UI를 사용할 것이므로 추가

public class CatEscapeGameDirector : MonoBehaviour
{
    [SerializeField] private Image hpGauge;

    public void DecreaseHp() //체력을 감소시키는 메서드 생성
    {
        this.hpGauge.fillAmount -= 0.1f; //충돌할때마다 체력을 감소하기 위한 선언
    }
}

 

맴버변수에 선언

이름으로 게임오브젝트를 찾는 것에 FindObjectOfType<CatEscapeGameDirector>(); 추가

마지막에 충돌했을 때 체력이 감소하는 메서드 선언

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Windows.Speech;

public class ArrowController : MonoBehaviour
{
    [SerializeField] private float speed = 1f;
    [SerializeField] private float radius = 1f;

    private GameObject playerGo;

    //동적으로 생성되는 메서드는 씬에 있는것 을 Assign 할수 없다 
    private CatEscapeGameDirector gameDirector;
    void Start()
    {
        //이름으로 게임오브젝트를 찾는다 
        this.playerGo = GameObject.Find("player");
        this.gameDirector = GameObject.FindObjectOfType<CatEscapeGameDirector>();
    }

    void Update()
    {
        // 화살표가 내려오면서 Console에 찍히도록 
        Vector3 movement = Vector3.down * speed * Time.deltaTime; // 방향 * 속도 * 시간
        this.transform.Translate(movement);
        //Debug.LogFormat("y: {0}", this.transform.position.y);
        
        if(this.transform.position.y <= -3.56)
        {
            Destroy(this.gameObject);
        }
        // 두 텍스쳐(arrow, player) 간의 거리
        Vector2 p1 = this.transform.position;
        Vector2 p2 = this.playerGo.transform.position;
        Vector2 dir = p1 - p2; // 방향
        float distance = dir.magnitude; // 거리 
        // float distance = Vector2.Distane(p1,p2); // => 거리만 알고 싶을 때

        // 두 radius 간의 거리
        float r1 = this.radius;
        PlayerController controller = this.playerGo.GetComponent<PlayerController>();
        float r2 = controller.radius;// 여기서 보호 수준 때문에 PlayController.cs 의 radius를 퍼블릭으로 변경
        float sumRadius = r1 + r2;

        // 두 텍스쳐간의 거리가 두텍스쳐간의 radius의 합보다 가까워 지면 arrow가 충돌이라 인지하고 arrow를 사라지게 할 것이다.
        if(distance < sumRadius)
        {
            Debug.LogFormat("충돌함: {0}, {1}", distance, sumRadius);
            Destroy(this.gameObject) ;
            this.gameDirector.DecreaseHp();
        }
    }
    private void OnDrawGizmos()
    {
        //Gizmos.color = Color.red;
        //Gizmos.DrawWireSphere(this.transform.position, this.radius);
    }

}

 

그리고 마지막으로 만들어 hpGauge 오브젝트에 하이러라이키에 있는 hp 이미지를 넣으면 완성된다.

 

 

'산대특 > 게임 알고리즘' 카테고리의 다른 글

C# 대리자, 람다함수  (1) 2024.01.31
Git, SourceTree  (1) 2024.01.31
멤버 변수와 지역 변수  (0) 2024.01.29
유니티 실행 시 인터페이스  (0) 2024.01.25
게임 아이템 정보 출력  (0) 2024.01.24

Class의 멤버로는 멤버변수와 멤버메서드가 있다.

 

<멤버변수>

 

멤버변수란 Class 내에 선언되는 변수

멤버변수도 클래스변수, 인스턴스변수 2가지로 나눈다.

클래스변수는 static으로 선언하여 인스턴스를 생성하지 않아도 접근하여 사용할 수 있으며,

new를 통한 인스턴스 생성시 static은 제외하고 생성된다.

인스턴스 변수는 new를 통하여 인스턴스를 생성 시 메모리가 할당되어 인스턴스 생성 후 부터 사용

private수준의 변수에 접근할 때에는 Class내에서 "this."를 이용하여 접근하고,

public수준의 변수에 접근할 때에는 Class밖에서도 ClassName.변수명 을 통하여 접근이 가능

 


 

<지역변수>

지역변수는 각 Method내에서 선언되고 존재하는 변수

Method가 호출되면서 Stack에 변수포함 데이터들이 쌓이고,

Method가 소멸하면서 Stack이 비워지기 때문에 지역변수는 Method가 소멸할 때 같이 소멸

즉 지역변수는 Method내부가 아닌 다른 곳에서 사용하려고 하면 사용할 수 없다.

'산대특 > 게임 알고리즘' 카테고리의 다른 글

C# 대리자, 람다함수  (1) 2024.01.31
Git, SourceTree  (1) 2024.01.31
CatEscape 게임  (2) 2024.01.30
유니티 실행 시 인터페이스  (0) 2024.01.25
게임 아이템 정보 출력  (0) 2024.01.24

유니티를 실행했을 때 인터페이스

참고: https://docs.unity3d.com/kr/2018.4/Manual/Le

 

Toolbar :

 

 

Scene View :

 

 

Hierarchy Window :

 

 

Inspector Window :

 

Toolbar :

'산대특 > 게임 알고리즘' 카테고리의 다른 글

C# 대리자, 람다함수  (1) 2024.01.31
Git, SourceTree  (1) 2024.01.31
CatEscape 게임  (2) 2024.01.30
멤버 변수와 지역 변수  (0) 2024.01.29
게임 아이템 정보 출력  (0) 2024.01.24

<예시 이미지>

이미지 예시

 

1. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Hand Axe";
            string weaponType = "Axe";
            float DamagePerSecond = 3.2f;
            int minDamage = 2;
            int maxDamage = 3;
            float AttacksPerSecond = 1.30f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

 

 

1. 출력

 

2. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Aidan's Revenge";
            string weaponType = "Axe";
            float DamagePerSecond = 10.4f;
            int minDamage = 6;
            int maxDamage = 10;
            float AttacksPerSecond = 1.30f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

2. 출력

 

3. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Weathered Hand Axe";
            string weaponType = "Axe";
            float DamagePerSecond = 3.0f;
            int minDamage = 2;
            int maxDamage = 3;
            float AttacksPerSecond = 1.20f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

3. 출력

 

4. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Broad Axe";
            string weaponType = "Axe";
            float DamagePerSecond = 7.1f;
            int minDamage = 4;
            int maxDamage = 7;
            float AttacksPerSecond = 1.30f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

4.  출력

 

5. 코드

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Heavy Axe";
            string weaponType = "Axe";
            float DamagePerSecond = 17.5f;
            int minDamage = 10;
            int maxDamage = 17;
            float AttacksPerSecond = 1.30f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

5. 출력

 

6. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Marauder Axe";
            string weaponType = "Axe";
            float DamagePerSecond = 26.6f;
            int minDamage = 15;
            int maxDamage = 26;
            float AttacksPerSecond = 1.30f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

6. 출력

 

7. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Toporok";
            string weaponType = "Axe";
            float DamagePerSecond = 101.4f;
            int minDamage = 55;
            int maxDamage = 101;
            float AttacksPerSecond = 1.30f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

7. 출력

 

8. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Masakari";
            string weaponType = "Axe";
            float DamagePerSecond = 118.3f;
            int minDamage = 64;
            int maxDamage = 118;
            float AttacksPerSecond = 1.30f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

8. 출력

 

9. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Tomahawk";
            string weaponType = "Axe";
            float DamagePerSecond = 129.3f;
            int minDamage = 70;
            int maxDamage = 129 ;
            float AttacksPerSecond = 1.30f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

9. 출력

 

10. 코드

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20240124
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string weaponName = "Two-Handed Club";
            string weaponType = "Two-Handed Mace";
            float DamagePerSecond = 15.8f;
            int minDamage = 17;
            int maxDamage = 18 ;
            float AttacksPerSecond = 0.90f;

            Console.WriteLine(weaponName);
            Console.WriteLine(weaponType);
            Console.WriteLine(DamagePerSecond);
            Console.WriteLine("Damage Per Second");
            Console.WriteLine("{0}-{1} Damage", minDamage, maxDamage);
            Console.WriteLine($"{AttacksPerSecond:F2} Attacks Per Second");
        }
    }
}

 

10. 출력

'산대특 > 게임 알고리즘' 카테고리의 다른 글

C# 대리자, 람다함수  (1) 2024.01.31
Git, SourceTree  (1) 2024.01.31
CatEscape 게임  (2) 2024.01.30
멤버 변수와 지역 변수  (0) 2024.01.29
유니티 실행 시 인터페이스  (0) 2024.01.25

TypeScript 프로젝트 환경 구성하기

 

1. 프로젝트 폴더 생성

2. 폴더 안으로 이동

mkdir (폴더명)
cd (폴더명)

 

2. 새로운 프로젝트 초기화

 

npm init -y

 

3. 프로젝트 내부에서 npm을 사용할 준비가 되었으므로, 이제 TypeScript를 설치

 

npm install typescript --save-dev

 

4. 프로젝트 루트 디렉토리에 tsconfig.json 파일을 생성, 이어 밑의 내용을 붙이기

 

 

5. 이제 src 폴더 밑에 TypeScript 언어로 된 파일을 작성 가능

src 폴더에 index.ts 파일을 만들어서 TypeScript 코드를 작성

 

 

6. 만약 TypeScript 언어를 JavaScript로 컴파일한 결과를 확인하고 싶다면 아래와 같은 명령어를 터미널에 입력

npx tsc --project ./tsconfig.json

명령어를 터미널에 입력하면 위와 같이 컴파일 된 결과가 dist 폴더에 들어가게 됨

 

TypeScript ESLint와 Prettier 설정하기

TypeScript는 2020년까지만 TSLint를 지원하고, 이후부터는 typescript-eslint를 사용해야 한다.

만일 TypeScript 프로젝트에서 ESLint나 Prettier를 사용하고 싶다면, 아래의 안내를 따른다.

1. VSCode 에디터를 사용할 것이므로, 확장 프로그램인 ESLint를 설치

2. 그리고 VSCode 에디터에 다음 설정을 적용, 이동하는 명령어 cmd + shift + p

{
  // ... 
  "editor.codeActionsOnSave": {
      "source.fixAll.eslint": true
  },
  "eslint.alwaysShowStatus": true,
  "eslint.workingDirectories": [
      {"mode": "auto"}
  ],
  "eslint.validate": [
      "javascript",
      "typescript"
  ],
}

위의 내용은 사용자 설정에 넣어야 하며, 기존에 설치한 확장 프로그램들이 있다면 안이 채워져 있을 수 있다.

채워져 있다면 그 밑에 바로 내용을 넣어주면 된다.

 

 

3. 마지막으로 VSCode 에디터 설정 중 format on save가 설정되어 있는지 확인하고, 되어 있다면 설정을 해제

설정으로 이동하는 명령어는 cmd + ,

 

4. 이서서 Prettier 확장 프로그램도 설치

이어 몇 가지 필요한 라이브러리를 설치

npm i -D eslint prettier eslint-plugin-prettier @typescript-eslint/eslint-plugin @typescript-eslint/parser

 

 

6. 프로젝트 폴더 밑에 .eslintrc.js 파일을 만들고 이하 내용을 붙여 넣는다.

module.exports = {
  root: true,
  extends: [
    'plugin:@typescript-eslint/eslint-recommended',
    'plugin:@typescript-eslint/recommended',
  ],
  plugins: ['prettier', '@typescript-eslint'],
  rules: {
    'prettier/prettier': [
      'error',
      {
        doubleQuote: true,
        tabWidth: 2,
        printWidth: 80,
        bracketSpacing: true,
        arrowParens: 'avoid',
      },
    ],
    '@typescript-eslint/no-explicit-any': 'off',
    '@typescript-eslint/explicit-function-return-type': 'off',
    'prefer-const': 'off',
  },
  parserOptions: {
    parser: '@typescript-eslint/parser',
  },
};

해당 파일 내부에는 prettiertypescript-eslint에 대한 설정이 되어 있다.

rules 프로퍼티 내에 작성이 되어 있는 내용들은 옵션이며,

또한 필요하다면 React와 같은 라이브러리에도 해당 eslint가 적용될 수 있도록

env 같은 프로퍼티를 추가적으로 작성할 수 있다.

따라서 개발자의 취향에 따라 eslint 설정은 천차만별일 수 있다.

피그마를 활용한 어플리케이션 기획

 

 

 

피그마를 활용하여 앞으로 계획할 프로젝트의 초안에 대해 만들었다.

첫 번째 사진 우선 각 프레임이다.

 

두 번째 사진은 각 프레임간에 prototype이다.

 

마지막으로 완성된 피그마를 영상으로 첨부하였다.

 

 

 

 

버튼을 클릭하면 추가되는 영역까지는 아직 못하였지만,

충분히 할 수 있다고 생각하고

시간이 날 때 다시 도전해볼 예정이다.

 

 

 

웹 표준

웹 표준이란 W3C(World Wide Web Consortium)에서 권고하는 ‘웹에서 표준적으로 사용되는 기술이나 규칙’으로,

사용자가 어떠한 운영체제나 브라우저를 사용하더라도 웹페이지가 동일하게 보이고 정상적으로 작동할 수

있도록 하는 웹 페이지 제작 기법을 담고 있다.

웹 개발에 사용되는 언어인 HTML, CSS, JavaScript 등의 기술을 다룬다.

세 기술은 화면의 구조, 표현, 동작을 각각 담당합니다.

 

웹 표준의 장점

1. 유지 보수의 용이성

 

각 영역이 분리되면서 유지 보수가 용이해졌고, 코드가 경량화되면서 트래픽 비용이 감소하는 효과도 생겼다.

 

2. 웹 호환성 확보

 

웹 표준을 준수하여 웹 사이트를 제작하면 웹 브라우저의 종류나 버전,

운영 체제나 사용 기기 종류에 상관없이 항상 동일한 결과

 

3. 검색 효율성 증대

 

웹 표준에 맞춰 웹 사이트를 작성하는 것만으로도 검색 엔진에서 더 높은 우선순위로 노출된다.

 

4. 웹 접근성 향상

 

브라우저의 종류, 운영 체제의 종류, 기기의 종류 등 웹에 접근할 수 있는 환경은 매우 다양하고,

이 모든 환경과 사용자에 맞춰서 웹 페이지를 개발하는 일은 쉽지 않지만,

이것을 해결한다.

 

 

Sementic HTML이란?

 

semantic : 의미의, 의미가 있는 이라는 뜻의 영단어

HTML : 화면의 구조를 만드는 마크업 언어

이러한 화면을 시멘틱 요소를 통해

이렇게 분리할 수 있고 보기 편할 뿐 더러, 수정 및 관리하기도 편리하다.

 

1. 개발자 간 소통

 

여러 명의 개발자가 웹 페이지를 개발하면서 <div><span>으로만 HTML 코드를 작성한다고 해보자

그렇다면 요소의 이름을 보고서는 각 요소가 어떤 기능을 하는지 전혀 파악할 수 없기 때문에

주석을 작성해서 설명하거나 idclass를 사용해서 일일이 표기해야 한다.

 

2. 검색 효율성

 

시멘틱 요소를 사용하면, 어떤 요소에 더 중요한 내용이 들어있을지 우선순위를 정할 수 있고,

우선순위가 높다고 파악된 페이지를 검색 결과 상단에 표시된다.

 

3. 웹 접근성

 

웹 접근성은 나이, 성별, 장애 여부, 사용 환경을 떠나서 항상 동일한 수준의 정보를 제공할 수 있어야 함을 뜻한다.

예시를 들면, 시각 장애인의 경우 웹 페이지에 접근할 때 음성으로 화면을 스크린리더를 이용하는데,

화면의 구조에 대한 정보까지 추가로 전달해 줄 수 있어 콘텐츠를 좀 더 정확하게 전달

 


 

웹 접근성

 

일반적으로 웹 접근성은 장애인, 고령자 등이 웹 사이트에서 제공하는 정보에

비장애인과 동등하게 접근하고 이해할 수 있도록 보장하는 것을 뜻한다.

이런 상황을 해결하고자 노력하는 것이 바로 웹 접근성(Web Accessibility)

 

웹 접근성 실태

 

안타깝게도, 우리나라의 웹 접근성 수준은 높은 정보화 수준에도 불구하고 높지 않다.

2021년 기준, 일반 국민의 정보화 수준을 100이라고 할 때,

장애인, 고령층 등 디지털 취약 계층의 정보화 지수는 75.4점이었고,

우리나라 웹 사이트들의 웹 접근성 평균 점수는 100점 만점에 60.8점이다.

 

국내 온라인 쇼핑몰 사이트를 보면 상품의 상세 정보가 이미지로 올라와 있는 경우가 많고,

텍스트로 표시된 정보는 굉장히 제한적이다.

이런 문제점을 파악하고 이미지 속 글자를 인식하여 텍스트로 변환, 스크린 리더가 읽을 수 있게

만드는 기능을 제공하는 사이트도 있지만,

이미지 속 글자를 인식하고 변환하는 과정에서 시간이 소요되기 때문에

텍스트로 작성되어 있는 경우와 비교했을 때 정보에 접근하는데 시간이 더 걸리게 된다.

 


 

웹 접근성을 갖추면 얻을 수 있는 효과

 

1. 사용자층 확대

 

웹 접근성을 확보하면 장애인, 고령자 등 정보 소외 계층도 웹 사이트를 자유롭게 이용할 수 있게 된다.

그만큼 사이트의 이용자를 늘릴 수 있고, 새로운 고객층을 확보할 수 있게 된다.

실제로 웹 접근성 향상을 통해 매출이 증가한 외국 쇼핑몰 사례도 있으며,

국내 온라인 쇼핑몰에서도 노년층의 매출이 증가 추세를 보이고 있다.

 

2. 다양한 환경 지원

 

앞서 이야기했듯 정보 소외 계층이 아니더라도 정보에 접근하기 어려운 상황에 처할 수 있다.

운전 중이라 화면을 보기 어렵거나, 마우스를 사용할 수 없는 상황 등이 있다.

웹 접근성을 향상 시키면 다양한 환경, 다양한 기기에서의 웹 사이트를 자유롭게 사용할 수 있게 되므로

서비스의 사용 범위가 확대되고, 자연스럽게 서비스의 이용자 수 증가를 기대할 수 있다.

 

3. 사회적 이미지 향상

 

기업의 사회적 책임에 대한 중요성이 점점 증가하고 있는 상황에서,

웹 접근성 확보를 통해 기업이 정보 소외 계층을 위한 사회 공헌 및 복지 향상에 힘쓰고 있음을 보여줄 수 있다.

기업의 사회적 이미지가 향상되면 그만큼 이용자 수의 증가는 물론 충성 고객을 확보할 수 있는 가능성이 늘어나게 된다.

 

 

 

상태(state)란?

상태는 변하는 데이터입니다. 특별히 UI, 프론트엔드 개발에서는 "동적으로 표현되는 데이터"입니다.

 

로컬 상태란?

다른 컴포넌트와 데이터를 공유하지 않는 폼(form) 데이터는 대부분 로컬 상태

input box, select box 등과 같이 입력값을 받는 경우가 이에 해당

 

전역 상태란?

다른 컴포넌트와 상태를 공유하고 영향을 끼치는 상태

서로 다른 컴포넌트가 사용하는 상태의 종류가 다르면, 꼭 전역 상태일 필요는 없다.

출처(source)가 달라도 된다.

그러나, 서로 다른 컴포넌트가 동일한 상태를 다룬다면, 이 출처는 오직 한 곳이어야 한다.

만일 사본이 있을 경우, 두 데이터는 서로 동기화(sync)하는 과정이 필요한데, 이는 문제를 어렵게 만든다.

 

그렇다면 전역으로 상태를 관리해야 하는 경우는?

ex) 홈페이지 다크모드, 국제화 설정(홈페이지 영어 -> 한글로 번역 )

 

Side Effect란?

"함수의 입력 외에도 함수의 결과에 영향을 미치는 요인"입니다. 대표적으로 네트워크 요청, API 호출이 Side Effect"

 

하지만 상태 관리 툴이 반드시 필요하지는 않다.

상태 관리 툴이 없어도 충분히 규모 있는 애플리케이션을 만들 수 있다.

그러므로 장단점을 인지하고 사용해야 한다.

 

 

위 컴포넌트의 state를 props를 통해 전달하고자 하는 컴포넌트로 전달하기 위해 그 사이는 props를 전달하는 용도로만 쓰이는 컴포넌트들을 거치면서 데이터를 전달하는 현상을 의미한다.

위 그림처럼 컴포넌트 A의 state를 컴포넌트 D로 전달하기 위해선 사이에 있는 컴포넌트 B, C를 거쳐야 한다.

 

<Props Drilling의 문제점>

Props의 전달 횟수가 5회 이내로 많지 않다면 Props Drilling 은 큰 문제가 되지 않지만,

규모가 커지고 구조가 복잡해지면서 Props의 전달 과정이 늘어난다면 아래와 같은 문제가 발생한다.

 

● 코드의 가독성이 매우 나빠지게 됩니다.

● 코드의 유지보수 또한 힘들어지게 됩니다.

● state 변경 시 Props 전달 과정에서 불필요하게 관여된 컴포넌트들 또한 리렌더링이 발생.

따라서, 웹성능에 악영향을 줄 수 있다.

 

이러한 상황에 다양한 상태관리 라이브러리(Redux, Context api, Mobx, Recoil)를 사용하여 방지할 수 있다.

 


 

Redux

 

Redux에서는 컴포넌트와 상태를 분리하는 패턴을 배운다.

따라서 상태 변경 로직을 컴포넌트로부터 분리하여 표현에 집중한, 보다 단순한 함수 컴포넌트로 만들 수 있다.

 

기존에 배운 React의 데이터 흐름에 따르면, 최상위 컴포넌트에 위치시키는 것이 적절하다.

하지만 이런 상태 배치는 다음과 같은 이유로 다소 비효율적이라고 느껴질 수 있다.

 

1. 해당 상태를 직접 사용하지 않는 최상위 컴포넌트, 컴포넌트1, 컴포넌트2도 상태 데이터를 가짐

2. 상태 끌어올리기, Props 내려주기를 여러 번 거쳐야 함

3. 애플리케이션이 복잡해질수록 데이터 흐름도 복잡해짐

4. 컴포넌트 구조가 바뀐다면, 지금의 데이터 흐름을 완전히 바꿔야 할 수도 있음

 

라이브러리인 Redux는, 전역 상태를 관리할 수 있는 저장소인 Store를 제공함으로써 이 문제들을 해결

Redux의 구조 / 참조:codestates

  1. 상태가 변경되어야 하는 이벤트가 발생하면, 변경될 상태에 대한 정보가 담긴 Action 객체가 생성
  2. 이 Action 객체는 Dispatch 함수의 인자로 전달.
  3. Dispatch 함수는 Action 객체를 Reducer 함수로 전달
  4. Reducer 함수는 Action 객체의 값을 확인하고, 그 값에 따라 전역 상태 저장소 Store의 상태를 변경
  5. 상태가 변경되면, React는 화면을 다시 렌더링

   즉, Redux에서는 Action → Dispatch → Reducer → Store 순서로 데이터가 단방향으로 흐르게 된다.

 

 

 

+ https://facebookarchive.github.io/flux/docs/in-depth-overview/

좋은 UX를 만드는 요소

 

1. 유용성(Useful) : 사용 가능한가?

2. 사용성(Usable) : 사용하기 쉬운가?

3. 매력성(Desirable) : 매력적인가?

4. 신뢰성(Credible) : 신뢰할 수 있는가?

5. 접근성(Accessible) : 접근하기 쉬운가?

6. 검색 가능성(Findable) : 찾기 쉬운가?

7. 가치성(Valuable) : 가치를 제공하는가?

 


 

User Flow

 

 

User Flow 다이어그램을 그리면 좋은 이유

 

 

1. 사용자 흐름 상 어색하거나 매끄럽지 않은 부분을 발견하여 수정할 수 있음

2. 있으면 좋은 기능을 발견하여 추가하거나 없어도 상관없는 기능을 발견하고 삭제할 수 있음

 


 

제이콥 닐슨의 10가지 사용성 평가 기준 (Jakob's Ten Usability Heuristics)

여기서, Heuristic(휴리스틱)이란? '체험적인'이라는 뜻으로, 완벽한 지식 대신 직관과 경험을 활용하는 방법론

 

1. 시스템 상태의 가시성 (Visibility of system status)

합리적인 시간 내에 적절한 피드백을 통해 사용자에게 진행 상황에 대한 정보를 항상 제공해야 한다.

Visibility of system status

 

2. 시스템과 현실 세계의 일치 (Match between system and the real world)

내부 전문용어가 아닌 사용자에게 친숙한 단어, 구문 및 개념을 사용

Match between system and the real world

 

3. 사용자 제어 및 자유 (User control and freedom)

사용자는 종종 실수를 한다.

현재 진행 중인 작업에서 벗어날 수 있는 방법,

혹은 실수로 수행한 작업을 취소할 수 있는 방법, ’탈출구’를 명확하게 제공해야 한다.

User control and freedom

 

4. 일관성 및 표준 (Consistency and standards)

외부 일관성 : 일관적인 사용자 경험을 제공하기 위해서 플랫폼 및 업계의 관습을 따르자.

사용자에게 익숙한 UI를 제공해라. 잘 알려진 UI 디자인 패턴을 사용하는 것이 좋다.

내부 일관성 : 사용자가 혼란스럽지 않도록 제품의 인터페이스나 정보 제공에 일관성이 있어야 한다.

예시) 한 제품 내에서 같은 인터페이스를 유지한다.(버튼의 모양, 위치, 아이콘 크기 등)

 

Consistency and standards

 

5. 오류 방지 (Error prevention)

오류가 발생하기 쉬운 상황을 제거하여 사용자의 실수를 방지해야 한다.

Error prevention

 

6. 기억보다는 직관 (Recognition rather than recall)

사용자가 기억해야 하는 정보를 줄인다.

Recognition rather than recall

 

7. 사용의 유연성과 효율성 (Flexibility and efficiency of use)

초보자와 전문가 모두에게 개별 맞춤 기능을 제공하도록 한다.

Flexibility and efficiency of use

 

8. 미학적이고 미니멀한 디자인 (Aesthetic and minimalist design)

인터페이스에는 관련이 없거나 불필요한 정보가 포함되지 않도록 한다.

콘텐츠와 기능의 우선순위를 정하고 우선순위가 높은 것을 잘 제공하고 있는지 확인해야 한다.

Aesthetic and minimalist design

 

9. 오류의 인식, 진단, 복구를 지원 (Help users recognize, diagnose, and recover from errors)

사용자가 이해할 수 있는 언어를 사용하여 문제가 무엇인지 정확하게 표시하고, 해결 방법을 제안해야 한다.

Help users recognize, diagnose, and recover from errors)

 

10. 도움말 및 설명 문서 (Help and documentation)

추가 설명이 필요 없는 것이 가장 좋지만, 상황에 따라 이해하는 데 도움이 되는 문서를 제공해야 한다.

Help and documentation

 

'코드스테이츠 프론트과정' 카테고리의 다른 글

[사용자 친화 웹] 웹 표준 & 접근성  (0) 2023.06.28
[React] 상태 관리  (0) 2023.06.23
[사용자 친화 웹] UI/UX -1  (2) 2023.06.13
[객체 지향 프로그래밍]  (0) 2023.05.11
[클래스와 인스턴스]  (0) 2023.05.11

+ Recent posts