Difference between revisions of "2021 - Tile"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "=Actual Code= <syntaxhighlight lang=c#> </syntaxhighlight> =Things to note= Protected Virtual Constructor")
 
(Things to note)
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
=Actual Code=
 
=Actual Code=
 
<syntaxhighlight lang=c#>
 
<syntaxhighlight lang=c#>
 +
class Tile
 +
    {
 +
        protected string terrain;
 +
        protected int x, y, z;
 +
        protected Piece pieceInTile;
 +
        protected List<Tile> neighbours = new List<Tile>();
  
 +
        public Tile(int xcoord, int ycoord, int zcoord)
 +
        {
 +
            x = xcoord;
 +
            y = ycoord;
 +
            z = zcoord;
 +
            terrain = " ";
 +
            pieceInTile = null;
 +
        }
 +
 +
        public int GetDistanceToTileT(Tile t)
 +
        {
 +
            return Math.Max(Math.Max(Math.Abs(Getx() - t.Getx()), Math.Abs(Gety() - t.Gety())), Math.Abs(Getz() - t.Getz()));
 +
        }
 +
 +
        public void AddToNeighbours(Tile n)
 +
        {
 +
            neighbours.Add(n);
 +
        }
 +
 +
        public List<Tile> GetNeighbours()
 +
        {
 +
            return neighbours;
 +
        }
 +
 +
        public void SetPiece(Piece thePiece)
 +
        {
 +
            pieceInTile = thePiece;
 +
        }
 +
 +
        public void SetTerrain(string t)
 +
        {
 +
            terrain = t;
 +
        }
 +
 +
        public int Getx()
 +
        {
 +
            return x;
 +
        }
 +
 +
        public int Gety()
 +
        {
 +
            return y;
 +
        }
 +
 +
        public int Getz()
 +
        {
 +
            return z;
 +
        }
 +
 +
        public string GetTerrain()
 +
        {
 +
            return terrain;
 +
        }
 +
 +
        public Piece GetPieceInTile()
 +
        {
 +
            return pieceInTile;
 +
        }
 +
    }
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
=Things to note=
 +
This is a single tile in the grid/HexGrid.
  
=Things to note=
+
This is a containing class for Piece's, ie the piece currently on this tile.
Protected
 
  
Virtual
+
Use of protected.
  
Constructor
+
Use of public.

Latest revision as of 11:53, 3 September 2020

Actual Code

class Tile
    {
        protected string terrain;
        protected int x, y, z;
        protected Piece pieceInTile;
        protected List<Tile> neighbours = new List<Tile>();

        public Tile(int xcoord, int ycoord, int zcoord)
        {
            x = xcoord;
            y = ycoord;
            z = zcoord;
            terrain = " ";
            pieceInTile = null;
        }

        public int GetDistanceToTileT(Tile t)
        {
            return Math.Max(Math.Max(Math.Abs(Getx() - t.Getx()), Math.Abs(Gety() - t.Gety())), Math.Abs(Getz() - t.Getz()));
        }

        public void AddToNeighbours(Tile n)
        {
            neighbours.Add(n);
        }

        public List<Tile> GetNeighbours()
        {
            return neighbours;
        }

        public void SetPiece(Piece thePiece)
        {
            pieceInTile = thePiece;
        }

        public void SetTerrain(string t)
        {
            terrain = t;
        }

        public int Getx()
        {
            return x;
        }

        public int Gety()
        {
            return y;
        }

        public int Getz()
        {
            return z;
        }

        public string GetTerrain()
        {
            return terrain;
        }

        public Piece GetPieceInTile()
        {
            return pieceInTile;
        }
    }

Things to note

This is a single tile in the grid/HexGrid.

This is a containing class for Piece's, ie the piece currently on this tile.

Use of protected.

Use of public.