Exemplo n.º 1
0
    void UpdateTournamentsHandler(IdObject idObject)
    {
        if (idObject.SpaceType.Equals(SpaceType.Tournament))
        {
            var tournament = idObject as TournamentObject;
            if (currenTournament.Id.Equals(tournament.Id) && tournament.State.Equals(ChainTypes.TournamentState.Concluded))
            {
                UpdateTournament(tournament);
            }
        }

        if (!idObject.SpaceType.Equals(SpaceType.Match))
        {
            return;
        }

        var match = new MatchObject();

        if (idObject.SpaceType.Equals(SpaceType.Match))
        {
            match = idObject as MatchObject;
        }

        if (match.IsNull() || !match.Tournament.Equals(currenTournament.Id))
        {
            return;
        }

        if (match.State.Equals(ChainTypes.MatchState.Complete) && infoPanel.activeSelf &&
            currenTournament.State.Equals(ChainTypes.TournamentState.InProgress))
        {
            ResetTournemanets();
            ShowTournamentInfo(currenTournament);
        }
    }
Exemplo n.º 2
0
        public Token ReadFormattingToken()
        {
            var         maxPrefix         = 0;
            MatchObject resultMatchObject = null;

            foreach (var shell in shells)
            {
                var matchObject = shell.MatchText(text, currentPosition);
                if (maxPrefix < matchObject?.PrefixLength)
                {
                    maxPrefix         = matchObject.PrefixLength;
                    resultMatchObject = matchObject;
                }
            }
            if (resultMatchObject == null)
            {
                return(null);
            }
            var content    = GetContent(text, resultMatchObject);
            var attributes = new List <Attribute>();

            if (resultMatchObject.Attribute != null)
            {
                attributes.Add(resultMatchObject.Attribute);
            }
            var resultToken = new Token(content, attributes, resultMatchObject.ConvertToHtml, resultMatchObject.Shell);

            currentPosition = resultMatchObject.StartSuffix + resultMatchObject.SuffixLength;
            return(resultToken);
        }
Exemplo n.º 3
0
 public void MergeFrom(RunRequest other)
 {
     if (other == null)
     {
         return;
     }
     if (other.ProfileId.Length != 0)
     {
         ProfileId = other.ProfileId;
     }
     if (other.ProposalId.Length != 0)
     {
         ProposalId = other.ProposalId;
     }
     if (other.ResultId.Length != 0)
     {
         ResultId = other.ResultId;
     }
     if (other.matchObject_ != null)
     {
         if (matchObject_ == null)
         {
             matchObject_ = new global::Messages.MatchObject();
         }
         MatchObject.MergeFrom(other.MatchObject);
     }
     if (other.Timestamp.Length != 0)
     {
         Timestamp = other.Timestamp;
     }
     _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
 }
Exemplo n.º 4
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (ProfileId.Length != 0)
            {
                hash ^= ProfileId.GetHashCode();
            }
            if (ProposalId.Length != 0)
            {
                hash ^= ProposalId.GetHashCode();
            }
            if (ResultId.Length != 0)
            {
                hash ^= ResultId.GetHashCode();
            }
            if (matchObject_ != null)
            {
                hash ^= MatchObject.GetHashCode();
            }
            if (Timestamp.Length != 0)
            {
                hash ^= Timestamp.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemplo n.º 5
0
        private static string GetContent(string originalText, MatchObject matchObject)
        {
            var startText  = matchObject.StartPrefix + matchObject.PrefixLength;
            var textLength = matchObject.StartSuffix - (matchObject.StartPrefix + matchObject.PrefixLength);

            return(originalText.Substring(startText, textLength));
        }
Exemplo n.º 6
0
 public MatchContainer(int number, MatchObject match, AccountObject me, AccountObject opponent, Action <MatchContainer> matchCompleteCallback = null)
 {
     this.number                = number;
     this.match                 = match;
     this.me                    = me;
     this.opponent              = opponent;
     MatchComplete              = matchCompleteCallback;
     Repository.OnObjectUpdate += Repository_OnObjectUpdate;
 }
Exemplo n.º 7
0
    void Update()
    {
        if (_gmaeStatusManager.CurrentStateIndex != GameState.GameRun && _gmaeStatusManager.CurrentStateIndex != GameState.Menu)
        {
            DeleteObject();
            return;
        }
        List <MatchObject> TempList            = _DataMatch._matchColorObjectList;
        int MatchObjectCount                   = 0;
        List <MatchObject> NewLMatchObjectList = new List <MatchObject>();

        for (int i = 0; i < TempList.Count; i++)
        {
            if (TempList[i]._id == _CreateObjectId)
            {
                MatchObjectCount++;
                NewLMatchObjectList.Add(_DataMatch._matchColorObjectList[i]);
            }
        }
        if (superGameObject.transform.childCount < MatchObjectCount && _drawBlock._ScreenSettingCompletionFlag)
        {
            //確認已開啟攝影機
            if (_drawBlock.MatchHeight == 0 && _drawBlock.MatchWidth == 0)
            {
                return;
            }
            // ==========================
            // set public Width Height ==
            // ==========================
            _Width  = _drawBlock.MatchWidth;
            _Height = _drawBlock.MatchHeight;
            MatchObject matchObject = NewLMatchObjectList[superGameObject.transform.childCount];
            if (_CreateObjectId == matchObject._id)
            {
                CreateObject(matchObject);
            }
        }
        else if (superGameObject.transform.childCount > MatchObjectCount)
        {
            DeleteObject();
        }
        else
        {
            for (int i = superGameObject.transform.childCount - 1; i >= 0; i--)
            {
                MatchObject matchObject = NewLMatchObjectList[i];
                if (_CreateObjectId == matchObject._id)
                {
                    UpdatePos(superGameObject.transform.GetChild(i).gameObject, _speed, matchObject);
                }
            }
        }
    }
Exemplo n.º 8
0
    public void UpdatePos(GameObject Object, float speed, MatchObject matchObject)
    {
        RectTransform childGameObjectRect = Object.GetComponent <RectTransform>();
        //轉換對應座標並更新值
        Point transPos = _posTrans.TransToScreen2Pos(new Point(matchObject._pos.x, matchObject._pos.y));

        childGameObjectRect.anchoredPosition = Vector3.Lerp(childGameObjectRect.anchoredPosition, new Vector2((float)transPos.x, (float)transPos.y), speed);
        childGameObjectRect.localPosition    = new Vector3(childGameObjectRect.localPosition.x, childGameObjectRect.localPosition.y, 0);
        //轉換對應大小並更新值
        Point transScale = _posTrans.TransToScreen2Pos(new Point(matchObject._scale.x, matchObject._scale.y));

        Object.transform.localScale = Vector3.Lerp(Object.transform.localScale, new Vector3((float)transScale.x, (float)transScale.y, 50), speed);
        //更新旋轉角度
        Object.transform.eulerAngles = new Vector3(0, 0, (float)((matchObject._rotation + .5f) * 180));
        return;
    }
Exemplo n.º 9
0
    public void UpdateMatchInfo(MatchObject updatedMatch)
    {
        if (updatedMatch.ToString().Equals(match.ToString()))
        {
            return;
        }
        var currentState = MatchState;

        match = updatedMatch;
        if (!match.State.Equals(currentState))
        {
            // change state
            switch (match.State)
            {
            case ChainTypes.MatchState.Complete:
                // match complete
                if (match.MatchWinners.OrEmpty().Length == 1)
                {
                    if (match.MatchWinners[0].Equals(me.Id))
                    {
                        winner = me;
                    }
                    else
                    if (match.MatchWinners[0].Equals(opponent.Id))
                    {
                        winner = opponent;
                    }
                }
                if (!MatchComplete.IsNull())
                {
                    MatchComplete.Invoke(this);
                }
                Dispose();
                break;

            case ChainTypes.MatchState.InProgress:
                break;

            case ChainTypes.MatchState.WaitingOnPreviousMatches:
                break;
            }
        }
        OnMatchChanged.Invoke(this);
    }
Exemplo n.º 10
0
    //設定偵測物體參數
    private bool setMatchObject(int index, List <Point> pointMatList, List <MatOfPoint> contours, List <MatOfPoint> hullPoints, Mat result, List <MatchObject> matchObjectList)
    {
        pointMatList = arrangedPoint(pointMatList);
        float RectWidth  = calculateWidth(pointMatList);
        float RectHeight = calculateHeight(pointMatList);

        if (RectWidth > 3 && RectHeight > 3 && pointsTooClose(pointMatList))
        {
            _DepthRect = Imgproc.boundingRect(contours[index]);
            MatchObject matchObject = new MatchObject();
            matchObject._pos      = calculateCenter(pointMatList);
            matchObject._scale    = new Vector3(RectWidth, RectHeight, 10);
            matchObject._rotation = calculateSlope(pointMatList);
            Imgproc.drawContours(result, hullPoints, -1, new Scalar(0, 255, 0), 2);
            matchObjectList.Add(matchObject);
            return(true);
        }
        return(false);
    }
Exemplo n.º 11
0
    public void UpdatePos(GameObject Object, float speed, MatchObject matchObject)
    {
        RectTransform childGameObjectRect = Object.GetComponent <RectTransform>();
        //判斷哪一方的炮台
        Transform laserBall = childGameObjectRect.Find("Gun/LaserBall");

        if (matchObject._pos.x > _drawBlock.MatchWidth / 2)
        {
            if (laserBall != null)
            {
                laserBall.GetComponent <LaserBall>().setWhichPlayerBall("right");
            }
        }
        else
        {
            if (laserBall != null)
            {
                laserBall.GetComponent <LaserBall>().setWhichPlayerBall("left");
            }
        }

        //轉換對應座標並更新值
        Point transPos = _posTrans.TransToScreen2Pos(new Point(matchObject._pos.x, matchObject._pos.y));
        int   posX = (int)childGameObjectRect.anchoredPosition.x, posY = (int)childGameObjectRect.anchoredPosition.y;
        int   moveRangeWidth = (int)(_Width * 0.1), moveRangeHeight = (int)(_Height * 0.1);

        if (((posX + moveRangeWidth < (int)transPos.x) && (posX - moveRangeWidth > (int)transPos.x) ||
             (posY + moveRangeHeight < (int)transPos.y) && (posY - moveRangeHeight > (int)transPos.y)) ||
            ((Object.transform.eulerAngles.z + 5 < matchObject._rotation) && (Object.transform.eulerAngles.z - 5 < matchObject._rotation)))
        {
            if (Object.transform.Find("Gun/LaserBall(Clone)") != null)
            {
                Destroy(Object.transform.Find("Gun/LaserBall(Clone)").gameObject);
            }
        }
        childGameObjectRect.anchoredPosition = Vector3.Lerp(childGameObjectRect.anchoredPosition, new Vector2((float)transPos.x, (float)transPos.y), speed);
        childGameObjectRect.localPosition    = new Vector3(childGameObjectRect.localPosition.x, childGameObjectRect.localPosition.y, 0);
        //轉換對應大小並更新值
        childGameObject.transform.localScale = Vector3.Lerp(childGameObject.transform.localScale, new Vector3(matchObject._scale.x, matchObject._scale.y, 22), speed);
        //更新旋轉角度
        Object.transform.eulerAngles = new Vector3(0, 0, matchObject._rotation);
        return;
    }
Exemplo n.º 12
0
    public void NewMatch(MatchObject newMatch, AccountObject me, AccountObject opponent, Action <MatchContainer, GameContainer> newGameCallback, Action <MatchContainer, GameContainer> gameCompleteCallback, Action <MatchContainer, GameContainer> gameExpectedMoveCallback)
    {
        startedMatches.Add(newMatch);
        var game = newMatch.Games.Last();

        Repository.GetInPromise(game, () => ApiManager.Instance.Database.GetGame(game.Id)).Then(newGame => {
            if (!currentMatch.IsNull() && !currentMatch.Id.Equals(newMatch.Id))
            {
                completedMatches[currentMatch.Id] = currentMatch;
            }
            currentMatch = new MatchContainer(completedMatches.Count + 1, newMatch, me, opponent, completedMatch => {
                matchCompleteCallback.Invoke(completedMatches[completedMatch.Id] = completedMatch);
            });
            newMatchCallback.Invoke(currentMatch);
            currentMatch.OnNewGame          += newGameCallback;
            currentMatch.OnGameComplete     += gameCompleteCallback;
            currentMatch.OnGameExpectedMove += gameExpectedMoveCallback;
            currentMatch.NewGame(newGame).CheckState();
        }).Catch(error => Unity.Console.Error(Unity.Console.SetRedColor(error)));
    }
Exemplo n.º 13
0
    public void CreateObject(MatchObject matchObject)
    {
        childGameObject = Instantiate(copyGameObject);                  //複製copyGameObject物件(連同該物件身上的腳本一起複製)
        childGameObject.transform.SetParent(superGameObject.transform); //放到superGameObject物件內
        RectTransform childGameObjectRect = childGameObject.GetComponent <RectTransform>();

        //座標系統統一(左下0,0)
        childGameObjectRect.anchorMin = new Vector2(0, 0);
        childGameObjectRect.anchorMax = new Vector2(0, 0);
        childGameObjectRect.pivot     = new Vector2(.5f, .5f);
        //初始化轉換座標class
        RectTransform superGameObjectRect = superGameObject.GetComponent <RectTransform>();

        _posTrans = new clickPositionTrans(_drawBlock.MatchWidth, _drawBlock.MatchHeight, superGameObjectRect.rect.width, superGameObjectRect.rect.height);
        //初始化位置
        UpdatePos(childGameObject, _speed, matchObject);
        //childGameObject.AddComponent<NullScript>();//動態增加名為"NullScript"的腳本到此物件身上
        //下面這一行的功能為將複製出來的子物件命名為CopyObject

        childGameObject.name = "CopyObject";
    }
Exemplo n.º 14
0
    private void refreshUI()
    {
        // destroy old match objects
        List <GameObject> children = new List <GameObject>();

        foreach (Transform c in searchParent.transform)
        {
            children.Add(c.gameObject);
        }
        foreach (GameObject c in children)
        {
            Destroy(c);
        }

        // add new ones
        Vector3 match_pos = new Vector3(0, 0, 0);
        float   y_inc     = -40;

        menuSelector.menuItems.RemoveRange(1, menuSelector.menuItems.Count - 1);
        foreach (MatchDesc desc in matchList)
        {
            GameObject match_temp = (GameObject)Instantiate(matchObject, match_pos, Quaternion.identity);
            match_temp.transform.SetParent(searchParent.transform, false);
            MatchObject m_obj = match_temp.GetComponent <MatchObject>();

            // set attributes of the match
            m_obj.nameText.text   = desc.name;
            m_obj.playerText.text = desc.currentSize.ToString();

            // link to menu selector object
            menuSelector.menuItems.Add(m_obj.nameObject);

            // create button onclick action
            Button b_temp = m_obj.nameObject.GetComponent <Button>();
            b_temp.onClick.AddListener(delegate { buttonClicked(desc); });

            match_pos.y += y_inc;
        }
    }
Exemplo n.º 15
0
 void Update()
 {
     if (_gmaeStatusManager.CurrentStateIndex != GameState.GameRun)
     {
         return;
     }
     if (superGameObject.transform.childCount < _DataMatch._matchObjectList.Count && _drawBlock._ScreenSettingCompletionFlag)
     {
         //確認已開啟攝影機
         if (_drawBlock.MatchHeight == 0 && _drawBlock.MatchWidth == 0)
         {
             return;
         }
         // ==========================
         // set public Width Height ==
         // ==========================
         _Width  = _drawBlock.MatchWidth;
         _Height = _drawBlock.MatchHeight;
         MatchObject matchObject = _DataMatch._matchObjectList[superGameObject.transform.childCount];
         CreateObject(matchObject);
     }
     else if (superGameObject.transform.childCount > _DataMatch._matchObjectList.Count)
     {
         DeleteObject();
     }
     else
     {
         for (int i = superGameObject.transform.childCount - 1; i >= 0; i--)
         {
             MatchObject matchObject = _DataMatch._matchObjectList[i];
             UpdatePos(superGameObject.transform.GetChild(i).gameObject, _speed, matchObject);
         }
     }
     if (Input.GetKeyUp(KeyCode.R))
     {
         copyGameObject.GetComponent <MeshRenderer>().enabled = !copyGameObject.GetComponent <MeshRenderer>().enabled;
     }
 }
Exemplo n.º 16
0
    //設定偵測物體參數
    private List <MatchObject> setColorMatchObject(List <Point> ConsistP, List <List <Point> > trianglePointList, List <Scalar> clickRGB, List <Scalar> clickHsv, Mat resultMat, List <int> HullCountList)
    {
        List <MatchObject> matchObjectList = new List <MatchObject>();

        for (int i = 0; i < ConsistP.Count; i += 4)
        {
            int ID = inRange(ConsistP[i], ConsistP[i + 1], clickRGB[i / 4], clickHsv[i / 4]);
            if ((ID == 0 || ID == 1) && HullCountList[i / 4] != 3)
            {
                continue;
            }
            if (ID != -1)
            {
                List <Point> nowPoint = new List <Point>();
                nowPoint.Add(ConsistP[i]);
                nowPoint.Add(ConsistP[i + 1]);
                nowPoint.Add(ConsistP[i + 2]);
                nowPoint.Add(ConsistP[i + 3]);
                Imgproc.rectangle(resultMat, ConsistP[i], ConsistP[i + 1], new Scalar(255, 0, 255), 1);
                Imgproc.putText(resultMat, "ID=" + ID.ToString(), ConsistP[i], 1, 1, new Scalar(255, 0, 255), 1);
                MatchObject matchObject = new MatchObject();
                matchObject._centerPos = calculateCenter(nowPoint);
                if (ID == 0 || ID == 1)
                {
                    matchObject._pos = getTriangleCenter(trianglePointList[i / 4]);
                }
                else
                {
                    matchObject._pos = calculateCenter(nowPoint);
                }
                //Debug.Log("center: "+ matchObject._pos);
                matchObject._scale = new Vector3(22, 22, 22);
                matchObject._id    = ID;
                if (ID == 2)
                {
                    matchObject._rotation = 0;
                }
                else
                {
                    if (_useRotateLaserGenerator)
                    {
                        matchObject._rotation = (float)(getTriangleRotate(trianglePointList[i / 4], new Point(matchObject._pos.x, matchObject._pos.y)) * 180 / Math.PI);
                    }
                    else
                    {
                        if (matchObject._pos.x > resultMat.width() / 2)
                        {
                            matchObject._rotation = 180f;
                        }
                        else
                        {
                            matchObject._rotation = 0f;
                        }
                    }
                }
                matchObjectList.Add(matchObject);
            }
        }
        _matchColorObjectList.Clear();
        return(matchObjectList);
    }
Exemplo n.º 17
0
 public MatchObject GetHighestMatch()
 {
     ResultMatchObject highestResultMatch = null;
     int itemIndex = 0;
     int highestItemIndex = 0;
     foreach (ResultMatchObject resMatch in resultMatchList)
     {
         if (highestResultMatch == null || resMatch.match > highestResultMatch.match)
         {
             highestResultMatch = resMatch;
             highestItemIndex = itemIndex;
         }
         itemIndex++;
     }
     MatchObject matchObject = new MatchObject();
     matchObject.highestMatch = highestResultMatch.match;
     matchObject.outIndex = this.outIndex;
     matchObject.resultIndex = highestResultMatch.resultIndex;
     matchObject.resultItemIndex = highestItemIndex;
     return matchObject;
 }
Exemplo n.º 18
0
    public IEnumerator UpdatePlayers(MatchObject info, MatchObject[] matches)
    {
        secondPlayer.CurrentPlayerState = PlayerState.Looser;
        firstPlayer.CurrentPlayerState  = PlayerState.Looser;
        if (info == null)
        {
            yield break;
        }

        var accountIds = new List <uint>();

        foreach (var account in info.Players)
        {
            accountIds.Add(account.Id);
        }

        if (info.State.Equals(ChainTypes.MatchState.WaitingOnPreviousMatches) && info.Players.Length > 0)
        {
            var previousMatch        = new MatchObject();
            var indexOfPreviousMatch = 1;
            for (int i = 0; i < matches.Length; i++)
            {
                if (matches[i].State == ChainTypes.MatchState.Complete &&
                    info.Players.Contains(matches[i].MatchWinners[0]))
                {
                    previousMatch        = matches[i];
                    indexOfPreviousMatch = i + 1;
                }
            }

            ApiManager.Instance.Database.GetAccount(previousMatch.MatchWinners[0].Id)
            .Then(winner => {
                SetPlayersUndefined();
                if ((indexOfPreviousMatch) % 2 == 0)
                {
                    secondPlayer.SetUsername(winner.Name);
                    secondPlayer.CurrentPlayerState = PlayerState.Winner;
                }
                else
                {
                    firstPlayer.SetUsername(winner.Name);
                    firstPlayer.CurrentPlayerState = PlayerState.Winner;
                }
            });
        }
        else
        {
            ApiManager.Instance.Database.GetAccounts(accountIds.ToArray())
            .Then(accountResult => {
                if (accountResult.Length > 0)
                {
                    firstPlayer.SetUsername(accountResult[0].Name);
                    secondPlayer.SetUsername(accountResult[1].Name);
                    if (info.MatchWinners.Length == 0)
                    {
                        firstPlayer.CurrentPlayerState  = PlayerState.Winner;
                        secondPlayer.CurrentPlayerState = PlayerState.Winner;
                    }
                    else
                    {
                        if (info.MatchWinners[0].Id.Equals(accountResult[0].Id.Id))
                        {
                            firstPlayer.CurrentPlayerState  = PlayerState.Winner;
                            secondPlayer.CurrentPlayerState = PlayerState.Looser;
                        }
                        else
                        {
                            firstPlayer.CurrentPlayerState  = PlayerState.Looser;
                            secondPlayer.CurrentPlayerState = PlayerState.Winner;
                        }
                    }
                }
                else
                {
                    SetPlayersUndefined();
                }
            });
        }
    }