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
- 티스토리챌린지
- 디지털트윈
- 유니티 sparkmain(clone)
- removeAll
- sparkmain(clone) 무한생성
- 최소신장트리 mst
- Simulation
- 오블완
- articulation body
- readonly
- unity sparkmain(clone)
- 행동트리
- dropdown
- GetComponent
- 트리구조
- 깊이탐색
- navisworks api
- 너비탐색
- unity korea
- 드롭다운
- 크루스칼
- 최단거리 알고리즘
- 유니티
- raycast
- Unity
- BFS
- dfs
- C#
- sparkmain(clone)
- list clear
Archives
- Today
- Total
낑깡의 게임 프로그래밍 도전기
제트카라 재 커스텀 본문
반응형
SMALL
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();
}
}
}
반응형
LIST