Exemplo n.º 1
0
        public async Task <ActionResult> PatchMatchItemAsync([FromHeader(Name = "Authorization"), Required] string authorization, [FromRoute, Required] long id)
        {
            var validation = Token.ValidateAuthorization(authorization);

            if (!validation.IsValid)
            {
                return(BadRequest(validation.Result));
            }

            var user = await _context.Users.FirstOrDefaultAsync(x => x.Token == validation.Token);

            if (user == null)
            {
                return(Unauthorized());
            }

            MatchItem matchItem = await _context.Matchs.FirstOrDefaultAsync(x => x.Id == id && x.UserFK == user.Id);

            if (matchItem == null)
            {
                return(NotFound(new ErrorResponse {
                    Error = "Match id not found or doesn't belong to this user"
                }));
            }

            matchItem.IsActive = false;

            await _context.SaveChangesAsync();

            return(Ok());
        }
Exemplo n.º 2
0
    //Making the AI recognize possible matches after the player turn
    IEnumerator ReadyEnemyTurn()
    {
        yield return(new WaitForSeconds(2f));

        Debug.Log("Enemy turn start");
        Dictionary <TilePoint, Data.TileTypes> st = FindHint();

        List <TilePoint> tileMatchList = new List <TilePoint>();

        foreach (KeyValuePair <TilePoint, Data.TileTypes> item in st)
        {
            tileMatchList.Add(item.Key);
        }

        // Divide size of match list in 2 to get actual number of matches
        int firstMatchIndex = tileMatchList.Count / 2;

        // Choose one of those matches randomly
        int randomMatchIndex = Random.Range(0, firstMatchIndex);

        // Get the first tile coordinate of one of those random matches
        TilePoint tile1 = tileMatchList[randomMatchIndex * 2];

        // Get the second tile coordinate of one of those random matches
        TilePoint tile2 = tileMatchList[randomMatchIndex * 2 + 1];

        MatchItem item1 = FindTile(tile1);
        MatchItem item2 = FindTile(tile2);

        isDoing = true;
        DoSwapTile(item1, item2);
        yield return(StartCoroutine(CheckMatch3Tile(0.5f, item1, item2)));

        Debug.Log("AI turn end");
    }
Exemplo n.º 3
0
    // Click Event
    void OnClickAction(MatchItem tile)
    {
        if (isDoing)
        {
            return;
        }

        if (tile == null)
        {
            return;
        }
        if (curTile == null)
        {
            curTile = tile;
            choice.transform.localPosition = curTile.transform.localPosition;
            choice.enabled = true;
        }
        else
        {
            if (Mathf.Abs(curTile.point.x - tile.point.x) + Mathf.Abs(curTile.point.y - tile.point.y) != 1)
            {
                curTile        = null;
                choice.enabled = false;
                return;
            }
            isDoing = true;
            DoSwapTile(curTile, tile);
            DoSwapMotion(curTile.transform, tile.transform);
            StartCoroutine(CheckMatch3Tile(0.5f, curTile, tile));
            curTile        = null;
            choice.enabled = false;
        }
    }
Exemplo n.º 4
0
        private void OnParse(MatchItem SelectedItem)
        {
            if (SelectedItem != null)
            {
                MatchItem m = SelectedItem;

                textEditor.ScrollTo(m.CurrentLine, 0);

                if (_colorizerCollection.Count > 0 && textEditor.Document.LineCount > 1)
                {
                    textEditor.TextArea.TextView.LineTransformers.Remove(_colorizerCollection[0]);
                    IHighlighter    documentHighlighter = textEditor.TextArea.GetService(typeof(IHighlighter)) as IHighlighter;
                    HighlightedLine result = documentHighlighter.HighlightLine(textEditor.Document.GetLineByNumber(_prevHighlightedLine).LineNumber);

                    // invalidate specific Line
                    textEditor.TextArea.TextView.Redraw(result.DocumentLine);
                    _colorizerCollection.Clear();
                }


                // Add Colors
                LineColorizer currentHighligtedLine = new LineColorizer(m.CurrentLine);

                textEditor.TextArea.TextView.LineTransformers.Add(currentHighligtedLine);

                _colorizerCollection.Add(currentHighligtedLine);

                // invalidate specific Line
                textEditor.TextArea.TextView.Redraw();

                //Keep track of previous line
                _prevHighlightedLine = m.CurrentLine;
            }
        }
Exemplo n.º 5
0
    // Do Empty Tile Move Down after matching 3
    private void DoEmptyDown()
    {
        for (var x = 0; x < Data.tileWidth; x++)
        {
            for (var y = 0; y < Data.tileHeight; y++)
            {
                var thiscell = cells[x, y];
                if (!thiscell.IsEmpty)
                {
                    continue;
                }
                int y1;
                for (y1 = y; y1 > 0; y1--)
                {
                    DoSwapTile(FindTile(new TilePoint(x, y1)), FindTile(new TilePoint(x, y1 - 1)));
                }
            }
        }
        for (var x = 0; x < Data.tileWidth; x++)
        {
            int y;
            for (y = Data.tileHeight - 1; y >= 0; y--)
            {
                var thiscell = cells[x, y];
                if (thiscell.IsEmpty)
                {
                    break;
                }
            }
            if (y < 0)
            {
                continue;
            }
            var y1 = y;
            for (y = 0; y <= y1; y++)
            {
                MatchItem tile = FindTile(new TilePoint(x, y));
                tile.transform.localPosition = new Vector3(x * cellWidth, (y - (y1 + 1)) * -cellHeight, 0f);
                tile.cell.SetRandomTile(6);
                int spriteIndex = (int)tile.cell.cellType - 1;
                tile.spriteIndex = spriteIndex;
                Sprite         sprite   = sprites[spriteIndex];
                SpriteRenderer renderer = tile.GetComponent <SpriteRenderer>();
                renderer.sprite  = sprite;
                renderer.enabled = true;
            }
        }

        foreach (MatchItem tile in tiles)
        {
            Vector3 pos  = new Vector3(tile.point.x * cellWidth, tile.point.y * -cellHeight);
            float   dist = Vector3.Distance(tile.transform.localPosition, pos) * 0.01f;
            dist = 1f;
            TweenParms parms = new TweenParms().Prop("localPosition", pos).Ease(easeType);
            HOTween.To(tile.transform, 0.5f * dist, parms);
        }
        StartCoroutine(CheckMatch3TileOnly(0.5f));
    }
Exemplo n.º 6
0
        /// <summary>
        /// Updates the interpolator based on Time.deltaTime.
        /// </summary>
        /// <returns>True.  (Never completes.)</returns>
        public override bool Update()
        {
            if (!m_IsInitialized)
            {
                if (!Initialize())
                {
                    return(false);
                }
            }

            Vector3 lookAtPos;

            if (MatchItem)
            {
                lookAtPos = MatchOffset == Vector3.zero
                    ? MatchItem.position
                    : MatchItem.TransformPoint(MatchOffset);
            }
            else
            {
                lookAtPos = MatchOffset;
            }

            if (KeepVertical)
            {
                lookAtPos.y = ItemToTransform.position.y;
            }

            var diff = lookAtPos - ItemToTransform.position;

            if (diff != Vector3.zero && diff.sqrMagnitude > 0)
            {
                m_DesiredRotation =
                    Quaternion.LookRotation(diff, UpVector == Vector3.zero ? Vector3.up : UpVector);
            }

            m_LastRotation =
                Quaternion.Slerp(m_LastRotation, m_DesiredRotation, Speed * Time.deltaTime);

            InterpolatedValue = m_LastRotation.eulerAngles;

            if (AutoUpdate)
            {
                if (RigidBody && !RigidBody.isKinematic)
                {
                    RigidBody.MoveRotation(m_LastRotation);
                }
                else
                {
                    ItemToTransform.rotation = m_LastRotation;
                }
            }

            return(true);
        }
        public ActionResult Play(Match match)
        {
            Random random    = new Random();
            var    matchItem = new MatchItem
            {
                MatchId  = match.Id,
                UserName = User.Identity.Name,
                Number   = random.Next(0, 100)
            };

            return(View(matchItem));
        }
Exemplo n.º 8
0
        public async Task PutMatch(string endpoint, DateTime timestamp, MatchItem dto)
        {
            var endpointData = await db.Endpoints.FindAsync(endpoint);

            if (endpoint == null)
            {
                throw new Exception("Bad endpoint");
            }

            var data = dto.ToData(endpointData, timestamp);

            await db.SaveChangesAsync();
        }
Exemplo n.º 9
0
    // Swap Two Tile
    void DoSwapTile(MatchItem a, MatchItem b)
    {
        TilePoint p1 = a.point;
        TilePoint p2 = b.point;

        Cell cell = cells[p1.x, p1.y];

        cells[p1.x, p1.y] = cells[p2.x, p2.y];
        cells[p2.x, p2.y] = cell;

        a.point = p2;
        b.point = p1;
    }
Exemplo n.º 10
0
        public static string ToIntersectsString(MatchProvider provider, MatchItem match)
        {
            string intersects = string.Empty;

            foreach (MatchItem m in provider)
            {
                if (match.isIntersectWith(m))
                {
                    intersects += ("\n" + m.getDescription());
                }
            }

            return(intersects);
        }
Exemplo n.º 11
0
        public static Match ToData(this MatchItem dto, Endpoint endpoint, DateTime timestamp)
        {
            var totalPlayers = dto.scoreboard.Length;

            return(new Match {
                EndpointId = endpoint.Id,
                Timestamp = timestamp,
                Map = dto.map,
                FragLimit = dto.fragLimit,
                GameMode = dto.gameMode,
                TimeElapsed = dto.timeElapsed,
                TimeLimit = dto.timeLimit,
                PlayersCount = totalPlayers,
                Scoreboard = dto.scoreboard.Select((x, ind) => x.ToData(CalcScoreboardPercent(ind, totalPlayers))).ToArray()
            });
        }
Exemplo n.º 12
0
        public static Queue <MatchItem> CopyKVQueue(Queue <MatchItem> srcQueue)
        {
            Queue <MatchItem> orgQueue = new Queue <MatchItem>();

            foreach (MatchItem matchItem in srcQueue)
            {
                MatchItem item = new MatchItem();
                foreach (KeyValuePair <string, string> pair in matchItem.itemQueue)
                {
                    item.itemQueue.Enqueue(new KeyValuePair <string, string>(pair.Key, pair.Value));
                }
                item.itemResult = matchItem.itemResult;
                orgQueue.Enqueue(item);
            }
            return(orgQueue);
        }
Exemplo n.º 13
0
    // Check Match-3 Tile
    IEnumerator CheckMatch3Tile(float delayTime, MatchItem a, MatchItem b)
    {
        yield return(new WaitForSeconds(delayTime));

        Dictionary <TilePoint, Data.TileTypes> stack = FindMatch(cells);

        if (stack.Count > 0)
        {
            CheckMatch3(stack);
        }
        else
        {
            DoSwapTile(a, b);
            DoSwapMotion(a.transform, b.transform);
            ReadyGameTurn();
        }
    }
Exemplo n.º 14
0
    //Make animation fade out after matching tiles and before creating new tiles to drop down
    IEnumerator animateDelete(MatchItem item, int index)
    {
        SpriteRenderer sr = item.GetComponent <SpriteRenderer>();

        for (int i = 0; i < 4; i++)
        {
            sr.sprite = deleteSprites[index + i];
            yield return(new WaitForSeconds(0.1f));
        }

        GameObject instance = Instantiate(explosionPrefab) as GameObject;

        instance.transform.parent        = effectArea;
        instance.transform.localPosition = new Vector3(item.point.x * cellWidth, item.point.y * -cellHeight, -5f);
        item.cell.cellType = Data.TileTypes.Empty;
        sr.enabled         = false;
    }
Exemplo n.º 15
0
        public async Task Play(int number, string currentUser)
        {
            var currentMatch = await GetCurrentMatch();

            if (currentMatch == null)
            {
                throw new Exception("there is no available match");
            }

            var matchItem = new MatchItem
            {
                MatchId = currentMatch.Id,
                email   = currentUser,
                Number  = number
            };

            await _matchItemRepository.AddAsync(matchItem);
        }
Exemplo n.º 16
0
        public ActionResult GameResult(MatchItem matchItem)
        {
            var currentMatch = db.Matches.FirstOrDefault(m => m.Id == matchItem.MatchId);

            if (!db.MatchItems.Any(i => i.Id == matchItem.Id))
            {
                db.MatchItems.Add(matchItem);
                db.SaveChanges();
            }

            if (currentMatch.Expired < DateTime.Now)
            {
                var matchItems = db.MatchItems.Where(i => i.MatchId == currentMatch.Id).ToList();
                currentMatch.WinUserName = matchItems.FirstOrDefault(m => m.Number == currentMatch.Items.Max(i => i.Number)).UserName;
                db.SaveChanges();
            }

            return(View(currentMatch));
        }
Exemplo n.º 17
0
    /// <summary>
    /// 创建
    /// </summary>
    public void CreateItem()
    {
        for (int i = 0; i < itemList.Count; i++)
        {
            Destroy(itemList[i].gameObject);
        }
        itemList.Clear();
        List <net_protocol.MatcherInfo> matcherInfoList = MatchModel.Instance.matcherInfoList;

        for (int i = 0; i < matcherInfoList.Count; i++)
        {
            Transform trans = i % 2 == 0?content1:content2;
            MatchItem item  = Instantiate(prefab1, trans);
            item.gameObject.SetActive(true);
            item._page = this;
            item.Init(matcherInfoList[i]);
            itemList.Add(item);
        }
    }
Exemplo n.º 18
0
 //Swiping the pieces by drag and drop
 void OnClickUpAction(MatchItem tile)
 {
     if (curTile != null)
     {
         if (Mathf.Abs(curTile.point.x - tile.point.x) + Mathf.Abs(curTile.point.y - tile.point.y) != 1)
         {
             curTile.gameObject.GetComponent <SpriteRenderer>().sprite = sprites[curTile.spriteIndex];
             curTile        = null;
             choice.enabled = false;
             return;
         }
         isDoing = true;
         DoSwapTile(curTile, tile);
         DoSwapMotion(curTile.transform, tile.transform);
         StartCoroutine(CheckMatch3Tile(0.5f, curTile, tile));
         curTile.gameObject.GetComponent <SpriteRenderer>().sprite = sprites[curTile.spriteIndex];
         curTile        = null;
         choice.enabled = false;
     }
 }
Exemplo n.º 19
0
        private void Init()
        {
            MatchItem item    = new MatchItem();
            bool      first   = true;
            bool      inmatch = false;
            int       offset  = 0;

            for (int i = mOffset; i < mTemplate.Length; i++)
            {
                if (mTemplate[i] == '{')
                {
                    if (!first)
                    {
                        item = new MatchItem();
                    }
                    inmatch = true;
                    offset  = i;
                }
                else if (mTemplate[i] == '}')
                {
                    if (first)
                    {
                        first = false;
                    }
                    item.Name = new string(mTemplate.AsSpan().Slice(offset + 1, i - offset - 1));
                    mItems.Add(item);
                    inmatch = false;
                }
                else
                {
                    if (mItems.Count > 0 && !inmatch)
                    {
                        item.Eof += mTemplate[i];
                    }
                    if (mItems.Count == 0 && !inmatch)
                    {
                        item.Start += mTemplate[i];
                    }
                }
            }
        }
Exemplo n.º 20
0
    // Click Event - highlighting the piece the playerr is holding to swipe
    void OnClickAction(MatchItem tile)
    {
        //StartCoroutine(animateDelete(tile.GetComponent<SpriteRenderer>(), (tile.spriteIndex) * 4));

        if (isDoing)
        {
            return;
        }

        if (tile == null)
        {
            return;
        }
        if (curTile == null)
        {
            curTile = tile;
            curTile.gameObject.GetComponent <SpriteRenderer>().sprite = spritesSelected[tile.spriteIndex];
            choice.transform.localPosition = curTile.transform.localPosition;
            choice.enabled = true;
        }
    }
Exemplo n.º 21
0
    // Find Match-3 Tile with Position
    MatchItem FindTileWithPosition(Vector2 pos)
    {
        Vector3   pos3    = new Vector3(pos.x, pos.y, 0f) - (grid.transform.localPosition);
        MatchItem curTile = null;

        foreach (MatchItem tile in tiles)
        {
            if (curTile == null)
            {
                curTile = tile;
                continue;
            }
            float dist1 = Vector3.Distance(curTile.transform.localPosition, pos3);
            float dist2 = Vector3.Distance(tile.transform.localPosition, pos3);
            if (dist1 > dist2)
            {
                curTile = tile;
            }
        }
        return(curTile);
    }
Exemplo n.º 22
0
 // Display Tile Grid
 public void DisplayTileGrid()
 {
     tiles = new List <MatchItem>();
     for (var x = 0; x < Data.tileWidth; x++)
     {
         for (var y = 0; y < Data.tileHeight; y++)
         {
             int        type       = (int)cells[x, y].cellType;
             string     spriteName = sprites[(type - 1)];
             GameObject instance   = NGUITools.AddChild(grid, matchItemPrefab) as GameObject;
             instance.GetComponent <UISprite>().spriteName = spriteName;
             instance.transform.localScale    = Vector3.one * cellScale;
             instance.transform.localPosition = new Vector3(x * cellWidth, y * -cellHeight, 0f);
             MatchItem tile = instance.GetComponent <MatchItem>();
             tile.target = gameObject;
             tile.cell   = cells[x, y];
             tile.point  = new TilePoint(x, y);
             tiles.Add(tile);
         }
     }
 }
Exemplo n.º 23
0
    // Check Match-3 Tile
    IEnumerator CheckMatch3Tile(float delayTime, MatchItem a, MatchItem b)
    {
        yield return(new WaitForSeconds(delayTime));

        Dictionary <TilePoint, Data.TileTypes> stack = FindMatch(cells);

        canDoInput = false;

        if (playerHumanTurn)
        {
            if (stack.Count > 0)
            {
                lastStackCount = stack.Count;
                CheckMatch3(stack);
            }
            else
            {
                DoSwapTile(a, b);
                DoSwapMotion(a.transform, b.transform);
                isDoing    = false;
                canDoInput = true;
            }
        }

        //AI turn
        else
        {
            if (stack.Count > 0)
            {
                lastStackCount = stack.Count;
                DoSwapMotion(a.transform, b.transform);
                CheckMatch3(stack);
            }
            else
            {
                DoSwapTile(a, b);
                DoAITurn();
            }
        }
    }
Exemplo n.º 24
0
 // Display Tile Grid
 public void DisplayTileGrid()
 {
     tiles = new List <MatchItem>();
     for (var x = 0; x < Data.tileWidth; x++)
     {
         for (var y = 0; y < Data.tileHeight; y++)
         {
             int        type     = (int)cells[x, y].cellType;
             Sprite     sprite   = sprites[(type - 1)];
             GameObject instance = Instantiate(matchItemPrefab) as GameObject;
             instance.transform.parent = grid.transform;
             //instance.transform.localPosition = Vector3.zero;
             instance.GetComponent <SpriteRenderer>().sprite = sprite;
             instance.transform.localScale    = Vector3.one * cellScale;
             instance.transform.localPosition = new Vector3(x * cellWidth, y * -cellHeight, 0f);
             MatchItem tile = instance.GetComponent <MatchItem>();
             tile.target = gameObject;
             tile.cell   = cells[x, y];
             tile.point  = new TilePoint(x, y);
             tiles.Add(tile);
         }
     }
 }
Exemplo n.º 25
0
 public bool Execute(string url, Dictionary <string, string> parameters)
 {
     if (mItems.Count == 0)
     {
         return(url == mTemplate);
     }
     else
     {
         int offset = mOffset;
         for (int i = 0; i < mItems.Count; i++)
         {
             MatchItem item = mItems[i];
             string    value;
             var       count = item.Match(url, offset, out value);
             if (count <= 0)
             {
                 return(false);
             }
             parameters[item.Name] = value;
             offset += count;
         }
         return(true);
     }
 }
Exemplo n.º 26
0
        private void AddMatchItem2Tree(MatchItem matchItem)
        {
            var nodeMatchItem = new TreeNode($"{matchItem.Name}, results={matchItem.Results.Count}")
            {
                Tag = matchItem
            };
            var nodeSample = new TreeNode($"Sample, set={matchItem.Sample.Entities.Count}")
            {
                Tag = matchItem.Sample
            };

            nodeMatchItem.Nodes.Add(nodeSample);
            foreach (var result in matchItem.Results)
            {
                var nodeResult = new TreeNode($"MatchResult, set={result.Entities.Distinct().Count()}")
                {
                    Tag = result
                };
                nodeMatchItem.Nodes.Add(nodeResult);
            }
            nodeMatchItem.ExpandAll();
            tree.Nodes.Add(nodeMatchItem);
            grpxItemList.Text = $"匹配结果,共匹配{tree.Nodes.Count}次";
        }
Exemplo n.º 27
0
 public bool Execut(string url, QueryString queryString)
 {
     if (mItems.Count == 0)
     {
         return(url == mTemplate);
     }
     else
     {
         int offset = mOffset;
         for (int i = 0; i < mItems.Count; i++)
         {
             MatchItem item = mItems[i];
             string    value;
             var       count = item.Match(url, offset, out value);
             if (count <= 0)
             {
                 return(false);
             }
             queryString.Add(item.Name, value);
             offset += count;
         }
         return(true);
     }
 }
Exemplo n.º 28
0
        public void Read_Daug(string[] exportLines, ref MatchData fileData)
        {
            List <string> columns = new List <string>();

            Read_DaughterFile_Title(exportLines, ref fileData);
            columns            = exportLines[1].Split(Constant.Export_File_Delimiter).ToList();
            fileData.FileMaker = Quotes.RemoveQuotes(columns[2]).ToString();
            string    expCode   = "NONE";
            bool      tillDes   = false;
            string    result    = Constant.MatchSucces;
            MatchItem matchItem = new MatchItem();

            #region for loop
            foreach (string line in exportLines)
            {
                columns = line.Split(Constant.Export_File_Delimiter).ToList();
                switch (Quotes.RemoveQuotes(columns[0]).ToLower())
                {
                case "source":
                    /* start second round, store previous data */
                    if (tillDes)
                    {
                        if (expCode.Equals("NONE"))
                        {
                            FileProcessor.GiveLog("Read Error, All Plate Empty");
                            result = Constant.AllEmptyError;
                        }
                        matchItem.itemResult = result;
                        fileData.MatchQueue.Enqueue(matchItem);

                        expCode   = "NONE";
                        tillDes   = false;
                        result    = Constant.MatchSucces;
                        matchItem = new MatchItem();
                    }

                    if (!(Quotes.RemoveQuotes(columns[2]).Equals(Constant.StrEmpty)))
                    {
                        if (expCode.Equals("NONE"))
                        {
                            expCode = Quotes.RemoveQuotes(columns[2]).GetExpCode();
                        }
                        else
                        {
                            if (!expCode.Equals(Quotes.RemoveQuotes(columns[2]).GetExpCode()))
                            {
                                FileProcessor.GiveLog("Source Experiment Code Error " + Quotes.RemoveQuotes(columns[2]));
                                result = Constant.ExpCodeError;
                            }
                        }
                        matchItem.itemQueue.Enqueue(new KeyValuePair <string, string>(Constant.StrSrc, Quotes.RemoveQuotes(columns[2])));
                    }
                    else
                    {
                        matchItem.itemQueue.Enqueue(new KeyValuePair <string, string>(Constant.StrSrc, Constant.StrEmpty));
                    }
                    break;

                case "destination":
                    tillDes = true;
                    if (!(Quotes.RemoveQuotes(columns[2]).Equals(Constant.StrEmpty)))
                    {
                        if (expCode.Equals("NONE"))
                        {
                            expCode = Quotes.RemoveQuotes(columns[2]).GetExpCode();
                        }
                        else
                        {
                            if (!expCode.Equals(Quotes.RemoveQuotes(columns[2]).GetExpCode()))
                            {
                                FileProcessor.GiveLog("Destination Experiment Code Error " + Quotes.RemoveQuotes(columns[2]));
                                result = Constant.ExpCodeError;
                            }
                        }
                        matchItem.itemQueue.Enqueue(new KeyValuePair <string, string>(Constant.StrDes, Quotes.RemoveQuotes(columns[2])));
                    }
                    else
                    {
                        matchItem.itemQueue.Enqueue(new KeyValuePair <string, string>(Constant.StrDes, Constant.StrEmpty));
                    }
                    break;
                }
            }
            #endregion
            if (expCode.Equals("NONE"))
            {
                FileProcessor.GiveLog("Read Error, All Plate Empty");
                result = Constant.AllEmptyError;
            }

            matchItem.itemResult = result;
            fileData.MatchQueue.Enqueue(matchItem);

            expCode   = "NONE";
            tillDes   = false;
            result    = Constant.MatchSucces;
            matchItem = new MatchItem();
        }
Exemplo n.º 29
0
    // Check Match-3 Tile
    void CheckMatch3(Dictionary <TilePoint, Data.TileTypes> stack, MatchItem a, MatchItem b)
    {
        List <MatchItem> destroyListBomb = new List <MatchItem>();
        List <MatchItem> destroyList     = new List <MatchItem>();
        List <MatchItem> bombList        = new List <MatchItem>();

        if (a != null)
        {
            switch (a.cell.cellType)
            {
            case Data.TileTypes.AtBomb:
            case Data.TileTypes.ShBomb:
            case Data.TileTypes.HBomb:
            case Data.TileTypes.ScBomb:
            case Data.TileTypes.GBomb:
                if (FindTile(new TilePoint(a.point.x, a.point.y + 1)) != null)
                {
                    destroyListBomb.Add(FindTile(new TilePoint(a.point.x, a.point.y + 1)));
                }
                if (FindTile(new TilePoint(a.point.x, a.point.y - 1)) != null)
                {
                    destroyListBomb.Add(FindTile(new TilePoint(a.point.x, a.point.y - 1)));
                }
                if (FindTile(new TilePoint(a.point.x - 1, a.point.y)) != null)
                {
                    destroyListBomb.Add(FindTile(new TilePoint(a.point.x - 1, a.point.y)));
                }
                if (FindTile(new TilePoint(a.point.x + 1, a.point.y)) != null)
                {
                    destroyListBomb.Add(FindTile(new TilePoint(a.point.x + 1, a.point.y)));
                }
                stack.Add(a.point, a.cell.cellType);
                break;

            default:
                break;
            }

            switch (b.cell.cellType)
            {
            case Data.TileTypes.AtBomb:
            case Data.TileTypes.ShBomb:
            case Data.TileTypes.HBomb:
            case Data.TileTypes.ScBomb:
            case Data.TileTypes.GBomb:
                if (FindTile(new TilePoint(b.point.x, b.point.y + 1)) != null)
                {
                    destroyListBomb.Add(FindTile(new TilePoint(b.point.x, b.point.y + 1)));
                }
                if (FindTile(new TilePoint(b.point.x, b.point.y - 1)) != null)
                {
                    destroyListBomb.Add(FindTile(new TilePoint(b.point.x, b.point.y - 1)));
                }
                if (FindTile(new TilePoint(b.point.x - 1, b.point.y)) != null)
                {
                    destroyListBomb.Add(FindTile(new TilePoint(b.point.x - 1, b.point.y)));
                }
                if (FindTile(new TilePoint(b.point.x + 1, b.point.y)) != null)
                {
                    destroyListBomb.Add(FindTile(new TilePoint(b.point.x + 1, b.point.y)));
                }
                stack.Add(b.point, b.cell.cellType);
                break;

            default:
                break;
            }
        }

        while (findBomb(destroyListBomb) != null)
        {
            MatchItem item = findBomb(destroyListBomb);
            switch (item.cell.cellType)
            {
            case Data.TileTypes.AtBomb:
            case Data.TileTypes.ShBomb:
            case Data.TileTypes.HBomb:
            case Data.TileTypes.ScBomb:
            case Data.TileTypes.GBomb:
                stack.Add(item.point, item.cell.cellType);
                destroyListBomb.Remove(item);
                if (FindTile(new TilePoint(item.point.x, item.point.y + 1)) != null)
                {
                    if (!stack.ContainsKey(new TilePoint(item.point.x, item.point.y + 1)))
                    {
                        destroyListBomb.Add(FindTile(new TilePoint(item.point.x, item.point.y + 1)));
                    }
                }
                if (FindTile(new TilePoint(item.point.x, item.point.y - 1)) != null)
                {
                    if (!stack.ContainsKey(new TilePoint(item.point.x, item.point.y - 1)))
                    {
                        destroyListBomb.Add(FindTile(new TilePoint(item.point.x, item.point.y - 1)));
                    }
                }
                if (FindTile(new TilePoint(item.point.x - 1, item.point.y)) != null)
                {
                    if (!stack.ContainsKey(new TilePoint(item.point.x - 1, item.point.y)))
                    {
                        destroyListBomb.Add(FindTile(new TilePoint(item.point.x - 1, item.point.y)));
                    }
                }
                if (FindTile(new TilePoint(item.point.x + 1, item.point.y)) != null)
                {
                    if (!stack.ContainsKey(new TilePoint(item.point.x + 1, item.point.y)))
                    {
                        destroyListBomb.Add(FindTile(new TilePoint(item.point.x + 1, item.point.y)));
                    }
                }
                break;

            default:
                break;
            }
        }

        foreach (MatchItem item in destroyListBomb.ToArray())
        {
            if (stack.ContainsKey(item.point))
            {
                destroyListBomb.Remove(item);
            }
        }

        foreach (KeyValuePair <TilePoint, Data.TileTypes> item in stack)
        {
            destroyList.Add(FindTile(item.Key));
        }



        if (3 < destroyList.Count)
        {
            byte matchCount = 0;
            byte matchGroup = 0;
            int  inc        = 0;
            for (int baseindex = 0; baseindex < destroyList.Count; baseindex++)
            {
                matchCount = 1;
                if (baseindex != 0)
                {
                    if (destroyList[baseindex].matchGroup != destroyList[baseindex - 1].matchGroup)
                    {
                        matchGroup++;
                        destroyList[baseindex].matchGroup = matchGroup;
                    }
                }
                else
                {
                    matchGroup++;
                    destroyList[0].matchGroup = matchGroup;
                }

                //右方向
                inc = 1;
                bool isMatch = false;
                for (int x = 0; x < destroyList.Count; x++)
                {
                    for (int x1 = 0; x1 < destroyList.Count; x1++)
                    {
                        if ((destroyList[baseindex].point.x + inc == destroyList[x1].point.x) &&
                            (destroyList[baseindex].point.y == destroyList[x1].point.y) &&
                            (destroyList[baseindex].cell.cellType == destroyList[x1].cell.cellType))
                        {
                            matchCount++;
                            destroyList[x1].matchGroup = matchGroup;
                            isMatch = true;
                        }
                    }
                    if (isMatch)
                    {
                        inc++;
                        isMatch = false;
                    }
                    else
                    {
                        break;
                    }
                }

                //左方向
                inc     = 1;
                isMatch = false;
                for (int x = 0; x < destroyList.Count; x++)
                {
                    for (int x1 = 0; x1 < destroyList.Count; x1++)
                    {
                        if ((destroyList[baseindex].point.x - inc == destroyList[x1].point.x) &&
                            (destroyList[baseindex].point.y == destroyList[x1].point.y) &&
                            (destroyList[baseindex].cell.cellType == destroyList[x1].cell.cellType))
                        {
                            matchCount++;
                            destroyList[x1].matchGroup = matchGroup;
                            isMatch = true;
                        }
                    }
                    if (isMatch)
                    {
                        inc++;
                        isMatch = false;
                    }
                    else
                    {
                        break;
                    }
                }

                //下方向
                inc     = 1;
                isMatch = false;
                for (int x = 0; x < destroyList.Count; x++)
                {
                    for (int x1 = 0; x1 < destroyList.Count; x1++)
                    {
                        if ((destroyList[baseindex].point.x == destroyList[x1].point.x) &&
                            (destroyList[baseindex].point.y + inc == destroyList[x1].point.y) &&
                            (destroyList[baseindex].cell.cellType == destroyList[x1].cell.cellType))
                        {
                            matchCount++;
                            destroyList[x1].matchGroup = matchGroup;
                            isMatch = true;
                        }
                    }
                    if (isMatch)
                    {
                        inc++;
                        isMatch = false;
                    }
                    else
                    {
                        break;
                    }
                }

                //上方向
                inc     = 1;
                isMatch = false;
                for (int x = 0; x < destroyList.Count; x++)
                {
                    for (int x1 = 0; x1 < destroyList.Count; x1++)
                    {
                        if ((destroyList[baseindex].point.x == destroyList[x1].point.x) &&
                            (destroyList[baseindex].point.y - inc == destroyList[x1].point.y) &&
                            (destroyList[baseindex].cell.cellType == destroyList[x1].cell.cellType))
                        {
                            matchCount++;
                            destroyList[x1].matchGroup = matchGroup;
                            isMatch = true;
                        }
                    }
                    if (isMatch)
                    {
                        inc++;
                        isMatch = false;
                    }
                    else
                    {
                        break;
                    }
                }

                destroyList[baseindex].matchCount = matchCount;
            }

            if (a != null)
            {
                foreach (MatchItem item in destroyList)
                {
                    if (4 <= item.matchCount)
                    {
                        if (item.Equals(a) || item.Equals(b))
                        {
                            switch (item.matchCount)
                            {
                            case 4:
                            case 5:
                            case 6:
                            case 7:
                            default:
                                if ((int)item.cell.cellType < 6)
                                {
                                    item.cell.cellType = item.cell.cellType + 5;
                                    bombList.Add(item);
                                }
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                int matchGroupCount = 0;
                foreach (MatchItem item in destroyList)
                {
                    if (matchGroupCount <= item.matchGroup)
                    {
                        matchGroupCount = item.matchGroup;
                    }
                }

                List <MatchItem>[] matchGroupList = new List <MatchItem> [matchGroupCount];


                foreach (MatchItem item in destroyList)
                {
                    //Debug.Log(item != null);
                    if (matchGroupList[item.matchGroup - 1] == null)
                    {
                        matchGroupList[item.matchGroup - 1] = new List <MatchItem>();
                    }
                    matchGroupList[item.matchGroup - 1].Add(item);
                }

                MatchItem bombTile;
                foreach (List <MatchItem> matchList in matchGroupList)
                {
                    bombTile = matchList[0];
                    foreach (MatchItem item in matchList)
                    {
                        if (bombTile.matchCount < item.matchCount)
                        {
                            bombTile = item;
                        }
                    }
                    if (4 <= bombTile.matchCount)
                    {
                        bombTile.cell.cellType = bombTile.cell.cellType + 5;
                        bombList.Add(bombTile);
                        destroyList.Remove(bombTile);
                    }
                }
            }
        }

        foreach (MatchItem itembomb in bombList)
        {
            foreach (MatchItem item in destroyList.ToArray())
            {
                if (itembomb.Equals(item))
                {
                    destroyList.Remove(itembomb);
                }
            }
        }


        foreach (MatchItem item in destroyListBomb)
        {
            int type = (int)item.cell.cellType;
            item.cell.cellType = Data.TileTypes.Empty;
            item.GetComponent <SpriteRenderer>().enabled = false;
            GameObject instance = Instantiate(explosionPrefab) as GameObject;
            instance.transform.parent        = effectArea;
            instance.transform.localPosition = new Vector3(item.point.x * cellWidth, item.point.y * -cellHeight, -5f);

            DoStarEffect(instance.transform.localPosition, type);
        }

        foreach (MatchItem item in bombList)
        {
            Sprite         sprite   = sprites[(int)item.cell.cellType - 1];
            SpriteRenderer renderer = item.GetComponent <SpriteRenderer>();
            renderer.sprite  = sprite;
            renderer.enabled = true;
        }

        foreach (MatchItem item in destroyList)
        {
            int type = (int)item.cell.cellType;
            audioMatchSource[(int)(item.cell.cellType) - 1].Play();

//            if (type <= 5) {
            item.cell.cellType = Data.TileTypes.Empty;
            item.GetComponent <SpriteRenderer>().enabled = false;
//            }

            GameObject instance = Instantiate(explosionPrefab) as GameObject;
            instance.transform.parent        = effectArea;
            instance.transform.localPosition = new Vector3(item.point.x * cellWidth, item.point.y * -cellHeight, -5f);

            DoStarEffect(instance.transform.localPosition, type);

//            if(6 <= type) {
//                Sprite sprite = sprites[(int)item.cell.cellType - 1];
//                SpriteRenderer renderer = item.GetComponent<SpriteRenderer>();
//                renderer.sprite = sprite;
//                renderer.enabled = true;
//            }
        }
        //		StartCoroutine( AttackMonster(0.7f) );
        StartCoroutine(FillEmpty(0.5f));
    }
Exemplo n.º 30
0
 // Check Match-3 Tile
 IEnumerator CheckMatch3Tile(float delayTime, MatchItem a, MatchItem b)
 {
     yield return new WaitForSeconds(delayTime);
     Dictionary<TilePoint, Data.TileTypes> stack = FindMatch(cells);
     if (stack.Count>0) {
         CheckMatch3(stack);
     } else {
         DoSwapTile(a, b);
         DoSwapMotion(a.transform, b.transform);
         ReadyGameTurn();
     }
 }
Exemplo n.º 31
0
 // Find Match-3 Tile with Position
 MatchItem FindTileWithPosition(Vector2 pos)
 {
     Vector3 pos3 = new Vector3(pos.x, pos.y, 0f) - (grid.transform.localPosition);
     MatchItem curTile = null;
     foreach(MatchItem tile in tiles) {
         if (curTile == null) {
             curTile = tile;
             continue;
         }
         float dist1 = Vector3.Distance( curTile.transform.localPosition , pos3);
         float dist2 = Vector3.Distance( tile.transform.localPosition , pos3);
         if (dist1 > dist2) {
             curTile = tile;
         }
     }
     float dist = Vector3.Distance( curTile.transform.localPosition , pos3);
     return curTile;
 }
Exemplo n.º 32
0
        public MatchItem MatchWith(tblTimeReport_Transaction_Input Item)
        {
            FieldInfo[] piItem = this.GetType().GetFields();
               MatchItem item = new MatchItem();
               item.MatchIdentifier = Item.Job_No;
               //TableEditStatus csak a kliensben határozza meg a tábla szerkeszthetőségét,
               //ezéert nem kell vizsgálni

               try
               {
                   var ItemNonNull = (from p in piItem
                                      where p.GetValue(this) != null && p.Name != "TableEditStatus"
                                      select new { Name = p.Name, Value = p.GetValue(this) }).ToList();

                   foreach (var non_null in ItemNonNull)
                   {
                       var value = Item.GetType().GetField(non_null.Name).GetValue(Item);

                       int hash1 = 0;
                       int hash2 = 0;

                       hash2 = non_null.Value.GetHashCode();

                       if (value != null)
                       {
                           hash1 = Item.GetType().GetField(non_null.Name).GetValue(Item).GetHashCode();
                       }
                       else
                       {
                           int valueInt;
                           bool isInt = int.TryParse(non_null.Value.ToString(), out valueInt);

                           bool valueBool;
                           bool isBool = bool.TryParse(non_null.Value.ToString(), out valueBool);

                           decimal valueDec;
                           bool isDecimal = decimal.TryParse(non_null.Value.ToString(), out valueDec);

                           if (isInt && (int)non_null.Value == 0)
                           {
                               hash2 = 0;
                           }

                           else if (isBool && (bool)non_null.Value == false)
                           {
                               hash2 = 0;
                           }
                           else if (isDecimal && valueDec == 0)
                           {
                               hash2 = 0;
                           }
                           else if ((string)non_null.Value == "")
                           {
                               hash2 = 0;
                           }
                       }

                       if (hash1 == hash2)
                       {
                           item.IsMatch = true;
                       }
                       else
                       {
                           item.IsMatch = false;
                           item.InvalidField = non_null.Name;
                           break;
                       }

                   }
               }

               catch (Exception ex)
               {
                   item.IsMatch = false;
                   item.FailedOnException = true;
                   item.InvalidField = ex.ToString();
               }

               return item;
        }
Exemplo n.º 33
0
    // Click Event
    void OnClickAction(MatchItem tile)
    {
        if (isDoing) return;

        if (tile==null) return;
        if (curTile==null) {
            curTile = tile;
            choice.transform.localPosition = curTile.transform.localPosition;
            choice.enabled = true;
        } else {
            if ( Mathf.Abs( curTile.point.x - tile.point.x ) + Mathf.Abs( curTile.point.y - tile.point.y ) != 1 ) {
                curTile = null;
                choice.enabled = false;
                return;
            }
            isDoing = true;
            DoSwapTile(curTile, tile);
            DoSwapMotion(curTile.transform, tile.transform);
            StartCoroutine( CheckMatch3Tile(0.5f, curTile, tile) );
            curTile = null;
            choice.enabled = false;
        }
    }
Exemplo n.º 34
0
    // Swap Two Tile
    void DoSwapTile(MatchItem a, MatchItem b)
    {
        TilePoint p1 = a.point;
        TilePoint p2 = b.point;

        Cell cell = cells[p1.x, p1.y];
        cells[p1.x, p1.y] = cells[p2.x, p2.y];
        cells[p2.x, p2.y] = cell;

        a.point = p2;
        b.point = p1;
    }
Exemplo n.º 35
0
        /// <summary>
        /// Responsible for parsing the Text and return the collection
        /// for Document Map
        /// </summary>
        /// <returns></returns>
        private List <MatchItem> MethodsCollection()
        {
            List <MatchItem> methodsCollection = new List <MatchItem>();

            Regex        r = null;
            Match        m;
            RegexOptions theOptions = RegexOptions.None;

            theOptions |= RegexOptions.IgnoreCase;
            theOptions |= RegexOptions.Multiline;
            theOptions |= RegexOptions.IgnorePatternWhitespace;

            #region Testing regex
            //string regextPattern = @"@Q(?:[^Q]+|QQ)*Q|Q(?:[^Q\\]+|\\.)*Q".Replace('Q', '\"');

            //Finds all strings
            //string regextPattern = @"((private)|(public)|(sealed)|(protected)|(virtual)|(internal))+([a-z]|[A-Z]|[0-9]|[\s])*([\()([a-z]|[A-Z]|[0-9]|[\s])*([\)|\{]+)";

            //Finds All Methods
            //string regextPattern = @"((private)|(public)|(sealed)|(protected)|(virtual)|(internal))+([a-z]|[A-Z]|[0-9]|[\s])*([\()([a-z]|[A-Z]|[0-9]|[\s])*([\)|\(]+)";
            //string regextPattern2 = @"\s+|(<<|>>|\+\+|--|==|\!=|>=|<=|\{|\}|\[|\]|\(|\)|\.|,|:|;|\+|-|\*|/|%|&|\||\^|!|~|=|\<|\>|\?)";
            //string regextPattern2 = @"^(?=.*?\b(private|public|sealed)\b)(?=.*?\b(\b)(?=.*?\b)\b).*$";
            //string regextPattern = @"((private)|(public)|(sealed)|(protected)|(virtual)|(internal))+([a-z]|[A-Z]|[0-9]|[\s])*([\()([a-z]|[A-Z]|[0-9]|[\s])*([\)|\{]+)";
            //m = Regex.Match(this._document.Text, regextPattern2);
            //MatchCollection MethodSignatureCollection = Regex.Match(this._document.Text, regextPattern);

            // Matches a complete line of text that contains any of the words "private", "public" etc.
            // The first backreference will contain the word the line actually contains. If it contains more than one of the words,
            // then the last (rightmost) word will be captured into the first backreference. This is because the star is greedy.
            // Finally, .*$ causes the regex to actually match the line, after the lookaheads have determined it meets the requirements.
            #endregion

            // Specify the correct match pattern
            // need to be altered for different language
            //string regextPattern2 = @"^.*\b(namespace|private|public|sealed|protected|virtual|internal)\b.*$";

            try
            {
                r = new Regex(_regextPattern, theOptions);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Failed to execute regular expression! ");

                _messageService.ShowError("Failed to execute regular expression!\n\n"
                                          + ex.Message + "\n", "Error");
            }

            for (int i = 1; i < Document.LineCount; i++)
            {
                // Get the current line number
                DocumentLine line = Document.GetLineByNumber(i);

                // Try to Match the contect fo line with specified pattern
                m = r.Match(Document.GetText(line));

                // If line is has match create new MatchItem and add it
                // to collection
                if (m.Success)
                {
                    MatchItem mi = new MatchItem();
                    mi.CurrentLine  = i;
                    mi.CurrentMatch = m;
                    methodsCollection.Add(mi);
                }
            }
            return(methodsCollection);
        }