Beispiel #1
0
    // void moveTowardsNetworkTransform(){
    //     //if the piece is grabbed by the local player, instantly move it
    //     if(networkPiece.grabbedByLocalPlayer && false){
    //         transform.position = networkPiece.transform.position;
    //         transform.rotation = networkPiece.transform.rotation;
    //     }

    //     //if not, smoothly move it towards the network position (in world space)
    //     else {
    //         transform.rotation = networkPiece.transform.rotation;
    //         Vector3 dir = networkPiece.transform.position - transform.position;
    //         transform.Translate(dir * 0.4f, Space.World);
    //     }

    //     if(transform.position.z > 0.01f) transform.position = new Vector3(transform.position.x, transform.position.y, 0.0f);
    // }

    public void Setup(PieceData data)
    {
        GetComponent <MeshFilter>().mesh = data.mesh;
        MeshCollider collider = gameObject.AddComponent <MeshCollider>();

        collider.sharedMesh = data.colliderMesh;
    }
Beispiel #2
0
    // Start is called before the first frame update
    void Start()
    {
        matrixTest = new PieceData[16, 10];
        nativeTest = new NativeArray <PieceData>(160, Allocator.Temp);
        for (int x = 0; x < 16; x++)
        {
            for (int y = 0; y < 10; y++)
            {
                matrixTest[x, y] = new PieceData()
                {
                    x = x,
                    y = y
                };
            }
        }

        int index = 0;

        foreach (var item in matrixTest)
        {
            nativeTest[index] = item;
            index++;
        }

        Debug.Log($"X: {nativeTest[96].x} | Y: {nativeTest[96].y}");

        nativeTest.Dispose();
    }
Beispiel #3
0
 void SetType(PieceData type)
 {
     // update the graphics and all that.
     this.type             = type;
     spriteRenderer.sprite = type.sprite;
     spriteRenderer.color  = type.color;
 }
Beispiel #4
0
    public void AddPieceToList(APiece piece)
    {
        if (SelectedPieces.Contains(piece))
        {
            int indexOfDuplicate = SelectedPieces.IndexOf(piece);
            SelectedPieces.RemoveRange(indexOfDuplicate + 1, SelectedPieces.Count - indexOfDuplicate - 1);
        }
        else
        {
            if (SelectedPieces.Count >= 1)
            {
                PieceData previousPieceData = SelectedPieces[0].GetComponent <PieceData>();
                PieceData currentPieceData  = piece.GetComponent <PieceData>();

                if (previousPieceData.Color == currentPieceData.Color && MyUtils.IsTileAdjacent(SelectedPieces[SelectedPieces.Count - 1].ParentTile, piece.ParentTile) && previousPieceData.Type != EPieceType.Bomb)
                {
                    SelectedPieces.Add(piece);
                }
            }
            else
            {
                SelectedPieces.Add(piece);
            }
        }

        UpdateHighlight();
    }
Beispiel #5
0
    /// <summary>
    /// Searchs the normal moves.
    /// </summary>
    /// <param name="piece">Piece.</param>
    /// <param name="moves">Moves.</param>
    private void SearchNormalMoves(PieceData piece, MoveSet moves)
    {
        TileNode cur = node;

        // extend out by the range and search for more.
        for (int r = 0; r < piece.range; r++)
        {
            // move to next tile
            cur = cur.adjacent[piece.direction];

            // check if current tile is one you can move to
            if (CheckCurrentTileMove(cur))
            {
                moves.AddMove(node, false, cur);
            }

            // check if any more moves can be made after (not including range)
            if (!CheckFurtherMovement(cur))
            {
                break;
            }

            // run checks to see if hooking is possible
            if (CheckHookMove(cur, piece))
            {
                moves.AddMove(node, true, cur, cur.adjacent[hook.direction]);
            }
        }
    }
    void Start()
    {
        _propertyBlock = new MaterialPropertyBlock();
        _matrices      = new Matrix4x4[_count];
        _data          = new PieceData[_count];
        _colors        = new Vector4[_count];

        for (int i = 0; i < _count; i++)
        {
            _matrices[i] = Matrix4x4.identity;
            _data[i]     = new PieceData();//
            _data[i].rot = Quaternion.Euler(
                360f * Random.value,
                360f * Random.value,
                360f * Random.value
                );
            _data[i].scale = new Vector3(
                0.1f, 0.2f + 5.0f * Random.value, 0.1f
                );
            _colors[i] = new Vector4(
                Random.value,
                Random.value * 0.8f,
                Random.value * 0.4f,
                1f
                );
        }

        //SetScale();
    }
Beispiel #7
0
    private void createPieces(PieceData type)
    {
        GameObject piece  = Instantiate(piecePrefab, container.transform);
        PieceInfo  script = piece.GetComponent <PieceInfo>();

        script.SetValues(type);
        pieces.Add(piece);
    }
Beispiel #8
0
        public void testConstructorPieceData_OK()
        {
            PieceData myPlayer = new PieceData(22, 1, 1);

            Assert.AreEqual(myPlayer.jugador, 1);
            Assert.AreEqual(myPlayer.posicionEnMano, 1);
            Assert.AreEqual(myPlayer.valor, 22);
        }
Beispiel #9
0
 /// <summary>
 /// Takes a piece owned by an opposing player.
 /// </summary>
 /// <param name="piece"></param>
 public void TakePiece(PieceData piece)
 {
     // Can only take pieces owned by other players
     if (piece.colour != colour && piece.type == PieceData.Type.Normal)
     {
         takenPieces.Add(piece);
     }
 }
Beispiel #10
0
        public void PromoteTo(int pos, EPieceType piece)
        {
            EChessTeam color = GetColorFromPos(pos);
            PieceData  data  = GetPieceFromPos(pos, color);

            SetBitValue(EPieceTypeToBitBoardIndex(data.piece, color), pos, false);
            SetBitValue(EPieceTypeToBitBoardIndex(piece, color), pos, true);
        }
        public GameObject Create(PieceData pieceData)
        {
            GameObject gridItemObject = Create();

            ConstructPiece(pieceData, gridItemObject);

            return(gridItemObject);
        }
Beispiel #12
0
        public void Construct(PieceData pieceData)
        {
            this.pieceData = pieceData;
            text.text      = pieceData.Text;
            GridItemMover gridItemMover = GetComponent <GridItemMover>();

            gridItemMover.SetupRownAndColumn(pieceData.PlaceInGrid, 0, 0);
        }
Beispiel #13
0
 public static Inventory.IItem FromDataToInventory(PieceData data)
 {
     return(new InventoryPiece()
     {
         piece = ReadData(data),
         quantity = data.Quantity
     });
 }
Beispiel #14
0
    void SetUpGameFromData()
    {
        UIViewController.DeactivateUIView("MainView");
        UIViewController.DeactivateUIView("ResultsView");

        if (!_bgAssets)
        {
            _bgAssets = true;
            for (int i = 0; i < BGSprites.Count; i++)
            {
                BGSprites[i].enabled = true;
            }
        }

        ClearAllObjects();
        if (_redTeam != null)
        {
            _redTeam.Reset();
        }
        if (_blueTeam != null)
        {
            _blueTeam.Reset();
        }

        CreateFlags();

        // create teams
        List <Piece> redPieces = new List <Piece>();

        _redTeam = new Team(TeamColor.RED, null, _redFlag.Position);
        List <Piece> bluePieces = new List <Piece>();

        _blueTeam = new Team(TeamColor.BLUE, null, _blueFlag.Position);
        List <Piece> currentPieceList;
        Team         team;

        for (int i = 0; i < OnlineManager.Instance.GameData.pieces.Count; i++)
        {
            PieceData pieceData = OnlineManager.Instance.GameData.pieces[i];
            if (pieceData.team_name == "red")
            {
                team             = _redTeam;
                currentPieceList = redPieces;
            }
            else
            {
                team             = _blueTeam;
                currentPieceList = bluePieces;
            }
            CreatePiece(currentPieceList, pieceData);
        }

        _redTeam.Pieces = redPieces;
        _redTeam.SetPieceLookups();
        _blueTeam.Pieces = bluePieces;
        _blueTeam.SetPieceLookups();
        _startTime = DateTime.UtcNow;
    }
        public void PieceIsCorrectlyRetrieved()
        {
            List <PieceData> pieceDataList = CreatePieceDataList(3);
            PieceDataSorter  pieceSorter   = CreatePieceDataSorter(pieceDataList);

            PieceData pieceData = pieceSorter.GetRandomPieceData();

            Assert.IsNotNull(pieceData);
        }
Beispiel #16
0
        void Load()
        {
            int count = (int)TutorialPiece.None;

            for (int i = 0; i < count; i++)
            {
                m_Pieces[(TutorialPiece)i] = new PieceData();
            }
        }
        public void EachTimeDataIsRetrievedItIsRemovedFromList()
        {
            List <PieceData> pieceDataList = CreatePieceDataList(3);
            PieceDataSorter  pieceSorter   = CreatePieceDataSorter(pieceDataList);

            PieceData retrievedPieceData = pieceSorter.GetRandomPieceData();

            Assert.IsFalse(pieceDataList.Contains(retrievedPieceData));
        }
Beispiel #18
0
    private void GeneratePieceMesh(PieceData p)
    {
        //use HashSet to prevent double vertices
        HashSet <Vector2> vertices2DSet         = new HashSet <Vector2>();
        HashSet <Vector2> vertices2DColliderSet = new HashSet <Vector2>();

        foreach (Neighbour n in p.neighbours)
        {
            //if this 'neighbour' is the boundary, set edgeType to straight
            if (n.id == -1)
            {
                n.edgeType = PEdge.EdgeType.Straight;
            }

            //else if the edgeType wasn't set to something yet, set it here
            //and also set the corresponding neighbours edgeType to the opposite type
            else if (n.edgeType == PEdge.EdgeType.Nothing)
            {
                PieceData neighbourPiece = GetPieceData(n.id);
                Neighbour meAsNeighbour  = neighbourPiece.GetNeigbourWithID(p.id);

                if (randomBool(p.id))
                {
                    n.edgeType             = PEdge.EdgeType.Shaped;
                    meAsNeighbour.edgeType = PEdge.EdgeType.ShapedInverse;
                }
                else
                {
                    n.edgeType             = PEdge.EdgeType.ShapedInverse;
                    meAsNeighbour.edgeType = PEdge.EdgeType.Shaped;
                }
            }

            PEdge edge          = new PEdge(p.baseVertices[n.v1], p.baseVertices[n.v2], n.edgeType, meshDetail);
            PEdge edgeLowDetail = new PEdge(p.baseVertices[n.v1], p.baseVertices[n.v2], n.edgeType, colliderDetail);

            edge.points.ForEach(point => vertices2DSet.Add(point));
            edgeLowDetail.points.ForEach(point => vertices2DColliderSet.Add(point));
        }

        List <Vector2> vertices2D         = vertices2DSet.ToList();
        List <Vector2> vertices2DCollider = vertices2DColliderSet.ToList();

        //create final visual mesh
        Triangulator triangulator = new Triangulator(vertices2D);

        int[]     triangles = triangulator.Triangulate();
        Vector3[] vertices  = vertices2D.ConvertAll(v2 => new Vector3(v2.x, v2.y, 0f)).ToArray();
        p.mesh = MeshFunctions.ExtrudeFlatPiece(vertices, triangles, thickness);
        ProjectUV(p.mesh, p.position);

        //create final collider mesh
        triangulator = new Triangulator(vertices2DCollider);
        int[]     colliderTriangles = triangulator.Triangulate();
        Vector3[] colliderVertices  = vertices2DCollider.ConvertAll(v2 => new Vector3(v2.x, v2.y, 0f)).ToArray();
        p.colliderMesh = MeshFunctions.ExtrudeFlatPieceNoSplit(colliderVertices, colliderTriangles, thickness);
    }
Beispiel #19
0
 /// <summary>
 /// Setter for the pieceData.
 /// </summary>
 /// <param name="pieceDataToSet"> The pieceData to override the current data. </param>
 public void SetPieceData(PieceData pieceDataToSet)
 {
     pieceData.playerIdx         = pieceDataToSet.playerIdx;
     pieceData.currentIndex      = pieceDataToSet.currentIndex;
     pieceData.madeFirstMove     = pieceDataToSet.madeFirstMove;
     pieceData.isKing            = pieceDataToSet.isKing;
     pieceData.isDead            = pieceDataToSet.isDead;
     pieceData.hasPostPlayAction = pieceDataToSet.hasPostPlayAction;
 }
Beispiel #20
0
    /// <summary>
    /// Searchs the reverse hook moves.
    /// </summary>
    /// <param name="piece">Piece.</param>
    /// <param name="moves">Moves.</param>
    private void SearchReverseHookMoves(PieceData piece, MoveSet moves)
    {
        TileNode cur    = node.adjacent[hook.direction];
        TileNode hooked = node.adjacent[hook.direction];

        #region reverse hook condition
        // can't revese hook your own pieces
        if (piece.colour == owningColour)
        {
            return;
        }

        // must have tower of 6 to hook
        if (pieces.Count != 6)
        {
            return;
        }

        // check if able to move on the given tile
        if (!CheckCurrentTileMove(cur))
        {
            return;
        }

        // Can't jump or move along the way
        if (cur.type == TileNode.Type.Way && cur.adjacent[piece.direction] != node)
        {
            return;
        }

        #endregion

        // add hook'd
        //moves.AddMove(node, false, hooked);

        #region move search
        // extend out by the range and search for more.
        for (int r = 0; r < piece.range; r++)
        {
            // move to next tile
            cur = cur.adjacent[piece.direction];

            // check if current tile is one you can move to
            if (CheckCurrentTileMove(cur))
            {
                moves.AddMove(node, true, hooked, cur);
            }

            // check if any more moves can be made after (not including range)
            if (!CheckFurtherMovement(cur))
            {
                break;
            }
        }
        #endregion
    }
Beispiel #21
0
    /// <summary>
    /// 补充队列
    /// </summary>
    void FillNextPiece()
    {
        FillNextBag();
        this.nextPieces.Enqueue(nextBag.Dequeue());

        this.selectedPrefab = piecePrefabs[this.nextPieces.Peek()];
        this.selectedData   = pieceDatas[this.nextPieces.Peek()];

        UpdatePreview();
    }
Beispiel #22
0
    void createPiecePrototypes()
    {
        moveNameMap     = new Dictionary <string, Move> ();
        moves           = new List <Move> ();
        piecePrefabs    = new Dictionary <string, GameObject> ();
        piecePrototypes = new Dictionary <string, Piece> ();

        MoveData.loadMoveData();
        PieceData.loadPieceData();
    }
Beispiel #23
0
 public void SetValues(PieceData data)
 {
     render        = this.GetComponent <SpriteRenderer>();
     color         = data.color;
     type          = data.type;
     isActive      = data.isActive;
     moved         = data.moved;
     value         = data.value;
     render.sprite = data.skin;
 }
Beispiel #24
0
 /// <summary>
 /// Constructor for a new tower
 /// </summary>
 /// <param name="owner"></param>
 /// <param name="startingPiece"></param>
 /// <param name="startNode"></param>
 public PieceTower(Player owner, PieceData startingPiece, TileNode startNode)
 {
     pieces       = new List <PieceData>(6);
     owningColour = owner.colour;
     owningPlayer = owner;
     AddPiece(startingPiece);
     node = startNode;
     MoveTo(startNode);
     startingPiece.SetupTextures();
 }
        public void EachPieceDataTakenIsDifferent()
        {
            List <PieceData> pieceDataList = CreatePieceDataList(3);
            PieceDataSorter  pieceSorter   = CreatePieceDataSorter(pieceDataList);

            PieceData firstPieceData  = pieceSorter.GetRandomPieceData();
            PieceData secondPieceData = pieceSorter.GetRandomPieceData();

            Assert.AreNotEqual(firstPieceData, secondPieceData);
        }
Beispiel #26
0
        public void PutPiece(PieceData pieza)
        {
            int StartPieceInt  = pieza.valor;
            int PiecePosition  = pieza.posicionEnMano;
            int PlayerPosition = pieza.jugador;

            HidePieceInHand(PiecePosition, PlayerPosition);
            ShowPieceInTable(StartPieceInt);
            DecrementPlayerAvailablepPieces(PlayerPosition);
        }
Beispiel #27
0
 private void Awake()
 {
     if (_instance != null && _instance != this)
     {
         Destroy(this.gameObject);
     }
     else
     {
         _instance = this;
     }
 }
Beispiel #28
0
    private IEnumerator Spawn()
    {
        //TODO: Play spawn VFX/particles
        yield return(spawnDelay);

        var currentPieceData = NextPieceData;
        var pieceController  = Instantiate(currentPieceData.prefab, spawnPosition, Quaternion.identity).GetComponent <PieceController>();

        ActivePieces.AddNewPiece(pieceController);
        NextPieceData = GetRandomData();
    }
Beispiel #29
0
        public void ShowPiece(PieceData pieza, int myPosition)
        {
            int PieceValue     = pieza.valor;
            int PiecePosition  = pieza.posicionEnMano;
            int PlayerPosition = pieza.jugador;

            //Se muestra al jugador una pieza que se encuentra en su poder
            PaintPiece(PieceValue, PiecePosition, PlayerPosition, myPosition);
            // Se actualiza el valor de las piezas de las que dispone el jugador
            UpdatePlayerAvailablesPiecesInformacion(PlayerPosition);
        }
Beispiel #30
0
        /// <summary>
        /// CALLBACK METHODS
        /// se encarga de enviar al jugador de la mesa
        /// un objeto que contiene los datos de la pieza de domino
        /// del jugador.
        /// </summary>
        public void ShowPiece(PieceData piece)
        {
            /// <summary>
            ///Se muestra al jugador una pieza que se encuentra en su poder
            /// </summary>
            domino.PaintPieceInPlayerHand(piece.PieceValue, piece.PiecePosition, piece.PlayerPosition);

            /// <summary>
            /// Se actualiza el valor de las piezas de las que dispone el jugador
            /// </summary>
            domino.IncrementPlayerAvailablePieces(piece.PlayerPosition);
        }
Beispiel #31
0
 void Load()
 {
     int count = (int)TutorialPiece.None;
     for (int i = 0; i < count; i++)
     {
         m_Pieces[(TutorialPiece)i] = new PieceData();
     }
 }