/// <summary> /// Creates a plus score item. /// </summary> /// <param name="value">Value.</param> /// <param name="posX">Position x. [1, +INF)</param> /// <param name="posY">Position y. [1, +INF)</param> public static void CreatePlusScore(int value, int posX, int posY) { ItemScorePlus item = (ItemScorePlus)CreatePrefabAtBlock(instance.scorePlusPrefab, posX, posY); item.SetValue(value); Debug.LogFormat("Created a plus-score({0}) @({1},{2}).", value, posX, posY); }
public void CalculateCode() { StringBuilder s = new StringBuilder(); s.Append("MP"); //protocol name if (sizeX > 999 || sizeY > 999) { throw new UnityException("Too big. Cannot encode"); } //size denote. usually as "010" s.Append((sizeX > sizeY ? sizeX.ToString() : sizeY.ToString()) .PadLeft(3, '0')); inStack = 0; curVal = 0; for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { CodeToAChar(points[y * sizeX + x].isUsed, s); } } if (inStack != 0) { s.Append(GetCurrentChar()); } //Now handles the items. //first we parse it into 5n length string with '#' int appendLen = 5 - s.Length % 5; s.Append('#', appendLen); //now adds the items. ItemBase[] items = FindObjectsOfType <ItemBase>(); foreach (ItemBase K in items) { if (K is ItemScorePlus) { ItemScorePlus item = K as ItemScorePlus; if (item.posX > 16 || item.posY > 16) { Debug.LogWarning("An item out of coding range."); continue; } if (item.scoreDelta > 0) { s.Append("PL"); if (item.scoreDelta > 16) { item.SetValue(16); } //+1 is denoted as '0', and +16 as 'F' s.Append(FindHexChar(item.scoreDelta - 1)); s.Append(FindHexChar(item.posX - 1)); s.Append(FindHexChar(item.posY - 1)); } else { s.Append("MN"); if (item.scoreDelta < -16) { item.SetValue(-16); } //-1 is denoted as '0', and -16 as 'F' s.Append(FindHexChar(-1 - item.scoreDelta)); s.Append(FindHexChar(item.posX - 1)); s.Append(FindHexChar(item.posY - 1)); } //if an item is a plus-score, it cannot be other. continue; } if (K is ItemScoreMultiply) { ItemScoreMultiply item = K as ItemScoreMultiply; if (item.scoreFactor >= 0 && item.scoreFactor <= 15) { if (1 == item.scoreFactor) { Debug.LogWarning("A x1 item has no meaning. It will be ignored."); continue; } if (item.posX > 16 || item.posY > 16) { Debug.LogWarning("An item out of coding range."); continue; } s.Append("MT"); //x0 is denoted as '0', and x15 as 'F' s.Append(FindHexChar(item.scoreFactor)); s.Append(FindHexChar(item.posX - 1)); s.Append(FindHexChar(item.posY - 1)); } else { Debug.LogWarning("This protocol cannot support this multiply item."); } //if an item is a multi-score, it cannot be other. continue; } Debug.LogWarningFormat("An unknown item detected:{0}", K.gameObject.name); } levelCode = s.ToString(); Debug.Log(levelCode); }