HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaMinor

Piano Tiles-like-Game: Mouse LorMorR

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
lormorrliketilesgamepianomouse

Problem

I'm currently trying to get somewhat familiar with swing and so I made a little game called "Mouse LorMorR" (Mouse Left or Middle or Right). The game consists of a timer, a score display and three JPanels that display which mouse button you should click. By clicking the wrong mouse button or letting the timer run out the timer and score reset.

I'd like to know what I can improve.

MainClass

package com.Skrelp.LorMorR;

public class MainClass {

    public static void main(String[] args) {
        new LorMorRFrame();
    }

}


LorMorRFrame

```
package com.Skrelp.LorMorR;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class LorMorRFrame extends JFrame implements MouseListener{

private static final long serialVersionUID = -508527838627274300L;

private static final int RIGHT = 0;
private static final int MIDDLE = 1;
private static final int LEFT = 2;

public boolean colorBash = false;
private int easterEgg = 0;
private int wantedMouseButton = MIDDLE;
JPanel mainPanel, subPanelCenter, subPanelSouth, panelLeft, panelRight, panelMiddle;
JButton buttonLeft, buttonRight, buttonMiddle;
ExtraPanel extraPanel;

public LorMorRFrame(){
super("Mouse LorMorR");
GridLayout grid13 = new GridLayout(1, 3);
mainPanel = new JPanel(new BorderLayout());
subPanelCenter = new JPanel(grid13);
subPanelSouth = new JPanel(grid13);
panelLeft = new JPanel();
buttonLeft = new JButton("Left");
panelRight = new JPanel();
buttonRight = new JButton("Right");
pan

Solution

Your LorMorRFrame seems too long! Try separating those ActionListeners from the prepare methods into a single separate class that implements it.

I understand this is your first game version, but I'd also suggest to improve a little more on the main game controller class: try not to automatically prepare and start the game. The user might want to just see their history, so preparing was unnecessary. And if the user wants to play, he probably also wants to have some time to get ready before starting: it could be after any key, for example. Furthermore, I couldn't find what happens when the game ends, you could enhance that gaming life cycle architecture.

Note: I'm sorry I didn't have time to run your code, so consider my feedback just from a coding perspective.

Context

StackExchange Code Review Q#119081, answer score: 2

Revisions (0)

No revisions yet.