Commit aad117c6 authored by 황호기's avatar 황호기

로직과 보여주는 부분 분리 시작

parent 46229780
......@@ -38,7 +38,7 @@ public class GameLogic : MonoBehaviour {
if ( party1.LeaderAlive )
yield return party1.SetLeaderCard();
yield return party1.UseSkill();
party1.CalcBonus();
party1.CalcAndAssignBonus();
yield return party1.Action();
if ( CheckGameOver() )
break;
......@@ -47,7 +47,7 @@ public class GameLogic : MonoBehaviour {
if ( party2.LeaderAlive )
yield return party2.SetLeaderCard();
yield return party2.UseSkill();
party2.CalcBonus();
party2.CalcAndAssignBonus();
yield return party2.Action();
if ( CheckGameOver() )
break;
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class PartyObj
{
}
\ No newline at end of file
......@@ -9,32 +9,38 @@ 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 };
CardData[] cardDatas = new CardData[ 5 ];
for ( int i = 0; i < 5; i++ )
{
if ( characters[ i ] != null )
cardDatas[ i ] = characters[ i ].SelectedCard;
}
var powerBonus = 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 };
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 )
{
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;
}
......@@ -42,32 +48,32 @@ namespace TBR.Data
{
if ( cardDatas[ i ] != null )
{
bonus[ i ] *= pairTable[ counts[ cardDatas[ i ].Number ] ];
powerBonus[ i ] *= pairTable[ numberCounts[ cardDatas[ 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)
var elementBonus = new int[ 5 ] { -2, -2, -2, -2, -2 };
int[] elementCounts = new int[ 5 ];
foreach ( var c in cardDatas )
{
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 )
{
int matchBonus = 1;
for ( int j = 0; j < counts[ ( int )cardDatas[ i ].Element ]; j++ )
for ( int j = 0; j < elementCounts[ ( int )cardDatas[ i ].Element ]; j++ )
matchBonus *= 2;
bonus[ i ] += matchBonus;
elementBonus[ i ] += matchBonus;
}
}
return bonus;
for ( int i = 0; i < 5; i++ )
{
if ( characters[ i ] != null )
characters[ i ].SetBonus( powerBonus[ i ], elementBonus[ i ] );
}
return "";
}
}
}
......@@ -44,21 +44,9 @@ public class Party
}
}
public void CalcBonus()
public string CalcAndAssignBonus()
{
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 ] );
}
return Calculator.CalcAndAssignBonus( Characters );
}
public IEnumerator Action()
......
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