Esempio n. 1
0
        public void Insert(Pice entity)
        {
            entity.Stavka_menija.ID = Guid.NewGuid().ToString();
            entity.ID = entity.Stavka_menija.ID;

            _provider.Insert(entity);
        }
Esempio n. 2
0
 public void Insert(Pice pice, int index)
 {
     list.Insert(index, pice);
     pice.sideIndex        = index;
     pice.transform.parent = scrollView.content;
     SetContentLength(list.Count * cellWidth);
 }
Esempio n. 3
0
 public void Append(Pice pice)
 {
     list.Add(pice);
     pice.sideIndex        = list.Count - 1;
     pice.transform.parent = scrollView.content;
     SetContentLength(list.Count * cellWidth);
 }
Esempio n. 4
0
 public void Remove(Pice pice, int indexX, int indexY)
 {
     if (isIndexInvalid(indexX, indexY))
     {
         data[indexX, indexY].Remove(pice);
     }
 }
Esempio n. 5
0
 public static void Link(Pice pice1, LinkDirectory directory, Pice pice2)
 {
     // set pice1
     {
         var info = new Linking();
         info.directory = directory;
         info.pice      = pice2;
         pice1.linkingList.Add(info);
         if (pice1.linkingList.Count == 1)
         {
             pice1.FlashAsLink();
         }
     }
     // set pice2
     {
         var info = new Linking();
         info.directory = LinkDirectoryUtil.Reverse(directory);
         info.pice      = pice1;
         pice2.linkingList.Add(info);
         if (pice2.linkingList.Count == 1)
         {
             pice2.FlashAsLink();
         }
     }
 }
Esempio n. 6
0
    public static void TryLink(Pice pice1, LinkDirectory directory, Pice pice2)
    {
        // 如果任一 pice 不在 board 上,则不予处理
        if (pice1.owner != PiceOwner.Board || pice2.owner != PiceOwner.Board)
        {
            return;
        }

        // 如果 pice1 的指定方向上已经连结,则不予处理
        var alreadyLinked = false;

        pice1.linkingList.ForEach(info => {
            if (info.directory == directory)
            {
                alreadyLinked = true;
            }
        });
        if (alreadyLinked)
        {
            return;
        }

        // 连接两个 pice
        Link(pice1, directory, pice2);
    }
Esempio n. 7
0
    public Vector2Int GetNearestCellIndex(Pice pice)
    {
        var px                = pice.transform.position.x;
        var py                = pice.transform.position.y;
        var minCenterX        = 0f;
        var minCenterY        = 0f;
        var minDistanceSquare = float.MaxValue;
        var minIndex          = -1;

        for (var index = 0; index <= maxIndex; index++)
        {
            var indexX         = IndexToIndexX(index);
            var indexY         = IndexToIndexY(index);
            var centerX        = GetCenterX(indexX);
            var centerY        = GetCenterY(indexY);
            var distanceSquare = Mathf.Pow(px - centerX, 2) + Mathf.Pow(py - centerY, 2);
            if (distanceSquare < minDistanceSquare)
            {
                minDistanceSquare = distanceSquare;
                minCenterX        = centerX;
                minCenterY        = centerY;
                minIndex          = index;
            }
        }
        var indexX_ = IndexToIndexX(minIndex);
        var indexY_ = IndexToIndexY(minIndex);

        return(new Vector2Int(indexX_, indexY_));
    }
 public void Insert(Pice entity)
 {
     using (var db = new Entities())
     {
         db.Pices.Add(entity);
         db.SaveChanges();
     }
 }
Esempio n. 9
0
 private Pice[,] CreateBord(int x, int y, List <Pice> ListOfPices)
 {
     Pice[,] bord = new Pice[x, y];
     foreach (Pice p in ListOfPices)
     {
         bord[p.pozition.pozX, p.pozition.pozY] = p;
     }
     return(bord);
 }
Esempio n. 10
0
    private void Push(int indexX, int indexY, Pice pice)
    {
        var stack = this.data[indexX, indexY];

        stack.Push(pice);
        pice.owner  = PiceOwner.Board;
        pice.boardX = indexX;
        pice.boardY = indexY;
    }
Esempio n. 11
0
 public static void SetBlockToBoard(Pice pice, int indexX, int indexY)
 {
     PiceMover.SetBlockToFloat(pice);
     pice.ForeachPiceOfBlockWhitShift((onePice, shift) => {
         var onePiceIndexX = indexX + shift.x;
         var onePiceIndexY = indexY + shift.y;
         Puzzle.instance.board.Put(onePice, onePiceIndexX, onePiceIndexY);
     });
 }
Esempio n. 12
0
    private void RemovePiceFromData(Pice pice, int indexX, int indexY)
    {
        var stack = data[indexX, indexY];

        if (stack.Contains(pice))
        {
            stack.Remove(pice);
        }
    }
        public IHttpActionResult PostPice(Pice pice)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _manager.Insert(pice);
            return(CreatedAtRoute("DefaultApi", new { id = pice.ID }, pice));
        }
        public IHttpActionResult GetPice(string id)
        {
            Pice pice = _manager.GetById(id);

            if (pice == null)
            {
                return(NotFound());
            }

            return(Ok(pice));
        }
Esempio n. 15
0
 public bool Update(Pice entity)
 {
     if (_provider.GetById(entity.ID) == null)
     {
         return(false);
     }
     else
     {
         _provider.Update(entity);
         return(true);
     }
 }
Esempio n. 16
0
        public void Update(Pice entity)
        {
            using (var db = new Entities())
            {
                Pice toChange = db.Pices.Where(x => x.ID.Equals(entity.ID)).Include(x => x.Stavka_menija).FirstOrDefault();
                toChange.ALKOHOLNO          = entity.ALKOHOLNO;
                toChange.ZAP                = entity.ZAP;
                toChange.Stavka_menija.CENA = entity.Stavka_menija.CENA;
                toChange.Stavka_menija.NAZ  = entity.Stavka_menija.NAZ;

                db.Entry(toChange).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
        }
Esempio n. 17
0
        public async Task <IActionResult> UpisiPice(int ind, [FromBody] Pice pice)
        {
            if (pice.Cena > 0 && pice.Naziv.Length - 1 > 0)
            {
                Context.Pica.Add(pice);
                await Context.SaveChangesAsync();

                return(Ok(pice.ID));
            }
            else
            {
                return(BadRequest());
            }
        }
Esempio n. 18
0
 public void Put(Pice pice, int indexX, int indexY)
 {
     if (isIndexInvalid(indexX, indexY))
     {
         this.Push(indexX, indexY, pice);
         pice.boardX = indexX;
         pice.boardY = indexY;
     }
     else
     {
         pice.boardX = indexX;
         pice.boardY = indexY;
     }
 }
Esempio n. 19
0
 public static void SetToSide(Pice pice, int index)
 {
     Assert.IsTrue(pice.linkingList.Count == 0, "only non-linked pice can'bt be set to side.");
     PiceMover.SetBlockToFloat(pice);
     if (index != -1)
     {
         Puzzle.instance.side.Insert(pice, index);
         pice.owner = PiceOwner.Side;
     }
     else
     {
         Puzzle.instance.side.Append(pice);
         pice.owner = PiceOwner.Side;
     }
 }
Esempio n. 20
0
        public void Delete(string id)
        {
            using (var db = new Entities())
            {
                Pice pice = db.Pices.Where(p => p.ID.Equals(id)).FirstOrDefault();
                db.Entry(pice).State = System.Data.Entity.EntityState.Deleted;

                Stavka_menija stavka = db.Stavka_menija.Where(s => s.ID.Equals(id)).FirstOrDefault();
                stavka.Nalazi_se.Clear();
                db.Entry(stavka).State = System.Data.Entity.EntityState.Modified;
                db.Entry(stavka).State = System.Data.Entity.EntityState.Deleted;

                db.SaveChanges();
            }
        }
Esempio n. 21
0
        public async Task <IActionResult> IzmeniPice(int id, [FromBody] Pice pice)
        {
            var p = await Context.Pica.FindAsync(id);

            if (pice.Cena > 0 && pice.Naziv.Length - 1 > 0)
            {
                p.Naziv = pice.Naziv;
                p.Cena  = pice.Cena;
                Context.Pica.Update(p);
                await Context.SaveChangesAsync();

                return(Ok());
            }
            else
            {
                return(StatusCode(406));
            }
        }
Esempio n. 22
0
 public static void SetBlockToFloat(Pice pice)
 {
     if (pice.owner == PiceOwner.Board)
     {
         pice.ForeachPiceOfBlock(onePice => {
             // 断言:所有 block 上的 pice 都应该在 board 上
             Assert.IsTrue(onePice.owner == PiceOwner.Board, "a pice of bloack in board which owner is not set to baord.");
             Puzzle.instance.board.Remove(onePice, onePice.boardX, onePice.boardY);
             pice.owner = PiceOwner.Floating;
         });
     }
     else if (pice.owner == PiceOwner.Side)
     {
         Assert.IsTrue(pice.linkingList.Count == 0, "a linked-pice found in side. there is something wrong.");
         Puzzle.instance.side.Remove(pice);
         pice.owner = PiceOwner.Floating;
     }
 }
Esempio n. 23
0
 public DataSource()
 {
     Korisnik  k1    = DajKorisnikaPoId(1);
     Korisnik  k2    = DajKorisnikaPoId(2);
     Korisnik  k3    = DajKorisnikaPoId(3);
     Stol      s1    = DajStolPoBroju(1);
     Stol      s2    = DajStolPoBroju(2);
     Stol      s4    = DajStolPoBroju(3);
     Pjesma    p1    = DajPjesmuPoId(1);
     Pjesma    p2    = DajPjesmuPoId(2);
     Pjesma    p3    = DajPjesmuPoId(3);
     Pjesma    p4    = DajPjesmuPoId(4);
     Playlista pl1   = DajPlaylistuPoNazivu("playlista1");
     Playlista pl2   = DajPlaylistuPoNazivu("playlista2");
     Pice      pice1 = DajPicePoID(1);
     Pice      pice2 = DajPicePoID(2);
     Pice      pice3 = DajPicePoID(3);
     Pice      pice4 = DajPicePoID(4);
 }
Esempio n. 24
0
 public void UpdatePiceOwner(Pice pice)
 {
     if (pice.owner == PiceOwner.Side)
     {
         var inSide = side.Rect.Contains(pice.transform.position);
         if (!inSide)
         {
             // 认为从side中拖出
             //side.Remove(pice);
             PiceMover.SetBlockToFloat(pice);
             side.RepositionPiceList();
             pice.TweenToScale(1);
             side.scrollView.AnimateFixContentPosition();
         }
         else
         {
             var rect = side.GetCellRect(pice.sideIndex);
             if (!rect.Contains(pice.transform.position))
             {
                 // 认为在side中移动了位置
                 //side.Remove(pice);
                 PiceMover.SetBlockToFloat(pice);
                 var insertIndex = side.GetNearestCellIndex(pice);
                 PiceMover.SetToSide(pice, insertIndex);
                 side.RepositionPiceList();
                 side.scrollView.AnimateFixContentPosition();
             }
         }
     }
     else if (pice.owner != PiceOwner.Side)
     {
         var inSide = side.Rect.Contains(pice.transform.position);
         if (inSide)
         {
             // 认为拖入side
             var insertIndex = side.GetNearestCellIndex(pice);
             PiceMover.SetToSide(pice, insertIndex);
             side.RepositionPiceList();
             side.scrollView.AnimateFixContentPosition();
         }
     }
 }
Esempio n. 25
0
    public void OnRootPiceDragEnd(Pice pice)
    {
        lastDragPice = pice;
        UpdatePiceOwner(pice);
        // 没有连结的 pice, 当拖放释放点不在 board 上时,自动回到 side 上
        if (pice.linkingList.Count == 0)
        {
            var inboard = board.Rect.Contains(pice.transform.position);
            if (!inboard)
            {
                var insertIndex = side.GetNearestCellIndex(pice);
                PiceMover.SetToSide(pice, insertIndex);
                side.RepositionPiceList();
                side.scrollView.AnimateFixContentPosition();
                return;
            }
        }

        // 应该放置到 board 上时
        //board.PlacePice(pice);
        var index = board.GetNearestCellIndex(pice);

        PiceMover.SetBlockToBoard(pice, index.x, index.y);
        var x = board.GetCenterX(index.x);
        var y = board.GetCenterY(index.y);

        pice.TweenBlockToPosition(x, y);
        //board.RepositionAllPice();

        CheckNewLink();
        CheckNewFix();
        var complete = IsAllPiceFixed();

        if (complete)
        {
            Debug.Log("[Core] Complete");
            CoroutineManager.Create(PlayCompleteTask());
        }
    }
Esempio n. 26
0
        public void playGame()
        {
            int playerTurn = 0;

            while (!gameState)
            {
                PrintBord();
                Console.WriteLine("Player" + listOfPlayers[playerTurn].playerNumber + " next to move");
                Console.WriteLine("select pozition x :");
                int x = Convert.ToInt16(Console.ReadLine());
                Console.WriteLine("select Pozition y :");
                int y = Convert.ToInt16(Console.ReadLine());

                Pice selectedPice = bord[x, y];
                if (selectedPice == null && !listOfPlayers[playerTurn].playerPices.Contains(bord[x, y]))
                {
                    continue;
                }
                List <Pozition> poz = selectedPice.GetAllMoves(this.bord);
                // implement later a way to stop mooving foward till we select where to move
                PrintPozitions(poz);

                Console.WriteLine("select pozition x :");
                int chozePozition = Convert.ToInt16(Console.ReadLine());

                Pozition newPozition = poz[chozePozition];

                if (bord[newPozition.pozX, newPozition.pozY] != null)
                {
                    bord[newPozition.pozX, newPozition.pozY].player.DeletePice(bord[newPozition.pozX, newPozition.pozY]);
                }
                bord[x, y] = null;
                bord[newPozition.pozX, newPozition.pozY] = selectedPice;
                selectedPice.pozition = newPozition;

                playerTurn = (playerTurn + 1) % listOfPlayers.Length;
            }
        }
        public IHttpActionResult PutPice(string id, Pice pice)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != pice.ID)
            {
                return(BadRequest());
            }

            bool ret = _manager.Update(pice);

            if (ret)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
Esempio n. 28
0
    public int GetNearestCellIndex(Pice pice)
    {
        var px                = pice.transform.position.x;
        var py                = pice.transform.position.y;
        var minCenterX        = 0f;
        var minCenterY        = 0f;
        var minDistanceSquare = float.MaxValue;
        var minIndex          = -1;

        for (var index = 0; index < count; index++)
        {
            var centerX        = GetCellCenterX(index);
            var centerY        = GetCellCenterY(index);
            var distanceSquare = Mathf.Pow(px - centerX, 2) + Mathf.Pow(py - centerY, 2);
            if (distanceSquare < minDistanceSquare)
            {
                minDistanceSquare = distanceSquare;
                minCenterX        = centerX;
                minCenterY        = centerY;
                minIndex          = index;
            }
        }
        return(minIndex);
    }
Esempio n. 29
0
    private bool Contains(int indexX, int indexY, Pice pice)
    {
        var stack = data[indexX, indexY];

        return(stack.Contains(pice));
    }
Esempio n. 30
0
        public Pice GetById(string id)
        {
            Pice pice = db.Pices.Where(p => p.ID.Equals(id)).Include(x => x.Stavka_menija).FirstOrDefault();

            return(pice);
        }