Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help: Boggle in Java
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
akafurious




PostPosted: Sat Dec 11, 2010 5:35 pm   Post subject: Help: Boggle in Java

I am making a Boggle game, but need some help. the code i have reads a text file that has 5454 words and then makes a game 4x4 game board by reading the letters of words in the text file. the problem is that i need to use a sorting algorithm the algorithm i picked is selection sorting but i am having a problem implementing it.


code:

/*
 * Boggle
 */

import java.util.*; //imports scanner and other userful objects
import java.io.*;  //java input/output for file reading


public class myBoggle
{
    static String[][]game = new String[4][4];
    static String[]words = new String[5454];  //5454 - 4 letter words
   
   
   
    public static void main(String [] args) {

        Scanner input = new Scanner(System.in);  //instantiate scanner object
        readWords(words);
        makeBoard(game);
        printBoard(game);
       
       
       
    }

   
/*readWords reads in the list of all 4 letter words from words.txt file*/
    public static void readWords(String []words){
        File textFile = new File("words.txt");
        FileReader in;
        BufferedReader readFile;
        String line;
        try{
            in= new FileReader(textFile);
            readFile = new BufferedReader(in);
            for (int i=0; i<words.length; i++){
                line = readFile.readLine();
                words[i]=line;
            } 
            readFile.close();
            in.close();
        }catch(IOException e){  //handles file errors
            System.out.println("Error with input file");
        }
    }

    /*makeBoard creates a game board with random capital letters*/
    public static void makeBoard(String [][]game){
        //The ASCII codes for the letters A to Z are 65 to 90
        //for random integer use formula (90-65+1) + 1
        Random r = new Random();
        int num;
        for (int i=0; i<game.length; i++)
            for (int j=0; j<game[0].length;j++){
                num = r.nextInt(26)+65;  //random int grom 65 to 90
                game[i][j] = "       [" +"" +(char)num +"]"; //cast integer as character
        }

    }

    /* printBoard prints the game board for the user */
    public static void printBoard(String [][]game){
        for (int i=0; i<game.length; i++){
            for (int j=0; j<game[0].length; j++)
                System.out.print(game[i][j]);
            System.out.println();
        }
    }
 
 
   

   }
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Mon Dec 13, 2010 12:52 pm   Post subject: RE:Help: Boggle in Java

Well it would help us if you had a specific problem, or at least posted your attempt. I can't find an attempt at selection sort in your code. If you're just looking to learn how to implement selection sort from scratch, you can start at the Wikipedia page:
http://en.wikipedia.org/wiki/Selection_sort
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: