Exemple #1
0
        /// <summary>
        /// Applies the specified move to the board.
        /// </summary>
        /// <param name="dir"></param>
        /// <returns></returns>
        public virtual bool Move(Direction dir)
        {
            MoveMatrix.ForEachCell((i, j) =>
            {
                MoveMatrix[i, j] = 0;
            });
            Board = RotateBoardBeforeMove(dir);
            bool moved = ShiftTilesLeft();

            if (moved)
            {
                SpawnNewTile();
                NextNumber = PickANumber();
            }

            Board      = RotateBoardAfterMove(dir);
            MoveMatrix = MoveMatrix.RotateClockwise(360 - RotationMap[dir]);
            return(moved);
        }
Exemple #2
0
    void onClick(GameObject obj)
    {
        print("click!");

        if (obj != currPosi)
        {
            print("move to  " + obj.name);

            if (currPosi != null)
            {
                currPosi.GetComponent <Image> ().color = Color.white;
            }
            obj.GetComponent <Image> ().color = Color.gray;



            // calculate move time
            int time = MoveMatrix.calcuTime(currPosi.name, obj.name);

            GameObject clockObj = GameObject.Find("Canvas/PhonePanel/Clock");

            string clockText;
            if (clockObj != null)
            {
                Text clock = (Text)clockObj.GetComponent <Text> ();
                clockText = clock.text;
            }
            else
            {
                clockText = PlayerPrefs.GetString("Time");
            }


            print(clockText.Substring(0, 2));


            // update time
            int hour   = int.Parse(clockText.Substring(0, 2));
            int minute = int.Parse(clockText.Substring(3, 2));

            int week = PlayerPrefs.GetInt("Week");
            int date = PlayerPrefs.GetInt("Date");

            minute = minute + time;
            if (minute >= 60)
            {
                minute -= 60;
                hour   += 1;
            }

            if (hour >= 24)
            {
                hour -= 24;
                date++;
            }

            if (date >= 7)
            {
                date -= 7;
                week++;
            }


            string zeroHour = "0", zeroMinute = "0";
            if (hour >= 10)
            {
                zeroHour = "";
            }
            if (minute >= 10)
            {
                zeroMinute = "";
            }

            string currTime = zeroHour + hour.ToString() + ":" + zeroMinute + minute.ToString();

            currPosi = obj;

            // update playerprefs
            PlayerPrefs.SetString("Position", currPosi.name);
            PlayerPrefs.SetString("Time", currTime);
            PlayerPrefs.SetInt("Week", week);
            PlayerPrefs.SetInt("Date", date);

            // update UI text
            if (clockObj != null)
            {
                Text clock = (Text)clockObj.GetComponent <Text> ();
                clock.text = currTime;
            }

            updateDate();

            GameObject nameObj = GameObject.Find("Canvas/InfoPanel/Username");
            Text       name    = (Text)nameObj.GetComponent <Text> ();
            name.text = PlayerPrefs.GetString("Name");

            //update state
            GameObject stateObj    = GameObject.Find("Canvas/InfoPanel/State");
            Text       state       = (Text)stateObj.GetComponent <Text> ();
            string     stateString = getStateString(currPosi.name);
            if (stateString != null)
            {
                state.text = "位置: " + stateString;
            }
        }
    }