Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Wheel of Fortune - Simple Game

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Wheel of Fortune - Simple Game

    Well my Java class has been assigned to design a basic Wheel of Fortune game !! Sounds fun right? WRONG!! LoL.. Here is the thing, we have each been given a portion of the game to code, I got the -Update Player Data- portion.. I don't know if I should do this as a seperate .java or .class file from the main game.java or if I can simply add this to the current code?? I have to be able to Add/Subtract Points (Money), 1st Time Reset Points (money) to Zero, and 1st Enter Player Name .... I think I know how I need to code this, JButton, JLabel... right? Or am I looking at this incorrectly?? Right now we have a base to work with.. see below.. Thanks for the help!!

    import java.awt.*;
    import java.awt.event.*;
    import java.text.DecimalFormat;
    import java.util.Random;
    import javax.swing.*;
     
    @SuppressWarnings("serial")
    public class Game extends JFrame {
     
    	private JLabel gameLogoJLabel;
    	private JLabel testDataJLabel;
    	private JPanel letterOptionsJPanel;
    	private JPanel puzzleJPanel;
     
     
    	JButton[][] grid; //names the array of buttons
    	JButton[][] puzzleGrid;
        private static final char[] TotalAlphabet = {'A','B','C','D','E','F','G'
    		,'H','I','J','K','L','M','N'
    		,'O','P','Q','R','S','T','U'
    		,'V','W','X','Y','Z'};//Display in window for JButtons
        private  char[] puzzleChars = new char[60];
    	// no-argument constructor
    	public Game(){
    		createUserInterface();
    	}
     
    	private void createUserInterface(){		
    		// get content pane for attaching GUI components
     
    		Container contentPane = getContentPane();
    		contentPane.setBackground(Color.BLACK);
    		contentPane.setLayout( null );
    		 //JScrollPane scrollBar=new JScrollPane(contentPane,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); 
     
    		testDataJLabel = new JLabel();
    		testDataJLabel.setBounds(850,250,200,18);
    		//testDataJLabel.setBackground(Color.WHITE);
    		testDataJLabel.setForeground(Color.WHITE);
    		 contentPane.add(testDataJLabel);
     
    		letterOptionsJPanel = new JPanel();
    		letterOptionsJPanel.setBounds(50,250,670,100);
    		letterOptionsJPanel.setLayout(new GridLayout(2,13));
    		grid=new JButton[2][13]; //allocate the size of grid 
            int count = 0;//for Alphabet assignment
            for(int r=0; r<2; r++){
                    for(int c=0; c<13; c++){
                            grid[r][c]=new JButton(""+TotalAlphabet[count]+""); 
                            grid[r][c].setActionCommand("disable");
     
     
                            grid[r][c].addActionListener(new ActionListener(){
                            	public void actionPerformed(ActionEvent event){
                            		gridactionPerformed(event);
                            	}
                            });
                            letterOptionsJPanel.add(grid[r][c]); //adds button to grid
                            count++;
                    }
            }
    		contentPane.add(letterOptionsJPanel); 
     
    		puzzleJPanel = new JPanel();
    		puzzleJPanel.setBounds(50,360,900,200);
    		puzzleJPanel.setLayout(new GridLayout(3,20));
    		String puzzleString = "Can you guess what it is";
    		int puzzleLength = puzzleString.length();
     
     
    		int spacesBegin = puzzleLength;
    			for(int letters = 0;letters < 60; letters++)
    			{
    				if (letters >= spacesBegin)
    				{
    					puzzleChars[letters]=' ';
    				}
    				else
    				{
    					puzzleChars[letters]=puzzleString.charAt(letters);
    				}
    			}
     
    		testDataJLabel.setText(puzzleString);
    		puzzleGrid=new JButton[3][20]; //allocate the size of grid 
     
     
            int puzzlecount = 0;//for Alphabet assignment
     
            for(int r=0; r<3; r++){
                    for(int c=0; c<20; c++){
                            puzzleGrid[r][c]=new JButton(""+puzzleChars[puzzlecount]+""); 
                            puzzleGrid[r][c].setActionCommand("disable");
     
     
                            puzzleJPanel.add(puzzleGrid[r][c]); //adds button to grid
                            puzzlecount++;
                    }
            }
     
     
     
           contentPane.add(puzzleJPanel); 
     
     
    	    gameLogoJLabel = new JLabel();
    	    gameLogoJLabel.setIcon(new ImageIcon("C:/Users/jamesb/Downloads/Wheel_of_Fortune/board.png"));
    	    gameLogoJLabel.setBounds(50,15,800,232);
    	    gameLogoJLabel.setHorizontalAlignment(JLabel.CENTER);
    	    contentPane.add(gameLogoJLabel);
     
     
    	    // set properties of application's window
    		setTitle( "Wheel of Fortune" ); // set title bar string
    		setSize( 1105, 800 );      // set window size
    		setVisible( true );       // display window
     
     
    	} // end createUserInterface
     
    	 public void gridactionPerformed(ActionEvent e) { 
         	JButton passedButton =(JButton) e.getSource();
         	String letter = passedButton.getText();
         	if (letter.equals("A") )
         		grid[0][0].setEnabled(false);
         	else if (letter.equals("B"))
         		grid[0][1].setEnabled(false);
         	else if (letter.equals("C"))
         		grid[0][2].setEnabled(false);
         	else if (letter.equals("D"))
         		grid[0][3].setEnabled(false);
         	else if (letter.equals("E"))
         		grid[0][4].setEnabled(false);
         	else if (letter.equals("F"))
         		grid[0][5].setEnabled(false);
         	else if (letter.equals("G"))
         		grid[0][6].setEnabled(false);
         	else if (letter.equals("H"))
         		grid[0][7].setEnabled(false);
         	else if (letter.equals("I"))
         		grid[0][8].setEnabled(false);
         	else if (letter.equals("J"))
         		grid[0][9].setEnabled(false);
         	else if (letter.equals("K"))
         		grid[0][10].setEnabled(false);
         	else if (letter.equals("L"))
         		grid[0][11].setEnabled(false);
         	else if (letter.equals("M"))
         		grid[0][12].setEnabled(false);
         	else if (letter.equals("N"))
         		grid[1][0].setEnabled(false);
         	else if (letter.equals("O"))
         		grid[1][1].setEnabled(false);
         	else if (letter.equals("P"))
         		grid[1][2].setEnabled(false);
         	else if (letter.equals("Q"))
         		grid[1][3].setEnabled(false);
         	else if (letter.equals("R"))
         		grid[1][4].setEnabled(false);
         	else if (letter.equals("S"))
         		grid[1][5].setEnabled(false);
         	else if (letter.equals("T"))
         		grid[1][6].setEnabled(false);
         	else if (letter.equals("U"))
         		grid[1][7].setEnabled(false);
         	else if (letter.equals("V"))
         		grid[1][8].setEnabled(false);
         	else if (letter.equals("W"))
         		grid[1][9].setEnabled(false);
         	else if (letter.equals("X"))
         		grid[1][10].setEnabled(false);
         	else if (letter.equals("Y"))
         		grid[1][11].setEnabled(false);
         	else if (letter.equals("Z"))
         		grid[1][12].setEnabled(false);
     
     
            } 
     
    	// main method
    	public static void main( String args[] ){
    		Game application = new Game();
    		application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
     
    	} // end method main
     
    } // end Game class


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Wheel of Fortune - Simple Game

    Depends upon the requirements. If you are required to do with Buttons and Labels etc, then use else, there can be many other ways too.

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Wheel of Fortune - Simple Game

    Quote Originally Posted by Mr.777 View Post
    Depends upon the requirements. If you are required to do with Buttons and Labels etc, then use else, there can be many other ways too.
    I would like there to be a button at the least to reset the current player total ... but I'm thinking this should all be included with the 'New Game' module.. Because clicking the 'New Game' button will reset so maybe that will call to my module as well... but also have it separate?

  4. #4
    Junior Member
    Join Date
    Jan 2012
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Wheel of Fortune - Simple Game

    Ok... here is my start..

    	public void initBoard(int player)  
    	   {
    	       players[player].initMyBoard(locInPuzzleBoard);
    	   }
     
     
    	   public void execute()
    	   {
    	      for ( int i = 0; i < players.length; i++ ) {
    	         try {
    	             players[i] = new Player( server.accept(), this, i );
    	             players[i].start();
    		 }
    	         catch( IOException e ) 
    	         {
    	             e.printStackTrace();
    	             System.exit(1);
    	         }
    	      }
    	      players[0].setTurn();
    	   }

Similar Threads

  1. Need help with a wheel of fortune game
    By DanTheSand in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 14th, 2012, 05:03 PM
  2. Simple game that requires me to load game settings from a file
    By 14fenix in forum Java Theory & Questions
    Replies: 5
    Last Post: December 1st, 2011, 09:21 PM
  3. Simple game problem
    By frozen java in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 30th, 2011, 09:14 PM
  4. Programming AI for simple game?
    By YouGoLast in forum Java Theory & Questions
    Replies: 2
    Last Post: May 28th, 2011, 08:53 AM
  5. Simple game in Java
    By velop in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 27th, 2010, 05:04 AM