public String setComputerName() { String[] computerNames = { "R2-D2", "Awesome-O", "Robbie the Robot", "C3PO", "Marvin", "Deep Thought", "Hal-9000", "Terminator", "The Borg", "Milton", "Tony the Robot", "Sonny", "Bender", "Calculon" }; computerNameGenerator.SetMinimum(0); computerNameGenerator.SetMaximum(13); Byte indexNumber = Convert.ToByte(computerNameGenerator.GenerateRandomNumber()); return(computerNames[indexNumber]); }
/**@author Paul Harvey * * Set the ship size. Between 2 and 6. */ public Byte setShipSize(Byte min, Byte max) { shipSizeGenerator.SetMinimum(min); shipSizeGenerator.SetMaximum(max); Byte size = Convert.ToByte(shipSizeGenerator.GenerateRandomNumber()); return(size); }
public Byte setNumComputerShips() { numComputerShipsGenerator.SetMinimum(2); numComputerShipsGenerator.SetMaximum(5); Byte numComputerShips = Convert.ToByte(numComputerShipsGenerator.GenerateRandomNumber()); return(numComputerShips); }
public String setSecondPosition(Byte size, String coord, String[,] board) { String[,] placeholderBoard = board; Boolean errorFlag = false; /* * giveOptions: procedure that chooses up to 4 available options. * The computer user will randomly choose the second position. */ giveOptions(size, coord, placeholderBoard); Boolean LoopBreak = true; do { directionGenerator.SetMinimum(0); directionGenerator.SetMaximum(3); direction = Convert.ToByte(directionGenerator.GenerateRandomNumber()); Debug.WriteLine("availOptions[" + direction + "] =" + availOptions[direction]); if (availOptions[direction].Equals("XX")) { // dont break loop LoopBreak = true; } else { secondCoord = availOptions[direction]; LoopBreak = false; } if (availOptions[0].Equals("XX") && availOptions[1].Equals("XX") && availOptions[2].Equals("XX") && availOptions[2].Equals("XX")) { // God forbid we end up in an endless loop. secondCoord = "XX"; LoopBreak = false; errorFlag = true; } Debug.WriteLine("Ship Class - Setting Direction"); } while (LoopBreak == true); // peel out the individual coordinates if (!errorFlag) { Char xcharCoord = secondCoord[0]; Char ycharCoord = secondCoord[1]; secondCoordinates = "" + xcharCoord.ToString() + ycharCoord.ToString(); } return(secondCoordinates); }
/**@author Paul Harvey * * Set the first position of the boat. The human will require coordinate * validation. The computer will not. * * @param playerNum */ public String setFirstPosition() { xCoordGenerator.SetMinimum(0); xCoordGenerator.SetMaximum(9); xCoord = Convert.ToByte(xCoordGenerator.GenerateRandomNumber()); yCoordGenerator.SetMinimum(0); yCoordGenerator.SetMaximum(9); yCoord = Convert.ToByte(yCoordGenerator.GenerateRandomNumber()); firstCoordinates = "" + xCoord.ToString() + yCoord.ToString(); return(firstCoordinates); }