Game
Game
*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.IntStream;
class BubbleUtil {
private static final int BUBBLE_SIZE = 50;
return newOrigin;
}
@Override
public void run() {
int neighborhoodSize = BUBBLE_SIZE + 18 * (CURR_ROUND == 0 ? 1 : CURR_ROUND
- 1);
List<Point> tempOrigins = new ArrayList<>();
for(Point origin: BUBBLE_ORIGINS) {
tempOrigins.add(new Point(origin));
}
while (!Thread.currentThread().isInterrupted() && !
BUBBLE_ORIGINS.isEmpty()) {
for (int i = 0; i < BUBBLE_ORIGINS.size(); i++) {
Point origin;
if((origin = BubbleUtil.findValidRandomNeighbor(i,
neighborhoodSize, GAME_PANEL, BUBBLE_ORIGINS, FIXED_ORIGINS)) != null && !
BUBBLE_ORIGINS.isEmpty())
BUBBLE_ORIGINS.set(i, origin);
}
try {
Thread.sleep(3000);
GAME_PANEL.repaint();
} catch (InterruptedException e) {
System.out.println("Thread interrupted");
}
}
}
}
public Game() {
mainMenuFrame = new JFrame("Let's Play");
mainMenuFrame.add(menuPanel);
mainMenuFrame.setSize(500, 250);
mainMenuFrame.setVisible(true);
mainMenuFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
selectedBubbleCount = difficultySlider.getValue();
playAreaFrame = new JFrame("Bubble Burst Game - Round: " + (currentRound +
1));
playAreaFrame.setSize(600, 600);
playAreaFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
playAreaPanel = createGamePanel();
playAreaFrame.add(playAreaPanel);
playAreaFrame.setVisible(true);
mainMenuFrame.setVisible(false);
showBubblePlacementGuide();
}
if (bubbleOrigins.isEmpty()) {
if (animationThread != null) {
animationThread.interrupt();
}
if (currentRound < 10) {
proceedToNextRound();
} else {
gameIsWon = true;
handleGameOver(JOptionPane.INFORMATION_MESSAGE, "You Won,
Congrats!");
}
}
}
else {
gameIsWon = false;
handleGameOver(JOptionPane.ERROR_MESSAGE, "You Lost as you didn't click
on bubble, try again");
}
}