카드 디버그 모드

카드 뒤집기 게임은 초기설정이 뒷면이다.

앞면을 수정해야 할 때, 모두 뒷면만 보이기 때문에 Debug 모드를 만들었다.

  • 카드와 보드에 public bool Debug 생성
  • 보드 초기화시 카드가 생성된다. 그때 보드의 Debug 값을 카드도 받아간다.
  • 카드는 업데이트에서 카드를 open하는 함수를 호출한다.

난이도 조절

카드 뒤집기의 난이도는 여러 요소로 조정 가능하다.

그 중 우리팀은 카드 종류의 갯수와 카드가 다시 뒷면으로 넘어가는 시간을 조정하기로 했다.

카드 종류의 갯수는 Board.cs에서, 카드가 다시 뒷면으로 넘어가는 시간은 Card.cs에서 조정한다.

  • 카드 갯수를 조정하기위해, public int Level을 받아온다.
  • 이후 Level에 맞게 카드의 index를 조정한다.
    • 1단계 5종류
    • 2단계 7종류
    • 3단계 10종류
  • 보드에서 카드를 생성할때, 카드에게도 Level값을 넣어준다.
// Board.cs

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

public class Board : MonoBehaviour
{
    public GameObject card;
    public bool Debug_Mode = false;
    public int Level = 1;

    void Start()
    {
        // Level 1일때
        int[] arr = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4 };

        if (Level == 2)
        {
            arr = new int[] { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 , 6, 6, 6, 6, 7, 7, 7, 7};
        }
        else if (Level == 3)
        {
            arr = new int[] { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9 };
        }

        arr = arr.OrderBy(x => Random.Range(0f, 10f)).ToArray();

        for (int i = 0; i < 20; i++)
        {
            GameObject callCard = Instantiate(card, this.transform); 
            callCard.name = i.ToString();
            float x = (i % 4) * 1.4f - 2.1f;
            float y = (i / 4) * 1.4f - 4.0f;
            callCard.transform.position = new Vector2(x, y);

            Card cardScript = callCard.GetComponent<Card>();
            cardScript.LevelValue = Level;
            
            callCard.GetComponent<Card>().Setting(arr[i]);
            // 카드에 Level값 넣어준다.
            callCard.GetComponent<Card>().LevelValue = Level;
            // 카드에 Debug모드를 알려준다.
            callCard.GetComponent<Card>().Debug_Mode = Debug_Mode;
        }
        GameManager.Instance.cardCount = arr.Length;
    }

}
// Card.cs

public class Card : MonoBehaviour
{
	.
    .
    .
    
    public bool Debug_Mode = false;
    public int idx = 0;
    public float LevelValue = 1;
    
    void Update()
    {
    	// Debug모드로 카드를 뒤집어 앞면을 보여준다.
        if (Debug_Mode)
            anim.SetTrigger("isOpen");
    }
    
    public void OpenCard()  
    {
        if (!GameManager.Instance.isCanOpen) return;
        if (GameManager.Instance.firstTry == null)
        {
            GameManager.Instance.firstTry = this;
            anim.SetTrigger("isOpen");
            audioSource.PlayOneShot(clip, 0.3f);
        }
        else 
        {
            GameManager.Instance.secondTry = this; 
            if (GameManager.Instance.firstTry.name == GameManager.Instance.secondTry.name)
            {
                GameManager.Instance.secondTry = null;
                return;
            }
            anim.SetTrigger("isOpen");

            // 난이도 조절 가능. 카드 뒤집히는 속도
            Invoke("Match", 0.5f / (LevelValue / 2)); 

            GameManager.Instance.isCanOpen = false;
            audioSource.PlayOneShot(clip, 0.3f);
        }
    }
    
    .
    .
    .
}

태그: ,

카테고리:

업데이트:

댓글남기기