Beispiel #1
0
    /// <summary>
    /// show word from collection with desired index
    /// </summary>
    /// <param name="index">index of the element</param>
    public void ShowScramble(int index)
    {
        charObjs.Clear();
        foreach (Transform child in container)
        {
            Destroy(child.gameObject);
        }

        if (index > words.Length - 1)
        {
            //Debug.LogError("index out of range,please enter range between 0 to " + (words.Length - 1).ToString());
            Debug.Log("You Won");
            return;
        }

        char[] chars = words[index].GetString().ToCharArray();
        foreach (char c in chars)
        {
            CharObj clone = Instantiate(prefab.gameObject).GetComponent <CharObj>();
            clone.transform.SetParent(container);

            charObjs.Add(clone.Init(c));
        }

        currentWord = index;
        StartCoroutine(TimeLimit());
    }
Beispiel #2
0
    public CharObj BorrowObj(BattleObjManager.E_BATTLE_OBJECT_TYPE type)
    {
        CharObj            obj  = null;
        QObjPool <CharObj> pool = null;

        m_pools.TryGetValue(type, out pool);
        if (pool == null)
        {
            InitBattleObjPool(
                CharObjPoolConfigerMediator.Instance.GetConfiger(type).Paths,
                type,
                CharObjPoolConfigerMediator.Instance.GetConfiger(type).Count);

            m_pools.TryGetValue(type, out pool);
            //return obj;
        }

        if (pool == null)
        {
            return(obj);
        }

        obj = pool.BorrowObj();

        return(obj);
    }
Beispiel #3
0
 private void DrawCharObj(CharObj charObj)
 {
     _textConsole.Cursor.Print(new ColoredString("[" + charObj.Glyph + "]:", charObj.GlyphColor, Color.Transparent));
     _textConsole.Cursor.Print(' ' + charObj.Name);
     _textConsole.Cursor.CarriageReturn();
     _textConsole.Cursor.LineFeed();
 }
Beispiel #4
0
 /// <summary>
 /// 向BattleManager还CharObj对象
 /// 还的对象是之前借走的。
 /// </summary>
 /// <param name="obj"></param>
 public void ReturnCharObj(CharObj obj)
 {
     //obj.Deactive();
     //先从缓存中移除
     CharObjCache.Instance.Remove(obj);
     //再还给对象池
     CharObjPoolManager.Instance.ReturnObj(obj);
 }
    public CharObj Find(int serverEntityID)
    {
        //Debug.Log("Find " + serverEntityID);
        CharObj charObj = null;

        m_cache.TryGetValue(serverEntityID, out charObj);

        return(charObj);
    }
Beispiel #6
0
    public void Swap(int indexA, int indexB)
    {
        CharObj tmpA = charObjs[indexA];

        charObjs[indexA] = charObjs[indexB];
        charObjs[indexB] = tmpA;

        charObjs[indexA].transform.SetAsLastSibling();
        charObjs[indexB].transform.SetAsLastSibling();

        CheckWord();
    }
Beispiel #7
0
    public void ReturnObj(CharObj obj)
    {
        QObjPool <CharObj> pool = null;

        m_pools.TryGetValue(obj.Type, out pool);
        if (pool == null)
        {
            return;
        }
        CharObjCreator creator = pool.BAK_CREATOR as CharObjCreator;

        creator.HideObject(obj);
        pool.ReturnObj(obj);
    }
Beispiel #8
0
    public void Select(CharObj charObj)
    {
        if (firstSelected)
        {
            Swap(firstSelected.index, charObj.index);

            //unselect
            firstSelected.Select();
            charObj.Select();
        }
        else
        {
            firstSelected = charObj;
        }
    }
Beispiel #9
0
    /// <summary>
    /// 在场景取一个对象必须是已知类型,服务器的两个编号的
    /// </summary>
    /// <param name="type"></param>
    /// <param name="serverEntityID"></param>
    /// <param name="serverEntityType">暂时冗余参数,目前暂时全部填0</param>
    /// <returns></returns>
    public CharObj BorrowCharObj(BattleObjManager.E_BATTLE_OBJECT_TYPE type,
                                 int serverEntityID, int serverEntityType)
    {
        bool    retCode = false;
        CharObj obj     = null;

        //Debug.Log("BorrowCharObj " + serverEntityID);
        //先从缓存中取
        obj = CharObjCache.Instance.Find(serverEntityID);
        if (obj != null)
        {
            //Debug.Log("缓存中找到 " + serverEntityID);
            //obj.Deactive();
            return(obj);
        }

        //缓存中没有才从对象池中取
        obj = CharObjPoolManager.Instance.BorrowObj(type);
        if (obj == null)
        {
            Debug.LogError("CharObjPoolManager.Instance.BorrowObj 取到空Obj " + type.ToString());
            return(obj);
        }

        //retCode = obj.IsValid();
        //if (!retCode)
        //{
        //    Debug.LogError("取到CharObj非法,请联系BattleObjManager作者");
        //    return obj;
        //}

        //为CharObj打上身份证号:)
        obj.ServerEntityID = serverEntityID;
        obj.Type           = type;
        //obj.CharController.ServerEntityID = serverEntityID;
        //obj.CharController.CharType       = type;
        //Debug.Log(type.ToString());

        //从对象池中取出的对象要放入缓存中
        CharObjCache.Instance.Add(obj);

        return(obj);
    }
    public bool Add(CharObj charObj)
    {
        bool result = false;

        if (charObj == null)
        {
            return(result);
        }

        CharObj _charObj;

        m_cache.TryGetValue(charObj.ServerEntityID, out _charObj);
        if (_charObj != null)
        {
            result = true;
            return(result);
        }

        m_cache.Add(charObj.ServerEntityID, charObj);

        result = true;
        return(result);
    }
    public bool Remove(CharObj charObj)
    {
        bool result = false;

        if (charObj == null)
        {
            return(result);
        }

        CharObj _charObj = null;

        m_cache.TryGetValue(charObj.ServerEntityID, out charObj);
        if (_charObj == null)
        {
            result = true;
            return(result);
        }

        m_cache[charObj.ServerEntityID] = null;
        m_cache.Remove(charObj.ServerEntityID);

        result = true;
        return(result);
    }
Beispiel #12
0
 public void Unselect()
 {
     firstSelected = null;
 }
        }// end SplitStringDictionary()

        static void Main(string[] args)
        {
            string testString = "Hello world";
            var    app        = new Program();



            Console.WriteLine("\n\n");
            var countChars = app.SplitStringDictionary(testString);

            foreach (var item in countChars)
            {
                Console.WriteLine($"{item.Key} : {item.Value} ");
            }



            Console.WriteLine("\n\n");

            List <AlphaCount> alphaCountList = new List <AlphaCount>();

            foreach (var c in testString.ToCharArray())
            {
                if (!app.IsContainCharAndUpdate(alphaCountList, c))
                {
                    alphaCountList.Add(new AlphaCount {
                        CharValue = c, Count = 1
                    });
                }
            }

            foreach (var item in alphaCountList)
            {
                Console.WriteLine($">>> {item.CharValue} : {item.Count} ");
            }

            Console.WriteLine("\n\n");
            List <int> integerList  = new List <int>();
            List <int> integerList2 = new List <int>();

            integerList.Add(1);
            integerList.Add(2);
            integerList.Add(3);
            integerList.Add(4);

            foreach (var item in integerList)
            {
                integerList2.Add(item);
                Console.WriteLine($"### {item} ");
            }

            Console.WriteLine("\n");
            integerList.Add(5);
            foreach (var item in integerList2)
            {
                Console.WriteLine($"*** {item} ");
            }

            Console.WriteLine("\n");

            // Restoring the list
            integerList.Clear();
            foreach (var item in integerList2)
            {
                integerList.Add(item);
                Console.WriteLine($"Adding {item} ");
            }

            Console.WriteLine("\n");

            foreach (var item in integerList)
            {
                integerList2.Add(item);
                Console.WriteLine($"Restored: {item} ");
            }


            Console.WriteLine("\n\n");
            List <Pair <char, int> > pairList = new List <Pair <char, int> >();

            pairList.Add(new Pair <char, int>()
            {
                First = 'h', Second = 1
            });
            pairList.Add(new Pair <char, int>()
            {
                First = 'e', Second = 1
            });
            pairList.Add(new Pair <char, int>()
            {
                First = 'l', Second = 2
            });
            pairList.Add(new Pair <char, int>()
            {
                First = 'o', Second = 1
            });

            foreach (var item in pairList)
            {
                Console.WriteLine($"==> {item.First}, {item.Second}");
            }

            List <Pair <int, int> > pairList2 = new List <Pair <int, int> >();

            pairList2.Add(new Pair <int, int>()
            {
                First = 1, Second = 1
            });
            pairList2.Add(new Pair <int, int>()
            {
                First = 2, Second = 1
            });
            pairList2.Add(new Pair <int, int>()
            {
                First = 3, Second = 2
            });
            pairList2.Add(new Pair <int, int>()
            {
                First = 4, Second = 1
            });

            foreach (var item in pairList2)
            {
                Console.WriteLine($"==> {item.First}, {item.Second}");
            }

            CharObj[] charObjs = new CharObj[testString.Length];

            var count = 0;

            foreach (var c in testString.ToCharArray())
            {
                charObjs[count] = new CharObj(c, 1);
                count++;
            }

            count = 0;

            Console.WriteLine("\n\n");
            foreach (var item in charObjs)
            {
                Console.WriteLine($"==> {item.charApp}, {item.num}");
            }

            Console.WriteLine("\n\nProgram Finished ...");
        }