Skip to content

Commit

Permalink
matrix wordbank orientation feature
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisEDelRio committed Apr 29, 2024
1 parent 271a6a5 commit 8db9afa
Show file tree
Hide file tree
Showing 27 changed files with 52 additions and 34 deletions.
6 changes: 3 additions & 3 deletions src/main/java/uta/cse3310/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ public void fillWordBank(ArrayList<Words> usedWordList){
wordBank.clear(); //Clears the bank before adding in case there's some words left in there from last game
}

for(Words w : usedWordList){
if(w != null && w.word != null){
wordBank.add(w.word);
for(String w : matrix.wordBankList){
if(w != null && w != null){
wordBank.add(w);
}
}

Expand Down
65 changes: 49 additions & 16 deletions src/main/java/uta/cse3310/Matrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class Matrix {
printGrid(); //prints completed grid //debugging
printUsedWordList(); //debugging

wordBankList = new ArrayList<String>();

}

//initialize our grid to all zeros only to be used at the start
Expand Down Expand Up @@ -123,13 +125,19 @@ public void fillGrid(){

int orientation = rand.nextInt(2);
if(orientation == 0){ //regular word orietation
horizontalWordInsert(word);
//horizontalWordInsert(word)
if(horizontalWordInsert(word)){ //if word was inserted
wordBankList.add(word); //include in word bank correct orientation
}
}else{
//invert our word
StringBuilder SBWord = new StringBuilder(word);
SBWord.reverse();
String inverseWord = SBWord.toString();
horizontalWordInsert(inverseWord);
//horizontalWordInsert(inverseWord);
if(horizontalWordInsert(inverseWord)){ //if word got inserted
wordBankList.add(word); //inlcude in word bank correct orientation
}
}
}
//System.out.println(calcDensity()); //debugging
Expand All @@ -144,13 +152,20 @@ public void fillGrid(){

int orientation = rand.nextInt(2);
if(orientation == 0){ //regular word orietation
verticalWordInsert(word);
//verticalWordInsert(word);
if(verticalWordInsert(word)){
wordBankList.add(word);
}

}else{
//invert our word
StringBuilder SBWord = new StringBuilder(word);
SBWord.reverse();
String inverseWord = SBWord.toString();
verticalWordInsert(inverseWord);
//verticalWordInsert(inverseWord);
if(verticalWordInsert(inverseWord)){
wordBankList.add(word);
}
}
}
//System.out.println(calcDensity()); //debugging
Expand All @@ -165,13 +180,19 @@ public void fillGrid(){

int orientation = rand.nextInt(2);
if(orientation == 0){ //regular word orietation
diagonalWordInsert1(word);
//diagonalWordInsert1(word);
if(diagonalWordInsert1(word)){
wordBankList.add(word);
}
}else{
//invert our word
StringBuilder SBWord = new StringBuilder(word);
SBWord.reverse();
String inverseWord = SBWord.toString();
diagonalWordInsert1(inverseWord);
//diagonalWordInsert1(inverseWord);
if(diagonalWordInsert1(inverseWord)){
wordBankList.add(word);
}
}
}
//System.out.println(calcDensity()); //debugging
Expand All @@ -186,21 +207,27 @@ public void fillGrid(){

int orientation = rand.nextInt(2);
if(orientation == 0){ //regular word orietation
diagonalWordInsert2(word);
//diagonalWordInsert2(word);
if(diagonalWordInsert2(word)){
wordBankList.add(word);
}
}else{
//invert our word
StringBuilder SBWord = new StringBuilder(word);
SBWord.reverse();
String inverseWord = SBWord.toString();
diagonalWordInsert2(inverseWord);
//diagonalWordInsert2(inverseWord);
if(diagonalWordInsert2(inverseWord)){
wordBankList.add(word);
}
}
}
//System.out.println(calcDensity()); //debugging

}

//inserts horizontal words also saves inserted words
public void horizontalWordInsert(String word){
//inserts horizontal words also saves inserted words returns true if word was inserted
public boolean horizontalWordInsert(String word){

//System.out.println("Word Recieved: " + word); //debugging

Expand Down Expand Up @@ -257,13 +284,16 @@ public void horizontalWordInsert(String word){
}
Words wrd = new Words(word, x, y, x_endpoint, y);
usedWordList.add(wrd);
return true;
}
}
}

return false; //nothing inserted
}

//inserts vertical words also saves inserted words
public void verticalWordInsert(String word){
public boolean verticalWordInsert(String word){

//System.out.println("Word Recieved: " + word); //debugging

Expand Down Expand Up @@ -321,14 +351,16 @@ public void verticalWordInsert(String word){
}
Words wrd = new Words(word, x, y, x, y_endpoint);
usedWordList.add(wrd);
return true;
}
}
}
return false;

}

//inserts diagonal words TOP-LEFT -> BOTTOM-RIGHT also saves inserted words
public void diagonalWordInsert1(String word){
public boolean diagonalWordInsert1(String word){

//System.out.println("Word Recieved: " + word); //debugging

Expand Down Expand Up @@ -387,16 +419,16 @@ public void diagonalWordInsert1(String word){
}
Words wrd = new Words(word, x, y, x_endpoint, y_endpoint);
usedWordList.add(wrd);

return true;
}
}
}

return false;

}

//inserts diagonal words TOP-RIGHT -> BOTTOM-LEFT also saves inserted words
public void diagonalWordInsert2(String word){
public boolean diagonalWordInsert2(String word){
//System.out.println("Word Recieved: " + word); //debugging

//select a random spot in the 50x50 grid to start the insert
Expand Down Expand Up @@ -455,10 +487,11 @@ public void diagonalWordInsert2(String word){
}
Words wrd = new Words(word, x, y, x_endpoint, y_endpoint);
usedWordList.add(wrd);
return true;
}
}
}

return false;

}

Expand Down
Binary file removed target/classes/com/example/Chat.class
Binary file not shown.
Binary file removed target/classes/uta/cse3310/Chat$Message.class
Binary file not shown.
Binary file removed target/classes/uta/cse3310/Chat.class
Binary file not shown.
Binary file removed target/classes/uta/cse3310/Game.class
Binary file not shown.
Binary file removed target/classes/uta/cse3310/HttpServer.class
Binary file not shown.
Binary file removed target/classes/uta/cse3310/Lobby.class
Binary file not shown.
Binary file removed target/classes/uta/cse3310/Main.class
Binary file not shown.
Binary file removed target/classes/uta/cse3310/Matrix.class
Binary file not shown.
Binary file removed target/classes/uta/cse3310/Player.class
Binary file not shown.
Binary file removed target/classes/uta/cse3310/UserMsg.class
Binary file not shown.
Binary file removed target/classes/uta/cse3310/Words.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 0 additions & 15 deletions target/classes/uta/cse3310/backEndFunctionalityExamples/Tasks.txt

This file was deleted.

Binary file not shown.
Binary file removed target/test-classes/uta/cse3310/Before.class
Binary file not shown.
Binary file removed target/test-classes/uta/cse3310/ChatTest.class
Binary file not shown.
Binary file removed target/test-classes/uta/cse3310/GameTest.class
Binary file not shown.
Binary file removed target/test-classes/uta/cse3310/LobbyTest.class
Binary file not shown.
Binary file removed target/test-classes/uta/cse3310/MainTest.class
Binary file not shown.
Binary file removed target/test-classes/uta/cse3310/MatrixTest.class
Binary file not shown.
Binary file removed target/test-classes/uta/cse3310/PlayerTest.class
Binary file not shown.
Binary file removed target/test-classes/uta/cse3310/UserMsgTest.class
Binary file not shown.

0 comments on commit 8db9afa

Please sign in to comment.