Inheritance: MonoBehaviour
示例#1
0
 void SetCornerValues(GridSquare square)
 {
     square.bottomLeftValue  = GetValueForPoint(square.bottomLeftCorner);
     square.bottomRightValue = GetValueForPoint(square.bottomRightCorner);
     square.topLeftValue     = GetValueForPoint(square.topLeftCorner);
     square.topRightValue    = GetValueForPoint(square.topRightCorner);
 }
示例#2
0
    public void Move()
    {
        GridSquare nextSquare = TerminalSquare.North;

        From = TerminalSquare.transform.position + new Vector3(0, 0.5f, 0);
        Progress %= 1.0f;

        switch (Direction)
        {
            case GridDirection.North:
                nextSquare = TerminalSquare.North;
                break;
            case GridDirection.East:
                nextSquare = TerminalSquare.East;
                break;
            case GridDirection.South:
                nextSquare = TerminalSquare.South;
                break;
            case GridDirection.West:
                nextSquare = TerminalSquare.West;
                break;
        }

        if (nextSquare == null)
            Destroy(gameObject);
        else
        {
            To = nextSquare.transform.position + new Vector3(0, 0.5f, 0);
            TerminalSquare = nextSquare;
        }
    }
示例#3
0
文件: Game.cs 项目: asostechnix/katas
        public GameState Draw(Mark mark, GridSquare square)
        {
            if (_lastMarkDrawn == Mark.Empty && mark == Mark.O)
            {
                throw new Exception();
            }

            if (_marks[(int)square] != Mark.Empty)
            {
                throw new Exception();
            }

            if (_lastMarkDrawn == mark)
            {
                throw new Exception();
            }

            _marks[(int)square] = mark;
            _lastMarkDrawn      = mark;

            if (_marks.Take(3).All(m => m == mark))
            {
                return(GameState.Win);
            }

            return(GameState.Undefined);
        }
示例#4
0
 public void PlaceDoor(GridSquare nextSq)
 {
     if (quadrant == Quadrant.FirstQuadrant && nextSq.quadrant == Quadrant.SecondQuadrant)
     {
         LockDoor(1, KeyRequired.Quad1toQuad2);
     }
     else if (quadrant == Quadrant.SecondQuadrant && nextSq.quadrant == Quadrant.FirstQuadrant)
     {
         LockDoor(3, KeyRequired.Quad1toQuad2);
     }
     else if (quadrant == Quadrant.FirstQuadrant && nextSq.quadrant == Quadrant.ThirdQuadrant)
     {
         LockDoor(0, KeyRequired.Quad1toQuad3);
     }
     else if (quadrant == Quadrant.ThirdQuadrant && nextSq.quadrant == Quadrant.FirstQuadrant)
     {
         LockDoor(2, KeyRequired.Quad1toQuad3);
     }
     else if (quadrant == Quadrant.SecondQuadrant && nextSq.quadrant == Quadrant.FourthQuadrant)
     {
         LockDoor(0, KeyRequired.Quad2toQuad4);
     }
     else if (quadrant == Quadrant.FourthQuadrant && nextSq.quadrant == Quadrant.SecondQuadrant)
     {
         LockDoor(2, KeyRequired.Quad2toQuad4);
     }
     else if (quadrant == Quadrant.ThirdQuadrant && nextSq.quadrant == Quadrant.FourthQuadrant)
     {
         LockDoor(1, KeyRequired.Quad3toQuad4);
     }
     else if (quadrant == Quadrant.FourthQuadrant && nextSq.quadrant == Quadrant.ThirdQuadrant)
     {
         LockDoor(3, KeyRequired.Quad3toQuad4);
     }
 }
        private void CreateGrid(string gridname, int width, int height, int marginleft, int margintop, int griddistance)
        {
            int a = 0;
            int b = 0;

            for (int j = 0; j < 10 * height; j += height)
            {
                for (int i = 0; i < 10 * width; i += width)
                {
                    Rectangle         rect     = new Rectangle();
                    HitState.HitValue hitvalue = HitState.HitValue.Empty;
                    var gridSquare             = new GridSquare(rect, hitvalue);
                    game.GridSquares.Add(gridSquare);
                    rect.StrokeThickness = 1;
                    rect.Stroke          = _blackBrush;
                    rect.Width           = width;
                    rect.Height          = height;
                    rect.Fill            = _blueBrush;
                    rect.Name            = $"{gridname}_{b}_{a}";
                    if (gridname == "fleet")
                    {
                        rect.MouseLeftButtonDown  += FleetGrid_MouseLeftButtonDown;
                        rect.MouseRightButtonDown += FleetGrid_MouseRightButtonDown;
                    }
                    Canvas.SetLeft(rect, i + marginleft);
                    Canvas.SetTop(rect, j + griddistance + margintop);
                    _rectangles.Add(rect);

                    b++;
                }
                a++;
                b = 0;
            }
        }
示例#6
0
 private static bool Valid(List <ShipPositionExtended> ships)
 {
     if (ships == null)
     {
         return(false);
     }
     foreach (var ship in ships)
     {
         if (!ship.isValid())
         {
             return(false);
         }
     }
     for (int column = 1; column <= 10; column++)
     {
         foreach (var row in letters)
         {
             var grid = new GridSquare(row, column);
             if (ships.Select(x => x.Contains(grid) ? 1 : 0).Aggregate((x, y) => x + y) > 1)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
示例#7
0
 public void makeMove(GridSquare from, GridSquare to)
 {
     /*bool whitePlayer = from.getPlayer().isWhitePlayer();
      * if(to.getPlayer() != null) //attack
      * {
      *  if (whitePlayer)
      *      blackPieces.Remove(to);
      *  else
      *      whitePieces.Remove(to);
      * }
      * to.setPlayer(from.getPlayer());
      * to.setPiece(from.getPiece());
      * //from.empty();
      * if (whitePlayer)
      * {
      *  whitePieces.Add(to);
      *  whiteTurn = false;
      *  bPlayer.SetActive(true);
      * }
      * else
      * {
      *  blackPieces.Add(to);
      *  whiteTurn = true;
      *  wPlayer.SetActive(true);
      * }*/
 }
示例#8
0
    // Use this for initialization
    void Start()
    {
        rb       = this.GetComponent <Rigidbody>();
        x_pos    = this.transform.position.x;
        z_pos    = this.transform.position.z;
        y_pos    = this.transform.position.y;
        grid     = GameObject.Find("Grid").GetComponent <Grid>();
        curr_pos = grid.squares[(int)x_pos, (int)z_pos].GetComponent <GridSquare>();
        fighting = false;
        running  = false;
        facing   = 'n';
        key_lock = false;

        DEX    = 15;
        WIS    = 15;
        HEALTH = 187;
        DAMAGE = 22;
        EXP    = 0;

        GameObject.Find("Health").GetComponent <UnityEngine.UI.Text>().text       = "HP: " + HEALTH;
        GameObject.Find("Damage").GetComponent <UnityEngine.UI.Text>().text       = "DAM: " + DAMAGE;
        GameObject.Find("Dexterity").GetComponent <UnityEngine.UI.Text>().text    = "DEX: " + DEX;
        GameObject.Find("Wisdom").GetComponent <UnityEngine.UI.Text>().text       = "WIS: " + WIS;
        GameObject.Find("Strength").GetComponent <UnityEngine.UI.Text>().text     = "EXP: " + EXP;
        GameObject.Find("Intelligence").GetComponent <UnityEngine.UI.Text>().text = "INT: 15";

        log_lines     = 0;
        levelComplete = false;
    }
示例#9
0
文件: Player.cs 项目: logandee/Rover
    // Update is called once per frame
    //void Update()
    //{
    //    this.UnitSprite.color = Color.Lerp(Color.white, Color.black, Mathf.PingPong(Time.time, 1));

    //    Move();
    //}

    public bool AttemptMovementByPlayer(Vector2Int destinationCoords)
    {
        bool coordsAreValid = Utility.CheckIfCoordsAreValid(destinationCoords);

        if (coordsAreValid)
        {
            GridSquare destinationGS = Game.MapGrid[destinationCoords.x, destinationCoords.y];

            MoveToGridSquare(Game.MapGrid[Coords.x, Coords.y], destinationGS);

            if (destinationGS.GroundItem != null)
            {
                GetGroundItem(destinationGS.GroundItem);
            }

            if (destinationCoords.x == Game.instance.DungeonMap.KeyDoor.y && destinationCoords.y == Game.instance.DungeonMap.KeyDoor.x) // remember that x & y are flipped for dun map
            {
                UnityEngine.SceneManagement.SceneManager.LoadScene("VictoryScene");
            }

            return(true);
        }
        else
        {
            return(false);
        }
    }
示例#10
0
    public void SetMatches(int newmatches)
    {
        if (newmatches < 0 || newmatches > 16)          //out of range
        {
            print("tried to set letter tile to weird number");
            return;
        }
        if (newmatches == 0)
        {
//			print ("tile dead");
            GridSquare gs = transform.parent.gameObject.GetComponent <GridSquare> ();
            if (gs != null)
            {
                gs.SetTile(null);
            }
            Destroy(gameObject);
            return;
        }
        matches = newmatches;
        string spriteName = "NumberSprites/" + matches.ToString();

        if (matches == 16)
        {
            spriteName = "NumberSprites/inf";
        }
        numberSprite.GetComponent <SpriteRenderer> ().sprite = Resources.Load <Sprite> (spriteName);
    }
示例#11
0
        private IGridSquare GetNeighbourSquare(IGridSquare g, Orientation o, int step = 1)
        {
            int  col = g.Column;
            char row = g.Row;

            switch (o)
            {
            case Orientation.East:
                col += step;
                break;

            case Orientation.West:
                col -= step;
                break;

            case Orientation.North:
                row = (char)(row - step);
                break;

            case Orientation.South:
                row = (char)(row + step);
                break;
            }
            GridSquare result = new GridSquare(row, col);

            return(result);
        }
示例#12
0
文件: ArtInt.cs 项目: logandee/Rover
    public bool AttemptMovementByAI()
    {
        if (CoordsPath.Count > 0 && Self.Coords != DestinationCoords)
        {
            GridSquare[,] grid = Game.MapGrid; // for convenience

            FindPath(grid[Self.Coords.x, Self.Coords.y], grid[DestinationCoords.x, DestinationCoords.y]);

            int        x          = CoordsPath[0].x;
            int        y          = CoordsPath[0].y;
            GridSquare gsToMoveTo = grid[x, y];

            bool canMoveToCoords = CheckMovementValidity(gsToMoveTo);

            if (canMoveToCoords)
            {
                Self.MoveToGridSquare(grid[Self.Coords.x, Self.Coords.y], gsToMoveTo);
                CoordsPath.RemoveAt(0); // after successful movement, remove GS from path
                return(true);
            }
            else
            {
                return(false);
            }
        }
        else
        {
            return(false);
        }
    }
    private void CheckToAddRowsBelow(GridSquare cell)
    {
        //if cell is occupied and on the highest row.
        //add a new row - then set all of them unlandable, other than the one's adjacent to current cell.
        int highest = GetHighestLayer();

        if (cell.Occupied && cell.LayerIndex.x == highest)
        {
            var newRow = InitRow(highest + 1, false);
            GridCells.Add(newRow);

            var SurrondingCells = CheckSurrondingCells(cell, true);

            foreach (GridSquare square in newRow.Row)
            {
                if (!SurrondingCells.Contains(square))
                {
                    square.SetLanded(false);
                }
            }

            if (GridCells.Count > 8)
            {
                StartCoroutine(myEasing.CoMoveY(0, 0.5f, transform.localPosition.y, transform.localPosition.y + MagicSpacing * 0.9f, transform, Easing.Function.Sinusoidal, Easing.Direction.Out));
                RemoveRow(GridCells.Find(x => x.Layer == GetLowestLayer()));
            }
        }
    }
示例#14
0
    public void Build()
    {
        if (grid == null)
        {
            grid = CreateGrid();
        }

        if (random == null)
        {
            random    = CreateRng();
            grid.name = $"Dungeon Grid {seed}";
        }
        int curID = 0;

        for (int i = 0; i < gridWidth; i++)
        {
            for (int j = 0; j < gridHeight; j++)
            {
                GridSquare sq = CreateSquare(new Vector3Int(i, 0, j), curID);
                sq.transform.position = grid.BoardToWorld(new Vector3Int(i, 0, j));
                sq.gameObject.SetActive(true);
                curID++;
            }
        }
        CreateRandomMaze(0);
    }
    private List <GridSquare> CheckCellsAbove(GridSquare cell, bool CheckUnOccupied = false)
    {
        Vector2 CellIndex = cell.LayerIndex;

        List <GridSquare> SurrondingCells = new List <GridSquare>();

        //search different cells depending if on an odd or even row.
        //even - check y-1 and y on both above and below rows.
        int left = 0, right = 0;

        if (CellIndex.x % 2 == 0)
        {
            left  = -1;
            right = 0;
        }
        //odd - check y and y +1 on both above and below rows.
        else
        {
            left  = 0;
            right = 1;
        }

        //row above
        var row = GridCells.Find(x => x.Layer == CellIndex.x - 1);

        SurrondingCells.AddRange(FindAdjacentCellsInRow(CellIndex, row, left, right, CheckUnOccupied));

        return(SurrondingCells);
    }
    public override GridSquare GetNextSquare(Action action)
    {
        int newRow = Row, newCol = Col;

        switch (action)
        {
        case Action.Up:
            newRow -= 1;
            break;

        case Action.Down:
            newRow += 1;
            break;

        case Action.Left:
            newCol -= 1;
            break;

        case Action.Right:
            newCol += 1;
            break;

        default:
            throw new System.ArgumentException("Unsupported Action");
        }
        if (!ParentGrid.CoordsInRange(newRow, newCol))
        {
            return(this);
        }
        GridSquare newSquare = ParentGrid.GetSquareAt(newRow, newCol);

        return(newSquare == null ? this : newSquare.Walkable?newSquare : this);
    }
示例#17
0
        void MarchingSquares()
        {
            foreach (Isosurface mesh in Meshes)
            {
                mesh.Reset();
            }

            for (int gridIndex = 0; gridIndex < grid.Length; gridIndex++)
            {
                GridSquare square = grid [gridIndex];
                foreach (Isosurface mesh in Meshes)
                {
                    int caseIndex = model.GetSquareConfiguration(square, mesh.ThresholdValue);

                    Vector3[] squareVertices  = model.CaseVertices [caseIndex];
                    int[]     squareTriangles = model.CaseTriangles [caseIndex];

                    mesh.AddTriangles(squareTriangles);
                    mesh.AddVertices(squareVertices, square);
                }
            }
            foreach (Isosurface mesh in Meshes)
            {
                mesh.DrawMesh();
            }
        }
    private List <GridSquare> FindAdjacentCellsInRow(Vector2 CellIndex, GridRow row, int left, int right, bool FindUnOccupied)
    {
        List <GridSquare> cells = new List <GridSquare>();

        if (row != null)
        {
            if (CellIndex.y + left > -1 && CellIndex.y + left < 6)
            {
                GridSquare adjacentCell = row.Row[(int)CellIndex.y + left];
                if (adjacentCell.Occupied || FindUnOccupied)
                {
                    cells.Add(adjacentCell);
                }
            }

            if (CellIndex.y + right > -1 && CellIndex.y + right < 6)
            {
                GridSquare adjacentCell = row.Row[(int)CellIndex.y + right];
                if (adjacentCell.Occupied || FindUnOccupied)
                {
                    cells.Add(adjacentCell);
                }
            }
        }

        return(cells);
    }
示例#19
0
    void Explode(GridControl grid)
    {
        BombTickSFX.Stop();
        SwapBombSFX.Play();
        int cipher = Random.Range(1, 26);

        foreach (GameObject go in grid.grid)
        {
            GridSquare gs = go.GetComponent <GridSquare>();
            if (gs && gs.tile)
            {
                LetterTile lt = gs.tile.GetComponent <LetterTile>();
                if (lt)
                {
                    int changedLetter = lt.letter + cipher;
                    if (changedLetter > Game.ascii_z)
                    {
                        changedLetter = changedLetter - 26;
                    }
                    lt.ChangeLetterSprite((char)changedLetter);
                    Instantiate(indicator, gs.tile.transform);
                }
            }
        }
    }
 public void DrawCaseAtPoint(int caseId, GridSquare square, Vector3 offset)
 {
     SetVertices(square, offset);
     SetUVs(caseId);
     vertexCount += 4;
     uvCount     += 4;
 }
示例#21
0
    //used to update colour based on the fishing rate.
    public void UpdateColour()
    {
        switch (FishRate)
        {
        case 1:
            GridSquare.GetComponent <Image>().color = new Color(204f / 255f, 204f / 255f, 255f / 255f);
            break;

        case 2:
            GridSquare.GetComponent <Image>().color = new Color(153f / 255f, 153f / 255f, 255f / 255f);
            break;

        case 3:
            GridSquare.GetComponent <Image>().color = new Color(102f / 255f, 102f / 255f, 255f / 255f);
            break;

        case 4:
            GridSquare.GetComponent <Image>().color = new Color(0f / 255f, 0f / 255f, 255f / 255f);
            break;

        default:
            GridSquare.GetComponent <Image>().color = new Color(255f / 255f, 255f / 255f, 255f / 255f);
            break;
        }
    }
示例#22
0
    public void Move(GridSquare nSquare)
    {
        _hoveredSquare          = nSquare;
        this.transform.position = nSquare.transform.position;

        _csp.diplayImage.sprite = nSquare.displayImage.sprite;
    }
示例#23
0
    private void CreateGrid()
    {
        GridX   = (int)transform.lossyScale.x | 0x1; // Force odd and ensure at least one
        GridY   = (int)transform.lossyScale.y | 0x1;
        GridZ   = (int)transform.lossyScale.z | 0x1;
        grid    = new GridSquare[GridX, GridY, GridZ];
        corners = new GridSquare[GridX - 1, GridY - 1, GridZ - 1]; // Ignoring outer corners

        for (int i = 0; i < GridX; i++)
        {
            for (int j = 0; j < GridY; j++)
            {
                for (int k = 0; k < GridZ; k++)
                {
                    grid[i, j, k] =
                        new GridSquare(transform.position + new Vector3(i - (GridX / 2), j - (GridY / 2), k - (GridZ / 2)), new Vector3(i, j, k));

                    if (i > 0 && j > 0 && k > 0)
                    {
                        corners[i - 1, j - 1, k - 1] =
                            new GridSquare(grid[i, j, k].Location - (Vector3.one * 0.5f), new Vector3(i - 1, j - 1, k - 1));
                    }
                }
            }
        }
    }
示例#24
0
    HashSet <GridSquare> GetRoomCells(GridSquare currCell, int remainingSize)
    {
        HashSet <GridSquare> cells = new HashSet <GridSquare>();

        currCell.includedInRoom = true;
        foreach (var neighbor in currCell.Neighbors)
        {
            if (remainingSize > 0)
            {
                if (!neighbor.includedInRoom)
                {
                    cells.UnionWith(GetRoomCells(neighbor, remainingSize - 1));
                }
                else
                {
                    cells.Add(neighbor);
                }
            }
            else
            {
                cells.Add(neighbor);
            }
        }
        return(cells);
    }
示例#25
0
        public GridSquare GetOptimumTarget(TrackingGrid grid, GridSquare lastShot)
        {
            Console.WriteLine("HunterKiller looking for target");

            GridSquare potentialTarget = LookForTarget(grid, lastShot);

            return(potentialTarget);
        }
示例#26
0
    public GridSquare GetCorner(Vector3 pos)
    {
        pos += Vector3.one * 0.5f;
        GridSquare square = GetSquare(pos);

        //SHOULD CHECK FOR OUTOFBOUNDS
        return(corners[(int)square.GridIndex.x - 1, (int)square.GridIndex.y - 1, (int)square.GridIndex.z - 1]);
    }
示例#27
0
    public void SlotIntoSquare(GridSquare square, float p)
    {
        GridObj.Init(square, square);

        Vector2 diagonal = square.Rect.LowerRight - square.Rect.UpperLeft;

        Rect.Init(square.Rect.UpperLeft + p * diagonal, square.Rect.LowerRight - p * diagonal);
    }
示例#28
0
    public void AddSquare(GridSquare square)
    {
        CacheMaps();
        allSquares.Add(square);
        squaresByPosition[square.Position] = square;

        ConnectSquareToNeighbors(square);
    }
示例#29
0
 void Start()
 {
     makingMove    = false;
     newTurn       = true;
     pieces        = null;
     moves         = null;
     selectedPiece = null;
 }
        public Point ToPoint(GridSquare g)
        {
            Point p = new Point();

            p.x = g.CoordX;
            p.y = g.CoordY;
            return(p);
        }
示例#31
0
    public GridSquare CreateSquare(Vector3Int pos, int curID)
    {
        GridSquare sq = Instantiate(squarePrefab, grid.transform);

        sq.Position = pos;
        sq.SetID(curID);
        grid.AddSquare(sq);
        return(sq);
    }
示例#32
0
    private bool evaluateSquare(GridSquare square,GridSquare current,bool[] visited)
    {
        GridSquare[] squares = {square.Top,square.Left,square.Bottom,square.Right};

        foreach (GridSquare s in squares)
        {
            if (s == current)
                continue;
            if (s == null)
                return false;
            if (visited[s.getHash ()])
                return false;
        }
        return true;
    }
示例#33
0
    private List<GridSquare> getGoodNeighbors(GridSquare current,bool[] visited,bool onlyUnexplored)
    {
        List<GridSquare> neighbors = new List<GridSquare>();
        GridSquare[] squares = {current.Top,current.Left,current.Bottom,current.Right};

        foreach (GridSquare s in squares)
        {
            if (s == null)
                continue;
            if (visited[s.getHash ()])
                continue;
            if (s.isBlocked ())
                continue;
            if (onlyUnexplored && current.isJunction()) {
                if (current.Junction.hasExplored (s))
                    continue;
            }
            if (evaluateSquare (s,current,visited))
                neighbors.Add (s);
        }

        return neighbors;
    }
示例#34
0
    /**
     * Creates a walled off block using cube prefabs, with an opening facing the given gridsquare.
     */
    private void instantiateEnclave(int blockX, int blockY, GridSquare entrance)
    {
        //Starting block
        GridSquare current = grid[blockX*4+1,blockY*4+1];

        Vector3 topLeft = this.collider.bounds.center - this.collider.bounds.extents;
        Vector3 bottomRight= this.collider.bounds.center + this.collider.bounds.extents;
        float y = this.collider.bounds.center.y;

        float x1 = topLeft.x;
        float dWidth = bottomRight.x-x1;
        float z1 = topLeft.z;
        float dHeight = bottomRight.z-z1;
        int i = blockX*4,j = blockY*4;

        GameObject instance;

        if (current.Bottom.Bottom != entrance) {
            instance = (GameObject) Instantiate(cubePrefab);
            instance.transform.position = new Vector3(x1+(i+1.5f)*(dWidth/width),y+2.5f,z1+(j+2.8f)*(dHeight/height));
            instance.transform.localScale = new Vector3(2.6f*dWidth/width,5.0f,0.1f*dHeight/height);
            instance.transform.parent = this.transform;
            boxManager.AddBox(instance.collider.bounds);
        }
        else
        {
            instance = (GameObject) Instantiate(cubePrefab);
            instance.transform.position = new Vector3(x1+(i+0.6f)*(dWidth/width),y+2.5f,z1+(j+2.8f)*(dHeight/height));
            instance.transform.localScale = new Vector3(0.8f*dWidth/width,5.0f,0.1f*dHeight/height);
            instance.transform.parent = this.transform;
            boxManager.AddBox(instance.collider.bounds);

            instance = (GameObject) Instantiate(cubePrefab);
            instance.transform.position = new Vector3(x1+(i+2.4f)*(dWidth/width),y+2.5f,z1+(j+2.8f)*(dHeight/height));
            instance.transform.localScale = new Vector3(0.8f*dWidth/width,5.0f,0.1f*dHeight/height);
            instance.transform.parent = this.transform;
            boxManager.AddBox(instance.collider.bounds);
        }

        if (current.Top.Top != entrance) {
            instance = (GameObject) Instantiate(cubePrefab);
            instance.transform.position = new Vector3(x1+(i+1.5f)*(dWidth/width),y+2.5f,z1+(j+0.2f)*(dHeight/height));
            instance.transform.localScale = new Vector3(2.6f*dWidth/width,5.0f,0.1f*dHeight/height);
            instance.transform.parent = this.transform;
            boxManager.AddBox(instance.collider.bounds);
        }
        else
        {
            instance = (GameObject) Instantiate(cubePrefab);
            instance.transform.position = new Vector3(x1+(i+0.6f)*(dWidth/width),y+2.5f,z1+(j+0.2f)*(dHeight/height));
            instance.transform.localScale = new Vector3(0.8f*dWidth/width,5.0f,0.1f*dHeight/height);
            instance.transform.parent = this.transform;
            boxManager.AddBox(instance.collider.bounds);

            instance = (GameObject) Instantiate(cubePrefab);
            instance.transform.position = new Vector3(x1+(i+2.4f)*(dWidth/width),y+2.5f,z1+(j+0.2f)*(dHeight/height));
            instance.transform.localScale = new Vector3(0.8f*dWidth/width,5.0f,0.1f*dHeight/height);
            instance.transform.parent = this.transform;
            boxManager.AddBox(instance.collider.bounds);
        }

        if (current.Left.Left != entrance) {
            instance = (GameObject) Instantiate(cubePrefab);
            instance.transform.position = new Vector3(x1+(i+0.2f)*(dWidth/width),y+2.5f,z1+(j+1.5f)*(dHeight/height));
            instance.transform.localScale = new Vector3(0.1f*dWidth/width,5.0f,2.6f*dHeight/height);
            instance.transform.parent = this.transform;
            boxManager.AddBox(instance.collider.bounds);
        }
        else
        {
            instance = (GameObject) Instantiate(cubePrefab);
            instance.transform.position = new Vector3(x1+(i+0.2f)*(dWidth/width),y+2.5f,z1+(j+0.6f)*(dHeight/height));
            instance.transform.localScale = new Vector3(0.1f*dWidth/width,5.0f,0.8f*dHeight/height);
            instance.transform.parent = this.transform;
            boxManager.AddBox(instance.collider.bounds);

            instance = (GameObject) Instantiate(cubePrefab);
            instance.transform.position = new Vector3(x1+(i+0.2f)*(dWidth/width),y+2.5f,z1+(j+2.4f)*(dHeight/height));
            instance.transform.localScale = new Vector3(0.1f*dWidth/width,5.0f,0.8f*dHeight/height);
            instance.transform.parent = this.transform;
            boxManager.AddBox(instance.collider.bounds);
        }

        if (current.Right.Right != entrance) {
            instance = (GameObject) Instantiate(cubePrefab);
            instance.transform.position = new Vector3(x1+(i+2.8f)*(dWidth/width),y+2.5f,z1+(j+1.5f)*(dHeight/height));
            instance.transform.localScale = new Vector3(0.1f*dWidth/width,5.0f,2.6f*dHeight/height);
            instance.transform.parent = this.transform;
            boxManager.AddBox(instance.collider.bounds);
        }
        else
        {
            instance = (GameObject) Instantiate(cubePrefab);
            instance.transform.position = new Vector3(x1+(i+2.8f)*(dWidth/width),y+2.5f,z1+(j+0.6f)*(dHeight/height));
            instance.transform.localScale = new Vector3(0.1f*dWidth/width,5.0f,0.8f*dHeight/height);
            instance.transform.parent = this.transform;
            boxManager.AddBox(instance.collider.bounds);

            instance = (GameObject) Instantiate(cubePrefab);
            instance.transform.position = new Vector3(x1+(i+2.8f)*(dWidth/width),y+2.5f,z1+(j+2.4f)*(dHeight/height));
            instance.transform.localScale = new Vector3(0.1f*dWidth/width,5.0f,0.8f*dHeight/height);
            instance.transform.parent = this.transform;
            boxManager.AddBox(instance.collider.bounds);
        }
    }
示例#35
0
 public float manhattanDistanceTo(GridSquare target)
 {
     return Mathf.Abs (target.Position.x - Position.x) + Mathf.Abs (target.Position.y - Position.y);
 }
示例#36
0
    IEnumerator GridBFS()
    {
        PlayerGrid  = new GridSquare[MAX_MOVE * 2 + 1, MAX_MOVE * 2 + 1];
        BlockedGrid = new bool[MAX_MOVE * 2 + 1, MAX_MOVE * 2 + 1];

        BFSQueue = new Queue();

        // Set player position to blocked immediately
        BlockedGrid[MAX_MOVE, MAX_MOVE] = true;
        GridSquare playerSpace = new GridSquare { coordinates = transform.position };

        BFSQueue.Enqueue(playerSpace);

        while (BFSQueue.Count != 0)
        {
            GridSquare cur = (GridSquare)BFSQueue.Dequeue();

            // Check the cardinal spaces around cur
            CheckAndAddAvailBFS(cur.coordinates.x, cur.coordinates.z + 1, cur.distance);
            CheckAndAddAvailBFS(cur.coordinates.x, cur.coordinates.z - 1, cur.distance);
            CheckAndAddAvailBFS(cur.coordinates.x + 1, cur.coordinates.z, cur.distance);
            CheckAndAddAvailBFS(cur.coordinates.x - 1, cur.coordinates.z, cur.distance);

            // Check the diagonal spaces around cur
            CheckAndAddAvailBFS(cur.coordinates.x + 1, cur.coordinates.z + 1, cur.distance + 0.4f);
            CheckAndAddAvailBFS(cur.coordinates.x - 1, cur.coordinates.z - 1, cur.distance + 0.4f);
            CheckAndAddAvailBFS(cur.coordinates.x + 1, cur.coordinates.z - 1, cur.distance + 0.4f);
            CheckAndAddAvailBFS(cur.coordinates.x - 1, cur.coordinates.z + 1, cur.distance + 0.4f);
        }
        yield return null;
    }
示例#37
0
    public AStarNode(GridSquare square, GridSquare target)
    {
        if (square == null)
            return;
        parent = null;
        this.square = square;
        this.target = target;
        neighbors = new List<GridSquare>();

        hScore = square.manhattanDistanceTo(this.target);

        GridSquare[] potentialNeighbors = {square.Top, square.Bottom, square.Left, square.Right};

        foreach (GridSquare s in potentialNeighbors) {
            //Complicated logic so that squares inside an enclave are accessible
            if (s == null)
                continue;
            if ((s != null && !s.isBlocked () && (!(square.isInStartBlock () || square.isInEndBlock()) || (!square.isBlocked () || square.isEnclaveEntrance())))
                || (square.isInStartBlock () && s.isInStartBlock())
                || (square.isInEndBlock () && s.isInEndBlock())
                || (s.isEnclaveEntrance())
                ) {
                neighbors.Add (s);
            }
        }
    }
示例#38
0
    void MovePlayer()
    {
        // Translate to next GridSquare
        if (moveList.Count > 0)
        {
            GridSquare finalSquare = (GridSquare)moveList[0];
            GridSquare curSpace = new GridSquare();
            curSpace.coordinates = transform.position;
            Vector3 curDir = Vector3.zero;
            float curDur = 0f;
            RaycastHit hit;
            if (!Physics.SphereCast(transform.position, 0.5f, finalSquare.coordinates - transform.position, 
                                    out hit, Vector3.Distance(finalSquare.coordinates, transform.position), 255, QueryTriggerInteraction.Ignore))
            {
                curDir = finalSquare.coordinates - curSpace.coordinates;
                // 0.2 seconds per meter
                curDur = Vector3.Distance(finalSquare.coordinates, curSpace.coordinates) * 0.2f;
                curSpace = finalSquare;
                moveEndSpace = curSpace;
                moveList.Clear();
            }
            else
            {
                int spaceCount = 0;

                // Set initial space to player pos

                // Check if next space is in same direction if there are still spaces to check
                do
                {
                    GridSquare tempSpace = (GridSquare)moveList[moveList.Count - 1];
                    Vector3 tempDir = tempSpace.coordinates - curSpace.coordinates;
                    // Duration based on cardinal or diagonal direction
                    // 0.2 seconds per meter
                    float durDiff = tempDir.magnitude * 0.2f;

                    // Pop last gridspace in list if it's in the same line as prev spaces or if it's the first pass
                    if (spaceCount == 0 || tempDir == curDir)
                    {
                        curSpace = tempSpace;
                        moveList.RemoveAt(moveList.Count - 1);
                        curDir = tempDir;
                        curDur += durDiff;

                        spaceCount++;
                    }
                    // Break if temp space isn't in line with previous spaces
                    else break;
                }
                while (moveList.Count > 0);

                if (moveList.Count == 0)
                    moveEndSpace = curSpace;
            }

            ArrayList spaceAndDur = new ArrayList();
            spaceAndDur.Add(curSpace);
            spaceAndDur.Add(curDur);
            float yRotationNeeded = Mathf.Acos(Vector3.Dot(transform.forward, curDir.normalized));
            float testX = transform.forward.x * Mathf.Cos(yRotationNeeded) - transform.forward.z * Mathf.Sin(yRotationNeeded);
            float testZ = transform.forward.x * Mathf.Sin(yRotationNeeded) + transform.forward.z * Mathf.Cos(yRotationNeeded);
            Vector3 testVector = new Vector3(testX, transform.forward.y, testZ);
            if (testVector.normalized == curDir.normalized)
                yRotationNeeded = -yRotationNeeded;
            // Move player to the furthest in-line space
            RotatePlayer(yRotationNeeded * 180f / Mathf.PI, spaceAndDur);
        }
        // Snap player to grid
        else
        {
            transform.position = new Vector3(curPosition.x, 0f, curPosition.z);
            playerMoveCount--;

            processFinalGridSquare(moveEndSpace);

            for (int i = 0; i < gridPlanes.Count; i++)
                Destroy((GameObject)gridPlanes[i]);
            gridPlanes.Clear();
        }
    }
示例#39
0
    void processFinalGridSquare(GridSquare curGrid)
    {
        Debug.Log("final square");
        destReached = curGrid.destination;

        Collider[] cargoArray = Physics.OverlapBox(new Vector3(curPosition.x, 0f, curPosition.z),
                                                       new Vector3(0.4f, 4f, 0.4f), Quaternion.identity,
                                                       255, QueryTriggerInteraction.Collide);

        for (int i = 0; i < cargoArray.Length; i++)
            if (cargoArray[i].tag.Equals("Cargo"))
            {
                GameObject.Destroy(cargoArray[i].gameObject);
                curGrid.cargo = true;
                break;
            }
        
        if (curGrid.cargo)
        {
            curr_Cargo++;
            hudScript.CargoUpdate(curr_Cargo, max_Cargo);
            //Add(Random.Range(5, 15), max_Cargo, true);
        }

        imHidden = curGrid.hidden;

        if (hyperJumping)
            hyperJumping = false;

        if (!destReached && playerMoveCount > 0)
        {
            newMove = true;
            holdMoves = false;
        }
    }
示例#40
0
 void MapSquareSelectedHandler(GridSquare square)
 {
     if (SelectedGridSquare != null)
     {
         SelectedGridSquare.Unselect();
     }
     SelectedGridSquare = square;
 }
示例#41
0
 // Use this for initialization
 void Start()
 {
     canMakeSquares = false;
     gravtiy = 2;
     for (int i = 0; i < sizeX; i++) {
         for (int j = 0; j < sizeY; j++)
         {
             gridSquareData[i, j] = new GridSquare();
         }
     }
     minSwipeDistY = 30f;
     minSwipeDistX = 30f;
 }
示例#42
0
 public bool IsAdjacent(GridSquare tarGS)
 {
     return EqualsPlusOrMinus(1, tarGS.X, this.X) && EqualsPlusOrMinus(1, tarGS.Y, this.Y);
 }
示例#43
0
    private void ActivateSquare(GridSquare tarGS)
    {
        if (tarGS.minedState == false)
        {

            unrevealedCount--;
            tarGS.viewState = ViewState.Show;
            AutoReveal (tarGS);
        }
        else
        {
            GameOver ();
        }
    }
示例#44
0
    void Awake()
    {
        uint i,j;

        width = Mathf.Max (Mathf.CeilToInt((float)width/4.0f),2)*4-1;
        height = Mathf.Max (Mathf.CeilToInt((float)height/4.0f),2)*4-1;
        Vector3 topLeft = this.collider.bounds.center - this.collider.bounds.extents;
        Vector3 bottomRight= this.collider.bounds.center + this.collider.bounds.extents;
        float y = this.collider.bounds.center.y;

        float x1 = topLeft.x;
        float dWidth = bottomRight.x-x1;
        float z1 = topLeft.z;
        float dHeight = bottomRight.z-z1;

        bool[,] usedGrid = new bool[3,3];

        grid = new GridSquare[width,height];

        float blockX,blockY,blockWidth,blockHeight;

        int addedHeight;

        int bX,bY;

        int startX = rnd.Next (1,width/4);
        int startY = rnd.Next (1,height/4);
        int endX=0,endY=0;

        GridSquare current,safeEntrance = null;

        //Loop through the array to create the actual grid O(n)
        for (j=0;j<height;++j) {
            for (i=0;i<width;++i) {
                grid[i,j] = new GridSquare(new Vector2(i,j),this);
            }
        }

        maze = null;
        while (maze == null)
        {
            startX = rnd.Next (1,width/4);
            startY = rnd.Next (1,height/4);
            maze = generateMaze(startX,startY);
        }

        this.startBlock = grid[startX*4+1, startY*4+1];

        Vector2 entranceVec = (maze.First.Value.Position + this.startBlock.Position) / 2;
        this.StartEntrance = grid[(int)entranceVec.x,(int)entranceVec.y];

        LinkedListNode<GridSquare> node = maze.Last;

        while (node != null) {
            current = node.Value.getAdjacentBlock(startX,startY);
            if (current == null) {
                node = node.Previous;
                continue;
            }

            safeEntrance = node.Value;
            endX = (int)current.Position.x/4;
            endY = (int)current.Position.y/4;

            this.endBlock = grid[endX*4+1, endY*4+1];

            entranceVec = (safeEntrance.Position + this.endBlock.Position) / 2;
            this.SafeEntrance = grid[(int)entranceVec.x,(int)entranceVec.y];

            break;
        }

        for (j=0;j<height;++j) {
            for (i=0;i<width;++i) {
                if ((i % 4 == 0) && (j % 4 == 0)) {

                    //Sidewalk
                    GameObject instance = (GameObject) Instantiate(cubePrefab);
                    instance.transform.position = new Vector3(x1+(i+1.5f)*(dWidth/width),y+0.1f,z1+(j+1.5f)*(dHeight/height));
                    instance.transform.localScale = new Vector3(3*dWidth/width,0.2f,3*dHeight/height);
                    instance.transform.parent = this.transform;
                    instance.collider.enabled = false;
                    if (endX*4 == i && endY*4 == j) {
                        instantiateEnclave(endX,endY,safeEntrance);
                        continue;
                    }
                    if (startX*4 == i && startY*4 == j) {
                        //Starting block
                        current = grid[startX*4+1,startY*4+1];

                        instantiateEnclave(startX,startY,maze.First.Value);

                        playerObject.transform.position = current.toVector3 ();
                        playerObject.transform.position = new Vector3(playerObject.transform.position.x,
                                0.5f,
                                playerObject.transform.position.z);
                        sheepSpawner.transform.position = current.toVector3();

                        continue;
                    }

                    //Streelamps
                    if(Random.value < 0.3f) {
                        instance = (GameObject) Instantiate(streetlampPrefab);
                        instance.transform.position = new Vector3(x1+(i+1.5f)*(dWidth/width)-1.4f*dWidth/width,y+0.1f,z1+(j+1.5f)*(dHeight/height)-1.4f*dHeight/height);
                        instance.transform.parent = this.transform;
                        instance.transform.Rotate(new Vector3(0,-135.0f,0));
                    }

                    if(Random.value < 0.3f) {
                        instance = (GameObject) Instantiate(streetlampPrefab);
                        instance.transform.position = new Vector3(x1+(i+1.5f)*(dWidth/width)+1.4f*dWidth/width,y+0.1f,z1+(j+1.5f)*(dHeight/height)-1.4f*dHeight/height);
                        instance.transform.parent = this.transform;
                        instance.transform.Rotate(new Vector3(0,135.0f,0));
                    }

                    if(Random.value < 0.3f) {
                        instance = (GameObject) Instantiate(streetlampPrefab);
                        instance.transform.position = new Vector3(x1+(i+1.5f)*(dWidth/width)-1.4f*dWidth/width,y+0.1f,z1+(j+1.5f)*(dHeight/height)+1.4f*dHeight/height);
                        instance.transform.parent = this.transform;
                        instance.transform.Rotate(new Vector3(0,-45.0f,0));
                    }

                    if(Random.value < 0.3f) {
                        instance = (GameObject) Instantiate(streetlampPrefab);
                        instance.transform.position = new Vector3(x1+(i+1.5f)*(dWidth/width)+1.4f*dWidth/width,y+0.1f,z1+(j+1.5f)*(dHeight/height)+1.4f*dHeight/height);
                        instance.transform.parent = this.transform;
                        instance.transform.Rotate(new Vector3(0,+45.0f,0));
                    }

                    //Collision Box
                    instance = (GameObject) Instantiate(cubePrefab);
                    instance.transform.position = new Vector3(x1+(i+1.5f)*(dWidth/width),y+5.0f,z1+(j+1.5f)*(dHeight/height));
                    instance.transform.localScale = new Vector3(2.5f*dWidth/width,10.0f,2.5f*dHeight/height);
                    instance.renderer.enabled = false;
                    instance.transform.parent = this.transform;
                    boxManager.AddBox (instance.collider.bounds);

                    blockX = (x1+(i+1.5f)*(dWidth/width)) - (0.5f*2.5f*dWidth/width);
                    blockY = (z1+(j+1.5f)*(dHeight/height)) - (0.5f*2.5f*dHeight/height);
                    blockWidth  = 2.5f*dWidth/width;
                    blockHeight = 2.5f*dHeight/height;

                    //Building Styles
                    switch(rnd.Next (0,3)) {
                    case 0:
                        addedHeight = rnd.Next (-6,7);
                        if (addedHeight >= 4)
                        {
                            addedHeight += rnd.Next (50,100);
                        }
                        instance = (GameObject) Instantiate(cubePrefab);
                        instance.transform.position = new Vector3(blockX + 0.5f * blockWidth,y+15.0f+addedHeight*0.5f,blockY + 0.5f * blockHeight);
                        instance.transform.localScale = new Vector3(blockWidth,30.0f+addedHeight,blockHeight);
                        instance.transform.parent = this.transform;
                        instance.collider.enabled = false;
                        break;
                    case 1:
                        for (bX = 0;bX < 3;++bX) {
                            for (bY = 0; bY < 3; ++bY) {
                                usedGrid[bX,bY] = false;
                            }
                        }

                        bX = rnd.Next (0,2);
                        bY = rnd.Next (0,2);

                        instance = (GameObject) Instantiate(cubePrefab);
                        addedHeight = rnd.Next (1,8);
                        instance.transform.position = new Vector3(blockX + bX * (blockWidth/3.0f) + (blockWidth/3),y+5.0f+addedHeight*0.5f,blockY + bY * (blockHeight/3.0f)+ (blockHeight/3));
                        instance.transform.localScale = new Vector3(1.9f*(blockWidth/3),10.0f+addedHeight,1.9f*(blockHeight/3));
                        instance.transform.parent = this.transform;
                        instance.collider.enabled = false;

                        usedGrid[bX,bY] = true;
                        usedGrid[bX+1,bY] = true;
                        usedGrid[bX,bY+1] = true;
                        usedGrid[bX+1,bY+1] = true;

                        for (bX = 0;bX < 3;++bX) {
                            for (bY = 0; bY < 3; ++bY) {
                                if (usedGrid[bX,bY] == false)
                                {
                                    instance = (GameObject) Instantiate(cubePrefab);
                                    addedHeight = rnd.Next (2,6);
                                    instance.transform.position = new Vector3(blockX + bX * (blockWidth/3.0f) + 0.5f * (blockWidth/3),y+2.5f+addedHeight*0.5f,blockY + bY * (blockHeight/3.0f)+ 0.5f * (blockHeight/3));
                                    instance.transform.localScale = new Vector3(0.9f*(blockWidth/3),5.0f+addedHeight,0.9f*(blockHeight/3));
                                    instance.transform.parent = this.transform;
                                    instance.collider.enabled = false;
                                }
                            }
                        }
                        break;
                    default:
                        for (bX = 0;bX < 3;++bX) {
                            for (bY = 0; bY < 3; ++bY) {
                                instance = (GameObject) Instantiate(cubePrefab);
                                addedHeight = rnd.Next (2,6);
                                instance.transform.position = new Vector3(blockX + bX * (blockWidth/3.0f) + 0.5f * (blockWidth/3),y+2.5f+addedHeight*0.5f,blockY + bY * (blockHeight/3.0f)+ 0.5f * (blockHeight/3));
                                instance.transform.localScale = new Vector3(0.9f*(blockWidth/3),5.0f+addedHeight,0.9f*(blockHeight/3));
                                instance.transform.parent = this.transform;
                                instance.collider.enabled = false;
                            }
                        }
                        break;
                    }
                }
            }
        }
    }
示例#45
0
    // Adds to queue if not visited/obstructed and if it's in MAX_MOVE range of player
    void CheckAndAddAvailBFS(float x, float z, float dist)
    {
        // Create array space vector
        Vector2 posOffset = new Vector2(x - transform.position.x + MAX_MOVE, z - transform.position.z + MAX_MOVE);

        if (posOffset.x > MAX_MOVE * 2 || posOffset.x < 0 ||
            posOffset.y > MAX_MOVE * 2 || posOffset.y < 0)
            return;

        if (dist < MAX_MOVE)
        {
            if (!BlockedGrid[(int)posOffset.x, (int)posOffset.y])   // Check for not visited
            {
                BlockedGrid[(int)posOffset.x, (int)posOffset.y] = true;

                // Check for collision
                if (!Physics.CheckBox(new Vector3(x, 0f, z),
                                      new Vector3(0.499f, 10f, 0.499f), Quaternion.identity,
                                      255, QueryTriggerInteraction.Ignore))
                {
                    bool hiddenSpace = false;
                    bool cargoSpace  = false;
                    bool destSpace   = false;

                    // Check for stealth trigger
                    Collider[] triggerArray = Physics.OverlapBox(new Vector3(x, 0f, z),
                                                                 new Vector3(0.499f, 10f, 0.499f), Quaternion.identity,
                                                                 255, QueryTriggerInteraction.Collide);
                    if (triggerArray.Length > 0)
                    {
                        /*
                         * NOTE: Loop will help catch unnecessary triggers.
                         *       Won't really be necessary in "release" build.
                         */
                        for (int i = 0; i < triggerArray.Length; i++)
                        {
                            if (triggerArray[i].tag.Equals("Stealth"))
                                hiddenSpace = true;
                            if (triggerArray[i].tag.Equals("Cargo"))
                                cargoSpace = true;
                            if (triggerArray[i].tag.Equals("Destination"))
                                destSpace = true;
                        }
                    }

                    // Everything is good: make space available for the player, and add it to the queue to be checked
                    GameObject tempGrid = (GameObject)GameObject.Instantiate(gridPlane, new Vector3(x, 0f, z), Quaternion.identity);
                    GridSpace  tempGS = tempGrid.GetComponent<GridSpace>();

                    Color gridColor = new Color(50f / 255f, 150f / 255f, 240f / 255f);

                    if (hyperJumping)
                        gridColor = Color.yellow;
                    if (hiddenSpace)
                        gridColor = Color.grey;
                    if (cargoSpace)
                        gridColor = Color.white;
                    if (destSpace)
                        gridColor = Color.green;

                    tempGS.baseColor = gridColor;
                        
                    gridPlanes.Add(tempGrid);

                    GridSquare newSpace = new GridSquare
                    {
                        coordinates = new Vector3(x, 0f, z),
                        hidden = hiddenSpace,
                        cargo = cargoSpace,
                        distance = dist + 1,
                        destination = destSpace
                    };

                    float gridMod = Mathf.Pow(newSpace.distance, 0.1f);

                    tempGrid.transform.localScale /= gridMod;
                    BoxCollider col = tempGrid.GetComponent<BoxCollider>();
                    col.size = new Vector3(col.size.x * gridMod, col.size.y, col.size.z * gridMod);

                    PlayerGrid[(int)posOffset.x, (int)posOffset.y] = newSpace;
                    if (dist + 1 <= 10)
                        BFSQueue.Enqueue(newSpace);
                }
                else
                {
                    GridSquare newSpace = new GridSquare
                    {
                        coordinates = new Vector3(x, 0f, z),
                        hidden = false,
                        cargo = false,
                        distance = 20,
                        destination = false
                    };

                    PlayerGrid[(int)posOffset.x, (int)posOffset.y] = newSpace;
                }
            }
            else if (PlayerGrid[(int)posOffset.x, (int)posOffset.y].distance > (dist + 1))
            {
                PlayerGrid[(int)posOffset.x, (int)posOffset.y].distance = dist + 1;
            }
        }
        else if (posOffset.x <= MAX_MOVE * 2 &&
                posOffset.y <= MAX_MOVE * 2)
        {
            GridSquare newSpace = new GridSquare
            {
                coordinates = new Vector3(x, 0f, z),
                hidden = false,
                cargo = false,
                distance = 20,
                destination = false
            };

            PlayerGrid[(int)posOffset.x, (int)posOffset.y] = newSpace;
        }
    }
示例#46
0
 public void exploreSquare(GridSquare square)
 {
     if (square == Square.Top)
     {
         top = true;
         return;
     }
     if (square == Square.Bottom)
     {
         bottom = true;
         return;
     }
     if (square == Square.Left)
     {
         left = true;
         return;
     }
     if (square == Square.Right)
     {
         right = true;
         return;
     }
 }
示例#47
0
 private void AutoReveal(GridSquare tarGS)
 {
     if (tarGS.adjacencyCount == 0) {
         foreach(GridSquare element in grid)
         {
             if (tarGS.IsAdjacent(element) && element.viewState == ViewState.Hide)
             {
                 ActivateSquare (element);
             }
         }
     }
 }
示例#48
0
 public bool hasExplored(GridSquare square)
 {
     if (square == Square.Top)
         return top;
     if (square == Square.Bottom)
         return bottom;
     if (square == Square.Left)
         return left;
     if (square == Square.Right)
         return right;
     return false;
 }
示例#49
0
	public List<GridSquare> getLegalGridSquares (GridSquare anchor) {
		List<GridSquare> legalGridSquares = new List<GridSquare> ();
		// Add the remaining GridSquare's based on type and orientation
		if (transform.eulerAngles.y > 315 || transform.eulerAngles.y < 45) { // Bow facing north
			facingDirection = "North";
			if (shipName == "Carrier") {
				// Clamp to board
				if (anchor.row > 8)
					anchor.row = 8;
				if (anchor.row < 3)
					anchor.row = 3;
				// Add the (possibly new) anchor first so that it will be in front
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + anchor.column).GetComponent <GridSquare> ());
				// Add the remaining GridSquare's
				legalGridSquares.Add (GameObject.Find ((anchor.row + 2) + " " + anchor.column).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find ((anchor.row + 1) + " " + anchor.column).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find ((anchor.row - 1) + " " + anchor.column).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find ((anchor.row - 2) + " " + anchor.column).GetComponent <GridSquare> ());
			} else if (shipName == "Battleship") {
				// Clamp to board
				if (anchor.row > 8)
					anchor.row = 8;
				if (anchor.row < 2)
					anchor.row = 2;
				// Add the (possibly new) anchor first so that it will be in front
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + anchor.column).GetComponent <GridSquare> ());
				// Add the remaining GridSquare's
				legalGridSquares.Add (GameObject.Find ((anchor.row + 2) + " " + anchor.column).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find ((anchor.row + 1) + " " + anchor.column).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find ((anchor.row - 1) + " " + anchor.column).GetComponent <GridSquare> ());
			} else if (shipName == "Cruiser" || shipName == "Submarine") {
				// Clamp to board
				if (anchor.row > 9)
					anchor.row = 9;
				if (anchor.row < 2)
					anchor.row = 2;
				// Add the (possibly new) anchor first so that it will be in front
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + anchor.column).GetComponent <GridSquare> ());
				// Add the remaining GridSquare's
				legalGridSquares.Add (GameObject.Find ((anchor.row + 1) + " " + anchor.column).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find ((anchor.row - 1) + " " + anchor.column).GetComponent <GridSquare> ());
			} else { // Destroyer
				// Clamp to board
				if (anchor.row > 9)
					anchor.row = 9;
				// Add the (possibly new) anchor first so that it will be in front
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + anchor.column).GetComponent <GridSquare> ());
				// Add the remaining GridSquare
				legalGridSquares.Add (GameObject.Find ((anchor.row + 1) + " " + anchor.column).GetComponent <GridSquare> ());
			}
		} else if (transform.eulerAngles.y <= 135) { // Bow facing west
			facingDirection = "West";
			if (shipName == "Carrier") {
				// Clamp to board
				if (anchor.column > 8)
					anchor.column = 8;
				if (anchor.column < 3)
					anchor.column = 3;
				// Add the (possibly new) anchor first so that it will be in front
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + anchor.column).GetComponent <GridSquare> ());
				// Add the remaining GridSquare's
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column + 2)).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column + 1)).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column - 1)).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column - 2)).GetComponent <GridSquare> ());
			} else if (shipName == "Battleship") {
				// Clamp to board
				if (anchor.column > 9)
					anchor.column = 9;
				if (anchor.column < 3)
					anchor.column = 3;
				// Add the (possibly new) anchor first so that it will be in front
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + anchor.column).GetComponent <GridSquare> ());
				// Add the remaining GridSquare's
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column + 1)).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column - 1)).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column - 2)).GetComponent <GridSquare> ());
			} else if (shipName == "Cruiser" || shipName == "Submarine") {
				// Clamp to board
				if (anchor.column > 9)
					anchor.column = 9;
				if (anchor.column < 2)
					anchor.column = 2;
				// Add the (possibly new) anchor first so that it will be in front
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + anchor.column).GetComponent <GridSquare> ());
				// Add the remaining GridSquare's
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column + 1)).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column - 1)).GetComponent <GridSquare> ());
			} else { // Destroyer
				// Clamp to board
				if (anchor.column < 2)
					anchor.row = 2;
				// Add the (possibly new) anchor first so that it will be in front
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + anchor.column).GetComponent <GridSquare> ());
				// Add the remaining GridSquare
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column - 1)).GetComponent <GridSquare> ());
			}
		} else if (transform.eulerAngles.y <= 225) { // Bow facing south
			facingDirection = "South";
			if (shipName == "Carrier") {
				// Clamp to board
				if (anchor.row > 8)
					anchor.row = 8;
				if (anchor.row < 3)
					anchor.row = 3;
				// Add the (possibly new) anchor first so that it will be in front
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + anchor.column).GetComponent <GridSquare> ());
				// Add the remaining GridSquare's
				legalGridSquares.Add (GameObject.Find ((anchor.row + 2) + " " + anchor.column).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find ((anchor.row + 1) + " " + anchor.column).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find ((anchor.row - 1) + " " + anchor.column).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find ((anchor.row - 2) + " " + anchor.column).GetComponent <GridSquare> ());
			} else if (shipName == "Battleship") {
				// Clamp to board
				if (anchor.row > 9)
					anchor.row = 9;
				if (anchor.row < 3)
					anchor.row = 3;
				// Add the (possibly new) anchor first so that it will be in front
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + anchor.column).GetComponent <GridSquare> ());
				// Add the remaining GridSquare's
				legalGridSquares.Add (GameObject.Find ((anchor.row - 2) + " " + anchor.column).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find ((anchor.row - 1) + " " + anchor.column).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find ((anchor.row + 1) + " " + anchor.column).GetComponent <GridSquare> ());
			} else if (shipName == "Cruiser" || shipName == "Submarine") {
				// Clamp to board
				if (anchor.row > 9)
					anchor.row = 9;
				if (anchor.row < 2)
					anchor.row = 2;
				// Add the (possibly new) anchor first so that it will be in front
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + anchor.column).GetComponent <GridSquare> ());
				// Add the remaining GridSquare's
				legalGridSquares.Add (GameObject.Find ((anchor.row + 1) + " " + anchor.column).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find ((anchor.row - 1) + " " + anchor.column).GetComponent <GridSquare> ());
			} else { // Destroyer
				// Clamp to board
				if (anchor.row < 2)
					anchor.row = 2;
				// Add the (possibly new) anchor first so that it will be in front
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + anchor.column).GetComponent <GridSquare> ());
				// Add the remaining GridSquare
				legalGridSquares.Add (GameObject.Find ((anchor.row - 1) + " " + anchor.column).GetComponent <GridSquare> ());
			}
		} else if (transform.eulerAngles.y <= 315) { // Bow facing east
			facingDirection = "East";
			if (shipName == "Carrier") {
				// Clamp to board
				if (anchor.column > 8)
					anchor.column = 8;
				if (anchor.column < 3)
					anchor.column = 3;
				// Add the (possibly new) anchor first so that it will be in front
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + anchor.column).GetComponent <GridSquare> ());
				// Add the remaining GridSquare's
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column + 2)).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column + 1)).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column - 1)).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column - 2)).GetComponent <GridSquare> ());
			} else if (shipName == "Battleship") {
				// Clamp to board
				if (anchor.column > 8)
					anchor.column = 8;
				if (anchor.column < 2)
					anchor.column = 2;
				// Add the (possibly new) anchor first so that it will be in front
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + anchor.column).GetComponent <GridSquare> ());
				// Add the remaining GridSquare's
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column - 1)).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column + 1)).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column + 2)).GetComponent <GridSquare> ());
			} else if (shipName == "Cruiser" || shipName == "Submarine") {
				// Clamp to board
				if (anchor.column > 9)
					anchor.column = 9;
				if (anchor.column < 2)
					anchor.column = 2;
				// Add the (possibly new) anchor first so that it will be in front
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + anchor.column).GetComponent <GridSquare> ());
				// Add the remaining GridSquare's
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column + 1)).GetComponent <GridSquare> ());
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column - 1)).GetComponent <GridSquare> ());
			} else { // Destroyer
				// Clamp to board
				if (anchor.column > 9)
					anchor.row = 9;
				// Add the (possibly new) anchor first so that it will be in front
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + anchor.column).GetComponent <GridSquare> ());
				// Add the remaining GridSquare
				legalGridSquares.Add (GameObject.Find (anchor.row + " " + (anchor.column + 1)).GetComponent <GridSquare> ());
			}
		}
		return legalGridSquares;
	}
示例#50
0
 private void FlagToggle(GridSquare tarGS)
 {
     if (tarGS.viewState == ViewState.Flag) {
         tarGS.viewState = ViewState.Hide;
     }
     else if (tarGS.viewState == ViewState.Hide)
     {
         tarGS.viewState = ViewState.Flag;
     }
 }
示例#51
0
    private void PopulateGrid(List<GridSquare> gridList)
    {
        for (int i = 0; i < dimension; i++)
        {
            for (int o = 0; o < dimension; o++)
            {
                bool newMinedState;
                if (rndm.Next (10) == 1) {
                    newMinedState = true;
                    mineCount++;
                }
                else
                {
                    newMinedState = false;
                }
                GridSquare newPoint = new GridSquare (i,o,newMinedState);
                gridList.Add (newPoint);

            }
        }

        for (int i = 0; i < grid.Count; i++) {
            grid [i].DetermineAdjacency(grid);
        }
    }
示例#52
0
 public Junction(GridSquare square)
 {
     Square = square;
 }