public ShipModel(int x, int y, int floorCount, vectorSide vector) { this.startX = x; this.startY = y; this.currentVector = vector; this.floorHealth = this.getFloorHealth(); this.shipMaxHealth = this.getShipMaxHealth(floorCount); this.statusFloorHealth = this.initStatusFloorHealth(floorCount); this.canBottomVector = this.getVectorValue(vectorSide.bottom); this.canTopVector = this.getVectorValue(vectorSide.top); this.canLeftVector = this.getVectorValue(vectorSide.left); this.canLeftDiagonalVector = this.getVectorValue(vectorSide.leftDiagonal); this.canRightDiagonaVector = this.getVectorValue(vectorSide.rightDiagonal); this.canRightVector = this.getVectorValue(vectorSide.right); this.vectorShip = this.getVectorShip(vector, floorCount, x, y); }
protected bool getVectorValue(vectorSide vectorSide) { string[] vectors = ConfigurationManager.AppSettings["VecrtorShipSides"].Split(','); foreach (string vector in vectors) { if (vector.Contains("All")) { return(true); } else if (vectorSide == vectorSide.top & vector.Trim().Contains("Top")) { return(true); } else if (vectorSide == vectorSide.bottom & vector.Trim().Contains("Bottom")) { return(true); } else if (vectorSide == vectorSide.left & vector.Trim().Contains("Left")) { return(true); } else if (vectorSide == vectorSide.leftDiagonal & vector.Trim().Contains("LeftDiagonal")) { return(true); } else if (vectorSide == vectorSide.left & vector.Trim().Contains("Right")) { return(true); } else if (vectorSide == vectorSide.leftDiagonal & vector.Trim().Contains("RightDiagonal")) { return(true); } else { return(false); } } return(false); }
protected List <int[]> getVectorShip(vectorSide side, int floorCount, int xStart, int yStart) { List <int[]> result = new List <int[]>(); if (side == vectorSide.top) { for (int i = yStart; i >= 0; i--) { int[] point = { i, xStart }; result.Add(point); } } if (side == vectorSide.bottom) { for (int i = yStart; i < floorCount; i++) { int[] point = { i, xStart }; result.Add(point); } } if (side == vectorSide.left) { for (int i = xStart; i >= 0; i--) { int[] point = { yStart, i }; result.Add(point); } } if (side == vectorSide.right) { for (int i = xStart; i < floorCount; i++) { int[] point = { yStart, i }; result.Add(point); } } if (side == vectorSide.leftDiagonal) { for (int i = yStart; i >= 0; i--) { for (int j = xStart; j >= 0; j--) { int[] point = { i, j }; result.Add(point); } } } if (side == vectorSide.leftDiagonal) { for (int i = yStart; i < floorCount; i++) { for (int j = xStart; j < floorCount; j++) { int[] point = { i, j }; result.Add(point); } } } return(result); }