예제 #1
0
        private int GetOverlayBoundaryPos(int overlaySize, int boundarySize)
        {
            PlacementDirection placementDirection = Trigger.Placement.GetDirection();

            if (placementDirection.IsIn(PlacementDirection.Top, PlacementDirection.Left))
            {
                return(0);
            }
            else
            {
                return(boundarySize - overlaySize);
            }
        }
예제 #2
0
        private int GetOverlayPosWithSize(int overlayPos, int overlaySize)
        {
            PlacementDirection placementDirection = Trigger.Placement.GetDirection();

            if (placementDirection.IsIn(PlacementDirection.Top, PlacementDirection.Left))
            {
                return(overlayPos - overlaySize);
            }
            else
            {
                return(overlayPos + overlaySize);
            }
        }
예제 #3
0
    Vector3 NextFormPos()
    {
        //making Sure Old Pos Exists and is parented correctly
        if (!oldPos)
        {
            oldPos                = new GameObject("oldPos " + gameObject.name).transform;
            oldPos.parent         = moveTarget;
            oldPos.localPosition  = Vector3.zero;
            oldPos.localPosition -= new Vector3(0, 0, distanceBetweenPoints.y);
            count = 0;
            return(oldPos.position);
        }
        else if (oldPos.parent != moveTarget)
        {
            oldPos.parent         = moveTarget;
            oldPos.localPosition  = Vector3.zero;
            oldPos.localPosition -= new Vector3(0, 0, distanceBetweenPoints.y);
            count = 0;
            return(oldPos.position);
        }


        if (count < maxNumOfColumns / 2)
        {
            count++;
            oldPos.localPosition += (pd == PlacementDirection.right) ? new Vector3(distanceBetweenPoints.x, 0, 0) : new Vector3(-distanceBetweenPoints.x, 0, 0);
        }
        else
        {
            count = 0;
            if (pd == PlacementDirection.left)
            {
                oldPos.localPosition -= new Vector3(0, 0, distanceBetweenPoints.y);
            }


            pd = (pd == PlacementDirection.right) ? PlacementDirection.left : PlacementDirection.right;
            oldPos.localPosition = (pd == PlacementDirection.right) ? new Vector3(0, 0, oldPos.localPosition.z) : new Vector3(-distanceBetweenPoints.x, 0, oldPos.localPosition.z);
        }

        return(oldPos.position);
    }
예제 #4
0
 public Game(Stream stdOut, SafeFileHandle h, int width, int height)
 {
     this.stdOut        = stdOut;
     this.h             = h;
     this.width         = width;
     this.height        = height;
     buf                = new byte[width * height];
     bufField           = new CharInfo[width * height];
     playfieldHeight    = 20;
     playfieldWidth     = 20;
     gridSize           = 2;
     displayfieldWidth  = playfieldHeight * gridSize;
     displayfieldHeight = playfieldHeight * gridSize;
     downCount          = 0; // test variable
     showLowerMessage   = true;
     lowerMessage       = "";
     currentPlayer      = 0;
     selectionState     = SelectionState.Initialization;
     placementDirection = PlacementDirection.Right;
 }
예제 #5
0
        public void WriteToBuffer()
        {
            int[] index = new int[4];
            for (int y = 0; y < playfieldHeight; y++)    // 20 = playfield height
            {
                for (int x = 0; x < playfieldWidth; x++) // 20 = playfield width
                {
                    index = ReturnIndexSquare(x, y);
                    AssignColor(index, 0x0001);
                }
            }

            for (int y = 0; y < playfieldHeight; y++)    // 20 = playfield height
            {
                for (int x = 0; x < playfieldWidth; x++) // 20 = playfield width
                {
                    switch (selectionState)
                    {
                    case SelectionState.PlayerOneSelection:
                        selectedIndex = highlightedIndex;
                        index         = ReturnIndexSquare(x, y);
                        if (index[0] == selectedIndex)
                        {
                            AssignColor(index, 0x0004);
                            switch (placementDirection)
                            {
                            case PlacementDirection.Right:
                            {
                                if (CheckIfRightPlacementValid(shipBeingPlace.length))
                                {
                                    for (int i = 1; i < shipBeingPlace.length; i++)
                                    {
                                        index = ReturnIndexSquare(x + i, y);
                                        AssignColor(index, 0x004);
                                    }
                                }
                                else
                                {
                                    placementDirection = PlacementDirection.Down;
                                }

                                break;
                            }

                            case PlacementDirection.Down:
                            {
                                if (CheckIfDownPlacementValid(shipBeingPlace.length))
                                {
                                    for (int i = 1; i < shipBeingPlace.length; i++)
                                    {
                                        index = ReturnIndexSquare(x, y + i);
                                        AssignColor(index, 0x004);
                                    }
                                }
                                else
                                {
                                    placementDirection = PlacementDirection.Left;
                                }

                                break;
                            }

                            case PlacementDirection.Left:
                            {
                                if (CheckIfLeftPlacementValid(shipBeingPlace.length))
                                {
                                    for (int i = 1; i < shipBeingPlace.length; i++)
                                    {
                                        index = ReturnIndexSquare(x - i, y);
                                        AssignColor(index, 0x004);
                                    }
                                }
                                else
                                {
                                    placementDirection = PlacementDirection.Up;
                                }

                                break;
                            }

                            case PlacementDirection.Up:
                            {
                                if (CheckIfUpPlacementValid(shipBeingPlace.length))
                                {
                                    for (int i = 1; i < shipBeingPlace.length; i++)
                                    {
                                        index = ReturnIndexSquare(x, y - i);
                                        AssignColor(index, 0x004);
                                    }
                                }
                                else
                                {
                                    placementDirection = PlacementDirection.Right;
                                }

                                break;
                            }
                            }
                        }

                        break;

                        break;

                    case SelectionState.PlayerTwoSelection:

                        break;

                    case SelectionState.PlayerOneTurn:
                    case SelectionState.PlayerTwoTurn:

                        index = ReturnIndexSquare(x, y);
                        if (index[0] == highlightedIndex)
                        {
                            AssignColor(index, 0x0002);      // Make selection green.
                        }
                        else
                        {
                            AssignColor(index, 0x0001);     // Make non-selected blue
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }
예제 #6
0
        private void ReadPlayerInput(ConsoleKey readKey)
        {
            downCount++;
            // Remove top padding and left padding to get index of 0,0 to calculate other x,y values.
            int selectionZeroed = ((topPad * width) + leftPad);
            int displayX        = (highlightedIndex % width) - leftPad;
            int displayY        = ((highlightedIndex - selectionZeroed) / (width)) % width;
            int playfieldX      = displayX / 2;
            int playfieldY      = displayY / 2;

            if (readKey == ConsoleKey.RightArrow)
            {
                if (playfieldX == 19)
                {
                    highlightedIndex -= (playfieldWidth * 2) - 2;
                }
                else
                {
                    highlightedIndex += 2;;
                }
            }
            else if (readKey == ConsoleKey.LeftArrow)
            {
                if (playfieldX == 0)
                {
                    highlightedIndex += (playfieldWidth * 2) - 2;
                }
                else
                {
                    highlightedIndex -= 2;
                }
            }
            else if (readKey == ConsoleKey.DownArrow)
            {
                if (playfieldY == 19)
                {
                    highlightedIndex = selectionZeroed + displayX;
                }
                else
                {
                    highlightedIndex += 2 * width;
                }
            }
            else if (readKey == ConsoleKey.UpArrow)
            {
                if (playfieldY == 0)
                {
                    highlightedIndex = highlightedIndex + ((displayfieldHeight) - 2) * width;
                }
                else
                {
                    highlightedIndex -= 2 * width;;
                }
            }
            else if (readKey == ConsoleKey.Enter)
            {
                switch (selectionState)
                {
                case SelectionState.PlayerOneSelection:
                    PlayerOneSelectLocations(new int[] { playfieldX, playfieldY });
                    break;

                default:
                    break;
                }
            }
            else if (readKey == ConsoleKey.Spacebar)
            {
                showLowerMessage = false;
                RemoveRighthandMessage();
                isChangePlayer = true;
            }
            else if (readKey == ConsoleKey.R)
            {
                placementDirection =
                    placementDirection == PlacementDirection.Right ? PlacementDirection.Down : (placementDirection == PlacementDirection.Down ? PlacementDirection.Left : (placementDirection == PlacementDirection.Left ? PlacementDirection.Up : PlacementDirection.Right));
            }
        }