Skip to main content
Better formatting.
Source Link
syb0rg
  • 21.8k
  • 10
  • 112
  • 191

Some comments:

  • Make sure you have a consistent indentation style. It makes it difficult to follow the code flow, if there are multiple lines with different indentation.

    Make sure you have a consistent indentation style. It makes it difficult to follow the code flow, if there are multiple lines with different indentation.

  • You should separate the view and the game logic. Having both the Swing design setup and the actual game logic mixed up—in a single method—makes the code very hard to navigate. Ideally, both should be in separate classes.

    You should separate the view and the game logic. Having both the Swing design setup and the actual game logic mixed up—in a single method—makes the code very hard to navigate. Ideally, both should be in separate classes.

  • Consider making a subclass of JFrame for your game view. It will be the only thing responsible for setting up the visuals. You can pass it a GameStructure object (which would be only the game logic), so it can combine everything.

    Consider making a subclass of JFrame for your game view. It will be the only thing responsible for setting up the visuals. You can pass it a GameStructure object (which would be only the game logic), so it can combine everything.

  • for(j = 0; j<64; j++) — Instead of hard-coding the length of the worldList, you should be able to adjust automatically if I add new words to the word list without changing anything else.

    for(j = 0; j<64; j++) — Instead of hard-coding the length of the worldList, you should be able to adjust automatically if I add new words to the word list without changing anything else.

  • tf.addActionListener(new ActionListener() { … — Instead of having an anonymous listener, consider making an actual type to clean everything up. As you only need to have a single listener, you can also make the class you’re in implement ActionListener, so you can pass this to addActionListener.

    tf.addActionListener(new ActionListener() { … — Instead of having an anonymous listener, consider making an actual type to clean everything up. As you only need to have a single listener, you can also make the class you’re in implement ActionListener, so you can pass this to addActionListener.

Some comments:

  • Make sure you have a consistent indentation style. It makes it difficult to follow the code flow, if there are multiple lines with different indentation.
  • You should separate the view and the game logic. Having both the Swing design setup and the actual game logic mixed up—in a single method—makes the code very hard to navigate. Ideally, both should be in separate classes.
  • Consider making a subclass of JFrame for your game view. It will be the only thing responsible for setting up the visuals. You can pass it a GameStructure object (which would be only the game logic), so it can combine everything.
  • for(j = 0; j<64; j++) — Instead of hard-coding the length of the worldList, you should be able to adjust automatically if I add new words to the word list without changing anything else.
  • tf.addActionListener(new ActionListener() { … — Instead of having an anonymous listener, consider making an actual type to clean everything up. As you only need to have a single listener, you can also make the class you’re in implement ActionListener, so you can pass this to addActionListener.

Some comments:

  • Make sure you have a consistent indentation style. It makes it difficult to follow the code flow, if there are multiple lines with different indentation.

  • You should separate the view and the game logic. Having both the Swing design setup and the actual game logic mixed up—in a single method—makes the code very hard to navigate. Ideally, both should be in separate classes.

  • Consider making a subclass of JFrame for your game view. It will be the only thing responsible for setting up the visuals. You can pass it a GameStructure object (which would be only the game logic), so it can combine everything.

  • for(j = 0; j<64; j++) — Instead of hard-coding the length of the worldList, you should be able to adjust automatically if I add new words to the word list without changing anything else.

  • tf.addActionListener(new ActionListener() { … — Instead of having an anonymous listener, consider making an actual type to clean everything up. As you only need to have a single listener, you can also make the class you’re in implement ActionListener, so you can pass this to addActionListener.

Source Link
poke
  • 752
  • 8
  • 14

Some comments:

  • Make sure you have a consistent indentation style. It makes it difficult to follow the code flow, if there are multiple lines with different indentation.
  • You should separate the view and the game logic. Having both the Swing design setup and the actual game logic mixed up—in a single method—makes the code very hard to navigate. Ideally, both should be in separate classes.
  • Consider making a subclass of JFrame for your game view. It will be the only thing responsible for setting up the visuals. You can pass it a GameStructure object (which would be only the game logic), so it can combine everything.
  • for(j = 0; j<64; j++) — Instead of hard-coding the length of the worldList, you should be able to adjust automatically if I add new words to the word list without changing anything else.
  • tf.addActionListener(new ActionListener() { … — Instead of having an anonymous listener, consider making an actual type to clean everything up. As you only need to have a single listener, you can also make the class you’re in implement ActionListener, so you can pass this to addActionListener.