id
stringlengths 36
36
| text
stringlengths 1
1.25M
|
---|---|
251c7bf2-d677-4207-be21-54170930df0c
|
@Test
public void testCreateExceptionNullMessageNullCause() throws Exception {
final RuntimeException exception = Reflections.createException(IllegalStateException.class, null, null);
assertTrue(exception.getClass().equals(IllegalStateException.class));
}
|
7284060e-2cf1-4996-8976-c9b63e9804c0
|
@Test
public void testCreateExceptionInvalidConstructor() throws Exception {
this.ee.expect(IllegalStateException.class);
this.ee.expectMessage("No constructor with no arguments found");
Reflections.createException(TestException.class, null, null);
}
|
dc56760b-9dad-429e-b2eb-65e7e105aff3
|
public TestException() {
super();
}
|
88741f95-f754-4280-9ce3-a2d42597e89c
|
public static void startGangup() {
int playerNumber = 1;
int[][] board = new int[8][8];
GuiMaster.println("Welcome to TB Game's Gangup. \n");
board = clearGangupBoard(board);
gangupLoop(board);
}
|
9f557367-b76b-4272-bf55-5981dc63665d
|
private static void gangupLoop(int[][] board) {
boolean continueLoop = true;
int playerNumber = 1;
int turnNumber = 1;
int consecutiveConectionsRequired = 3;
int numberOfPlayers = 4;
GangupDataObject recievedDataObject;
while (continueLoop == true){
recievedDataObject = placePiece(board, playerNumber);
if(recievedDataObject.getIsPiecePlaced()) {
if(checkForWin(turnNumber, recievedDataObject.getInputX(), recievedDataObject.getInputY(),
recievedDataObject.getBoard(), consecutiveConectionsRequired, numberOfPlayers)){
win(playerNumber);
continueLoop = false;
};
turnNumber++;
if(playerNumber < 4){
playerNumber++;
}
else{
playerNumber = 1;
}
}
else invalidMove();
}
}
|
cb7ceae5-1272-4539-a022-26480fbe3a84
|
private static GangupDataObject placePiece(int[][] board, int playerNumber){
int inputX, inputY;
int[] inputArray;
int[] inputAndPiecePlacedArray = new int[3];
inputArray = inputMove(board, playerNumber);
inputX = inputArray[0];
inputY = inputArray[1];
boolean isPiecePlaced = checkMove(inputX, inputY, board, playerNumber);
GangupDataObject returnObject = new GangupDataObject(isPiecePlaced, inputX, inputY, board);
return returnObject;
}
|
aa0f3418-0739-40c0-badc-2ad83daf1eef
|
private static int[] inputMove(int[][] board, int playerNumber){
GuiMaster.println("Player #" + playerNumber);
printGangupBoard(board);
GuiMaster.println("Where do you want to go?" + "\n" + "X:");
String tempString = GuiMaster.getEnteredText().trim();
int inputX;
int inputY;
if(tempString.matches("[1234567890]*")){
inputX = Integer.parseInt(tempString);
}
else{
inputX = -1;
}
GuiMaster.println("Y:");
tempString = GuiMaster.getEnteredText().trim();
if(tempString.matches("[1234567890]*")){
inputY = Integer.parseInt(tempString);
}
else{
inputY = -1;
}
int[] inputArray = {inputX, inputY};
return inputArray;
}
|
82a61ba3-0699-4fbe-91e3-7227a87030de
|
private static boolean checkMove(int inputX, int inputY, int [][] board, int playerNumber) {
if ((inputX <= 8 && inputX >= 1) && (inputY <= 8 && inputY >= 1) &&
(board[inputX-1][inputY-1]== 0)){
board[inputX-1][inputY-1] = playerNumber;
return true;
}
else{
return false;
}
}
|
6b28eb60-0606-4d0d-be83-57d8b337cf33
|
private static int[][] clearGangupBoard(int[][] board) {
for (int x = 0; x <= 7; x++) {
for (int y = 0; y <= 7; y++) {
board[x][y] = 0;
}
}
return board;
}
|
43c2373c-55ef-4b38-ae04-c6b190b78ed6
|
private static void printGangupBoard(int[][] board) {
for (int y = 8; y >= 1; y--) {
String stringToPrint= y + " ";
for (int x = 1; x <= 8; x++) {
stringToPrint+= board[x-1][y-1] + " ";
}
GuiMaster.println(stringToPrint);
}
GuiMaster.println("\n" + " 1 2 3 4 5 6 7 8");
}
|
4df9da45-cf67-4693-ae26-93e6ae38d4d3
|
private static void invalidMove() {
System.out.println("Invalid Move");
}
|
f1113000-4daa-4287-87fb-79b7c5f25727
|
private static boolean checkForWin(int turnNumber, int inputX, int inputY, int[][] board,
int consecutiveConectionsRequired, int numberOfPlayers){
if(turnNumber > (numberOfPlayers * (consecutiveConectionsRequired - 1))){
if(checkGrid(board[inputX-1][inputY-1], board, consecutiveConectionsRequired)){
return true;
}
}
return false;
}
|
98abc9d7-c2e8-465e-b489-ac5cfdfa8cd9
|
public static boolean checkGrid(int playerType, int [][] grid,
int consecutiveConectionsRequired){
int rows = grid.length;
int columns = grid[0].length;
// Check downward
for (int i = 0; i <= rows - consecutiveConectionsRequired; i++)
{
for (int j = 0; j < columns; j++)
{
int counter = 0;
for (int k = i; k < consecutiveConectionsRequired + i; k++)
{
if (grid[k][j] == playerType)
counter++;
}
if (counter == consecutiveConectionsRequired)
return true;
}
}
// Check across
for (int i = 0; i <= columns - consecutiveConectionsRequired; i++)
{
for (int j = 0; j < rows; j++)
{
int counter = 0;
for (int k = i; k < consecutiveConectionsRequired + i; k++)
{
if (grid[j][k] == playerType)
counter++;
}
if (counter == consecutiveConectionsRequired)
return true;
}
}
// Check left to right diagonally
for (int i = 0; i <= rows - consecutiveConectionsRequired; i++)
{
for (int j = 0; j <= columns - consecutiveConectionsRequired; j++)
{
int counter = 0;
for (int k = i, m = j; k < consecutiveConectionsRequired + i; k++, m++)
{
if (grid[k][m] == playerType)
counter++;
}
if (counter == consecutiveConectionsRequired)
return true;
}
}
// Check right to left diagonally
for (int i = 0; i <= rows - consecutiveConectionsRequired; i++)
{
for (int j = columns - 1; j >= columns - consecutiveConectionsRequired; j--)
{
int counter = 0;
for (int k = i, m = j; k < consecutiveConectionsRequired + i; k++, m--)
{
if (grid[k][m] == playerType)
counter++;
}
if (counter == consecutiveConectionsRequired)
return true;
}
}
return false;
}
|
909a86a7-3c2b-4c72-bb9f-3efbd5e389ca
|
private static void win(int playerNumber) {
GuiMaster.println("Good job player #" + playerNumber);
}
|
5a7c1b78-4378-4c56-ba1d-3f9859312563
|
public GangupDataObject(boolean isPiecePlaced, int inputX, int inputY, int[][] board){
this.isPiecePlaced = isPiecePlaced;
this.inputX = inputX;
this.inputY = inputY;
this.board = board;
}
|
972e2f5d-adc5-4694-9c65-966970ce5989
|
public GangupDataObject(){
isPiecePlaced = false;
inputX = -1;
inputY = -1;
board = null;
}
|
7ac5a045-1157-4c06-9dec-e1e7865c2344
|
public boolean getIsPiecePlaced(){
return isPiecePlaced;
}
|
3fafbfe8-b160-4078-91ba-6bdd5b2d8088
|
public int getInputX(){
return inputX;
}
|
b60c20ca-78f1-4fcb-81ff-73203fe572b6
|
public int getInputY(){
return inputY;
}
|
fd78cec1-c3d3-412c-946e-a5240050ec23
|
public int[][] getBoard(){
return board;
}
|
61529b93-c9fe-4d37-8b87-d24ec996e570
|
public static String capitalizeFully(String string){
boolean lastWasSpace = false;
char[] stringArray = string.toCharArray();
if(stringArray.length == 0){
return "-1";
}
for (int x = 0;x <= stringArray.length - 1; x++){
if(stringArray[x] == ' '){
lastWasSpace = true;
}
else if(lastWasSpace){
stringArray[x] = Character.toUpperCase(stringArray[x]);
lastWasSpace = false;
}
else if(x == 0){
stringArray[0] = Character.toUpperCase(stringArray[0]);
}
}
string = new String(stringArray);
return string;
}
|
28d0f7a8-f984-4dbe-a43d-d8247528c90a
|
public static String capitalizeEveryWord(String string){
boolean lastWasSpace = false;
char[] stringArray = string.toCharArray();
if(stringArray.length == 0){
return "-1";
}
stringArray[0] = Character.toUpperCase(stringArray[0]);
for (int x = 1;x <= stringArray.length - 1; x++){
if(stringArray[x] == ' '){
lastWasSpace = true;
}
else if(lastWasSpace){
stringArray[x] = Character.toUpperCase(stringArray[x]);
lastWasSpace = false;
}
else{
stringArray[x] = Character.toLowerCase(stringArray[x]);
}
}
string = new String(stringArray);
return string;
}
|
40047bf2-2601-4291-9d98-7671c16c5476
|
public static String capitalizeFirstLetter(String string){
char[] stringArray = string.toCharArray();
if(stringArray.length == 0){
return "-1";
}
stringArray[0] = Character.toUpperCase(stringArray[0]);
string = new String(stringArray);
return string;
}
|
4e348ff2-131f-499e-b5bd-21c540726c3b
|
public static String capitalizeFirstLetterOnly(String string){
char[] stringArray = string.toCharArray();
if(stringArray.length == 0){
return "-1";
}
stringArray[0] = Character.toUpperCase(stringArray[0]);
for (int x = 1;x <= stringArray.length - 1; x++){
stringArray[x] = Character.toLowerCase(stringArray[x]);
}
string = new String(stringArray);
return string;
}
|
4a42fc68-0f8a-4741-ae07-1b05143389c6
|
public static void startGui(){
JPanel middlePanel = new JPanel ();
middlePanel.setBorder(new TitledBorder(new EtchedBorder (), "TB Game" ) );
// create the middle panel components
display = new JTextArea(16,58 );
JScrollPane scroll = new JScrollPane(display);
display.getDocument().addDocumentListener(new AL());
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
//Add Textarea in to middle panel
middlePanel.add(scroll);
JFrame frame = new JFrame();
frame.add( middlePanel );
frame.setTitle("TB Game");
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
|
a5186930-2b7d-46a2-803e-7126b62d77b5
|
private static void setEnteredText(String enteredText) {
// TODO Auto-generated method stub
lastEnteredText = enteredText;
haveRecivedInput = true;
}
|
ac2b6891-f2bb-409e-a2a2-9f7ab7444adb
|
public static String getEnteredText(){
while(!haveRecivedInput){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
haveRecivedInput = false;
display.setCaretPosition(display.getDocument().getLength());
return lastEnteredText;
}
|
38796028-93de-49fc-a605-17b4f97a9fe3
|
public static void println(String message){
display.append(message + "\n");
haveRecivedInput = false;
display.setCaretPosition(display.getDocument().getLength());
}
|
b0fa9c9f-1b60-401f-bbec-34dc01d77922
|
@Override
public void insertUpdate(DocumentEvent e) {
boolean haveNotEncounteredInvis = true;
char lastChar;
String fieldText = null;
Document doc = (Document)e.getDocument();
try {
fieldText =doc.getText(0, doc.getLength());
} catch (BadLocationException e1) {
e1.printStackTrace();
}
if(fieldText.length() > 1){
lastChar = fieldText.charAt(fieldText.length() - 1);
if(lastChar == '\n'){
int x = fieldText.length()-2;
String enteredText = "";
char currentChar;
while(haveNotEncounteredInvis){
currentChar = fieldText.charAt(x);
if(currentChar == '\n' ){
setEnteredText(enteredText);
haveNotEncounteredInvis = false;
display.setCaretPosition(display.getDocument().getLength());
}
else if(x == 0){
enteredText = currentChar + enteredText;
setEnteredText(enteredText);
haveNotEncounteredInvis = false;
}
else{
enteredText = currentChar + enteredText;
}
x--;
}
}
}
}
|
ff59aea1-9ace-4279-8c4b-0deb5c62ee6b
|
@Override
public void removeUpdate(DocumentEvent e) {
}
|
0e73a30b-4545-4b48-8d53-dddcdc6fa82f
|
@Override
public void changedUpdate(DocumentEvent e) {
}
|
7e70a492-1045-4b5f-8026-8a78d879131e
|
public boolean openFile(String file, String fileIde) {
try { //it tries using the method used to read from a jar
scanner = new Scanner(TextFileToArray.class.getResourceAsStream(file));
return true;
} catch (Exception e1) { //if that fails, it tries to use the
try { //method to read from the IDE
scanner = new Scanner(new File(fileIde));
return true;
}
catch (Exception e2) { //if it fails it prints out an error
GuiMaster.println("WARNING: The file Elements.txt cannot be found.");
return false; // and returns to alchemy, which eventually
} //returns to main menu
}
}
|
51068ec2-4b54-4bea-81bc-cb360db02a92
|
public void readFile() {
int x = 0;
if (scanner.hasNext()) {
totalElements = Integer.parseInt(scanner.next());
elementStringArray = new String[totalElements];
elementListArray = new String[totalElements][totalElements];
}
if (scanner.hasNext()) {
totalStartingElements = Integer.parseInt(scanner.next());
}
while (scanner.hasNext()) {
elementStringArray[x] = scanner.next();
x++;
if (x >= totalElements) {
break;
}
}
x = 0;
int y = 0;
while (scanner.hasNext()) {
if (y == 0) {
scanner.next();
y++;
} else if (y == totalElements) {
elementListArray[x][y-1] = scanner.next();
y = 0;
x++;
} else {
elementListArray[x][y-1] = scanner.next();
y++;
}
}
}
|
bd44388f-ad76-44c9-8db5-c6467c264291
|
public static void closeFile() {
scanner.close();
}
|
1ee32cf1-0524-45b5-b50a-d02e53623d21
|
public static String[][] returnElementListArray() {
return elementListArray;
}
|
6b7997fb-61dc-4c6b-8412-41e7c07a0205
|
public static String[] returnElementStringArray() {
return elementStringArray;
}
|
6d146e7b-79fb-4232-9a97-19331a9ed38e
|
public static int returnTotalElements() {
return totalElements;
}
|
1834c333-bbe3-4a75-9533-a07b755778f1
|
public static int returnTotalStartingElements() {
return totalStartingElements;
}
|
0d0095fb-a66e-464a-8345-5b8f5a767a28
|
public static void printelementListArray() {
for (int x = 0; x <= totalElements - 1; x++) {
for (int y = 0; y <= totalElements - 1; y++) {
System.out.print(elementListArray[x][y] + ", ");
}
System.out.println();
}
}
|
d738f4c5-1ad5-45af-bd8a-179ebadc7fc6
|
public static void printElementStringArray() {
System.out.println();
for (int x = 0; x <= elementStringArray.length - 1; x++) {
System.out.print(elementStringArray[x] + " ");
}
}
|
40d14a25-6193-40a1-86ab-c6db6f5e7530
|
public static void startAlchemy() {
if(setUpVars()){ //Sets up variables, and if successful,
GuiMaster.println("\n" + "Welcome to Alchemy!" + "\n" + "\n" //print out a message,
+ "Instructions: To start, input the "
+ "first element that you would like to"
+ " mix and press \"Enter\" and then in the"
+ " same manner input the second element." + "\n" + "\n");
GuiMaster.println("To start, you have"); //then,
game(); //start the main game loop.
}
//if unsuccessful the program returns to the menu
}
|
8a2b045c-6686-4d84-9e36-48926215e480
|
private static void game() {
while (continueGame) {
listElements(); //Prints out the elements you have
String element1 = GuiMaster.getEnteredText();//inputs first element
if(elementValidize(element1)){ //checks first and second
String element2 = GuiMaster.getEnteredText();; //inputs second element
if(elementValidize(element2)){
int newElementInt = findNewElement(element1, element2);//finds new element's int
if(newElementInt != -1){
String newElement = elementString(newElementInt); //converts new element's int to string
if(!checkElementDiscovered(newElement)){ //Check valid checks if it's been discovered. If it has been
//then make it discovered.
elementsDiscovered[elementsNotNull(elementsDiscovered)] = newElementInt;
}
GuiMaster.println(element1 + " + " + element2 + " = " + newElement);
GuiMaster.println("The elements you have discovered are, \n");
}
}
}
}
}
|
c7e8ba6a-9ce5-497e-93df-0b2a6cf497fa
|
private static boolean setUpVars(){
TextFileToArray tfta = new TextFileToArray(); //Creates new object used to import data
if(tfta.openFile("/Elements.txt", "Elements.txt")){ // if opening Elements.txt is successful
tfta.readFile(); //reads the file
tfta.closeFile(); //closes file to prevent resource leak
elementArray = tfta.returnElementListArray(); //populates elementaArray from data import from
//file earlier
elementStringArray= tfta.returnElementStringArray(); // populates elementStringArray from data
//import form file earlier
totalElements = tfta.returnTotalElements();
totalStartingElements = tfta.returnTotalStartingElements();
elementsDiscovered = new int[totalElements];
fillArray(elementsDiscovered, totalStartingElements); //calls fillArray which populates
//elementsDiscovered with starting elements then fills the rest with -1 to represent nothing
return true; //returns true because reading the file was successful
}
return false; //failed reading file so returns false
}
|
24dbf8af-da27-4251-980a-e4fd10805978
|
private static void fillArray(int[] array, int actualDataSpots){
for (int x = 0; x <= array.length -1; x++){ //fills in starting elements
if(x <= actualDataSpots -1){
array[x] = x;
}
else { //fills the rest with -1
array[x] = -1;
}
}
}
|
d6ebcf20-0099-4824-a003-cfcfb84c59ae
|
private static void listElements(){
String stringToPrint = "";
for (int x = 0; x <= elementsDiscovered.length-1; x++){ //goes through elementsDiscovered
if(elementString(elementsDiscovered[x]) == null){ //finding the string of that postion's
stringToPrint += ".";
GuiMaster.println(stringToPrint); // int. then prints elements not null
break;
}
else{
stringToPrint+= elementString(elementsDiscovered[x]); // if an element is not null
if(x != elementsDiscovered.length-1){ //then it will print out element. Checks to see
if(elementString(elementsDiscovered[x+1]) != null){ // if it is the last element
stringToPrint+=", "; // or if the next element is null, if so it prints out
} // a period. Otherwise a comma is printed out.
}
else{
stringToPrint+=".";
GuiMaster.println(stringToPrint);
}
}
}
}
|
a341b53b-5a82-4c51-91f5-ed1db873a399
|
private static boolean elementValidize(String element) {
if (!checkElementDiscovered(element)) { //calls checkValid to see if the element is valid if it isn't it
invalidElement(element); // then it calls invalidElement to print out an error message
return false;
}
else{
return true;
}
}
|
5d20e590-06f0-4550-9092-43616cd1028f
|
private static void invalidElement(String element) {
GuiMaster.println(element +" is an element that does not exist or that you have not "
+ "discovered yet.");
GuiMaster.println("");
GuiMaster.println("Please try again.");
GuiMaster.println("The elements you have discovered are,\n");
}
|
a35aecf9-f258-4348-ac03-f7c12a21ec68
|
private static boolean checkElementDiscovered(String element) {
for (int x = 0; x <= elementsDiscovered.length -1; x++) { //goes through the elementsDiscovered
int elementInt = elementNumber(element); //and checks if the int of the element passed
if (elementInt == elementsDiscovered[x]){ //through matches any int in the elementsDiscovered
return true;
}
}
return false;
}
|
2f91cb05-20d7-48b1-9b0b-a707c3681cdf
|
private static int findNewElement(String element1, String element2) {
int element1Number = elementNumber(element1); //finds element number of element1
int element2Number = elementNumber(element2); //and element2
//System.out.println(element1 + " " + element2 + " " + element1Number + " " + element2Number);
// above used for debugging
String elementString = elementArray[element1Number][element2Number]; //finds the element in
if(elementString.equalsIgnoreCase("error")){ //the location those two elements int's map.
GuiMaster.println("Nothing can be made with those elements. \n"); //If equals error it
GuiMaster.println("The elements you have discovered are, \n"); // prints some text and
return -1; //Java wants me to put a return
}
else{
int elementNumber = elementNumber(elementString); //if actually element is in the location
return elementNumber; //the ints map then it returns that element
}
}
|
f2e4952f-8114-4e3c-bc20-6ce738f3d677
|
private static int elementNumber(String element) { //locates the element in elementStringArray and
for (int x = 0; x <= elementStringArray.length -1; x++) { //returns the string's int /
if (elementStringArray[x].equalsIgnoreCase(element)) { //the location of the string in the
return x; //array
}
}
return -2; //if not in there it returns -2
}
|
9e13d211-9c09-40e9-80b3-0cc7c1a53058
|
private static String elementString(int elementInt){
if (elementInt == -1){ //-1 equals nothing so it returns null
return null;
}
else{
String elementString = elementStringArray[elementInt]; //if not it returns the string
return elementString; //in that location in elementStringArray
}
}
|
03304b1a-68da-43c1-b670-2dd78e5f61f2
|
private static int elementsNotNull(int[] array){
int elementsNotNull = 0;
for (int x = 0; x <= array.length-1; x++){ //searches through the array
if (elementString(array[x]) != null){ //check the elements that are not null / int is not
elementsNotNull++; // -1
}
}
return elementsNotNull;
}
|
b2a8560c-68e6-4519-bdcb-8ef369e42081
|
public static void encrypt() {
String afterShiftOne = "";
GuiMaster.println("What do you wish to encrypt?");
byte[] inputArray = GuiMaster.getEnteredText().getBytes();
GuiMaster.println("How far do you wish to shift it?");
shift = Integer.parseInt(GuiMaster.getEnteredText());
GuiMaster.println("How many layers deep do you wish to encrypt?");
int layersDeep = Integer.parseInt(GuiMaster.getEnteredText());
for (int x = 0; layersDeep > x; x++) {
inputArray = reverseArray(inputArray);
inputArray = shiftArray(inputArray);
}
GuiMaster.println("Encrypted version:" + new String(inputArray));
}
|
02b4c570-2461-43f2-976a-be7d69781f83
|
public static byte[] reverseArray(byte[] array) {
int y = 0;
byte[] returnArray = new byte[array.length];
for (int x = array.length - 1; -1 < x; x--) {
returnArray[x] = array[y];
y++;
}
return returnArray;
}
|
72c9f3d9-20f1-4058-883a-c83bebcbadd1
|
public static byte[] shiftArray(byte[] array) {
byte tempByteStorage;
for (int x = 0; array.length > x; x++) {
tempByteStorage = (byte) (array[x] + shift);
shift = (int) (shift + 0);
array[x] = tempByteStorage;
}
shift = (int) (shift + 0);
return array;
}
|
40d934c0-b500-45ba-a774-3dd4fa4e8131
|
public static void decrypt() {
String afterShiftOne = "";
GuiMaster.println("What do you wish to decrypt?");
byte[] inputArray = GuiMaster.getEnteredText().getBytes();
GuiMaster.println("How far do you wish to deshift it?");
shift = 0 - Integer.parseInt(GuiMaster.getEnteredText());
GuiMaster.println("How many layers deep do you wish to decrypt?");
int layersDeep = Integer.parseInt(GuiMaster.getEnteredText());
// shift = shift - layersDeep * inputArray.length + layersDeep;
for (int x = 0; layersDeep > x; x++) {
inputArray = reverseArray(inputArray);
inputArray = deshiftArray(inputArray);
}
GuiMaster.println("Decrypted version:" + new String(inputArray));
}
|
05cc8a17-1ca2-4e65-a88d-6e392183abd7
|
public static byte[] deshiftArray(byte[] array) {
shift = (int) (shift + 0);
byte tempByteStorage;
for (int x = 0; array.length > x; x++) {
tempByteStorage = (byte) (array[x] + shift);
shift = (int) (shift + 0);
array[x] = tempByteStorage;
}
return array;
}
|
33f82478-470c-4092-904c-aa0ea8fc3845
|
public static void main(String[] args) {
menu();
}
|
38c6705a-3537-428a-a4d4-b28d6db3f49b
|
public static void menu() {
GuiMaster.startGui();
while(true){
GuiMaster.println(
"Welcome to the TextBased Game! \n"
+ "\n" + "Which game do you wish to play? \n"
+ "1 - Gangup - Work in Progress \n"
+ "2 - Encryption - Non GUI \n"
+ "3 - Decryption - Non GUI \n"
+ "4 - Encryption Gui \n"
+ "5 - Decryption Gui \n"
+ "6 - Alchemy - Work In Progress \n");
String whatToDo = GuiMaster.getEnteredText();
if (whatToDo == null) {
exit();
}
whatToDo = whatToDo.trim();
whatToDo = Capitalize.capitalizeEveryWord(whatToDo);
switch (whatToDo){
case "Gangup":
case "1":
Gangup.startGangup();
break;
case "Encryption":
case "2":
cryption.encrypt();
break;
case "Decryption":
case "3":
cryption.decrypt();
break;
case "Encryption Gui":
case "4":
cryptionGUI.encrypt();
break;
case "Decryption Gui":
case "5":
cryptionGUI.decrypt();
case "Alchemy":
case "6":
Alchemy.startAlchemy();
break;
default:
GuiMaster.println("Invalid Option");
}
}
}
|
3ef26a32-9017-44cd-b114-3e630c3ae89d
|
public static void exit() {
int quit;
quit = JOptionPane.showConfirmDialog(null,
"Do you wish to close TB Game?");
if (quit == 0) {
System.exit(0);
} else {
menu();
}
}
|
7bffa42e-3c7a-49d1-bd49-a31e5590805d
|
public static void encrypt() {
String afterShiftOne = "";
String input = JOptionPane
.showInputDialog("What do you wish to encrypt?");
byte[] inputArray = input.getBytes();
String shiftInput = JOptionPane
.showInputDialog("How far do you wish to shift it?");
shift = Integer.parseInt(shiftInput);
String layersDeepInput = JOptionPane
.showInputDialog("How many layers deep do you wish to encrypt?");
int layersDeep = Integer.parseInt(layersDeepInput);
for (int x = 0; layersDeep > x; x++) {
inputArray = reverseArray(inputArray);
inputArray = shiftArray(inputArray);
}
JOptionPane.showMessageDialog(null, "Encrypted version:"
+ new String(inputArray), "TB Game", JOptionPane.PLAIN_MESSAGE);
cryptionGUI.setClipboardContents(new String(inputArray));
}
|
0152fd34-9133-4696-8e75-64b476c5ad44
|
public static byte[] reverseArray(byte[] array) {
int y = 0;
byte[] returnArray = new byte[array.length];
for (int x = array.length - 1; -1 < x; x--) {
returnArray[x] = array[y];
y++;
}
return returnArray;
}
|
ed347ed5-65bc-45de-9635-464bb63fab2d
|
public static byte[] shiftArray(byte[] array) {
byte tempByteStorage;
for (int x = 0; array.length > x; x++) {
tempByteStorage = (byte) (array[x] + shift);
shift = (int) (shift + 1);
array[x] = tempByteStorage;
}
shift = (int) (shift + 1);
return array;
}
|
31db3528-c6ae-40ed-a072-f81d9c0bd1f7
|
public static void decrypt() {
String afterShiftOne = "";
String input = JOptionPane
.showInputDialog("What do you wish to decrypt?");
byte[] inputArray = input.getBytes();
String shiftInput = JOptionPane
.showInputDialog("How far do you wish to deshift it?");
shift = 0 -Integer.parseInt(shiftInput);
String layersDeepInput = JOptionPane
.showInputDialog("How many layers deep do you wish to encrypt?");
int layersDeep = Integer.parseInt(layersDeepInput);
shift = shift - (layersDeep * inputArray.length + layersDeep);
for (int x = 0; layersDeep > x; x++) {
inputArray = reverseArray(inputArray);
inputArray = deshiftArray(inputArray);
}
JOptionPane.showMessageDialog(null, "Decrypted version:"
+ new String(inputArray), "TB Game", JOptionPane.PLAIN_MESSAGE);
cryptionGUI.setClipboardContents(new String(inputArray));
}
|
c4b7b4ef-bb10-4ba8-84f4-a48465878864
|
public static byte[] deshiftArray(byte[] array) {
shift = (int) (shift + 1);
byte tempByteStorage;
for (int x = 0; array.length > x; x++) {
shift = (int) (shift + 1);
tempByteStorage = (byte) (array[x] + shift);
array[x] = tempByteStorage;
}
return array;
}
|
d232bd96-52b7-4413-8893-ddea74ca34a0
|
public static void setClipboardContents( String aString ){
StringSelection stringSelection = new StringSelection( aString );
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents( stringSelection, stringSelection );
}
|
4afa1883-c459-41e2-86f7-9d30508d85e0
|
@Override
public void lostOwnership(Clipboard arg0, Transferable arg1) {
// TODO Auto-generated method stub
}
|
97181b79-1fcc-4c47-b0f8-e15f9b1a39c0
|
public Board(int n, int win) {
size = n;
tokentowin = win;
tokensonboard = 0;
initalizeBoard();
}
|
6fc3f8f0-9817-4a67-9453-a300f686f6aa
|
final void initalizeBoard() {
Token dummy = new Token('-');
board = new Token[size][size];
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
board[i][j] = dummy;
}
}
}
|
3a508d43-591b-416d-b747-947e33a9dac5
|
public void setSize(int size) {
this.size = size;
initalizeBoard();
}
|
0a72f623-93dd-4692-b552-0b381658be57
|
public int getSize() {
return this.size;
}
|
31f271fd-79fe-4dce-898f-440394ad2a7e
|
public boolean addToken(int x, int y, Token t) {
boolean success;
if ((board[x][y].getType() == '-') && (tokensonboard < size * size)) {
board[x][y] = t;
tokensonboard++;
success = true;
} else {
success = false;
}
return success;
}
|
4304eb09-a367-4d45-b106-3b96f1447b9f
|
public int getGameState(int x, int y, char t) {
if (validateRows(t, x) || validateColumns(t, y) || validateDiagonal(t, x, y)) {
if (t == 'o') {
return 1;
} else if (t == 'x') {
return 2;
}
}
//dontetlen ellenorzese ezt kell utoljara hagyni
if (tokensonboard == size * size) {
return 3;
}
return 0;
}
|
5e9d4bb4-8972-4dbf-a9aa-5842e553e8bf
|
public boolean validateRows(char t, int x) {
int inarow = 0;
for (int j = 0; j < size; j++) {
if (board[x][j].getType() == t) {
inarow++;
} else {
inarow = 0;
}
if (inarow == tokentowin) {
return true;
}
}
return false;
}
|
6a4a6b84-10f6-4935-bb52-323f5bc5bec6
|
public boolean validateColumns(char t, int y) {
int inacolumn = 0;
for (int i = 0; i < size; i++) {
if (board[i][y].getType() == t) {
inacolumn++;
} else {
inacolumn = 0;
}
if (inacolumn == tokentowin) {
return true;
}
}
return false;
}
|
8a9439f6-31ed-414f-9da2-ed31bd5d24f3
|
public boolean validateDiagonal(char t, int x, int y) {
int inadiagonal = 0;
int ox = x;
int oy = y;
while (x != 0 && y != 0) {
x--;
y--;
}
while (x < size && y < size) {
if (board[x][y].getType() == t) {
inadiagonal++;
} else {
inadiagonal = 0;
}
x++;
y++;
if (inadiagonal == tokentowin) {
return true;
}
}
x = ox;
y = oy;
inadiagonal = 0;
while (x != 0 && y != size - 1) {
x--;
y++;
}
while (x < size && y >= 0) {
if (board[x][y].getType() == t) {
inadiagonal++;
} else {
inadiagonal = 0;
}
x++;
y--;
if (inadiagonal == tokentowin) {
return true;
}
}
return false;
}
|
34516c54-8557-4089-890c-01ebeb8270cf
|
public boolean isGameEnded(int x, int y, char t) {
if (getGameState(x, y, t) > 0) {
return true;
} else {
return false;
}
}
|
027c5924-16d0-431f-87fd-25799147ea64
|
public void printBoard() {
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
System.out.print(board[i][j].getType() + " ");
}
System.out.print("\n");
}
}
|
8888ade1-c40c-4e66-92f0-605106a25c1d
|
public int getTokentowin() {
return tokentowin;
}
|
fa8b65f3-2057-48c5-8484-ab077759360d
|
public void setTokentowin(int tokentowin) {
this.tokentowin = tokentowin;
}
|
c81e1ccb-1ab6-4a32-af57-c53bd440dcc1
|
public GUI(int width, int height, Game game) {
window = new JFrame();
jatek = game;
//bezarasakor a program is leall
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(width, height);
window.setLayout(new BorderLayout());
createMenuBar();
createTextArea();
window.setVisible(true);
}
|
d84461d8-7d0a-4f50-9acf-d9e19a72a17f
|
public void renderWindow(int width, int height) {
window.setSize(width, height);
window.setVisible(true);
}
|
ff63520f-41dc-489d-8b77-5fb33e9518a7
|
public final void createTextArea() {
text = new JTextArea();
JScrollPane sp = new JScrollPane(text);
sp.setPreferredSize(new Dimension(600, 80));
text.setEditable(false);
window.add(sp, BorderLayout.SOUTH);
window.validate();
window.repaint();
}
|
feae4698-50f0-47e3-9c8e-08ec0673d2d6
|
public void addText(String t) {
text.append(t + "\n");
text.setCaretPosition(text.getDocument().getLength());
}
|
a4b069fd-b6c8-49f6-8dba-2602248c843a
|
public void generateTable(int n) {
table = new JTable(n, n);
scrollPane = new JScrollPane(table);
DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
renderer.setHorizontalAlignment(JLabel.CENTER);
for (int i = 0; i < table.getColumnCount(); i++) {
table.setDefaultRenderer(table.getColumnClass(i), renderer);
}
table.setGridColor(Color.black);
table.setRowHeight(window.getWidth() / n);
table.setRowSelectionAllowed(false);
table.setColumnSelectionAllowed(false);
table.setFont(new Font("Serif", Font.BOLD, window.getWidth() / n));
table.updateUI();
//egerkezelés
table.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
int row = table.rowAtPoint(evt.getPoint());
int col = table.columnAtPoint(evt.getPoint());
if (row >= 0 && col >= 0 && !jatek.isGameWon()) {
Token t;
if (jatek.getElozoSiker()) {
t = jatek.getNextPlayer().getToken();
} else {
t = jatek.getPrevPlayer().getToken();
}
if (jatek.addToken(row, col, t)) {
table.setValueAt(t.getType(), row, col);
}
}
if (jatek.isGameWon()) {
table.setEnabled(false);
}
window.validate();
window.repaint();
}
});
window.add(scrollPane, BorderLayout.CENTER);
window.repaint();
}
|
66c2d062-13e1-472d-bd9b-abbfb8d5f709
|
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
int row = table.rowAtPoint(evt.getPoint());
int col = table.columnAtPoint(evt.getPoint());
if (row >= 0 && col >= 0 && !jatek.isGameWon()) {
Token t;
if (jatek.getElozoSiker()) {
t = jatek.getNextPlayer().getToken();
} else {
t = jatek.getPrevPlayer().getToken();
}
if (jatek.addToken(row, col, t)) {
table.setValueAt(t.getType(), row, col);
}
}
if (jatek.isGameWon()) {
table.setEnabled(false);
}
window.validate();
window.repaint();
}
|
3cf53fbf-45a1-4719-9138-62114052cd5e
|
public void gameSettingsPanel() {
final JPanel p = new JPanel();
final JTextField boardsize = new JTextField();
final JTextField towin = new JTextField();
JLabel size = new JLabel("Size of the table:");
JLabel win = new JLabel("Tokens to win:");
JButton go = new JButton("Begin");
boardsize.setMaximumSize(new Dimension(50, 20));
towin.setMaximumSize(new Dimension(50, 20));
//p.setLayout(new GridLayout(1, 5, 0, 0));
p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
p.setLayout(new BoxLayout(p, BoxLayout.LINE_AXIS));
p.add(size);
p.add(Box.createRigidArea(new Dimension(10, 0)));
p.add(boardsize);
p.add(Box.createRigidArea(new Dimension(10, 0)));
p.add(win);
p.add(Box.createRigidArea(new Dimension(10, 0)));
p.add(towin);
p.add(Box.createRigidArea(new Dimension(10, 0)));
p.add(go);
p.updateUI();
go.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
jatek.newGame(Integer.parseInt(boardsize.getText()), Integer.parseInt(towin.getText()));
p.setVisible(false);
}
});
window.add(p, BorderLayout.NORTH);
window.validate();
window.repaint();
}
|
ffb1433c-0e21-4cc0-8306-0ad1095b3514
|
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
jatek.newGame(Integer.parseInt(boardsize.getText()), Integer.parseInt(towin.getText()));
p.setVisible(false);
}
|
dc2a1189-62de-4eb0-a4f9-e5ae6c45784f
|
public final void createMenuBar() {
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenuItem newGameMenu = new JMenuItem("New game");
JMenuItem exitMenu = new JMenuItem("Exit");
fileMenu.setMnemonic(KeyEvent.VK_F);
menuBar.add(fileMenu);
newGameMenu.setAccelerator(KeyStroke.getKeyStroke("meta N"));
exitMenu.setAccelerator(KeyStroke.getKeyStroke("meta X"));
fileMenu.add(newGameMenu);
fileMenu.add(exitMenu);
newGameMenu.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
newGameAction();
}
public void mousePressed(java.awt.event.MouseEvent evt) {
newGameAction();
}
});
exitMenu.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
System.exit(0);
}
public void mousePressed(java.awt.event.MouseEvent evt) {
System.exit(0);
}
});
window.setJMenuBar(menuBar);
}
|
f1a06090-0e60-4f7c-b23f-2b55dc34d566
|
@Override
public void actionPerformed(ActionEvent ae) {
newGameAction();
}
|
cdb89482-5b84-45a8-9879-b3abae2aa04e
|
public void mousePressed(java.awt.event.MouseEvent evt) {
newGameAction();
}
|
41859e56-98f2-4cf3-bc95-763f380d5993
|
@Override
public void actionPerformed(ActionEvent ae) {
System.exit(0);
}
|
50e0a3cc-dcee-491e-8681-406f89bdaa42
|
public void mousePressed(java.awt.event.MouseEvent evt) {
System.exit(0);
}
|
d3d541c7-8400-4b3e-bff6-7081486f5583
|
public void newGameAction() {
if (table != null) {
window.remove(scrollPane);
text.setText("");
window.repaint();
}
gameSettingsPanel();
}
|
edd24222-53ea-480c-ae68-d118daa2a18c
|
public Player() {
name = null;
token = new Token('-');
}
|
5f4b1693-d83b-4b6c-9899-2ca7563fd815
|
public Player(char t) {
name = null;
token = new Token(t);
}
|
923c60b7-8051-4b37-9fbc-c3425389750c
|
public void setType(char t) {
if (t == 'o' || t == 'x') {
token.setType(t);
}
}
|
bfa7e2cf-e5c3-4323-be24-b3b45c91b526
|
public char getType() {
return token.getType();
}
|
9b109e0a-55e9-40fc-8ae2-b73da04f841d
|
public Token getToken() {
return token;
}
|
eba5e1b2-4601-40ab-9467-e52f644225bc
|
public Token(char t) {
type = t;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.