Skip to content

Instantly share code, notes, and snippets.

@memish
Last active December 11, 2018 16:07
Show Gist options
  • Save memish/660133f1c53bf1c7b92785de0f939966 to your computer and use it in GitHub Desktop.
Save memish/660133f1c53bf1c7b92785de0f939966 to your computer and use it in GitHub Desktop.
import java.io.FileWriter;
import java.net.*;
import java.io.*;
//Important Variables below
boolean admin = true;//if set to true this user can reset the game
String player = "MrMemmo_";//Username, do not use any spaces in the name
String dir = "http://172.16.37.184/latin2/";//change to correct directory
//Important variables above
FileWriter fw;
BufferedWriter bw;
PrintWriter output;
boolean start=false;
boolean readit = false;
boolean append = false;
String[] lines;
boolean startOut=true;
int size = 25;
String[] gameLines;
ArrayList<String> words = new ArrayList<String>(); //holds the words from the file
String word = "";
ArrayList<String> heldCards = new ArrayList<String>(); //the words the player has available
int NOS;
int curSent = -1;
ArrayList<String> sentences = new ArrayList<String>();//sentences
int clickedCard = 9;
String wfile = "writer.php";
String gfile = "latinwords.txt";
String fname = "latinwords2.txt";
void setup() {
// Create a new file in the sketch directory
size(800,600);
// openFile();
read();
readSentences();
getSentence();
}
public void readSentences() {
lines = loadStrings(dir + "sentences.txt");
NOS = sentences.size();
printArray(lines);
for (int i=0; i<lines.length; i++) {//look at each line
sentences.add(lines[i]);
//print(sentences.get(i));
}
}
void draw() {
background(150);
drawRect();
if(curSent !=-1){
fill(255);
textSize(30);
text(sentences.get(curSent), 30,30);
}
//button
fill(255,0,0);
rect(10,70,100,40);
fill(255,255,255);
gameLines = loadStrings(dir + gfile);
textSize(15);
for (int i=0; i<gameLines.length; i++) {//look at each line
text(gameLines[i],width - 250, (i * 20) + 75);
}
//int y = 20;
textSize(20);
fill(0);
for(int i = 0; i<heldCards.size(); i++){
text(heldCards.get(i),(i)*(width/6)+5,(3*height/4)+20);
//y += size;
}
}//end of draw
void drawRect(){
for(int i = 0; i<8; i++){
fill(255);
if(i==clickedCard){
fill(130);
}
rect(i*width/6, (3*height)/4, width/6, height/4);
}
}
public void read(){
lines = loadStrings(dir + "LatinStrings.txt");
//println("There are " + lines.length + "words.");
for(int i = 0; i < lines.length; i++){
words.add(lines[i]);
}
//println(words);
for(int i = 0; i < 6; i++){
int place = (int)(random(0, words.size()));
heldCards.add(words.remove(place));
//replace above code with method to put words in rectangles(from drew + ericas code)
}
}
void getSentence(){
curSent = (int)random(sentences.size());
}
void postNewItem (String data, String starter,String fn) {
try {
//"append"
URL url = new URL(dir + wfile + "?data=" + data + "&start="+starter+ "&fname="+fn);
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
is.close();
}catch (Exception ioe) {
println("IO" + ioe);
}
} // end of postNewItem() method
void mousePressed() {
//rect(10,70,100,40);
if(mouseX>10 && mouseX<110 && mouseY>70 && mouseY < 170){
if(admin==true){
postNewItem("NewGame", "no", "latinwords.txt");
curSent++;
}
}
if(mouseY > 3*height/4){
clickedCard = (int)(mouseX/(width/6));
sendCard(clickedCard);
print(clickedCard);
}
}
void sendCard(int card){
println(heldCards.size());
String s = heldCards.remove(card);
postNewItem(player + s.trim(), "append", "latinwords.txt");
int place = (int)(random(0, words.size()));
heldCards.add(words.remove(place));
//words.add(heldCards.remove(clickedCard));
println(heldCards.size());
}
@landjd19
Copy link

landjd19 commented Dec 11, 2018

change line 179 to words.add(heldCards.get(card)); and put it above String s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment