コード例 #1
0
        //Control game to add the unit to the board
        public void AddUnit()
        {
            //Prompt user to select the unit to be added to the board
            Console.WriteLine("Choose Unit");

            bool unitSelected = false;
            int  unitInt      = 0;

            //loop to select unit to be added
            while (!unitSelected)
            {
                Console.WriteLine(GetUnitList());
                try
                {
                    unitInt = Convert.ToInt32(Console.ReadLine());
                    if (unitInt < 3 && unitInt >= 0)
                    {
                        unitSelected = true;
                    }
                }
                catch (FormatException e)
                {
                    Console.WriteLine("Not an integer, Please enter an integer.");
                }
            }

            //Prompt user to choose location
            Console.WriteLine("Choose Space");

            bool            spaceSelected    = false;
            string          userCoords       = "";
            SpaceCoordinate lSpaceCoordinate = new SpaceCoordinate();

            //loop to select board space
            while (!spaceSelected)
            {
                Console.Write("Enter Coordinates [X, Y]: ");
                userCoords       = Console.ReadLine();
                lSpaceCoordinate = SpaceCoordinate.ParseCoordinate(userCoords);
                if (lSpaceCoordinate != null)
                {
                    if (ConfirmValidPlacement(mBoardOfPlay, lSpaceCoordinate))
                    {
                        spaceSelected = true;
                    }
                    else
                    {
                        Console.WriteLine("That coordinate is not valid for placement");
                    }
                }
                else
                {
                    Console.WriteLine("Input not a valid Coordinate");
                }
            }

            //use game controller to add a unit to the game board
            //using a basic unit and a parsed coordinate
            PlaceUnit(Unit.GetBasicUnit(unitInt), lSpaceCoordinate);
        }
コード例 #2
0
        /**
         * Constructor - Instantiate a grid given the bounds to be used, allows for negative bounds
         * Though this isn't really used so may be unnecessary.
         * Note - As this version is not prepared for delivery, it only insantiates a rectangular board in which
         * all nodes are walkable and targetable
         */
        public NodeGrid(int minXCoordArg, int maxXCoordArg, int minYCoordArg, int maxYCoordArg)
        {
            mBoardNodes = new List <BoardNode>();
            for (int i = minXCoordArg; i < maxXCoordArg; i++)
            {
                for (int j = minYCoordArg; j < maxYCoordArg; j++)
                {
                    SpaceCoordinate lCoord     = new SpaceCoordinate(i, j);
                    BoardNode       lBoardNode = new BoardNode(lCoord, true, true);
                    mBoardNodes.Add(lBoardNode);
                }
            }
            mXBounds    = new int[2];
            mXBounds[0] = minXCoordArg;
            mXBounds[1] = maxXCoordArg;

            mYBounds    = new int[2];
            mYBounds[0] = minYCoordArg;
            mYBounds[1] = maxYCoordArg;

            //Instantiate all directions on the node grid, there may be a better place to put these
            //but this allowed me to begin testing other features
            SpaceMovement DIR_UP         = new SpaceMovement(-1, 0, 10);
            SpaceMovement DIR_DOWN       = new SpaceMovement(1, 0, 10);
            SpaceMovement DIR_RIGHT      = new SpaceMovement(0, 1, 10);
            SpaceMovement DIR_LEFT       = new SpaceMovement(0, -1, 10);
            SpaceMovement DIR_UP_RIGHT   = new SpaceMovement(1, 1, 14);
            SpaceMovement DIR_UP_LEFT    = new SpaceMovement(1, -1, 14);
            SpaceMovement DIR_DOWN_RIGHT = new SpaceMovement(-1, 1, 14);
            SpaceMovement DIR_DOWN_LEFT  = new SpaceMovement(-1, -1, 14);

            //Two lists for containing all directions
            mBaseDir = new List <SpaceMovement>();
            mAllDir  = new List <SpaceMovement>();

            //Add the cardinal directions to the base direction list, in clockwise order
            mBaseDir.Add(DIR_UP);
            mBaseDir.Add(DIR_RIGHT);
            mBaseDir.Add(DIR_DOWN);
            mBaseDir.Add(DIR_LEFT);

            //Add all 8 directions to the all direction list, in clockwise order
            mAllDir.Add(DIR_UP);
            mAllDir.Add(DIR_UP_RIGHT);
            mAllDir.Add(DIR_RIGHT);
            mAllDir.Add(DIR_DOWN_RIGHT);
            mAllDir.Add(DIR_DOWN);
            mAllDir.Add(DIR_DOWN_LEFT);
            mAllDir.Add(DIR_LEFT);
            mAllDir.Add(DIR_UP_LEFT);

            //Instatiate each node's neighbor list
            foreach (BoardNode iNode in this.BoardNodes)
            {
                iNode.Neighbors = BoardNode.IdentifyNeighbors(this, iNode.Coordinates);
            }
        }
コード例 #3
0
        //checks if a space coordinate is within the bounds of the board, often used to check move validity
        public static bool withinBounds(Board boardArg, SpaceCoordinate coordArg)
        {
            bool xInBounds = false, yInBounds = false;

            if (coordArg.XCoordinate >= boardArg.NodeGrid.XBounds[0] && coordArg.XCoordinate < boardArg.NodeGrid.XBounds[1])
            {
                xInBounds = true;
            }
            if (coordArg.YCoordinate >= boardArg.NodeGrid.YBounds[0] && coordArg.YCoordinate < boardArg.NodeGrid.YBounds[1])
            {
                yInBounds = true;
            }
            return(xInBounds && yInBounds);
        }
コード例 #4
0
        //Nodes need to know what their neighbors are for pathfinding to be efficient
        public static List <BoardNode> IdentifyNeighbors(NodeGrid gridArg, SpaceCoordinate coordArg)
        {
            List <BoardNode> lNeighbors = new List <BoardNode>();

            foreach (SpaceMovement iMove in gridArg.ALL_DIRECTIONS)
            {
                SpaceCoordinate possNeighborCoord = coordArg.CoordAtMove(iMove);
                BoardNode       lNode             = gridArg.BoardNodes.Find(x => x.Coordinates.Equals(coordArg));
                if (lNode != null)
                {
                    lNeighbors.Add(lNode);
                }
            }
            return(lNeighbors);
        }
コード例 #5
0
 //Confirms that the given coordinate is open for placement of a boardpiece
 public bool ConfirmValidPlacement(Board boardArg, SpaceCoordinate coordArg)
 {
     if (mBoardOfPlay.GetOccupiedCoords().Contains(coordArg))
     {
         return(false);
     }
     if (!mBoardOfPlay.SpaceWalkable(coordArg))
     {
         return(false);
     }
     if (!Board.withinBounds(boardArg, coordArg))
     {
         return(false);
     }
     return(true);
 }
コード例 #6
0
        public BoardNode(SpaceCoordinate coordArg, bool walkArg, bool aimBool)
        {
            //Coordinates representing position
            mSpaceCoordinate = coordArg;

            //booleans used for pathfinding and targetting enemies
            IsWalkable = walkArg;
            IsAimable  = aimBool;

            //FGH costs are the values used to improve pathfinding in A*
            mGCostInt = 0;
            mHCostInt = 0;
            mFCostInt = 0;

            //used to track the last space in a particular path
            mParentNode = null;
        }
コード例 #7
0
        public string GetBoardString()
        {
            StringBuilder boardBuilder = new StringBuilder();
            StringBuilder rowBuilder   = new StringBuilder();
            List <String> rowList      = new List <String>();

            for (int iRow = mBoardVar.NodeGrid.YBounds[1] - 1; iRow >= mBoardVar.NodeGrid.YBounds[0]; iRow--)
            {
                for (int iCol = mBoardVar.NodeGrid.XBounds[0]; iCol <= mBoardVar.NodeGrid.XBounds[1] - 1; iCol++)
                {
                    SpaceCoordinate lCoord  = new SpaceCoordinate(iCol, iRow);
                    var             testVal = mBoardVar.BoardSpaces.Find(x => x.Node.Coordinates.Equals(lCoord));
                    rowBuilder.Append(mBoardVar.BoardSpaces.Find(x => x.Node.Coordinates.Equals(lCoord)).Icon);
                }
                rowList.Add(rowBuilder.ToString());
                rowBuilder.Clear();
            }
            int yAxis = mBoardVar.NodeGrid.YBounds[1] - 1;

            foreach (string iString in rowList)
            {
                boardBuilder.Append(yAxis);
                boardBuilder.Append(iString);
                if (yAxis == 0)
                {
                    boardBuilder.Append("\r\n");
                    boardBuilder.Append(" ");
                    for (int xAxis = mBoardVar.NodeGrid.XBounds[0]; xAxis < mBoardVar.NodeGrid.XBounds[1]; xAxis++)
                    {
                        boardBuilder.Append(xAxis.ToString());
                    }
                }
                boardBuilder.Append("\r\n");
                yAxis--;
            }
            return(boardBuilder.ToString());
        }
コード例 #8
0
 //returns if a board space is walkable, but this may not be necessary
 //Atrifacted by addition of nodes, likely could be replaced
 public bool SpaceWalkable(SpaceCoordinate coordArg)
 {
     return(GetBoardSpace(coordArg).Node.IsWalkable);
 }
コード例 #9
0
        //returns the board space that is at a particular movement from an initial coordinate
        public BoardSpace SpaceAtMove(SpaceCoordinate coordArg, SpaceMovement moveArg)
        {
            SpaceCoordinate lCoord = coordArg.CoordAtMove(moveArg);

            return(GetBoardSpace(lCoord));
        }
コード例 #10
0
        //Searches the board for a board space when given a coordinate
        //I welcome optimization of this, if you can think of a better way.
        private BoardSpace GetBoardSpace(SpaceCoordinate coordArg)
        {
            var testVal = this.BoardSpaces.Find(x => x.Node.Coordinates.Equals(coordArg));

            return(testVal);
        }
コード例 #11
0
 //Returns the character that represents whatever Icon a boardspace has
 public char GetSpaceIcon(SpaceCoordinate coordArg)
 {
     return(GetBoardSpace(coordArg).Icon);
 }
コード例 #12
0
 //Place a board piece at a coordinate, straightforward
 public void SetBoardPieceAt(BoardPiece pieceArg, SpaceCoordinate coordArg)
 {
     GetBoardSpace(coordArg).SetNewPieceValue(pieceArg);
 }
コード例 #13
0
 //Returns the boardpiece at a coordinate
 public BoardPiece GetBoardPieceAt(SpaceCoordinate coordArg)
 {
     return(GetBoardSpace(coordArg).PieceAt);
 }
コード例 #14
0
 public BoardNode GetNodeAt(SpaceCoordinate coordArg)
 {
     return(mBoardNodes.Find(x => x.Coordinates.Equals(coordArg)));
 }
コード例 #15
0
 public bool Equals(SpaceCoordinate other)
 {
     return(other != null &&
            this.Coordinates.XCoordinate == other.XCoordinate &&
            this.Coordinates.YCoordinate == other.YCoordinate);
 }
コード例 #16
0
        static void Main(string[] args)
        {
            //Instatiate Controller, and Boardview to fascilitate gameplay
            Game_Controller main_Controller = new Game_Controller();
            BoardView       main_BoardView  = new BoardView();

            main_BoardView.Board = main_Controller.GetBoard();


            Console.WriteLine(".");
            //Begin the actual game

            //set loop bolean true
            bool gameContinue = true;
            //Place two starting units
            SpaceCoordinate coordOne = new SpaceCoordinate(4, 2);
            SpaceCoordinate coordTwo = new SpaceCoordinate(5, 3);

            main_Controller.PlaceUnit(Unit.GetBasicUnit(1), coordOne);
            main_Controller.PlaceUnit(Unit.GetBasicUnit(0), coordTwo);

            //Actual gameplay loop
            while (gameContinue)
            {
                //Display the console after each cycle
                main_BoardView.PrintBoardConsole();
                //Query user
                Console.WriteLine("What would you like to do?");

                //Loop Control and user input  declaration
                bool optionSelected = false;
                int  userInt        = 0;

                //Action selection loop
                while (!optionSelected)
                {
                    //Game controller offers selection options
                    Console.WriteLine(main_Controller.GetOptionsList());
                    try
                    {
                        userInt = Convert.ToInt32(Console.ReadLine());
                        if (userInt < main_Controller.GetOptionsList().Length)
                        {
                            optionSelected = true;
                        }
                    }
                    catch (FormatException e)
                    {
                        Console.WriteLine("Not an integer, Please enter an integer.");
                    }
                }

                switch (userInt)
                {
                case 0:
                    //User wants to put a new unit onto the board
                    main_Controller.AddUnit();
                    break;

                case 1:
                    //User wants to do an action of a particular unit
                    main_Controller.SelectToken();
                    break;

                default:
                    Console.WriteLine("default");
                    break;
                }
            }
        }
コード例 #17
0
        //Places a unit at a coordinate
        public void PlaceUnit(Unit unitArg, SpaceCoordinate coordArg)
        {
            BoardPiece placedPiece = new BoardPiece(unitArg);

            mBoardOfPlay.SetBoardPieceAt(placedPiece, coordArg);
        }