Notice
Recent Posts
Recent Comments
Link
반응형
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 |
Tags
- 티스토리챌린지
- navisworks api
- dfs
- 유니티 sparkmain(clone)
- 크루스칼
- unity sparkmain(clone)
- sparkmain(clone) 무한생성
- 디지털트윈
- raycast
- GetComponent
- C#
- 행동트리
- articulation body
- readonly
- removeAll
- 드롭다운
- 트리구조
- 너비탐색
- 오블완
- 유니티
- 최단거리 알고리즘
- 습관형성 #직장인자기계발 #오공완
- 깊이탐색
- sparkmain(clone)
- 최소신장트리 mst
- dropdown
- Simulation
- list clear
- unity korea
- Unity
Archives
- Today
- Total
낑깡의 게임 프로그래밍 도전기
제트카라 재 커스텀 본문
반응형






using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class Card
{
public string name;
public int cost;
public Card(string name, int cost)
{
this.name = name;
this.cost = cost;
}
}
public class Deck : List<Card>
{
public class DeckEnumerator : IEnumerator
{
List<Card> cards;
public event Action onEmpty;
int curIndex = -1;
public DeckEnumerator(Deck deck)
{
cards = deck;
}
public object Current => cards[curIndex];
public bool MoveNext()
{
curIndex++;
bool isEmpty = curIndex >= cards.Count;
if (isEmpty)
onEmpty?.Invoke();
return !isEmpty;
}
public void Reset()
{
curIndex = -1;
}
}
public new DeckEnumerator GetEnumerator()
{
return new DeckEnumerator(this);
}
}
public class DeckController : MonoBehaviour
{
Deck deck;
public int hp = 30;
public int reduceHp = 1;
Deck.DeckEnumerator deckEnumerator;
void Start()
{
deck = new Deck();
deck.Add(new Card("강타", 3));
deck.Add(new Card("이글거리는도끼", 2));
deck.Add(new Card("방패올리기", 3));
deckEnumerator = deck.GetEnumerator();
deckEnumerator.onEmpty += () => {
Debug.Log("카드가 다 떨어졌습니다.");
hp -= reduceHp++;
};
}
void Draw()
{
if(deckEnumerator.MoveNext())
{
Card drawCard = (Card)deckEnumerator.Current;
Debug.Log(drawCard.name);
}
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
Draw();
}
}
}반응형
'Unity C#' 카테고리의 다른 글
| 유니티 C# Behaviour Tree(행동트리) ...어렵다 (0) | 2023.11.22 |
|---|---|
| 유니티 C# tree(트리) (0) | 2023.11.21 |
| C# 딕셔너리 (1) | 2023.11.16 |
| C# Queue(큐), 반복자 패턴, ?표 시리즈 (0) | 2023.11.15 |
| C# 상태머신 상태패턴 (0) | 2023.11.14 |