Commit 27bff278 authored by 황호기's avatar 황호기

데이터 로직과 보여주는 로직 분리 완료

parent 46229780
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TBR.Game;
public class CharacterObj : MonoBehaviour
{
private Character character;
public void SetCharacter(Character character)
{
this.character = character;
}
public IEnumerator SelectCard()
{
yield return null;
}
public IEnumerator UseSkill()
{
yield return null;
}
public IEnumerator Action()
{
yield return null;
}
}
......@@ -2,22 +2,26 @@
using System.Collections.Generic;
using UnityEngine;
using TBR.Data;
using TBR.Game;
public class GameLogic : MonoBehaviour {
public static GameLogic CurGameLogic;
private Party party1;
[SerializeField]
private CharacterObj[,] characters;
private DataLogic dataLogic;
[SerializeField]
private PartyUI partyUI1;
private Party party2;
[SerializeField]
private PartyUI partyUI2;
private int turn;
private int firstTurnParty;
// Use this for initialization
void Start () {
CurGameLogic = this;
dataLogic = new DataLogic();
StartCoroutine( MainLogic() );
}
......@@ -28,33 +32,60 @@ public class GameLogic : MonoBehaviour {
IEnumerator MainLogic()
{
//임시 코드(Hsymbol) - 어디선가 파티 데이터를 가져와서 파티를 만들어야 함
party1 = Party.MakeRandomParty();
party2 = Party.MakeRandomParty();
dataLogic.MakeRandomData();
for ( int p = 0; p < 2; p++ )
{
for ( int i = 0; i < 5; i++ )
{
characters[ p, i ].SetCharacter( dataLogic.Parties[ p ].Characters[ i ] );
}
}
yield return null;
turn = 0;
while (true)
while (turn < 40)
{
party1.SetNonLeaderCard();
if ( party1.LeaderAlive )
yield return party1.SetLeaderCard();
yield return party1.UseSkill();
party1.CalcBonus();
yield return party1.Action();
if ( CheckGameOver() )
break;
turn++;
party2.SetNonLeaderCard();
if ( party2.LeaderAlive )
yield return party2.SetLeaderCard();
yield return party2.UseSkill();
party2.CalcBonus();
yield return party2.Action();
int currentTurnParty = ( firstTurnParty + turn ) % 2;
yield return ShowNonLeaderCard( currentTurnParty );
if ( dataLogic.Parties[ currentTurnParty ].LeaderAlive )
yield return SetLeaderCard( currentTurnParty );
yield return UseSkill( currentTurnParty );
dataLogic.CalcAndAssignBonus( currentTurnParty );
yield return Action( currentTurnParty );
if ( CheckGameOver() )
break;
turn++;
}
}
public IEnumerator ShowNonLeaderCard( int partyNum )
{
dataLogic.SetNonLeaderCard( partyNum );
yield return null;
}
public IEnumerator SetLeaderCard(int partyNum)
{
yield return characters[ partyNum, dataLogic.Parties[ partyNum ].LeaderIndex ].SelectCard();
}
public IEnumerator UseSkill( int partyNum )
{
dataLogic.UseSkill( partyNum );
for ( int i = 0; i < 5; i++ )
{
yield return characters[ partyNum, i ].UseSkill();
}
}
public IEnumerator Action( int partyNum )
{
dataLogic.Action( partyNum );
for ( int i = 0; i < 5; i++ )
{
yield return characters[ partyNum, i ].Action();
}
}
private bool CheckGameOver()
{
return false;
......
using System.Collections.Generic;
using System.Linq;
using TBR.Game;
namespace TBR.Data
{
......@@ -9,65 +10,75 @@ namespace TBR.Data
private const int fullhouseBonus = 50;
private const int straightBonus = 30;
private const int twopairBonus = 5;
public static int[] GetPowerBonus(CardData[] cardDatas)
public static string CalcAndAssignBonus(Character[] characters )
{
var bonus = new int[ 5 ] { 1, 1, 1, 1, 1 };
if ( cardDatas[ 0 ] != null && cardDatas[ 1 ] != null && cardDatas[ 2 ] != null && cardDatas[ 3 ] != null && cardDatas[ 4 ] != null )
if ( cardDatas[ 0 ].Element == cardDatas[ 1 ].Element && cardDatas[ 1 ].Element == cardDatas[ 2 ].Element
&& cardDatas[ 2 ].Element == cardDatas[ 3 ].Element && cardDatas[ 3 ].Element == cardDatas[ 4 ].Element )
bonus = new int[ 5 ] { 2, 2, 2, 2, 2 };
List<int> counts = new List<int> { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
CardData[] cardData = new CardData[ 5 ];
for ( int i = 0; i < 5; i++ )
{
if ( characters[ i ] != null )
cardData[ i ] = characters[ i ].SelectedCard;
}
//PowerBonus
var powerBonus = new int[ 5 ] { 1, 1, 1, 1, 1 };
if ( cardData[ 0 ] != null && cardData[ 1 ] != null && cardData[ 2 ] != null && cardData[ 3 ] != null && cardData[ 4 ] != null )
if ( cardData[ 0 ].Element == cardData[ 1 ].Element && cardData[ 1 ].Element == cardData[ 2 ].Element
&& cardData[ 2 ].Element == cardData[ 3 ].Element && cardData[ 3 ].Element == cardData[ 4 ].Element )
powerBonus = new int[ 5 ] { 2, 2, 2, 2, 2 };
List<int> numberCounts = new List<int> { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
List<int> pairTable = new List<int>( pairBonus );
foreach ( var c in cardDatas )
foreach ( var c in cardData )
{
if ( c != null )
counts[ c.Number ]++;
numberCounts[ c.Number ]++;
}
if ( counts.Contains( 3 ) && counts.Contains( 2 ) )
if ( numberCounts.Contains( 3 ) && numberCounts.Contains( 2 ) )
{
pairTable[ 1 ] = fullhouseBonus;
pairTable[ 2 ] = fullhouseBonus;
}
else if ( counts.Count(c=>c==1)==5 )
else if ( numberCounts.Count(c=>c==1)==5 )
{
var firstNum = counts.IndexOf( 1 );
if ( counts[ firstNum ] == 1 && counts[ firstNum + 1 ] == 1 && counts[ firstNum + 2 ] == 1 && counts[ firstNum + 3 ] == 1 && counts[ firstNum + 4 ] == 1 )
var firstNum = numberCounts.IndexOf( 1 );
if ( numberCounts[ firstNum ] == 1 && numberCounts[ firstNum + 1 ] == 1 && numberCounts[ firstNum + 2 ] == 1 && numberCounts[ firstNum + 3 ] == 1 && numberCounts[ firstNum + 4 ] == 1 )
pairTable[ 0 ] = straightBonus;
}
else if ( counts.Count( c => c == 2 ) == 2 )
else if ( numberCounts.Count( c => c == 2 ) == 2 )
{
pairTable[ 1 ] = twopairBonus;
}
for ( int i = 0; i < 5; i++ )
{
if ( cardDatas[ i ] != null )
if ( cardData[ i ] != null )
{
bonus[ i ] *= pairTable[ counts[ cardDatas[ i ].Number ] ];
powerBonus[ i ] *= pairTable[ numberCounts[ cardData[ i ].Number ] ];
}
}
return bonus;
}
public static int[] GetCountBonus( CardData[] cardDatas )
{
var bonus = new int[ 5 ] { -2, -2, -2, -2, -2 };
int[] counts = new int[ 5 ];
foreach(var c in cardDatas)
//CountBonus
var countBonus = new int[ 5 ] { -2, -2, -2, -2, -2 };
int[] elementCounts = new int[ 5 ];
foreach ( var c in cardData )
{
if ( c != null )
counts[ ( int )c.Element ]++;
elementCounts[ ( int )c.Element ]++;
}
for(int i=0; i<5; i++ )
for ( int i = 0; i < 5; i++ )
{
if ( cardDatas[ i ] != null )
if ( cardData[ i ] != null )
{
int matchBonus = 1;
for ( int j = 0; j < counts[ ( int )cardDatas[ i ].Element ]; j++ )
for ( int j = 0; j < elementCounts[ ( int )cardData[ i ].Element ]; j++ )
matchBonus *= 2;
bonus[ i ] += matchBonus;
countBonus[ i ] += matchBonus;
}
}
return bonus;
for ( int i = 0; i < 5; i++ )
{
if ( characters[ i ] != null )
characters[ i ].SetBonus( powerBonus[ i ], countBonus[ i ] );
}
return "";
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TBR.Game
{
public enum BuffType
{
SwordUp
}
public class Buff
{
public BuffType Type { get; private set; }
public int Arg1 { get; private set; }
public int Arg2 { get; private set; }
public int BuffValue { get; private set; }
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TBR.Data;
namespace TBR.Game
{
public class Character
{
private CharacterData baseData;
public int HP { get; private set; }
public int MaxHP { get; private set; }
public int ShieldStack { get; private set; }
public List<Buff> buffs { get; private set; }
public int Sword { get; private set; }
public int Gun { get; private set; }
public int Mana { get; private set; }
public int Shield { get; private set; }
public int Heal { get; private set; }
public CardData SelectedCard { get; private set; }
public string SelectedSkill { get; private set; }
private int powerBonus;
private int countBonus;
public Character( CharacterData data )
{
baseData = data;
HP = data.HP;
MaxHP = HP * 2;
buffs = new List<Buff>();
Sword = data.Sword;
Gun = data.Gun;
Mana = data.Mana;
Shield = data.Shield;
Heal = data.Heal;
}
public void SetCard()
{
var selectedIndex = Random.Range( 0, 10 );
SelectedCard = baseData.CardCases[ selectedIndex ].Card;
SelectedSkill = baseData.CardCases[ selectedIndex ].SkillId;
}
public void SetBonus( int powerBonus, int countBonus )
{
this.powerBonus = powerBonus;
this.countBonus = countBonus;
}
public void UseSkill()
{
}
public void Action()
{
var actionId = baseData.ActionIds[ SelectedCard.Element ];
}
public static Character MakeRandomCharacter()
{
var data = new CharacterData();
data.Randomize();
var character = new Character( data );
return character;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TBR.Game
{
public class DataLogic
{
public Party[] Parties { get; private set; }
public DataLogic()
{
Parties = new Party[ 2 ];
}
public void MakeRandomData()
{
//임시 코드(Hsymbol) - 어디선가 파티 데이터를 가져와서 파티를 만들어야 함
Parties[ 0 ] = Party.MakeRandomParty();
Parties[ 1 ] = Party.MakeRandomParty();
}
public void SetNonLeaderCard(int partyNum)
{
Parties[ partyNum ].SetNonLeaderCard();
}
public void UseSkill( int partyNum )
{
Parties[ partyNum ].UseSkill();
}
public void CalcAndAssignBonus( int partyNum )
{
Parties[ partyNum ].CalcAndAssignBonus();
}
public void Action( int partyNum )
{
Parties[ partyNum ].Action();
}
}
}
using System;
using System.Collections;
using System.Linq;
using System.Text;
using TBR.Data;
namespace TBR.Game
{
public class Party
{
public Character[] Characters { get; private set; }
public string LeaderSkillId { get; private set; }
public int LeaderIndex { get; private set; }
public bool LeaderAlive { get; private set; }
public Party()
{
Characters = new Character[ 5 ];
}
public void SetPartyData( PartyData partyData )
{
}
public void SetNonLeaderCard()
{
for ( int i = 0; i < 5; i++ )
{
if ( i != LeaderIndex || !LeaderAlive )
Characters[ LeaderIndex ].SetCard();
}
}
public void UseSkill()
{
for ( int i = 0; i < 5; i++ )
{
if ( Characters[ i ] != null && string.IsNullOrEmpty( Characters[ i ].SelectedSkill ) == false )
Characters[ i ].UseSkill();
}
}
public void Action()
{
for ( int i = 0; i < 5; i++ )
{
if ( Characters[ i ] != null )
Characters[ i ].Action();
}
}
public string CalcAndAssignBonus()
{
return Calculator.CalcAndAssignBonus( Characters );
}
public static Party MakeRandomParty()
{
var party = new Party();
party.Characters[ 0 ] = Character.MakeRandomCharacter();
party.Characters[ 1 ] = Character.MakeRandomCharacter();
party.Characters[ 2 ] = Character.MakeRandomCharacter();
party.Characters[ 3 ] = Character.MakeRandomCharacter();
party.Characters[ 4 ] = Character.MakeRandomCharacter();
return party;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public enum BuffType
{
SwordUp
}
public class Buff
{
public BuffType Type { get; private set; }
public int Arg1 { get; private set; }
public int Arg2 { get; private set; }
public int BuffValue { get; private set; }
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TBR.Data;
public class Character
{
private CharacterData baseData;
public int HP { get; private set; }
public int MaxHP { get; private set; }
public int ShieldStack { get; private set; }
public List<Buff> buffs { get; private set; }
public int Sword { get; private set; }
public int Gun { get; private set; }
public int Mana { get; private set; }
public int Shield { get; private set; }
public int Heal { get; private set; }
public CardData SelectedCard { get; private set; }
public string SelectedSkill { get; private set; }
private int powerBonus;
private int countBonus;
public Character( CharacterData data )
{
baseData = data;
HP = data.HP;
MaxHP = HP * 2;
buffs = new List<Buff>();
Sword = data.Sword;
Gun = data.Gun;
Mana = data.Mana;
Shield = data.Shield;
Heal = data.Heal;
}
public void SetCard()
{
var selectedIndex = Random.Range( 0, 10 );
SelectedCard = baseData.CardCases[ selectedIndex ].Card;
SelectedSkill = baseData.CardCases[ selectedIndex ].SkillId;
}
public IEnumerator SelectCard()
{
yield return null;
}
public IEnumerator UseSkill()
{
yield return null;
}
public void SetBonus(int powerBonus, int countBonus)
{
this.powerBonus = powerBonus;
this.countBonus = countBonus;
}
public IEnumerator Action()
{
var actionId = baseData.ActionIds[ SelectedCard.Element ];
yield return null;
}
public static Character MakeRandomCharacter()
{
var data = new CharacterData();
data.Randomize();
var character = new Character( data );
return character;
}
}
using System;
using System.Collections;
using System.Linq;
using System.Text;
using TBR.Data;
public class Party
{
public Character[] Characters { get; private set; }
public string LeaderSkillId { get; private set; }
public int LeaderIndex { get; private set; }
public bool LeaderAlive { get; private set; }
public Party()
{
Characters = new Character[ 5 ];
}
public void SetPartyData(PartyData partyData)
{
}
public void SetNonLeaderCard()
{
for(int i=0;i<5;i++ )
{
if ( i != LeaderIndex || !LeaderAlive )
Characters[ LeaderIndex ].SetCard();
}
}
public IEnumerator SetLeaderCard()
{
yield return Characters[ LeaderIndex ].SelectCard();
}
public IEnumerator UseSkill()
{
for ( int i = 0; i < 5; i++ )
{
if ( string.IsNullOrEmpty( Characters[ i ].SelectedSkill ) )
yield return Characters[ i ].UseSkill();
}
}
public void CalcBonus()
{
CardData[] cards = new CardData[ 5 ];
for(int i=0;i<5;i++ )
{
if ( Characters[ i ] != null )
cards[ i ] = Characters[ i ].SelectedCard;
}
int[] powerBonus = Calculator.GetPowerBonus( cards );
int[] countBonus = Calculator.GetCountBonus( cards );
for ( int i = 0; i < 5; i++ )
{
if ( Characters[ i ] != null )
Characters[ i ].SetBonus( powerBonus[ i ], countBonus[ i ] );
}
}
public IEnumerator Action()
{
for ( int i = 0; i < 5; i++ )
{
if ( string.IsNullOrEmpty( Characters[ i ].SelectedSkill ) )
yield return Characters[ i ].Action();
}
}
public static Party MakeRandomParty()
{
var party = new Party();
party.Characters[ 0 ] = Character.MakeRandomCharacter();
party.Characters[ 1 ] = Character.MakeRandomCharacter();
party.Characters[ 2 ] = Character.MakeRandomCharacter();
party.Characters[ 3 ] = Character.MakeRandomCharacter();
party.Characters[ 4 ] = Character.MakeRandomCharacter();
return party;
}
}
m_EditorVersion: 2018.2.12f1
m_EditorVersion: 2018.2.13f1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment