Example #1
0
        public bool SetOutpost(Player player, BoardVertice vertice)
        {
            // Disqualify if insufficiant resources.
            if (resources.GetDilithium() < 1 || resources.GetTritanium() < 1 || resources.GetFood() < 1 || resources.GetOxygen() < 1)
            {
                return(false);
            }
            // Disqualify if outpost already present.
            if (vertice.HasOutpost())
            {
                return(false);
            }
            // Disqualify if outpost at adjacent vertices and no starship present.
            bool hasStarship = false;

            foreach (BoardVerticePath path in vertice.GetPaths())
            {
                if (path.HasStarship() && path.GetStarship().GetOwner().GetOrder() == order)
                {
                    hasStarship = true;
                }
                if (path.GetToVertice().HasOutpost())
                {
                    return(false);
                }
            }
            if (!hasStarship)
            {
                return(false);
            }
            // Evaluate second degree starship
            foreach (BoardVerticePath path in vertice.GetPaths())
            {
                if (path.HasStarship())
                {
                    foreach (BoardVerticePath nextDegreePath in path.GetToVertice().GetPaths())
                    {
                        if (nextDegreePath.HasStarship() && nextDegreePath.GetStarship().GetOwner().GetOrder() == order && nextDegreePath.GetToVertice().GetLocation() != vertice.GetLocation())
                        {
                            //create outpost
                            Outpost newOutpost = new Outpost(player, vertice);
                            // Add outpost to player
                            outposts.Add(newOutpost);
                            // Add outpost to vertice
                            vertice.SetOutpost(newOutpost);
                            // Remove resources from player
                            resources.RemoveDilithium(1);
                            resources.RemoveTritanium(1);
                            resources.RemoveFood(1);
                            resources.RemoveOxygen(1);
                            // Add points
                            points++;
                            return(true);
                        }
                    }
                }
            }
            // No second degree starship present.
            return(false);
        }
Example #2
0
 public bool SetFirstOutpost(Player player, BoardVertice vertice)
 {
     if (vertice.HasOutpost())
     {
         return(false);
     }
     else
     {
         //create outpost
         Outpost newOutpost = new Outpost(player, vertice);
         // add outpost to player
         outposts.Add(newOutpost);
         // add outpost to vertice
         vertice.SetOutpost(newOutpost);
         //add points
         points++;
         return(true);
     }
 }
        public Board()
        {
            // Create new board


            //Initialize random valued tiles
            int[]  boardResources  = Shuffle(Constants.BOARD_RESOURCES);
            int[]  numberResources = Shuffle(Constants.TILE_ACTIVATORS);
            Tile[] unlinkedTiles   = new Tile[Constants.TOTALTILES];
            for (int i = 0, j = 0; i < Constants.TOTALTILES; i++)
            {
                // Account for Asteroid
                if (boardResources[i] == Constants.NONE)
                {
                    unlinkedTiles[i] = new Tile(i, boardResources[i], 7, Constants.PORTS2VERTICE[i]);
                }
                else
                {
                    unlinkedTiles[i] = new Tile(i, boardResources[i], numberResources[j], Constants.PORTS2VERTICE[i]);
                    j++;
                }
            }

            //Initialize board vertices
            //BoardVertice[] unlinkedBoardVertices = new BoardVertice[Constants.TOTALBOARDVERTICES];
            for (int i = 0; i < Constants.TOTALBOARDVERTICES; i++)
            {
                unlinkedBoardVertices[i] = new BoardVertice(i);
            }

            //Set associated tiles to each board vertice
            for (int i = 0, j = 0; i < Constants.TOTALBOARDVERTICES; i++)
            {
                if (Constants.TILES2VERTICE[j] == Constants.NOTILE)
                {
                    j += 3;
                }
                else if (Constants.TILES2VERTICE[j + 1] == Constants.NOTILE)
                {
                    Tile[] tiles = { unlinkedTiles[Constants.TILES2VERTICE[j]] };
                    unlinkedBoardVertices[i].SetTiles(tiles);
                    j += 3;
                }
                else if (Constants.TILES2VERTICE[j + 2] == Constants.NOTILE)
                {
                    Tile[] tiles = { unlinkedTiles[Constants.TILES2VERTICE[j]], unlinkedTiles[Constants.TILES2VERTICE[j + 1]] };
                    unlinkedBoardVertices[i].SetTiles(tiles);
                    j += 3;
                }
                else
                {
                    Tile[] tiles = { unlinkedTiles[Constants.TILES2VERTICE[j]], unlinkedTiles[Constants.TILES2VERTICE[j + 1]], unlinkedTiles[Constants.TILES2VERTICE[j + 2]] };
                    unlinkedBoardVertices[i].SetTiles(tiles);
                    j += 3;
                }
            }



            //Set associated paths to each board vertice
            for (int i = 0, j = 0; i < Constants.TOTALBOARDVERTICES; i++)
            {
                if (Constants.PATHS2VERTICE[j] == Constants.NONE)
                {
                    j += 3;
                }
                else if (Constants.PATHS2VERTICE[j + 1] == Constants.NONE)
                {
                    BoardVerticePath[] paths = { new BoardVerticePath(unlinkedBoardVertices[i], unlinkedBoardVertices[Constants.PATHS2VERTICE[j]]) };
                    unlinkedBoardVertices[i].SetPaths(paths);
                    j += 3;
                }
                else if (Constants.PATHS2VERTICE[j + 2] == Constants.NONE)
                {
                    BoardVerticePath[] paths = { new BoardVerticePath(unlinkedBoardVertices[i], unlinkedBoardVertices[Constants.PATHS2VERTICE[j]]),
                                                 new BoardVerticePath(unlinkedBoardVertices[i], unlinkedBoardVertices[Constants.PATHS2VERTICE[j + 1]]) };
                    unlinkedBoardVertices[i].SetPaths(paths);
                    j += 3;
                }
                else
                {
                    BoardVerticePath[] paths = { new BoardVerticePath(unlinkedBoardVertices[i], unlinkedBoardVertices[Constants.PATHS2VERTICE[j]]),
                                                 new BoardVerticePath(unlinkedBoardVertices[i], unlinkedBoardVertices[Constants.PATHS2VERTICE[j + 1]]),
                                                 new BoardVerticePath(unlinkedBoardVertices[i], unlinkedBoardVertices[Constants.PATHS2VERTICE[j + 2]]) };
                    unlinkedBoardVertices[i].SetPaths(paths);
                    j += 3;
                }
            }
        }
 public Outpost(Player owner, BoardVertice location)
 {
     pointValue    = Constants.OUTPOST;
     this.owner    = owner;
     this.location = location;
 }
 public BoardVerticePath(BoardVertice fromVertice, BoardVertice toVertice)
 {
     this.fromVertice = fromVertice;
     this.toVertice   = toVertice;
     occupied         = false;
 }