Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Random;
- import java.util.Scanner;
- public class DP238M { //FO3/FNV Hacking Minigame
- static ArrayList<String> dict = DictionaryLoader.loadDictionary();
- static Scanner sc = new Scanner(System.in);
- //Terminal Difficulties: Password length - words
- //Very Easy: 4-5 - 5
- //Easy: 6-8 - 8
- //Average: 9-10 - 10
- //Hard: 11-12 - 12
- //Very Hard: 13-15 - 15
- public static void main(String[] args){
- int difficulty = randInt(0,4); //0 -> 4
- int wordlength = 0;
- int numwords = 0;
- switch(difficulty){
- case 0:
- wordlength = randInt(4,5);
- numwords = 5;
- break;
- case 1:
- wordlength = randInt(6,8);
- numwords = 8;
- break;
- case 2:
- wordlength = randInt(9,10);
- numwords = 10;
- break;
- case 3:
- wordlength = randInt(11,12);
- numwords = 12;
- break;
- case 4:
- wordlength = randInt(13,15);
- numwords = 15;
- break;
- }
- System.out.println("Difficulty: " + difficulty);
- System.out.println("Word Length: " + wordlength);
- System.out.println("Number of Words: " + numwords);
- ArrayList<String> validwords = new ArrayList<String>();
- for(int i=0; i<dict.size(); i++){
- if(dict.get(i).length() == wordlength){
- validwords.add(dict.get(i));
- }
- }
- //System.out.println("Selected subset containing " + validwords.size() + " words of length " + wordlength);
- System.out.println();
- ArrayList<String> usedwords = new ArrayList<String>();
- while(usedwords.size() < numwords){
- int w = randInt(0, validwords.size());
- usedwords.add(validwords.get(w));
- validwords.remove(w);
- }
- int correctword = randInt(0,usedwords.size()-1);
- String cw = usedwords.get(correctword);
- boolean foundcorrect = false;
- int guesses = 4;
- while(!foundcorrect && guesses > 0){
- for(int i=0; i<5; i++){
- System.out.println();
- }
- /*
- for(int i=0; i<usedwords.size(); i++){
- System.out.println();
- System.out.print(hexAfter(i) + " " + usedwords.get(i).toUpperCase() + " (" + i + ")");
- if(i == correctword){
- //System.out.print(" <---");
- }
- }
- System.out.println();
- */
- printTerminal(wordlength,numwords,guesses,usedwords);
- System.out.println("Make a selection ("+0+" - "+ (usedwords.size()-1)+")");
- int sel = sc.nextInt();
- String sw = usedwords.get(sel);
- int correctcounter = 0;
- for(int i=0; i<sw.length(); i++){
- if(sw.charAt(i) == cw.charAt(i))
- correctcounter++;
- }
- System.out.println("> " + sw.toUpperCase());
- if(correctcounter == wordlength){
- System.out.println("> Exact match!");
- System.out.println("> Please wait while system is accessed.");
- foundcorrect = true;
- }
- else{
- System.out.println("> Entry denied");
- System.out.println("> " + correctcounter+"/"+wordlength + " correct.");
- }
- guesses--;
- }
- }
- public static int randInt(int min, int max) {
- Random rand = new Random();
- int randomNum = rand.nextInt((max - min) + 1) + min;
- return randomNum;
- }
- public static String hexAfter(int n){
- String hex = "0x";
- String add = Integer.toHexString(3000+(int)Math.pow(n, 3));
- while(hex.length() + add.length() < 6){
- hex+="0";
- }
- hex+=add.toUpperCase();
- return hex;
- }
- public static void printTerminal(int wl, int nw, int ng, ArrayList<String> uw){
- //N ATTEMPT(S) LEFT [] [] [] []
- //0xF748 xxxxxxxxxxxxxxx 0xF814 xxxxxxxxxxxxxx
- char[] randchars = {')','/','@','^',']',';'};
- int numlines = 15;
- int totalspaces = numlines*2;
- int wordposition = (int)(totalspaces/nw)+1;
- int linelength = 15;
- System.out.println();
- System.out.print(ng + " ATTEMPT(S) LEFT: ");
- for(int i=0; i<ng; i++){
- System.out.print("# ");
- }
- System.out.println();
- for(int i=0; i<numlines; i++){
- int w1 = i;
- int w2 = i+1;
- String line = "";
- //First column
- line+=hexAfter(i);
- if(w1%wordposition == 0){
- line+=centreTextwithRandChars(uw.get(i/wordposition).toUpperCase(),15,randchars);
- }
- else{
- line+=centreTextwithRandChars("",15,randchars);
- }
- line+=" ";
- //Second column
- line+=hexAfter(i+numlines);
- if(w2%wordposition == 0){
- line+=centreTextwithRandChars(uw.get(((i+numlines)/wordposition)).toUpperCase(),15,randchars);
- }
- else{
- line+=centreTextwithRandChars("",15,randchars);
- }
- System.out.println(line);
- }
- }
- public static String centreTextwithRandChars(String c, int length, char[] cset){
- String centred = "";
- int startchar = (length-c.length())/2;
- for(int i=0; i<startchar; i++){
- centred+=cset[randInt(0,cset.length-1)];
- }
- centred+=c;
- while(centred.length()<length){
- centred+=cset[randInt(0,cset.length-1)];
- }
- return centred;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement