我需要帮助我做记分牌。以下是我想要达到的目标:
实际上我有四个表,每个表都有自己的记分牌,但对于这个问题,只有表1是我需要的,所以这里是我如何创建这种记分牌。
现在,我已经做到了:
if (gametable_no == 1)
{
for (int i = 0; i < tzPlayInfo.Instance.bc_gametable_history_list.Count; i++)
{
newString[0] += tzPlayInfo.Instance.bc_gametable_history_list[i].r;
newString[0] += ",";
}
string[] groupedString = newString[0].Split(',');
foreach (string allchars in groupedString)
{
int x = 0;
int y = 0;
GameObject o = Instantiate(prefab_big_road[0]) as GameObject;
o.transform.SetParent(pos_big_road[0]);
o.transform.localScale = Vector3.one;
o.transform.localPosition = new Vector3(2.0f, -5.0f, 0f);
o.transform.localPosition = new Vector3(o.transform.localPosition.x + x,
o.transform.localPosition.y + y, o.transform.localPosition.z);
if (allchars.Contains(playerwinnopairboth))
{
o.GetComponent<UISprite>().spriteName = "layout_player_bigline-01";
NGUITools.SetActive(o, true);
}
if (allchars.Contains(bankerwinnopairboth))
{
o.GetComponent<UISprite>().spriteName = "layout_banker_bigline-01";
NGUITools.SetActive(o, true);
}
if (allchars.Contains(tienopairboth))
{
o.GetComponent<UISprite>().spriteName = "layout_tie_bigline-01";
NGUITools.SetActive(o, true);
}
}
}
此代码只能实现如下目的:
输出是随机生成的,例如我有这个输出数据:
Gametable 1 history : P ,P ,P ,B ,B P,P P,TBP
我需要知道字符是否在
gametable 1 history data
中改变。例如:输出必须如下
如果值没有像
P ,P ,P
那样改变,则位置只会在y轴上增加,然后如果下一个值像B ,
那样不同,则它将移动到x轴。是否有方法检测字符串数组中的字符是否与其他值不同?
编辑
string[] newString = new string[4];
string[,] table = new string[70, 70];
string previousValue = "placeholder";
int xIndex = -1;
int yIndex = 0;
// First table
if (gametable_no == 1)
{
for (int i = 0; i < tzPlayInfo.Instance.bc_gametable_history_list.Count; i++)
{
newString[0] += tzPlayInfo.Instance.bc_gametable_history_list[i].r;
newString[0] += ",";
}
//string[] groupedString = GroupString(newString[0]);
string[] groupedString = newString[0].Split(',');
foreach (var allchars in groupedString)
{
GameObject o = Instantiate(prefab_big_road[0]) as GameObject;
o.transform.SetParent(pos_big_road[0]);
o.transform.localScale = Vector3.one;
if (table.GetLength(0) < xIndex)
{
break;
}
if (allchars.Equals(previousValue) && table.GetLength(1) < yIndex)
{
yIndex += 15;
table[xIndex, yIndex] = allchars;
}
else
{
xIndex += 15;
yIndex = 0;
table[xIndex, yIndex] = allchars;
}
previousValue = allchars;
o.transform.localPosition = new Vector3(xIndex, yIndex, 0f);
// Match the sprites
if (previousValue.Contains(playerwinnopairboth))
{
o.GetComponent<UISprite>().spriteName = "layout_player_bigline-01";
NGUITools.SetActive(o, true);
}
if (previousValue.Contains(bankerwinnopairboth))
{
o.GetComponent<UISprite>().spriteName = "layout_banker_bigline-01";
NGUITools.SetActive(o, true);
}
if (previousValue.Contains(tienopairboth))
{
o.GetComponent<UISprite>().spriteName = "layout_tie_bigline-01";
NGUITools.SetActive(o, true);
}
}
它只生成很少的预制件:
尽管我已经生成了这些数据:
在我的用户界面中,它只显示两个:
最佳答案
我建议使用多维数组作为表。
也许是这样的?
string[,] table = new string[30, 6];
string previousValue = "placeholder";
int xIndex = -1;
int yIndex = 0;
foreach (var value in groupedString)
{
if (table.GetLength(0) < xIndex)
{
break;
}
if (value.Equals(previousValue) && yIndex < table.GetLength(1))
{
yIndex += 1;
table[xIndex, yIndex] = value;
}
else
{
xIndex += 1;
yIndex = 0;
table[xIndex, yIndex] = value;
}
previousValue = value;
}
现在您应该有一个包含所有值的表,然后您可以在ui上显示这些值,并相应地匹配正确的sprite。
关于c# - 如果字符串数据数组不同,则递增位置C#(统一),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50126599/