UE - 멀티플레이 숫자야구
UnrealEngine
멀티플레이 숫자 야구 게임을 만들었다.
게임의 주요 로직은 게임 모드에서 관리한다.
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "BaseballGameModeBase.generated.h"
UENUM(BlueprintType)
enum class EBaseballResult : uint8
{
None UMETA(DisplayName = "None"), // 기본 상태
ThreeStrike UMETA(DisplayName = "ThreeStrike"), // 이김
Out UMETA(DisplayName = "Out"), // 짐
};
UCLASS()
class SAMPLECHAT_API ABaseballGameModeBase : public AGameModeBase
{
GENERATED_BODY()
public:
ABaseballGameModeBase();
virtual void BeginPlay() override;
UFUNCTION(BlueprintCallable)
void TryAnswer(FString UserID, FString Num);
UFUNCTION(BlueprintCallable)
void StartGame(); // 게임의 시작
UFUNCTION(BlueprintCallable)
void EndGame(); // 게임 종료
UFUNCTION(BlueprintCallable)
void StartRound(); // 라운드 시작
UFUNCTION(BlueprintCallable)
void StartTurn(); // 특정 플레이어의 턴 시작. 플레이어 구별은 CurrentTurnPlayerID로 구별
UFUNCTION(BlueprintCallable)
void EndTurn(); // 턴의 종료. 대기 중인 플레이어가 있다면 해당 플레이어에게, 없다면 다음 라운드로.
UFUNCTION(BlueprintImplementableEvent, Category="Baseball")
void GetALLUserIDs(); // 모든 플레이어의 아이디를 수집
protected:
void SendTurnResults();
UPROPERTY(EditDefaultsOnly, Category="Baseball")
int CurrentRound = 0;
UPROPERTY(EditDefaultsOnly, Category="Baseball")
int MaxRound = 3;
UPROPERTY(BlueprintReadWrite, Category="Baseball")
TArray<FString> UserIDs;
int32 UserIDIndex = 0;
//TQueue<FString> PlayerIDQueue;
UPROPERTY()
FString CurrentTurnPlayerID; // 현재 턴의 플레이어
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TMap<int, int> Answer; // 정답
UPROPERTY()
EBaseballResult CurrentTurnResult; // 해당 턴의 상태
};
랜덤 숫자와 정답 확인은 BlueprintFuntionLibrary에 구현했다.
1
2
3
4
5
6
7
8
9
10
11
UCLASS()
class SAMPLECHAT_API UBaseballBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category="Baseball")
static TMap<int32, int32> GetRandomNumbers(); // 중복없는 랜덤 숫자 3개를 반환
UFUNCTION(BlueprintCallable, Category="Baseball")
static void CheckAnswer(const TMap<int32, int32>& Result, const FString& Answer, int32& Strike, int32& Ball); // 정답 비교교
};
This post is licensed under CC BY 4.0 by the author.