and it didn't let me upload ROLLO.java so here it is:
// ROLLO player
// by unreality
// Tuesday, July 6th, 2010 and Wednesday too haha
import java.util.Scanner;
import java.io.File;
import java.util.ArrayList;
import java.io.FileWriter;
public class ROLLO
{
public static void main(String[] args)
{
Scanner inp = new Scanner(System.in);
System.out.print("\f\nROLLO!");
char[] word;
boolean run = true;
while (run)
{
word = generateWord();
String rec = getRecord();
System.out.print("\n\nThe computer has thought of a word. Enter your guesses at the prompt and hit enter!\nThe goal is to minimize your guesses.\nCurrent Record: "+rec+" guesses.\nType a tilde to give up. Type a 'q' to quit immediately.\nType a dash (-) to get a list of what you've guessed so far. Good luck!\n\n");
int gcount = 0;
String guess = "";
ArrayList<Integer> ar_s = new ArrayList<Integer>();
ArrayList<String> ar_g = new ArrayList<String>();
while (!guess.equals(" ") && !guess.equals("~"))
{
System.out.print(">: ");
guess = inp.next().toLowerCase();
if (guess.length() == 5)
{
int c = 0;
for (int i=0; i<5; i++) if (guess.charAt(i) == word[i]) c++;
System.out.print(" >>> "+c+"\n\n");
ar_g.add(guess);
ar_s.add(c);
gcount++;
if (c == 5) guess = " ";
}
else if (guess.equals("q")) System.exit(0);
else if (guess.equals("-"))
{
System.out.print("\nGUESS TABLE:\n\n");
for (int x=0; x<ar_s.size(); x++)
{
System.out.println(ar_g.get(x)+" - "+ar_s.get(x));
}
System.out.println();
}
else if (guess.equals("#"))
{
System.out.print("\n\n\t");
for (int i=0; i<5; i++) System.out.print(word[i]);
System.out.print("\n\n");
}
}
if (guess.equals(" ")) {
String extra = "";
if (isNumeric(rec))
{
int recc = Integer.parseInt(rec);
if (gcount == recc) extra = " You tied the record!";
if (gcount < recc) { extra = " That's the new record!"; setRecord(gcount); }
}
System.out.print("\nCongrats! You got it in "+gcount+" guesses!"+extra+"\nPlay again? (Y|N) ");
}
else
{
System.out.print("Give up? The word was ");
for (int i=0; i<5; i++) System.out.print(word[i]);
System.out.print("\nPlay again? (Y|N) ");
}
run = (inp.next().toUpperCase().charAt(0) == 'Y');
}
System.out.print("\n\n\tThanks for playing... have a great day...");
}
public static boolean isNumeric(String s)
{
for (int i=0; i<s.length(); i++) if (!isNumeric(s.charAt(i))) return false;
return true;
}
public static boolean isNumeric(char ch)
{
return (ch=='0' ||
ch=='1' ||
ch=='2' ||
ch=='3' ||
ch=='4' ||
ch=='5' ||
ch=='6' ||
ch=='7' ||
ch=='8' ||
ch=='9');
}
public static char[] generateWord()
{
Scanner f;
try {f = new Scanner(new File("fiveletterwords.txt"));}
catch(java.io.FileNotFoundException ff) { return "xxxxx".toCharArray(); }
int numthere = 0; String throwaway="xxxxx";
while (f.hasNext()) { throwaway=f.next(); if (throwaway.length() == 5) {numthere++;} }
int randomPos = (int)(Math.random() * numthere);
Scanner g;
try {g = new Scanner(new File("fiveletterwords.txt"));}
catch(java.io.FileNotFoundException ff) { return "xxxxx".toCharArray(); }
for (int ii=0; ii<randomPos; ii++) throwaway = g.next();
return throwaway.toCharArray();
}
public static String getRecord()
{
Scanner f;
try {f = new Scanner(new File("fiveletterwords.txt"));}
catch(java.io.FileNotFoundException ff) { return "1 bazillion"; }
int numthere = 0; String throwaway="xxxxx";
while (f.hasNext()) { throwaway=f.next(); numthere++; }
Scanner g;
try {g = new Scanner(new File("fiveletterwords.txt"));}
catch(java.io.FileNotFoundException ff) { return "1 bazillion"; }
for (int ii=0; ii<numthere; ii++) throwaway = g.next();
return throwaway;
}
public static void setRecord(int newr)
{
FileWriter fw;
try {fw = new FileWriter("fiveletterwords.txt", true); fw.write(newr+" "); fw.close(); }
catch(java.io.IOException ioe) { return; }
}
}
Question
unreality
you'll need both files in the same directory:
fiveletterwords.txt
and it didn't let me upload ROLLO.java so here it is:
Link to comment
Share on other sites
11 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.