Esempio n. 1
0
 private static void LoadCompletedCallBack(NumberColor color, Transform[] arrayNumImages, Transform group)
 {
     for (int i = 0; i < arrayNumImages.Length; i++)
     {
         if (arrayNumImages[i] == null)
         {
             return;
         }
     }
     for (int i = 0; i < arrayNumImages.Length; i++)
     {
         arrayNumImages[i].SetParent(group);
         arrayNumImages[i].gameObject.SetActive(true);
     }
     TimerManager.Register(1, () => {
         listGroup.Remove(group);
         UINumberImage[] images = group.GetComponentsInChildren <UINumberImage>();
         for (int i = 0; i < images.Length; i++)
         {
             Transform trans = images[i].transform;
             AddImageData(trans, color, images[i].Number);
             trans.SetParent(group.parent);
         }
         groupPool.Push(group);
     });
 }
Esempio n. 2
0
    private static void AddNumberToGroup(Transform group, int damage, NumberColor color)
    {
        if (!dicNumber.ContainsKey(color))
        {
            DebugTool.LogError("UINumberManager not exit color image, color\t" + color.ToString());
            return;
        }
        bool isHaveSub = dicSprite.ContainsKey(color) && dicSprite[color].ContainsKey(-1);
        int  length    = CalculateDamageLength(damage);

        if (isHaveSub)
        {
            length++;
        }
        Transform[] arrayNumImages = new Transform[length];
        if (isHaveSub)
        {
            AddSubToList(color, (Transform sub) => {
                arrayNumImages[0] = sub;
                LoadCompletedCallBack(color, arrayNumImages, group);
            });
        }
        AddNumberToList(damage, color, (Transform numberImage, int index) => {
            arrayNumImages[index] = numberImage;
            LoadCompletedCallBack(color, arrayNumImages, group);
        }, length - 1);
    }
Esempio n. 3
0
 private static void InitSpriteCache()
 {
     dicNumber = new Dictionary <NumberColor, Dictionary <int, List <Transform> > >();
     dicSprite = new Dictionary <NumberColor, Dictionary <int, Sprite> >();
     groupPool = new Stack <Transform>();
     listGroup = new List <Transform>();
     for (int i = 0; i < loadedAssets.Length; i++)
     {
         Sprite     sprite = loadedAssets[i] as Sprite;
         GameObject obj    = GameObject.Instantiate(numberPrefab);
         obj.transform.SetParent(GameManager.LogicScript.transform);
         UINumberImage image = obj.GetComponent <UINumberImage>();
         image.sprite = sprite;
         NumberColor color  = image.Color;
         int         number = image.Number;
         AddImageData(obj.transform, color, number);
         if (!dicSprite.ContainsKey(color))
         {
             dicSprite.Add(color, new Dictionary <int, Sprite>());
         }
         if (!dicSprite[color].ContainsKey(number))
         {
             dicSprite[color].Add(number, sprite);
         }
     }
 }
Esempio n. 4
0
 public void SetNumber(NumberColor color, int number )
 {
     string num_string = number.ToString ();
     int i = 0;
     if (number > 0) {
         foreach (Transform child in transform) {
             int num = int.Parse (num_string [i].ToString ());
             Sprite pic = NumMgr.while_number [num];
     /*
         if( color.CompareTo("white") == 0){
             pic = NumMgr.while_number[num];
         } else if( color.CompareTo("green") == 0 ){
             pic = NumMgr.green_number[num];
         } else if( color.CompareTo("red") == 0){
             pic = NumMgr.red_number[num];
         }
         pic = NumMgr.while_number[num];
     */
             child.gameObject.GetComponent<Image> ().sprite = pic;
             if (color == NumberColor.GREEN) {
                 child.gameObject.GetComponent<Image> ().color = Color.green;
             } else if ( color == NumberColor.RED ) {
                 child.gameObject.GetComponent<Image> ().color = Color.red;
             } else if (color == NumberColor.BLUE ) {
                 child.gameObject.GetComponent<Image> ().color = Color.blue;
             } else {
                 child.gameObject.GetComponent<Image> ().color = Color.white;
             }
             i++;
         }
     }
 }
Esempio n. 5
0
        public ColorHitChecker(int num)
        {
            NumberColor color = num.GetColor();

            this.AddHitNumber(Number.GetFactor(color));
            this.CheckValidate();
        }
Esempio n. 6
0
        public Bitmap ToBitmap(List <int> bits, Bitmap image)
        {
            if (IsImageTooSmall(bits.Count, image))
            {
                throw new ArgumentException("Image is too small!");
            }

            // Bitmap newImage = new Bitmap(image.Width, image.Height);
            Bitmap newImage = new Bitmap(image);

            BitmapUtil.Iterate(image, bits, (point, diff) =>
            {
                NumberColor numberColor = NumberColor.fromColor(image.GetPixel(point.X, point.Y));
                if (numberColor.R <= 253)
                {
                    numberColor.R += diff;
                }
                else if (numberColor.G <= 253)
                {
                    numberColor.G += diff;
                }
                else if (numberColor.B <= 253)
                {
                    numberColor.B += diff;
                }

                newImage.SetPixel(point.X, point.Y, numberColor.toColor());
            });
            return(newImage);
        }
Esempio n. 7
0
        public ColorBet(NumberColor color)
            : base(2)
        {
            if (color == NumberColor.None)
                throw new ArgumentException("Cannot bet on color 'none'");

            _color = color;
        }
Esempio n. 8
0
    private static IEnumerator CreateGroup(NumberColor color, System.Action <Transform> callback)
    {
        GameObject obj        = GameObject.Instantiate(numberGroup);
        Transform  groupTrans = obj.GetComponent <Transform>();

        callback(groupTrans);
        yield break;
    }
Esempio n. 9
0
        public static int[] GetFactor(NumberColor color)
        {
            switch (color)
            {
            case NumberColor.Red: return(RedNumbers);

            case NumberColor.Black: return(BlackNumbers);

            default: return(EmptyNumbers);
            }
        }
Esempio n. 10
0
 private static void AddImageData(Transform numberTrans, NumberColor color, int number)
 {
     if (!dicNumber.ContainsKey(color))
     {
         dicNumber.Add(color, new Dictionary <int, List <Transform> >());
     }
     if (!dicNumber[color].ContainsKey(number))
     {
         dicNumber[color].Add(number, new List <Transform>());
     }
     dicNumber[color][number].Add(numberTrans);
     numberTrans.gameObject.SetActive(false);
 }
Esempio n. 11
0
    private static IEnumerator CreateImage(NumberColor color, int number, System.Action <Transform> callback)
    {
        if (!dicSprite.ContainsKey(color))
        {
            DebugTool.LogError("UINumberManager not exit color\t" + color.ToString());
            yield break;
        }
        if (!dicSprite[color].ContainsKey(number))
        {
            DebugTool.LogError("UINumberManager not exit color number\t" + number);
            yield break;
        }
        GameObject    obj   = GameObject.Instantiate(numberPrefab);
        UINumberImage image = obj.GetComponent <UINumberImage>();

        image.sprite = dicSprite[color][number];
        AddImageData(obj.transform, color, number);
        callback(obj.transform);
        yield break;
    }
        public List <int> Parse(Bitmap bitmap, Bitmap basemap)
        {
            List <int> result = new List <int>();

            if (bitmap.Width != basemap.Width || bitmap.Height != basemap.Height)
            {
                throw new ArgumentException("Invalid base image!");
            }

            BitmapUtil.Iterate(bitmap, point =>
            {
                NumberColor bitmapColor  = NumberColor.fromColor(bitmap.GetPixel(point.X, point.Y));
                NumberColor basemapColor = NumberColor.fromColor(basemap.GetPixel(point.X, point.Y));
                if (PixelUtil.IsPixelReadable(bitmap.GetPixel(point.X, point.Y)) && PixelUtil.IsPixelReadable(basemap.GetPixel(point.X, point.Y)))
                {
                    int colorDiff = bitmapColor.SubtractNumberColor(basemapColor);
                    result.Add(colorDiff);
                }
            });
            return(result);
        }
Esempio n. 13
0
    private static void AddNumberToList(int damage, NumberColor color, System.Action <Transform, int> callback, int index)
    {
        int newDamage = damage / 10;
        int rest      = damage % 10;

        if (newDamage > 0)
        {
            AddNumberToList(newDamage, color, callback, index - 1);
        }
        if (!dicNumber[color].ContainsKey(rest))
        {
            DebugTool.LogError("UINumberManager not exit color number image, number\t" + rest);
            return;
        }
        List <Transform> list = dicNumber[color][rest];
        Transform        node = null;

        for (int i = 0; i < list.Count; i++)
        {
            if (!list[i].gameObject.activeSelf)
            {
                node = list[i];
                list.RemoveAt(i);
                break;
            }
        }
        if (node == null)
        {
            GameManager.LogicScript.StartCoroutine(
                CreateImage(color, rest, (Transform numberImage) => callback(numberImage, index)));
        }
        else
        {
            callback(node, index);
        }
    }
Esempio n. 14
0
    private static void AddSubToList(NumberColor color, System.Action <Transform> callback)
    {
        List <Transform> list = dicNumber[color][-1];
        Transform        node = null;

        for (int i = 0; i < list.Count; i++)
        {
            if (!list[i].gameObject.activeSelf)
            {
                node = list[i];
                list.RemoveAt(i);
                break;
            }
        }
        if (node == null)
        {
            GameManager.LogicScript.StartCoroutine(
                CreateImage(color, -1, (Transform numberImage) => callback(numberImage)));
        }
        else
        {
            callback(node);
        }
    }
Esempio n. 15
0
 public double GetPayoffColor(NumberColor color, double bid, Number result)
 {
     if (result.Color == NumberColor.None) return (bid / 2);
     else if (result.Color == color) return 2*bid;
     else return 0;
 }
Esempio n. 16
0
    // create number anime
    public void createNumber(Player target, int damage, NumberColor color)
    {
        int size = damage.ToString ().Length;
        string id;
        if (damage > 0) {
            id = size + "num";
        } else {
            id = "miss";
        }
        var number = gameMgr.NumberMgr.Obtain (id);
        number.SetNumber (color, damage);
        Vector2 position = target.gameObject.GetComponent<RectTransform>().position;
        if (target.is_monster) {
            position = target.gameObject.GetComponent<RectTransform> ().position;
        } else {
            position = target.original_head;
        }

        number.SetPosition (position);
        number.SetEnable ();
    }
Esempio n. 17
0
        public static bool IsPixelReadable(Color pixel)
        {
            NumberColor numberColor = NumberColor.fromColor(pixel);

            return(numberColor.A > 0);
        }
Esempio n. 18
0
        public static bool IsPixelWritable(Color pixel)
        {
            NumberColor numberColor = NumberColor.fromColor(pixel);

            return((numberColor.R <= 254 || numberColor.G <= 254 || numberColor.B <= 254) && numberColor.A > 0);
        }
Esempio n. 19
0
    public static void ShowDamageText(Transform parent, Vector3 position, int damage, NumberColor color = NumberColor.Default)
    {
        Transform group = null;

        if (groupPool.Count == 0 || (group = groupPool.Pop()) == null)
        {
            GameManager.LogicScript.StartCoroutine(CreateGroup(color,
                                                               (Transform groupTrans) => {
                groupTrans.SetParent(parent);
                groupTrans.position = position;
                AddNumberToGroup(groupTrans, damage, color);
                listGroup.Add(groupTrans);
            })
                                                   );
        }
        else
        {
            group.position = position;
            AddNumberToGroup(group, damage, color);
            listGroup.Add(group);
        }
    }