Ejemplo n.º 1
0
 public void Aquire(AdvancementSquare advSq)     // Advancement square now covers cell - display proper color & tint.
 {
     Debug.Log("Cell.Aquire() - add to list and display proper color & tint.");
     advSqs.Add(advSq);
     ColorAndTint();
     Debug.Log("Number of AdvSqs = " + advSqs.Count);
 }
Ejemplo n.º 2
0
 public void Divest(AdvancementSquare advSq) // Advancement square no longer covers cell - display last color & tint.
 {
     Debug.Log("Cell.Divest() - extract from list and display last color & tint.");
     advSqs.Remove(advSq);         // TODO: Trap for error - advSq not in list.
     ColorAndTint();
     Debug.Log("Number of AdvSqs = " + advSqs.Count);
 }
Ejemplo n.º 3
0
    // Partial public interface for highlighting rook advancement squares:
    public IEnumerator ClearAdvSqByPerimeter(AdvancementSquare advSq)
    {
        UnHighlightSquare(advSq.dstSquare);
        for (int perimeter = advSq.perimeters.Count - 1; perimeter >= 0; perimeter--)
        {
            if (debug)
            {
                print("^^^ Coroutine: clear perimeter " + (perimeter + 1));
            }

            for (int i = 0; i < advSq.perimeters[perimeter].Length; i++)
            {
                Vector3Int sq = advSq.perimeters[perimeter][i];

                // Skip squares off the board.
                if (IsOffBoard(sq, chessBoard.size))
                {
                    continue;
                }

                UnHighlightSquare(sq);
            }

            yield return(new WaitForSeconds(0.1f));            // TODO: put advSqByPerimeter speed under player control.
        }
    }
Ejemplo n.º 4
0
    // Called by HighLightSquareByGrid.SetSrcDstSquares().
    public bool AdvSq(Vector3Int srcSquare, Vector3Int dstSquare)
    {
        bool validAdvSq = true;

        this.srcSquare = srcSquare;
        this.dstSquare = dstSquare;
        print("AdvSq: " + srcSquare + " / " + dstSquare);
        perimeter = 0;

        bool sameX = srcSquare.x == dstSquare.x;
        bool sameY = srcSquare.y == dstSquare.y;
        bool sameZ = srcSquare.z == dstSquare.z;

        if ((sameX && sameY) || (sameX && sameZ) || (sameY && sameZ))
        {
            print("Linear rook move.");
            if (sameX && sameY)
            {
                print("Rook vertical linear move, Z varies.");
            }
            else if (sameX && sameZ)
            {
                print("Rook horizontal linear move, Y varies.");
            }
            else if (sameY && sameZ)
            {
                print("Rook horizontal linear move, X varies.");
            }
            //print("Number of perimeters = " + advSq.Perims);
        }
        else if (sameX || sameY || sameZ)
        {
            print("Quadrant rook move.");
            if (sameZ)
            {
                advSq = new RookAdvSqQuad("Horizontal", srcSquare, dstSquare);
                print("Rook Horizontal plane, advancement square number of perimeters = " + advSq.Perims);
            }
            else if (sameX)
            {
                advSq = new RookAdvSqQuad("RightVertical", srcSquare, dstSquare);
                print("Rook RightVertical plane, advancement square number of perimeters = " + advSq.Perims);
            }
            else if (sameY)
            {
                advSq = new RookAdvSqQuad("LeftVertical", srcSquare, dstSquare);
                print("Rook LeftVertical plane, advancement square number of perimeters = " + advSq.Perims);
            }
            doneShowing = false;
        }
        else
        {
            print("Not in a rook plane.");
            validAdvSq = false;
        }

        return(validAdvSq);
    }
Ejemplo n.º 5
0
    public IEnumerator ShowAdvSqByPerimeter(AdvancementSquare advSq)
    {
        for (int perimeter = 0; perimeter <= advSq.perimeters.Count; perimeter++)
        {
            if (debug)
            {
                print("^^^ Coroutine: show perimeter " + (perimeter + 1));
            }

            int prevPerimeter = perimeter - 1;
            int currPerimeter = perimeter;

            // Flatten ripple tilt of previous perimeter.
            if (perimeter > 0)
            {
                for (int i = 0; i < advSq.perimeters[prevPerimeter].Length; i++)
                {
                    Vector3Int sq = advSq.perimeters[prevPerimeter][i];

                    // Skip squares off the board.
                    if (IsOffBoard(sq, chessBoard.size))
                    {
                        continue;
                    }
                    chessBoard.cells[sq.x, sq.y, sq.z].square.transform.rotation = new Quaternion(0f, 0.0f, 0.0f, 0.0f);                     // Flatten.
                }
            }

            // Highlight and ripple tilt current perimeter.
            if (perimeter < advSq.perimeters.Count)
            {
                float xPos = (dstSquare.x > srcSquare.x) ? 0.1f : -0.1f;
                float yPos = (dstSquare.y > srcSquare.y) ? 0.1f : -0.1f;

                for (int i = 0; i < advSq.perimeters[currPerimeter].Length; i++)
                {
                    Vector3Int sq = advSq.perimeters[currPerimeter][i];

                    // Skip squares off the board.
                    if (IsOffBoard(sq, chessBoard.size))
                    {
                        continue;
                    }
                    chessBoard.cells[sq.x, sq.y, sq.z].square.transform.rotation = new Quaternion(4.0f, yPos, 0.0f, xPos);                     // Rotate.

                    HighlightSquare(sq.x, sq.y, sq.z, DetCellToSrc(srcSquare, sq, rookColor));
                }
            }

            yield return(new WaitForSeconds(0.2f));            // TODO: put advSqByPerimeter speed under player control.
        }
    }
Ejemplo n.º 6
0
    private void ColorAndTint()
    {
        if (advSqs.Count > 0)
        {
            int lastIndex           = advSqs.Count - 1;
            AdvancementSquare advSq = advSqs[lastIndex];

            // TODO: Determine plane type (Rook, Bishop, Duke).
            // TODO: Determine square type (black, white).
            // TODO: Find cell in perimeter, determine whether point, line, or quad.
            // TODO: Color and tint appropriately.
        }
        else
        {
            // TODO: Restore color to originalColor (white/black).
        }
    }
Ejemplo n.º 7
0
    AdvancementSquare CreateAdvSq(Vector3Int srcSq, Vector3Int dstSq)
    {
        AdvancementSquare        advSq  = null;
        List <AdvancementSquare> advSqs = new List <AdvancementSquare>();

        string plane = planesSelection.selectedPlane.text;

        if (planesSelection.rookPlanes.Contains(plane))
        {
            if ((advSq = highlightRookPlanes.AdvSq(srcSq, dstSq)) != null)
            {
                List <AdvancementSquare> testAdvSqs = new List <AdvancementSquare>();
                testAdvSqs.Add(advSq);
                testAdvSqs.Add(advSq);
                advSqs.AddRange(testAdvSqs);
            }
        }

        return(advSq);
    }
Ejemplo n.º 8
0
    void SetSrcDstSquares()     // Src/dst looks correct, complete & concise 9/28/19, but advSqs are wip.
    {
        Color srcColor = Color.yellow;
        Color dstColor = Color.magenta;

        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);  // From camera to mouse.
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))           // Ray hit a GameObject (square, piece, etc.).
        {
            Vector3Int raycastSquare = FindRaycastSquare(hit);

            // Click marks source square.
            if (Input.GetMouseButtonUp(1))
            {
                if (srcSquare == nullSquare)                                // Fresh srcSq.
                {
                    if (dstSquare == raycastSquare)                         // Overrides dstSq.
                    {
                        dstSquare = Unhighlight(raycastSquare);
                        print("Overrides dstSq.");
                    }
                    srcSquare = Highlight(raycastSquare, srcColor);
                    if (dstSquare != nullSquare)
                    {
                        print("Show new advSq.");
                    }
                    lastAdvSqLocked = false;
                }
                else if (raycastSquare == srcSquare)                        // Toggle srcSq.
                {
                    srcSquare = Unhighlight(srcSquare);
                    if (dstSquare != nullSquare)
                    {
                        print("Revert last advSq.");
                    }
                }
                else                                                        // Move srcSq.
                {
                    srcSquare = Unhighlight(srcSquare);
                    if (dstSquare == raycastSquare)                             // Lock advSq (srcSq ontop of dstSq).
                    {
                        print("Lock last advSq.");
                        lastAdvSqLocked = true;
                    }
                    else
                    {
                        srcSquare = Highlight(raycastSquare, srcColor);
                        if (dstSquare != nullSquare)
                        {
                            // Mock code until can return a new advancement square:
                            AdvancementSquare first  = new AdvancementSquare();
                            AdvancementSquare second = new AdvancementSquare();

                            // Mock code, is only returning 'Different':
                            MetaSet metaSet = AdvancementSquare.AreAdSqsMetaSet(first, second);
                            if (metaSet == MetaSet.SubSet || metaSet == MetaSet.SuperSet || metaSet == MetaSet.ShiftSet)
                            {
                                print("Resize or shift advSq");
                            }
                            else if (metaSet == MetaSet.Null)
                            {
                                if (!lastAdvSqLocked)
                                {
                                    print("Clear last advSq.");
                                }
                            }
                            else if (metaSet == MetaSet.Different)
                            {
                                if (!lastAdvSqLocked)
                                {
                                    print("Clear last advSq.");
                                }
                                print("Show next advSq.");
                                lastAdvSqLocked = false;
                            }
                            else if (metaSet == MetaSet.Identical)
                            {
                                print("Identical should never happen - Do nothing.");
                            }
                        }
                    }
                }
            }

            // Click marks destination square.
            if (Input.GetMouseButtonUp(0))
            {
                if (dstSquare == nullSquare)                                // Fresh dstSq.
                {
                    if (srcSquare == raycastSquare)                         // Overrides srcSq.
                    {
                        srcSquare = Unhighlight(srcSquare);
                        print("Overrides srcSq.");
                    }
                    dstSquare = Highlight(raycastSquare, dstColor);
                    if (srcSquare != nullSquare)
                    {
                        print("Show new advSq.");
                        AdvancementSquare advSq = CreateAdvSq(srcSquare, dstSquare);
                        if (advSq != null)
                        {
                            advSqs.Add(advSq);
                            StartCoroutine(highlightRookPlanes.ShowAdvSqByPerimeter(advSq));
                        }
                        print("  Size of advSqs = " + advSqs.Count);
                    }
                    lastAdvSqLocked = false;
                }
                else if (raycastSquare == dstSquare)                            // Toggle dstSq.
                {
                    dstSquare = Unhighlight(dstSquare);
                    if (srcSquare != nullSquare)
                    {
                        print("Revert last advSq.");
                        int prevAdvSqIndex = advSqs.Count - 1;
                        StartCoroutine(highlightRookPlanes.ClearAdvSqByPerimeter(advSqs[prevAdvSqIndex]));
                        advSqs.RemoveAt(prevAdvSqIndex);
                    }
                }
                else                                                                                            // Move dstSq.
                {
                    Unhighlight(dstSquare);
                    if (srcSquare == raycastSquare)                                     // Lock advSq (dstSq ontop of srcSq).
                    {
                        print("Lock last advSq.");
                        bool line = false;
                        highlightRookPlanes.HighlightSquare(dstSquare, line);
                        dstSquare       = nullSquare;
                        lastAdvSqLocked = true;
                    }
                    else
                    {
                        dstSquare = Highlight(raycastSquare, dstColor);
                        if (srcSquare != nullSquare)
                        {
                            // Mock code until can return a new advancement square:
                            AdvancementSquare first  = new AdvancementSquare();
                            AdvancementSquare second = new AdvancementSquare();

                            // Mock code, is only returning 'Different':
                            MetaSet metaSet = AdvancementSquare.AreAdSqsMetaSet(first, second);
                            if (metaSet == MetaSet.SubSet || metaSet == MetaSet.SuperSet)
                            {
                                print("Resize advSq (extend or contract perimeters).");
                            }
                            else if (metaSet == MetaSet.Null)
                            {
                                if (!lastAdvSqLocked)
                                {
                                    print("Clear last advSq.");
                                }
                            }
                            else if (metaSet == MetaSet.Different)
                            {
                                int prevAdvSqIndex       = advSqs.Count - 1;
                                AdvancementSquare advSq1 = advSqs[prevAdvSqIndex];
                                AdvancementSquare advSq2 = CreateAdvSq(srcSquare, dstSquare);
                                if (advSq2 != null)
                                {
                                    advSqs.Add(advSq2);
                                }
                                if (lastAdvSqLocked)
                                {
                                    print("Show next advSq.");
                                    StartCoroutine(highlightRookPlanes.ShowAdvSqByPerimeter(advSq2));
                                }
                                else
                                {
                                    print("Clear previous advSq and show next advSq.");
                                    StartCoroutine(highlightRookPlanes.ClearShowAdvSqsByPerimeter(advSq1, advSq2));
                                    advSqs.RemoveAt(prevAdvSqIndex);
                                    lastAdvSqLocked = false;
                                }
                            }
                            else if (metaSet == MetaSet.Identical)
                            {
                                print("Do nothing.");
                            }
                        }
                    }
                }
            }
        }
        else           // Clear src & dst squares off the board.
        {
            if (Input.GetMouseButtonUp(1))
            {
                if (srcSquare != nullSquare)
                {
                    srcSquare = Unhighlight(srcSquare);
                    print("Lock last advSq.");
                    lastAdvSqLocked = true;
                }
                if (srcSquare == nullSquare && dstSquare == nullSquare)
                {
                    print("--- Clear all advancement squares off the board.");
                    StartCoroutine(ClearAllAdvSqsInReverseOrder());
                }
            }
            if (Input.GetMouseButtonUp(0))
            {
                if (dstSquare != nullSquare)
                {
                    dstSquare = Unhighlight(dstSquare);
                    print("Lock last advSq.");
                    lastAdvSqLocked = true;
                }
                if (srcSquare == nullSquare && dstSquare == nullSquare)
                {
                    print("--- Clear all advancement squares off the board.");
                }
            }
        }
    }
Ejemplo n.º 9
0
 static public MetaSet AreAdSqsMetaSet(AdvancementSquare first, AdvancementSquare second)
 {
     return(MetaSet.Different);
 }
Ejemplo n.º 10
0
    // Called by HighLightSquareByGrid.SetSrcDstSquares().
    // TODO: Change to return List<>.
    public AdvancementSquare AdvSq(Vector3Int srcSquare, Vector3Int dstSquare)
    {
        List <AdvancementSquare> advSqs = new List <AdvancementSquare>();

        this.srcSquare = srcSquare;
        this.dstSquare = dstSquare;
        print("AdvSq: " + srcSquare + " / " + dstSquare);

        bool sameX = srcSquare.x == dstSquare.x;
        bool sameY = srcSquare.y == dstSquare.y;
        bool sameZ = srcSquare.z == dstSquare.z;

        if ((sameX && sameY) || (sameX && sameZ) || (sameY && sameZ))
        {
            print("Linear rook move.");
            AdvancementSquare advSqR1;
            AdvancementSquare advSqR2 = null;
            if (sameX && sameY)
            {
                advSqR1 = new RookAdvSqRect("RightVertical", srcSquare, dstSquare);
                print("Rook right vertical linear move, Y varies; number of perimeters = " + advSqR1.Perims);
                //advSqR2 = new RookAdvSqRect("LeftVertical", srcSquare, dstSquare);
                //print("Rook left vertical linear move, Z varies; number of perimeters = " + advSqR2.Perims);
            }
            else if (sameX && sameZ)
            {
                advSqR1 = new RookAdvSqRect("Horizontal", srcSquare, dstSquare);
                print("Rook horizontal linear move, Y varies; number of perimeters = " + advSqR1.Perims);
                //advSqR2 = new RookAdvSqRect("RightVertical", srcSquare, dstSquare);
                //print("Rook right vertical linear move, Y varies; number of perimeters = " + advSqR2.Perims);
            }
            else if (sameY && sameZ)
            {
                advSqR1 = new RookAdvSqRect("LeftVertical", srcSquare, dstSquare);
                print("Rook left vertical linear move, X varies; number of perimeters = " + advSqR1.Perims);
                //advSqR2 = new RookAdvSqRect("Horizontal", srcSquare, dstSquare);
                //print("Rook horizontal linear move, X varies; number of perimeters = " + advSqR2.Perims);
            }
            else
            {
                advSqR1 = null;
                advSqR2 = null;
            }
            if (advSqR1 != null)
            {
                advSqs.Add(advSqR1);
            }
            if (advSqR2 != null)
            {
                advSqs.Add(advSqR2);
            }
            return(advSqR1);
        }
        else if (sameX || sameY || sameZ)
        {
            print("Quadrant rook move.");
            AdvancementSquare advSq;
            if (sameZ)
            {
                advSq = new RookAdvSqQuad("Horizontal", srcSquare, dstSquare);
                print("Rook Horizontal plane, advancement square number of perimeters = " + advSq.Perims);
            }
            else if (sameX)
            {
                advSq = new RookAdvSqQuad("RightVertical", srcSquare, dstSquare);
                print("Rook RightVertical plane, advancement square number of perimeters = " + advSq.Perims);
            }
            else if (sameY)
            {
                advSq = new RookAdvSqQuad("LeftVertical", srcSquare, dstSquare);
                print("Rook LeftVertical plane, advancement square number of perimeters = " + advSq.Perims);
            }
            else
            {
                advSq = null;
            }
            if (advSq != null)
            {
                advSqs.Add(advSq);
            }
            return(advSq);
        }
        else
        {
            print("Not in a rook plane.");
            //validAdvSq = false;
            return(null);
        }
    }