Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author Carson Lees
- * Date: 4/14/2019
- * Program: TicTacToe
- */
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.Random;
- import java.util.Scanner;
- import javax.swing.JFrame;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
- public class TicTacToe extends JFrame{
- public static char N = '_';
- public static char S = '_';
- public static char E = '_';
- public static char W = '_';
- public static char M = '_';
- public static char NW = '_';
- public static char NE = '_';
- public static char SW = '_';
- public static char SE = '_';
- public static boolean Ntaken = false;
- public static boolean Staken = false;
- public static boolean Etaken = false;
- public static boolean Wtaken = false;
- public static boolean NWtaken = false;
- public static boolean NEtaken = false;
- public static boolean Mtaken = false;
- public static boolean SWtaken = false;
- public static boolean SEtaken = false;
- public static boolean win = false;
- public static boolean spaceTaken = false;
- public static boolean scriptStopped = false;
- public static String uText = "";
- public static String output = "";
- public static String screen = "";
- public static String board = "";
- public static String side = "?";
- public static String customTxtEnterText = "";
- public static String winMethod = "";
- public static String status = "x";
- public static char letter = ' ';
- public static void Encoder(String text) {
- int disSyn = 1;
- int timesLooped = 0;
- boolean containsDiscordSyntax = false;
- Scanner scanner = new Scanner(System.in);
- String referance1 = "qwertyuiopasdfghjklzxcvbnm1234567890!@#$%^&*()`~-=_+[]{}|;':,.<>/?QWERTYUIOPASDFGHJKLZXCVBNM";
- String referance2 = "-MS=rPNtyuBi45R_+OA[qVw.<EmQYC1J2?d>7F8fg&H*(0!@#9DU~]{hX}|ZbjkWl'opT)`Gzxc;s:,63/aeIn$L%K^v";
- String referanceA1 = ":,63/aeInrPtyuBi4s$L%g&H?d>7F8S=_-EmQYf'opT)`Gzxc;2l!@#9DU~]{hXN+OA[qVw.<ZbjkW*(0C1J5R}|MK^v";
- String referanceA2 = "9D)`[qVvyuBeInSYf'EaQ2lc;ZbjkW*(0C1XN+OAo&w.<!@rU~:=_-7F8#]{i4s$L%ghJ5R}|Mx,6^Hm3/PtGzKpT?d>";
- String referanceA3 = "$L%ghJ9@yuVv*(0C1x,6^rU~:=_XN+Hm3T?dDPteIzKp]{i4s>&w.<!OAoRnS)`[G}|M-7F8#/Yf'EaQ2lc;ZbjkBqW5";
- String referanceA4 = "uV?Q2lcL%~:w.v*(0C1x,6^rUS`[G}W5!OAoRngh{i4s;dDPteq@y-7F8#/)YIzKp]$>&|MJ9=_XN+Hm3T<'EaZbjkBf";
- //setting references
- System.out.print("Type something to be translated: ");
- String textHolder = text;
- while (disSyn >= 1) {//Loops if discord syntax is met
- text = textHolder; //Resets text to original state
- disSyn = disSyn - 1;//Subtracts 1 from dysSyn to break overall while loop
- if (text.length() == 1) {
- text = "___" + text;
- }
- if (text.length() == 2) {
- text = "__" + text;
- }
- if (text.length() == 3) {
- text = "_" + text;
- }
- //Encrypter only works with 4 characters or more, to avoid errors, underscores are added.
- int clock = 0;
- int clock2 = 0;
- int txtlengthMinusOne = text.length() - 1;
- int reflengthMinusone = referance1.length() - 1;
- int txtlength = text.length();
- int charAst = 0;
- int charUnd = 0;
- int charTil = 0;
- int charTil2 = 0;
- @SuppressWarnings("unused")
- char nextorigchar = 'x';
- char firstCharofText = 'x';
- char nextchar = 'x';
- char firstCharacter = 'x';
- String finalText = "";
- String jVA = "JnVnA";
- String placement = "";
- boolean modified = false;
- boolean discordSyntax = false;
- boolean underscore = false;
- boolean replaceNextChar = false;
- boolean firstCharDecided = false;
- //setting Variables
- Random random2 = new Random();
- int idPlacement = random2.nextInt(9);
- idPlacement++;
- //Decides where the reference digit is placed
- if (idPlacement == 6) {
- Random randomDecider = new Random();
- int decisionMaker = randomDecider.nextInt(2);
- decisionMaker++;
- if(decisionMaker == 1) {
- idPlacement = idPlacement + 1;
- } else {
- idPlacement = idPlacement - 1;
- }
- }
- //Makes sure idPlacement is not 6, so there can be a definite < 6 or > 6
- //Setting Identifier Placement [idPlacement]
- char setIdentifyer = text.charAt(txtlength - 4);
- if (setIdentifyer <= 6) {
- //If setIdentifyer is 1-5 then this digit is the identifier
- }
- if (setIdentifyer == 7) {
- //If setIdentifyer is 7 then identifier is at the front
- setIdentifyer = text.charAt(0);
- }
- if (setIdentifyer == 8) {
- //If setIdentifyer is 8 then identifier is at the front
- setIdentifyer = text.charAt(0);
- }
- if (setIdentifyer == 9) {
- //If setIdentifyer is 9 then identifier is at the front
- setIdentifyer = text.charAt(0);
- }
- //Sets the identifier based on a specific placement: front or back(before JVA)
- Random rand = new Random();
- int random = rand.nextInt(5);
- random++;
- if (setIdentifyer == '6') {
- modified = true;
- }
- if (setIdentifyer == '7') {
- modified = true;
- }
- if (setIdentifyer == '8') {
- modified = true;
- }//Determines if text is modified or not
- char lastChar = text.charAt(txtlength - 1);
- char seclastChar = text.charAt(txtlength - 2);
- char thilastChar = text.charAt(txtlength - 3);
- char firstChar = text.charAt(0);
- String last3Char = thilastChar + "n" + seclastChar + "n" + lastChar;
- System.out.println(last3Char);
- if (last3Char.equals(jVA)) {//Determines whether to encode or decode
- //decode
- System.out.println("decode");
- System.out.println(setIdentifyer);
- //setIdentifyer's placement is already determined by < or > if statements above
- if (setIdentifyer == '1') {
- //do nothing, maybe add something later?
- System.out.println("identifyer has been recieved for 1");
- }
- if (setIdentifyer == '2') {
- referance2 = referanceA1;
- System.out.println("identifyer has been recieved for 2");
- }
- if (setIdentifyer == '3') {
- referance2 = referanceA2;
- System.out.println("identifyer has been recieved for 3");
- }
- if (setIdentifyer == '4') {
- referance2 = referanceA3;
- System.out.println("identifyer has been recieved for 4");
- }
- if (setIdentifyer == '5') {
- referance2 = referanceA4;
- System.out.println("identifyer has been recieved for 5");
- }
- if (setIdentifyer == '6') {
- if (firstChar == '1') {
- //do nothing, maybe add something later?
- System.out.println("identifyer has been recieved for 1");
- }
- if (firstChar == '2') {
- referance2 = referanceA1;
- System.out.println("identifyer has been recieved for 2");
- }
- if (firstChar == '3') {
- referance2 = referanceA2;
- System.out.println("identifyer has been recieved for 3");
- }
- if (firstChar == '4') {
- referance2 = referanceA3;
- System.out.println("identifyer has been recieved for 4");
- }
- if (firstChar == '5') {
- referance2 = referanceA4;
- System.out.println("identifyer has been recieved for 5");
- }
- }
- if (setIdentifyer == '7') {
- if (firstChar == '1') {
- //do nothing, maybe add something later?
- System.out.println("identifyer has been recieved for 1");
- }
- if (firstChar == '2') {
- referance2 = referanceA1;
- System.out.println("identifyer has been recieved for 2");
- }
- if (firstChar == '3') {
- referance2 = referanceA2;
- System.out.println("identifyer has been recieved for 3");
- }
- if (firstChar == '4') {
- referance2 = referanceA3;
- System.out.println("identifyer has been recieved for 4");
- }
- if (firstChar == '5') {
- referance2 = referanceA4;
- System.out.println("identifyer has been recieved for 5");
- }
- }
- if (setIdentifyer == '8') {
- if (firstChar == '1') {
- //do nothing, maybe add something later?
- System.out.println("identifyer has been recieved for 1");
- }
- if (firstChar == '2') {
- referance2 = referanceA1;
- System.out.println("identifyer has been recieved for 2");
- }
- if (firstChar == '3') {
- referance2 = referanceA2;
- System.out.println("identifyer has been recieved for 3");
- }
- if (firstChar == '4') {
- referance2 = referanceA3;
- System.out.println("identifyer has been recieved for 4");
- }
- if (firstChar == '5') {
- referance2 = referanceA4;
- System.out.println("identifyer has been recieved for 5");
- }
- }
- if (setIdentifyer == '9') {
- if (firstChar == '1') {
- //do nothing, maybe add something later?
- System.out.println("identifyer has been recieved for 1");
- }
- if (firstChar == '2') {
- referance2 = referanceA1;
- System.out.println("identifyer has been recieved for 2");
- }
- if (firstChar == '3') {
- referance2 = referanceA2;
- System.out.println("identifyer has been recieved for 3");
- }
- if (firstChar == '4') {
- referance2 = referanceA3;
- System.out.println("identifyer has been recieved for 4");
- }
- if (firstChar == '5') {
- referance2 = referanceA4;
- System.out.println("identifyer has been recieved for 5");
- }
- clock++;
- clock++;//To avoid an unknown error that does not erase the front of the word
- }
- //Changes referance2 based on setIdentifyer
- if (modified == true) {
- String placeHolder = "";
- int clock4 = 1;
- while (clock4 <= text.length() - 1) {
- placeHolder = placeHolder + text.charAt(clock4);
- clock4++;
- }
- System.out.println(placeHolder + "");
- text = placeHolder;
- txtlengthMinusOne = txtlengthMinusOne - 1;
- }
- while (clock <= txtlengthMinusOne) {//Loop as many times as the length of your input
- clock2 = 0;
- System.out.println(text.charAt(clock));
- char origchar = text.charAt(clock);
- if (clock <= text.length() - 2) {//If this isn't the last loop
- nextorigchar = text.charAt(clock + 1);
- }
- while (clock2 <= reflengthMinusone) {//Loop as many times as the length of referance1
- if (referance2.charAt(clock2) == origchar) {
- //If the character at clock2 of referance1 = the character being worked with
- System.out.println(referance2.charAt(clock2));
- char newchar = referance1.charAt(clock2);
- //Locate and print the changed character
- finalText = finalText + newchar;//Splice everything together
- }
- clock2++;
- }
- clock++;
- }
- //Getting rid of "JVA"
- int clock3;
- if (modified == true) {
- clock3 = 1;
- } else {
- clock3 = 0;
- }
- int finalLength = finalText.length() - 5;
- String finalText2 = "";
- while (clock3 <= finalLength) {
- finalText2 = finalText2 + finalText.charAt(clock3);
- clock3++;
- }
- text = finalText2;
- clock = 0;
- firstCharofText = text.charAt(0);
- finalText = "";
- while (clock <= text.length() - 1) {
- if (text.charAt(clock) == ';') {
- if (text.charAt(clock + 1) == firstCharofText) {
- nextchar = ' ';
- finalText = finalText + nextchar;
- clock++;
- }
- } else {
- finalText = finalText + text.charAt(clock);
- }
- clock++;
- }
- if (finalText.length() == 4) {
- if (finalText.charAt(0) == '_') {
- underscore = true;
- }
- }//Detects underscores
- //Removing underscores
- if (underscore == true) {
- clock2 = 0;
- while (clock2 <= 3) {
- firstCharacter = finalText.charAt(0);
- if (firstCharacter == '_') {
- System.out.println("Underscore found");
- text = finalText;
- finalText = "";
- clock = 1;
- while (clock <= text.length() - 1) {
- finalText = finalText + text.charAt(clock);
- clock++;
- }
- }
- clock2++;
- }
- }
- System.out.println("");
- System.out.println("");
- //Printing Stylishly
- clock = 0;
- while (clock <= finalText.length() - 1) {
- if (finalText.charAt(clock) == '[') {
- if (finalText.charAt(clock + 1) == 'E') {
- if (finalText.charAt(clock + 2) == ']') {
- if (finalText.charAt(clock + 3) == ' ') {
- //try {
- //Thread.sleep(50);
- //} catch (InterruptedException e) {
- // TODO Auto-generated catch block
- //e.printStackTrace();
- //}
- System.out.print(finalText.charAt(clock));
- clock++;
- } else {
- //try {
- //Thread.sleep(1200);
- //} catch (InterruptedException e) {
- // TODO Auto-generated catch block
- //e.printStackTrace();
- //}
- clock += 3;
- if (finalText.charAt(clock) == ' ') {
- clock++;
- }
- System.out.println();
- }
- }
- }
- } else {
- //try {
- //Thread.sleep(50);
- //} catch (InterruptedException e) {
- // TODO Auto-generated catch block
- //e.printStackTrace();
- //}
- System.out.print(finalText.charAt(clock));
- clock++;
- }
- }
- System.out.println("");
- System.out.println("");
- System.out.println("");
- output = finalText;
- //end of decode
- } else {
- //encode
- if (idPlacement <= 6) {//Only if idPlacemant is below 6 (1-5)
- if (idPlacement == 1) {
- //do nothing, maybe add something later?
- }
- if (idPlacement == 2) {
- referance2 = referanceA1;
- }
- if (idPlacement == 3) {
- referance2 = referanceA2;
- }
- if (idPlacement == 4) {
- referance2 = referanceA3;
- }
- if (idPlacement == 5) {
- referance2 = referanceA4;
- }
- //Changes referance2 to a different set basted on the random integer
- //regular
- //1,2,3,4,5
- placement = "end";
- } else {
- //Uses integer "random"
- if (random == 1) {
- //do nothing, maybe add something later?
- }
- if (random == 2) {
- referance2 = referanceA1;
- }
- if (random == 3) {
- referance2 = referanceA2;
- }
- if (random == 4) {
- referance2 = referanceA3;
- }
- if (random == 5) {
- referance2 = referanceA4;
- }
- //Changes referance2 to a different set basted on the random integer
- //modified
- //7,8,9
- placement = "beginning";
- }
- while (clock <= txtlengthMinusOne) {//Loop as many times as the length of your input
- clock2 = 0;
- System.out.println(text.charAt(clock));
- char origchar = text.charAt(clock);
- if (replaceNextChar == true) {//replacing character
- origchar = text.charAt(0);
- replaceNextChar = false;
- }
- if (clock <= text.length() - 2) {//replacing second space character
- nextchar = text.charAt(clock + 1);
- if (origchar == ';') {
- if (nextchar == ';') {
- //replace next character with the third letter in the original text
- replaceNextChar = true;
- }
- }
- }
- while (clock2 <= reflengthMinusone) {//Loop as many times as the length of referance1
- if (referance1.charAt(clock2) == origchar) {
- //If the character at clock2 of referance1 = the character being worked with
- System.out.println(referance2.charAt(clock2));
- char newchar = referance2.charAt(clock2);
- //Locate and print the changed character
- finalText = finalText + newchar;//Splice everything together
- if (firstCharDecided == false) {
- firstCharofText = newchar;
- firstCharDecided = true;
- }//Only looped once! Sets first character as firstChar
- }
- clock2++;
- }
- clock++;
- }
- if (placement.equals("end")) {//Normal placement [end]
- finalText = finalText + "" + idPlacement;
- }
- if (placement.equals("beginning")) {//Modified placement [beginning with idPlacement at end]
- finalText = random + "a" + finalText + idPlacement;
- }
- finalText = finalText + "JVA";
- //Avoiding Discord Syntax
- clock = 0;
- while (clock <= finalText.length() - 1) {
- if (finalText.charAt(clock) == '*') {
- charAst++;
- System.out.println(charAst + " *s found");
- }
- if (finalText.charAt(clock) == '_') {
- charUnd++;
- System.out.println(charUnd + " _s found");
- }
- if (finalText.charAt(clock) == '~') {
- charTil++;
- System.out.println(charTil + " ~s found");
- }
- if (finalText.charAt(clock) == '`') {
- charTil2++;
- System.out.println(charTil2 + " `s found");
- }
- clock++;
- }
- if (charAst >= 1) {
- discordSyntax = true;
- }
- if (charUnd >= 1) {
- discordSyntax = true;
- }
- if (charTil >= 1) {
- discordSyntax = true;
- }
- if (charTil2 >= 1) {
- discordSyntax = true;
- }//Checking for amount discord syntax may be used
- if (timesLooped == 100) {
- containsDiscordSyntax = true;
- }
- if (discordSyntax == true) {
- System.out.println("Error: Output met Discord Syntax!");
- if (containsDiscordSyntax == false) {
- disSyn++;
- }//Stops when program "Gives Up"
- System.out.println("Error: Discord Syntax could not be avoided!");
- System.out.println("Warning! Your message contains Discord Syntax!");
- System.out.println("");
- System.out.println(finalText);
- System.out.println("");
- System.out.println("");
- System.out.println("");
- } else {
- System.out.println("");
- System.out.println(finalText);
- System.out.println("");
- System.out.println("");
- System.out.println("");
- //Print final encoded text
- }
- output = finalText;
- }//encode
- timesLooped++;//to avoid an endless loop
- }//Loop
- scanner.close();
- }//PSVM
- public static void Display() {
- txtChat.setText("");
- screen = NW + " | " + N + " | " + NE + "\n";
- txtChat.append(screen);
- screen = W + " | " + M + " | " + E + "\n";
- txtChat.append(screen);
- screen = SW + " | " + S + " | " + SE + "\n";
- txtChat.append(screen);
- }
- public static void ReadAndSet() {
- spaceTaken = false;
- if (uText.contains("NW")) {
- char character = side.charAt(0);
- if (NWtaken == true) {
- spaceTaken = true;
- } else {
- Replace("NW", character);
- NWtaken = true;
- }
- } else if (uText.contains("NE")) {
- char character = side.charAt(0);
- if (NEtaken == true) {
- spaceTaken = true;
- } else {
- Replace("NE", character);
- NEtaken = true;
- }
- } else if (uText.contains("SW")) {
- char character = side.charAt(0);
- if (SWtaken == true) {
- spaceTaken = true;
- } else {
- Replace("SW", character);
- SWtaken = true;
- }
- } else if (uText.contains("SE")) {
- char character = side.charAt(0);
- if (SEtaken == true) {
- spaceTaken = true;
- } else {
- Replace("SE", character);
- SEtaken = true;
- }
- } else if (uText.contains("N")) {
- char character = side.charAt(0);
- if (Ntaken == true) {
- spaceTaken = true;
- } else {
- Replace("N", character);
- Ntaken = true;
- }
- } else if (uText.contains("E")) {
- char character = side.charAt(0);
- if (Etaken == true) {
- spaceTaken = true;
- } else {
- Replace("E", character);
- Etaken = true;
- }
- } else if (uText.contains("S")) {
- char character = side.charAt(0);
- if (Staken == true) {
- spaceTaken = true;
- } else {
- Replace("S", character);
- Staken = true;
- }
- } else if (uText.contains("W")) {
- char character = side.charAt(0);
- if (Wtaken == true) {
- spaceTaken = true;
- } else {
- Replace("W", character);
- Wtaken = true;
- }
- } else if (uText.contains("M")) {
- char character = side.charAt(0);
- if (Mtaken == true) {
- spaceTaken = true;
- } else {
- Replace("M", character);
- Mtaken = true;
- }
- }
- Display();
- status = "won";
- ValidateWin();
- if (spaceTaken == true) {
- Say(2, "Sorry that is already taken!");
- }
- }
- public static void Replace(String location, char letter) {
- if (location.equals("NW")) {
- NW = letter;
- NWtaken = true;
- } else if (location.equals("N")) {
- N = letter;
- Ntaken = true;
- } else if (location.equals("NE")) {
- NE = letter;
- NEtaken = true;
- } else if (location.equals("W")) {
- W = letter;
- Wtaken = true;
- } else if (location.equals("M")) {
- M = letter;
- Mtaken = true;
- } else if (location.equals("E")) {
- E = letter;
- Etaken = true;
- } else if (location.equals("SW")) {
- SW = letter;
- SWtaken = true;
- } else if (location.equals("S")) {
- S = letter;
- Staken = true;
- } else if (location.equals("SE")) {
- SE = letter;
- SEtaken = true;
- }
- }
- public static void Encode(String text) {
- String text2 = "";
- int clock = 0;
- int textLength = text.length();
- while (clock < textLength) {
- if (text.charAt(clock) == ' ') {
- text2 = text2 + ";;";
- } else {
- text2 = text2 + text.charAt(clock);
- }
- clock++;
- }
- Encoder(text2);
- }
- public static void GetBoard() {
- board = NW + "" + N + "" + NE + "" + W + "" + M + "" + E + "" + SW + "" + S + "" + SE;
- }
- public static void ChangeBoard() {
- int changed = 0;
- char placeHolder;
- placeHolder = SE;
- SE = output.charAt(output.length() - 1);
- if (placeHolder != SE)
- changed++;
- SEtaken = true;
- placeHolder = S;
- S = output.charAt(output.length() - 2);
- if (placeHolder != S)
- changed++;
- Staken = true;
- placeHolder = SW;
- SW = output.charAt(output.length() - 3);
- if (placeHolder != SW)
- changed++;
- SWtaken = true;
- placeHolder = E;
- E = output.charAt(output.length() - 4);
- if (placeHolder != E)
- changed++;
- Etaken = true;
- placeHolder = M;
- M = output.charAt(output.length() - 5);
- if (placeHolder != M)
- changed++;
- Mtaken = true;
- placeHolder = W;
- W = output.charAt(output.length() - 6);
- if (placeHolder != W)
- changed++;
- Wtaken = true;
- placeHolder = NE;
- NE = output.charAt(output.length() - 7);
- if (placeHolder != NE)
- changed++;
- NEtaken = true;
- placeHolder = N;
- N = output.charAt(output.length() - 8);
- if (placeHolder != N)
- changed++;
- Ntaken = true;
- placeHolder = NW;
- NW = output.charAt(output.length() - 9);
- if (placeHolder != SW)
- changed++;
- NWtaken = true;
- Display();
- if (changed > 1) {
- Say(3, "Opponent Cheated! You win by default!");
- Say(1, "Please send them this error!");
- Encoder("You;;lose!;;You;;automatically;;lost;;for;;Cheating!");
- Say(2, output);
- }
- if (changed == 0) {
- Say(3, "Opponent did not make a move! Please send them this error!");
- Encoder("Error:;;You;;did;;not;;make;;a;;move!;;Please;;try;;again!");
- Say(2, output);
- }
- status = "lost";
- ValidateWin();
- if (scriptStopped == false) {
- Say(2, "Your Turn!");
- }
- }
- public static void Say(int entersBefore, String text) {
- while (entersBefore != 0) {
- txtChat.append("\n");
- entersBefore--;
- }
- txtChat.append(text);
- }
- public static void Directions() {
- txtChat.setText("");
- screen = NW + " | " + N + " | " + NE + "\n";
- txtChat.append(screen);
- screen = W + " | " + M + " | " + E + "\n";
- txtChat.append(screen);
- screen = SW + " | " + S + " | " + SE + "\n";
- txtChat.append(screen);
- Say(2, "For location, use:");
- Say(1, "NW, N, NE");
- Say(1, "W, M, E");
- Say(1, "SW, S SE");
- Say(2, "Format:");
- Say(1, "<Location>");
- Say(2, "Type \"Directions\" to view this again!");
- }
- public static void PickSide() {
- ClearScreen();
- Say(3, "What side are you on (\"X\" or \"O\"): ");
- txtEnter.setText("Side: ");
- customTxtEnterText = "Side: ";
- }
- public static void Wait(String timeUnit, int time) {
- int multiplier;
- if (timeUnit.equals("s")) {
- try {
- Thread.sleep(time);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } else if (timeUnit.equals("m")) {
- multiplier = 60;
- try {
- Thread.sleep(time * multiplier);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } else if (timeUnit.equals("h")) {
- multiplier = 3600;
- try {
- Thread.sleep(time * multiplier);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- public static void ClearScreen() {
- txtChat.setText("");
- }
- public static void ValidateWin() {
- //__X_X_X__
- if ((NE == M) && (M == SW)) {
- if ((NE != '_') && (M != '_') && (SW != '_')) {
- win = true;
- winMethod = "__X_X_X__";
- }
- }
- //X___X___X
- if ((NW == M) && (M == SE)) {
- if ((NW != '_') && (M != '_') && (SE != '_')) {
- win = true;
- winMethod = "X___X___X";
- }
- }
- //XXX______
- if ((NW == N) && (N == NE)) {
- if ((NW != '_') && (N != '_') && (NE != '_')) {
- win = true;
- winMethod = "XXX______";
- }
- }
- //___XXX___
- if ((W == M) && (M == E)) {
- if ((W != '_') && (M != '_') && (E != '_')) {
- win = true;
- winMethod = "___XXX___";
- }
- }
- //______XXX
- if ((SW == S) && (S == SE)) {
- if ((SW != '_') && (S != '_') && (SE != '_')) {
- win = true;
- winMethod = "______XXX";
- }
- }
- //__X__X__X
- if ((NE == E) && (E == SE)) {
- if ((NE != '_') && (E != '_') && (SE != '_')) {
- win = true;
- winMethod = "__X__X__X";
- }
- }
- //_X__X__X_
- if ((N == M) && (M == S)) {
- if ((N != '_') && (M != '_') && (S != '_')) {
- win = true;
- winMethod = "_X__X__X_";
- }
- }
- //X__X__X__
- if ((NW == W) && (W == SW)) {
- if ((NW != '_') && (W != '_') && (SW != '_')) {
- win = true;
- winMethod = "X__X__X__";
- }
- }
- EndGame();
- }
- public static void EndGame() {
- if (status.equals("won")) {
- if (win == true) {
- System.out.println(winMethod);
- Say(3, "You Won! Send the final code to your opponent!");
- Say(2, "Thanks For playing!");
- scriptStopped = true;
- }
- } else {
- if (win == true) {
- System.out.println(winMethod);
- Say(3, "You Lost!");
- Say(2, "Thanks For playing!");
- scriptStopped = true;
- }
- }
- }
- // Beginning of GUI Attributes:
- //Typing Area:
- private static JTextField txtEnter = new JTextField();
- //Chat Area:
- private static JTextArea txtChat = new JTextArea();
- public TicTacToe() throws InterruptedException{
- //Frame Attributes:
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setSize(600, 600);
- this.setVisible(true);
- this.setResizable(false);
- this.setLayout(null);
- this.setTitle("TicTacToe [Java Edition]");
- //txtEnter Attributes:
- txtEnter.setLocation(2, 540);
- txtEnter.setSize(590, 30);
- //txtChat Attributes:
- txtChat.setLocation(15, 5);
- txtChat.setSize(560, 510);
- txtChat.setEditable(false);
- //Add Items To Frame:
- this.add(txtEnter);
- this.add(txtChat);
- //txtEnter Action Event:
- txtEnter.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent arg0) {
- uText = txtEnter.getText();
- //txtChat.append(uText + "\n");
- if ((uText.length() > 4) && (uText.charAt(uText.length() - 1) == 'A')) {
- if ((uText.charAt(uText.length()-1) + "" + uText.charAt(uText.length() - 2) + "" + uText.charAt(uText.length() - 3)).equals("AVJ")) {
- Encoder(uText);
- if (output.charAt(output.length() - 1) == '!') {
- Say(2, output);
- } else
- ChangeBoard();
- }
- } else if (uText.contains("Directions")) {
- Directions();
- } else if (uText.contains("Side: ")) {
- if ((uText.charAt(uText.length() - 1) != 'X') && (uText.charAt(uText.length() - 1) != 'O')) {
- Say(1, "Something went wrong! Please Try Again!");
- PickSide();
- } else {
- customTxtEnterText = "";
- side = uText.charAt(uText.length() - 1) + "";
- Directions();
- }
- } else {
- ReadAndSet();
- GetBoard();
- Encode(board);
- if (scriptStopped == false) {
- txtChat.append("\n \n \n \n" + output + "\n \nSend this to the opponent!");
- }
- }
- txtEnter.setText(customTxtEnterText);
- customTxtEnterText = "";
- }
- });
- }
- public static void main(String[] args) throws InterruptedException {
- PickSide();
- new TicTacToe();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement