1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with Java work

Discussion in 'HTML, Graphics & Programming' started by sandeep, 14 Mar 2010.

  1. sandeep

    Hitman

    Joined: 8 Jan 2009

    Posts: 728

    Location: Goodmayes, Essex

    Hi Guys,

    I've almost completed my assignment but there's one problem, I can't get a simple score system set up.

    All src files are @ http://www.sinvise.net/src

    My problem is pointing to the Dots.java and the commented out code:

    Code:
    /*if(status[i][j] == 1)
                        {
                            dlg.setScore(dlg.getScore()+1);
                            p1Score.setText(Integer.toString(dlg.getScore()));
                        }
                        else
                        {
                            dlg.setScore2(dlg.getScore2()+1);
                            p2Score.setText(Integer.toString(dlg.getScore2()));
                }*/
    I am trying to get the score set and then output it onto the label, but my problem is that whenever it does this it works for both players where I just want it for player 1, on the first block and if it isn't player one then do player 2.

    Can someone give me a bit of guidance on this?

    Thanks.
     
  2. _TubbZ_

    Gangster

    Joined: 30 Jun 2009

    Posts: 406

    You seem to be creating a class for player and filling it up with duplicate methods for player 1 and 2. Surely you would be better off creating a player class and then declare p1 and p2 as an instance of that class?

    You have alot of code, what (if any) IDE are you using? as if its eclipse or Netbeans you maybe better off sticking in some break points and seeing where your logic is wrong.

    Also i don't get why you are looking at status which stores the row and column data to determine who has scored the point.

    I am guessing its a game of tick tack toe or something similar?

    If that is the case i would create a class to handle the positions and one to handle players then declare an array of the positions class and two players then go from there. the position class would have to store whether that position has been taken/selected and who by.
     
  3. sandeep

    Hitman

    Joined: 8 Jan 2009

    Posts: 728

    Location: Goodmayes, Essex

    Hi,

    Thanks for the info.

    It is a dots game where you have to make a square out of joining lines and each player gets a go.

    The code runs perfectly fine and everything works how it should, it's just the score part that's not going correctly.

    The reason I used status[j] was so I can determine the colour and then I would know which player to add the score on to.

    Add you said that I've created duplicate methods, it's just that I don't really want to get to implementing subclasses just yet, I want everything to work and then get on with the changes that I need to do.

    And I am using Netbeans.
     
  4. _TubbZ_

    Gangster

    Joined: 30 Jun 2009

    Posts: 406

    well stick some break points and prints in and run it in Debug mode to see what values the variables have to go into the block you don't want and work from there would be your best bet. :)
     
  5. sandeep

    Hitman

    Joined: 8 Jan 2009

    Posts: 728

    Location: Goodmayes, Essex

    I gave it a try and it doesn't break at the points that I want them to. Seems a bit weird. I passed the correct value and still a no go :( deadlines tomorrow ahh have to put my head in this
     
  6. sandeep

    Hitman

    Joined: 8 Jan 2009

    Posts: 728

    Location: Goodmayes, Essex

    I may have found out the problem.

    I can get the scores to work but the program gets repainted and the score get's updated inside a for loop so it's constantly adding the score.

    Now the only problem is, where do I put it so it doesn't update inside the loop?