Page 1 of 2 12 LastLast
Results 1 to 20 of 21
Like Tree1Likes

Thread: need help at assignment

  1. #1
    ng min teck is offline Member
    Join Date
    Jul 2012
    Posts
    9
    Rep Power
    0

    Default need help at assignment

    I need help for create roll dice function with below requirement
    need help at assignment-java.jpg


    When the Roll the dice button is clicked, it should perform the following actions:
    Simulate the rolling of a dice and place the counter in the correct square. If the position of the counter exceeds Square 32, it will go backwards. E.g. if the counter is on Square 31 and the dice number is 4, it will go backwards and land on Square 29.
    Update the message in the text area to display the game status.
    When the counter lands exactly on Square 32, a message will be displayed to show the completion of the game:

    Player class can have method like:


    resetPlayer

    getPlayerImage

    setPlayerImage

    getPosition

    setPosition

    getNumOfRolls

    setNumOfRolls

    getName

    setName

    rollDice



    Game class can have methods like:



    getPlayer

    advanceCurrentPlayer

    nextGame

    getHistory

    setHistory

    Thank

  2. #2
    lannie1980 is offline Member
    Join Date
    Mar 2012
    Posts
    88
    Rep Power
    0

    Default Re: need help at assignment

    Hi,

    Post the code you've written so far please then someone can help you much better.

  3. #3
    ng min teck is offline Member
    Join Date
    Jul 2012
    Posts
    9
    Rep Power
    0

    Default Re: need help at assignment

    Here
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package assignment;
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.ImageIcon;
    
    /**
     *
     * @author Ng Min Teck
     */
    public class AssignmentFrame extends JFrame implements ActionListener {
    
     
        private AssignmentGame gamecontrol;
        
        //North Panel
        private JPanel internorthpanel, northpanel;
        private JLabel myfirstjavagame, nameofplayer, selectacounter;
        private JTextField nameofplayertextfield;
        private ButtonGroup group;
        private JRadioButton redcounter;
        private JRadioButton bluecounter;
        //
        //South Panel
        private JPanel southpanel;
        private JButton startgamebtn;
        private JButton rollthedicebtn;
        private JButton viewhistorybtn;
        private JButton exitgamebtn;
        //
        //East Panel
        private JPanel eastpanel;
        private JTextArea textarea;
        //
        //West Panel
        private JPanel westpanel;
        //
        //Center Panel
        private JPanel centerpanel;
        private JButton[] number;
    
        private void north() {
            northpanel = new JPanel(new BorderLayout());
            myfirstjavagame = new JLabel("My First Java Game", JLabel.CENTER);
    
            internorthpanel = new JPanel(new FlowLayout());
            nameofplayer = new JLabel("Name of Player:");
            nameofplayertextfield = new JTextField(15);
    
            selectacounter = new JLabel("Select a Counter:");
    
            redcounter = new JRadioButton();
            bluecounter = new JRadioButton();
            group = new ButtonGroup();
            //radio button must group
            group.add(redcounter);
            group.add(bluecounter);
            redcounter.setSelected(true);
    
            internorthpanel.add(nameofplayer);
            internorthpanel.add(nameofplayertextfield);
            internorthpanel.add(selectacounter);
            internorthpanel.add(redcounter);
            internorthpanel.add(new JLabel(new ImageIcon("red.gif")));
            internorthpanel.add(bluecounter);
            internorthpanel.add(new JLabel(new ImageIcon("blue.gif")));
    
            northpanel.add(myfirstjavagame, BorderLayout.NORTH);
            northpanel.add(internorthpanel, BorderLayout.CENTER);
    
        }
    
        private void south() {
            southpanel = new JPanel(new FlowLayout());
    
            startgamebtn = new JButton("Start Game");
            rollthedicebtn = new JButton("Roll The Dice");
            rollthedicebtn.setEnabled(false);
            viewhistorybtn = new JButton("View History");
            exitgamebtn = new JButton("Exit Game");
    
            southpanel.add(startgamebtn);
            southpanel.add(rollthedicebtn);
            southpanel.add(viewhistorybtn);
            southpanel.add(exitgamebtn);
    
        }
    
        private void east() {
            eastpanel = new JPanel(new BorderLayout());
            textarea = new JTextArea(5, 10);
            eastpanel.add(textarea);
        }
    
        private void west() {
            westpanel = new JPanel(new FlowLayout());
        }
    
        private void center() {
            centerpanel = new JPanel(new GridLayout(0, 8));
    
            number = new JButton[33];
            //33 become we only need 32 so 32>33
    
            for (int i = 1; i < number.length; i++) {
                number[i] = new JButton("" + i);
            }
            // The min to max vlaue of array
    
            //Board game GUL
            for (int i = 32; i >= 25; i--) {
                centerpanel.add(number[i]);
            }
            for (int i = 17; i <= 24; i++) {
                centerpanel.add(number[i]);
            }
            for (int i = 16; i >= 9; i--) {
                centerpanel.add(number[i]);
            }
            for (int i = 1; i <= 8; i++) {
                centerpanel.add(number[i]);
            }
            //End of Boad game GUI                       
        }
    
        public AssignmentFrame() {
    
            north();
            south();
            east();
            west();
            center();
    
            setLayout(new BorderLayout());
            add(northpanel, BorderLayout.NORTH);
            add(southpanel, BorderLayout.SOUTH);
            add(eastpanel, BorderLayout.EAST);
            add(westpanel, BorderLayout.WEST);
            add(centerpanel, BorderLayout.CENTER);
            initactionlistener();
            //gamecontrol = new AssignmentGame();
            
        }
    
        public void initactionlistener() {
            startgamebtn.addActionListener(this);
            rollthedicebtn.addActionListener(this);
            viewhistorybtn.addActionListener(this);
            exitgamebtn.addActionListener(this);
    
        }
    
        @Override
        public void actionPerformed(ActionEvent e) {
    
            if (e.getSource() == rollthedicebtn) {
                dice();
            } else if (e.getSource() == startgamebtn) {
                start();
            } else if (e.getSource() == viewhistorybtn) {
                viewhistory();
            } else {
                exitgame();
            }
        }
    
        public void start() {
    
            AssignmentPlayer name= new AssignmentPlayer();
    
            String playername = nameofplayertextfield.getText().trim();
            if (playername.length() > 0) {
                if (redcounter.isSelected() == true) {
                   name.setPlayerImage(new ImageIcon("red.gif"));
                } else {
                   name.setPlayerImage(new ImageIcon("blue.gif"));
                }
               name.setName(playername);
               startgamebtn.setEnabled(false);         
               rollthedicebtn.setEnabled(true);                  
            }
        }
    
        public void dice() {
            int rollNumber = gamecontrol.getPlayer().rollDice();
            //rollDice from get player from gamecontrol set it here for using rollnumber alot of time
            String Msg = getName() + "rolled number:" +  rollNumber; 
            textarea.append(Msg);
    
        }
    
        public void viewhistory() {
        }
    
        public void exitgame() {
            
        }
    
       
    }
    
    Player
    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package assignment;
    import javax.swing.ImageIcon;
    /**
     *
     * @author Ng Min Teck
     */
    public class AssignmentPlayer {
        private String name;
        private ImageIcon playerImage;
        private int position;
        private int numofroll;   
        
        public ImageIcon getPlayerImage() {
            return playerImage;
        }
        
        public int getPosition() {        
            return position;
        }
        
        public int getNumOfRolls(){
            return numofroll;
        }
        
        public String getName(){
            return this.name;
        }
        
        public void setPlayerImage(ImageIcon newplayerimage){
            this.playerImage = newplayerimage;
        }
        
        public void setPosition(int newposition){
            this.position = newposition;
        }
        
        public void setNumOfRolls(int newnumofroll){
            this.numofroll = newnumofroll;
        }
        
        public void setName(String newname){
            this.name = newname;
        }
        
        public int rollDice(){
            return(int)(Math.random() * 6 + 1);
        }
        
      //  public boolean resetPlayer(maxiumgameboard){
            
      //  }
    }
    
    Game
    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package assignment;
    
    /**
     *
     * @author Ng Min Teck
     */
    public class AssignmentGame {
       private AssignmentPlayer player;
        
        private int boardSize;
        //private int currentplayer;
        
        private String history;
        private int gamenumber;
        
        public AssignmentGame(int boardSize){
            this.boardSize = 32;
        }
        
        public  AssignmentPlayer getPlayer(){
            return player;
        }
    
        public boolean advanceCurrentPlayer(int numberofsteps){
            
                    
      }
    
    // public void nextGame()
    
    //getHistory
    
    //setHistory
    
        
      
        
    }
    Last edited by Norm; 07-30-2012 at 06:27 PM. Reason: added code tags

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,267
    Rep Power
    25

    Default Re: need help at assignment

    Can you explain your problem creating the "roll dice" method?

    The code you posted needs a main() method to be able to execute it for testing.
    Last edited by Norm; 07-30-2012 at 06:35 PM.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    ng min teck is offline Member
    Join Date
    Jul 2012
    Posts
    9
    Rep Power
    0

    Default Re: need help at assignment

    My problem is need to make player can move at board game when the roll dice button have been clicked

    My lecture ask me create 4 class game,player,frame & the run program class, in assignment my lecture give me hint that using gamecontrol at frame to link the game class & player class together and he also giving all the method

    eh how come i can't reply?

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,267
    Rep Power
    25

    Default Re: need help at assignment

    How do you execute the code? There is no main() method.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    ng min teck is offline Member
    Join Date
    Jul 2012
    Posts
    9
    Rep Power
    0

    Default Re: need help at assignment

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package assignment;

    import javax.swing.JFrame;

    /**
    *
    * @author Ng Min Teck
    */
    public class Assignment {

    public static void main(String[] args) {

    AssignmentFrame f = new AssignmentFrame();

    f.setTitle("JPRG Assignment");
    f.setSize(800, 600);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
    }
    }

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,267
    Rep Power
    25

    Default Re: need help at assignment

    Do you get any errors when you execute the code?

    What are the steps for executing the program?
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    ng min teck is offline Member
    Join Date
    Jul 2012
    Posts
    9
    Rep Power
    0

    Default Re: need help at assignment

    you can excute the code by playing assignment class

    there is a error at assignmentframe
    Last edited by ng min teck; 08-01-2012 at 04:41 AM.

  10. #10
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: need help at assignment

    Quote Originally Posted by ng min teck View Post
    there is a error at assignmentframe line 146 //gamecontrol = new AssignmentGame();
    What type of error are you receiving?
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  11. #11
    ng min teck is offline Member
    Join Date
    Jul 2012
    Posts
    9
    Rep Power
    0

    Default Re: need help at assignment

    The main problem is what code should i use in java to move the player of number of step determine by what i rolled from the dice

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: need help at assignment

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,267
    Rep Power
    25

    Default Re: need help at assignment

    What are the steps for executing the program?
    When I start the code, the roll the dice button is not enabled. What is the used supposed to do to use the program?
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    ng min teck is offline Member
    Join Date
    Jul 2012
    Posts
    9
    Rep Power
    0

    Default Re: need help at assignment

    solved can you remove the code, because my shool just warn me not to post the code thank you, i can't edit the top post
    Last edited by ng min teck; 08-01-2012 at 04:41 AM.

  15. #15
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: need help at assignment

    Quote Originally Posted by ng min teck View Post
    solved can you remove the code, because my shool just warn me not to post the code thank you, i can't edit the top post
    This seems to be an ongoing problem. The ability for regular members to edit their posts expires after about 24 hours.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  16. #16
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: need help at assignment

    Nor should we have the code deleted or concealed. It was posted publicly and your school should be able to know this if it so desires.

  17. #17
    ng min teck is offline Member
    Join Date
    Jul 2012
    Posts
    9
    Rep Power
    0

    Default Re: need help at assignment

    i mean can i delete my code post as the request?
    Last edited by ng min teck; 08-01-2012 at 05:40 AM.

  18. #18
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: need help at assignment

    If it wasn't to be posted, you shouldn't have posted it. And no, it won't be deleted.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  19. #19
    ng min teck is offline Member
    Join Date
    Jul 2012
    Posts
    9
    Rep Power
    0

    Default Re: need help at assignment

    firstly i don't know i can't post the code, so my school ask me to remove. so i don't have no right request to delete my own post? i am very disappointed the service you provided
    Last edited by ng min teck; 08-01-2012 at 08:05 AM.

  20. #20
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: need help at assignment

    Quote Originally Posted by ng min teck View Post
    i am very disappointed the service you provided
    Demand your money back

    db
    gnarkill10 likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Page 1 of 2 12 LastLast

Similar Threads

  1. Need help for Assignment!!!
    By HolyPK in forum New To Java
    Replies: 6
    Last Post: 11-23-2011, 06:37 PM
  2. Can somebody help me in this assignment?
    By lulzim in forum New To Java
    Replies: 25
    Last Post: 03-01-2011, 11:02 PM
  3. help with an assignment!
    By Tek in forum New To Java
    Replies: 6
    Last Post: 10-24-2010, 11:32 PM
  4. Assignment
    By shinkymar in forum New To Java
    Replies: 2
    Last Post: 03-06-2010, 01:17 PM
  5. I am looking for help with an assignment
    By nanoo51969 in forum New To Java
    Replies: 1
    Last Post: 03-23-2009, 09:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •