728x90
package dynamic_beat;
public class Main {
public static final int SCREEN_WIDTH = 1280;
public static final int SCREEN_HEIGHT = 720;
public static final int NOTE_SPEED = 3;
public static final int SLEEP_TIME= 10;
public static final int REACH_TIME = 2;
public static void main(String[] args) {
new RythmGame();
}
}
package dynamic_beat;
public class Beat {
private int time;
private String noteType;
public int getTime() {
return time;
}
public void setTime(int time) {
this.time = time;
}
public String getNoteType() {
return noteType;
}
public void setNoteName(String noteType) {
this.noteType = noteType;
}
//생성자
public Beat(int time, String noteType) {
super();
this.time = time;
this.noteType = noteType;
}
}
package dynamic_beat;
public class Track {
private String titleImage;
private String startImage;
private String gameImage;
private String startMusic;
private String gameMusic;
private String titleName;
public String getGameImage() {
return gameImage;
}
public void setGameImage(String gameImage) {
this.gameImage = gameImage;
}
public void setGameMusic(String gameMusic) {
this.gameMusic = gameMusic;
}
public void setStartImage(String startImage) {
this.startImage = startImage;
}
public void setTitleImage(String titleImage) {
this.titleImage = titleImage;
}
public String getStartMusic() {
return startMusic;
}
public void setStartMusic(String startMusic) {
this.startMusic = startMusic;
}
public String getGameMusic() {
return gameMusic;
}
public String getStartImage() {
return startImage;
}
public String getTitleImage() {
return titleImage;
}
public String getTitleName() {
return titleName;
}
public void setTitleName(String titleName) {
this.titleName = titleName;
}
//Track 생성자 (곡정보 관리)
public Track(String titleImage, String startImage, String gameImage, String startMusic, String gameMusic, String titleName) {
super();
this.titleImage = titleImage;
this.startImage = startImage;
this.gameImage = gameImage;
this.startMusic = startMusic;
this.gameMusic = gameMusic;
this.titleName = titleName;
}
}
package dynamic_beat;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class KeyListener extends KeyAdapter { //키보드 이벤트 처리
@Override
public void keyPressed(KeyEvent e) { //키보드 키 눌렸을 때 이벤트 처리
// TODO 자동 생성된 메소드 스텁
super.keyPressed(e);
if(RythmGame.game == null) { //게임 진행중이지 않다면 이벤트 연결 return
return;
}
if(e.getKeyCode() == KeyEvent.VK_S) {
RythmGame.game.pressS();
}
else if(e.getKeyCode() == KeyEvent.VK_D) {
RythmGame.game.pressD();
}
else if(e.getKeyCode() == KeyEvent.VK_F) {
RythmGame.game.pressF();
}
else if(e.getKeyCode() == KeyEvent.VK_SPACE) {
RythmGame.game.pressSpace();
}
else if(e.getKeyCode() == KeyEvent.VK_J) {
RythmGame.game.pressJ();
}
else if(e.getKeyCode() == KeyEvent.VK_K) {
RythmGame.game.pressK();
}
else if(e.getKeyCode() == KeyEvent.VK_L) {
RythmGame.game.pressL();
}
}
@Override
public void keyReleased(KeyEvent e) { //키눌렀다가 뗐을 때 이벤트 처리
// TODO 자동 생성된 메소드 스텁
super.keyReleased(e);
if(RythmGame.game == null) { //게임 진행중이지 않다면 이벤트 연결 return
return;
}
if(e.getKeyCode() == KeyEvent.VK_S) {
RythmGame.game.releaseS();
}
else if(e.getKeyCode() == KeyEvent.VK_D) {
RythmGame.game.releaseD();
}
else if(e.getKeyCode() == KeyEvent.VK_F) {
RythmGame.game.releaseF();
}
else if(e.getKeyCode() == KeyEvent.VK_SPACE) {
RythmGame.game.releaseSpace();
}
else if(e.getKeyCode() == KeyEvent.VK_J) {
RythmGame.game.releaseJ();
}
else if(e.getKeyCode() == KeyEvent.VK_K) {
RythmGame.game.releaseK();
}
else if(e.getKeyCode() == KeyEvent.VK_L) {
RythmGame.game.releaseL();
}
}
}
package dynamic_beat;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import javazoom.jl.player.Player;
public class Music extends Thread {
private Player player;
private boolean isLoop;
private File file;
private FileInputStream fis;
private BufferedInputStream bis;
public Music(String name, boolean isLoop) {
try {
this.isLoop = isLoop;
file = new File(Main.class.getResource("/Music/"+ name).toURI()); //여기가 문제인 거 아닌가?
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
player = new Player(bis);
}catch(Exception e) {
System.out.println(e.getMessage());
}
}
public int getTime() {
if(player == null)
return 0;
return player.getPosition();
}
public void close() {
isLoop = false;
player.close();
this.interrupt();
}
@Override
public void run() {
try {
do {
player.play();
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
player = new Player(bis);
//player.play();
}while(isLoop);
}catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
package dynamic_beat;
public class Track {
private String titleImage;
private String startImage;
private String gameImage;
private String startMusic;
private String gameMusic;
private String titleName;
public String getGameImage() {
return gameImage;
}
public void setGameImage(String gameImage) {
this.gameImage = gameImage;
}
public void setGameMusic(String gameMusic) {
this.gameMusic = gameMusic;
}
public void setStartImage(String startImage) {
this.startImage = startImage;
}
public void setTitleImage(String titleImage) {
this.titleImage = titleImage;
}
public String getStartMusic() {
return startMusic;
}
public void setStartMusic(String startMusic) {
this.startMusic = startMusic;
}
public String getGameMusic() {
return gameMusic;
}
public String getStartImage() {
return startImage;
}
public String getTitleImage() {
return titleImage;
}
public String getTitleName() {
return titleName;
}
public void setTitleName(String titleName) {
this.titleName = titleName;
}
//Track 생성자 (곡정보 관리)
public Track(String titleImage, String startImage, String gameImage, String startMusic, String gameMusic, String titleName) {
super();
this.titleImage = titleImage;
this.startImage = startImage;
this.gameImage = gameImage;
this.startMusic = startMusic;
this.gameMusic = gameMusic;
this.titleName = titleName;
}
}
package dynamic_beat;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.ImageIcon;
public class Note extends Thread{
private Image noteBasicImage = new ImageIcon(Main.class.getResource("/Images/noteBasic.png")).getImage();
private int x, y= 580 - (1000/Main.SLEEP_TIME * Main.NOTE_SPEED) * Main.REACH_TIME;
private String noteType;
//노트 판정 처리
private boolean proceeded = true;
public String getNoteType() { //현재의 노트Type 반환
return noteType;
}
public boolean isProceeded() { //노트 진행여부 판단
return proceeded;
}
public void close() { //노트 멈추기
proceeded = false;
}
public Note(String noteType) {
if(noteType.equals("S")) { //눌리는 버튼 별로 x 좌표 초기화
x = 228;
}
else if (noteType.equals("D")) {
x = 332;
}
else if (noteType.equals("F")) {
x = 436;
}
else if (noteType.equals("Space")) {
x = 540;
}
else if (noteType.equals("J")) {
x = 744;
}
else if (noteType.equals("K")) {
x = 848;
}
else if (noteType.equals("L")) {
x = 952;
}
this.noteType = noteType;
}
public void screenDraw(Graphics2D g) {
if(noteType.equals("Space")) {
g.drawImage(noteBasicImage, x, y, null);
}
else {
g.drawImage(noteBasicImage, x, y, null);
g.drawImage(noteBasicImage, x+100, y, null);
}
}
public void drop() { //note떨어질 때
y += Main.NOTE_SPEED;
if(y > 620) { //y가 일정 범위 넘어가게 되면
System.out.println("Miss"); //Miss 출력하고
close();//note 진행을 close
}
}
@Override
public void run() { //스레드 run
// TODO 자동 생성된 메소드 스텁
super.run();
try {
while(true) { //무한반복
drop(); //한번 노트 떨어지고
if(proceeded) {//노트 진행중이면
Thread.sleep(Main.SLEEP_TIME); //반복적으로 쉬어줌
}else {
interrupt();
break;
}
}
}catch(Exception e) {
System.err.println(e.getMessage());
}
}
public String judge() { //노트 판정 함수 y축 단위 나눠서 판단
if(y >= 613) {
System.out.println("Late");
close();
return "Late";
}
else if(y >= 600) {
System.out.println("Good");
return "Good";
}
else if(y >= 587) {
System.out.println("Great");
return "Great";
}
else if(y >= 573) {
System.out.println("Perfect");
return "Perfect";
}
else if(y >= 565) {
System.out.println("Great");
return "Graet";
}
else if(y >= 550) {
System.out.println("Good");
return "Good";
}
else if(y >= 535) {
System.out.println("Early");
return "Early";
}
return "None";
}
public int getY() { //현재의 노트 y좌표 반환
return y;
}
}
package dynamic_beat;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class RythmGame extends JFrame{
private Image screenImage;
private Graphics screenGraphic;
private Image background = new ImageIcon(Main.class.getResource("/Images/introBackground.png")).getImage();
private JLabel menuBar = new JLabel(new ImageIcon(Main.class.getResource("/Images/menuBar.png")));
private ImageIcon exitButtonEnteredImage = new ImageIcon(Main.class.getResource("/Images/B2.jpg"));
private ImageIcon exitButtonBasicImage = new ImageIcon(Main.class.getResource("/Images/B1.png"));
private ImageIcon startButtonEnteredImage = new ImageIcon(Main.class.getResource("/Images/start_a.png"));
private ImageIcon startButtonBasicImage = new ImageIcon(Main.class.getResource("/Images/startB.png"));
private ImageIcon quitButtonEnteredImage = new ImageIcon(Main.class.getResource("/Images/endA.png"));
private ImageIcon quitButtonBasicImage = new ImageIcon(Main.class.getResource("/Images/endB.png"));
//화살표 이미지 아이콘
private ImageIcon leftButtonEnteredImage = new ImageIcon(Main.class.getResource("/Images/화살표4.png"));
private ImageIcon leftButtonBasicImage = new ImageIcon(Main.class.getResource("/Images/화살표3.png"));
private ImageIcon rightButtonEnteredImage = new ImageIcon(Main.class.getResource("/Images/화살표2.png"));
private ImageIcon rightButtonBasicImage = new ImageIcon(Main.class.getResource("/Images/화살표1.png"));
//easy, Hard이미지 아이콘 버튼
private ImageIcon easyButtonEnteredImage = new ImageIcon(Main.class.getResource("/Images/easyButtonEntered.png"));
private ImageIcon easyButtonBasicImage = new ImageIcon(Main.class.getResource("/Images/easyButtonBasic.png"));
private ImageIcon hardButtonEnteredImage = new ImageIcon(Main.class.getResource("/Images/hardButtonEntered.png"));
private ImageIcon hardButtonBasicImage = new ImageIcon(Main.class.getResource("/Images/hardButtonBasic.png"));
//back버튼 이미지
private ImageIcon backButtonEnteredImage = new ImageIcon(Main.class.getResource("/Images/backButtonEntered.png"));
private ImageIcon backButtonBasicImage = new ImageIcon(Main.class.getResource("/Images/backButtonBasic.png"));
//버튼
private JButton exitButton = new JButton(exitButtonBasicImage);
private JButton startButton = new JButton(startButtonBasicImage);
private JButton quitButton = new JButton(quitButtonBasicImage);
//화살표 버튼 (초기화)
private JButton leftButton = new JButton(leftButtonBasicImage); //위의 이미지 Basic 아이콘
private JButton rightButton = new JButton(rightButtonBasicImage);
//easy, hard버튼
private JButton easyButton = new JButton(easyButtonBasicImage);
private JButton hardButton = new JButton(hardButtonBasicImage);
//back 버튼
private JButton backButton = new JButton(backButtonBasicImage);
private int mouseX, mouseY; //마우스 x,y위치 변수
private boolean isMainScreen = false; // 처음에는 다른 백그라운드 화면 있기 때문에 false값 주고
private boolean isGameScreen = false;
ArrayList<Track> trackList = new ArrayList<Track>();
//음악-가수 이미지
private Image titleImage;
//게임 선택화면
private Image selectedImage;
//선택된 음악
private Music selectedMusic;
//introMusic
private Music introMusic = new Music("A.mp3", true);
private int nowSelected = 0; //Track 속 현재 선택된 인덱스 초기 0
public static Game game;
public RythmGame() {// 생성자
//곡 리스트 관리 객체 (곡이름이미지, 선택이미지, 게임이미지, 시작음악, 게임음악, 곡이름)
trackList.add(new Track("MN_1.png", "2_A.png", "1_A.jpg", "F_1.mp3", "F.mp3", "FreeStyle-Y")); //프리스타일 0
trackList.add(new Track("MN_3.png", "2_B.png ", "1_C.jpg", "S_1.mp3", "S.mp3", "Smile And Bye")); //소야앤썬 1
trackList.add(new Track("MN_2.png", "2_C.png", "1_B.jpg", "H_1.mp3", "H.mp3", "Booty Call")); //화요비 2
setUndecorated(true);
setTitle("Music Game");
setSize(Main.SCREEN_WIDTH, Main.SCREEN_HEIGHT); //창 크기
setResizable(false);//한 번 만들어진 창은 사용자가 인위적으로 변형 금지시킴
setLocationRelativeTo(null); //실행 시 컴퓨터 정중앙에 뜸
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //게임창 종료시 프로그램 완전 종료
setVisible(true); //게임창 화면에 정상 보여주기
setBackground(new Color(0, 0, 0, 0));
setLayout(null);
addKeyListener(new KeyListener()); //키 이벤트 연결
introMusic.start(); //인트로 음악 시작
//exit버튼
exitButton.setBounds(1245, 0, 30, 30);
exitButton.setBorderPainted(false);
exitButton.setContentAreaFilled(false);
exitButton.setFocusPainted(false);
exitButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
super.mouseEntered(e);
exitButton.setIcon(exitButtonEnteredImage); //마우스 눌렸을 때 이미지 교체
exitButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); //마우스 올라갔을 때 손가락 모양으로 바뀌고
}
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
exitButton.setIcon(exitButtonBasicImage);
exitButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));//마우스 나왔을 때 원래 상태로 바뀜
}
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
System.exit(0);
}
});
add(exitButton);
//start 버튼
startButton.setBounds(40, 200, 400, 100);
startButton.setBorderPainted(false);
startButton.setContentAreaFilled(false);
startButton.setFocusPainted(false);
startButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
super.mouseEntered(e);
startButton.setIcon(startButtonEnteredImage); //마우스 눌렸을 때 이미지 교체
startButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); //마우스 올라갔을 때 손가락 모양으로 바뀌고
}
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
startButton.setIcon(startButtonBasicImage);
startButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));//마우스 나왔을 때 원래 상태로 바뀜
}
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
introMusic.close(); //시작버튼 누르면 인트로 음악 종료
enterMain();//Main 들어가기 함수
}
});
add(startButton);
//quit버튼
quitButton.setBounds(40, 330, 400, 100);
quitButton.setBorderPainted(false);
quitButton.setContentAreaFilled(false);
quitButton.setFocusPainted(false);
quitButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
super.mouseEntered(e);
quitButton.setIcon(quitButtonEnteredImage); //마우스 눌렸을 때 이미지 교체
quitButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); //마우스 올라갔을 때 손가락 모양으로 바뀌고
}
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
quitButton.setIcon(quitButtonBasicImage);
quitButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));//마우스 나왔을 때 원래 상태로 바뀜
}
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
System.exit(0);
}
});
add(quitButton);
//left 버튼
leftButton.setVisible(false); //처음에는 보이지않도록 설정
leftButton.setBounds(140, 310, 60, 60);
leftButton.setBorderPainted(false);
leftButton.setContentAreaFilled(false);
leftButton.setFocusPainted(false);
leftButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
super.mouseEntered(e);
leftButton.setIcon(leftButtonEnteredImage); //마우스 눌렸을 때 이미지 교체
leftButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); //마우스 올라갔을 때 손가락 모양으로 바뀌고
}
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
leftButton.setIcon(leftButtonBasicImage);
leftButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));//마우스 나왔을 때 원래 상태로 바뀜
}
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
//왼쪽 버튼 이벤트
selectLeft();
}
});
add(leftButton);
//right 버튼
rightButton.setVisible(false); //처음에는 보이지않도록 설정
rightButton.setBounds(1080, 310, 60, 60);
rightButton.setBorderPainted(false);
rightButton.setContentAreaFilled(false);
rightButton.setFocusPainted(false);
rightButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
super.mouseEntered(e);
rightButton.setIcon(rightButtonEnteredImage); //마우스 눌렸을 때 이미지 교체
rightButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); //마우스 올라갔을 때 손가락 모양으로 바뀌고
}
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
rightButton.setIcon(rightButtonBasicImage);
rightButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));//마우스 나왔을 때 원래 상태로 바뀜
}
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
//오른쪽 버튼 이벤트
selectRight();
}
});
add(rightButton);
//easy 버튼
easyButton.setVisible(false); //처음에는 보이지않도록 설정
easyButton.setBounds(375, 580, 250, 67);
easyButton.setBorderPainted(false);
easyButton.setContentAreaFilled(false);
easyButton.setFocusPainted(false);
easyButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
super.mouseEntered(e);
easyButton.setIcon(easyButtonEnteredImage); //마우스 눌렸을 때 이미지 교체
easyButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); //마우스 올라갔을 때 손가락 모양으로 바뀌고
}
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
easyButton.setIcon(easyButtonBasicImage);
easyButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));//마우스 나왔을 때 원래 상태로 바뀜
}
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
gameStart(nowSelected, "Easy");
}
});
add(easyButton);
//hard버튼
hardButton.setVisible(false); //처음에는 보이지않도록 설정
hardButton.setBounds(655, 580, 250, 67);
hardButton.setBorderPainted(false);
hardButton.setContentAreaFilled(false);
hardButton.setFocusPainted(false);
hardButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
super.mouseEntered(e);
hardButton.setIcon(hardButtonEnteredImage); //마우스 눌렸을 때 이미지 교체
hardButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); //마우스 올라갔을 때 손가락 모양으로 바뀌고
}
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
hardButton.setIcon(hardButtonBasicImage);
hardButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));//마우스 나왔을 때 원래 상태로 바뀜
}
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
gameStart(nowSelected, "Hard");
}
});
add(hardButton);
//back 버튼
backButton.setVisible(false); //처음에는 보이지않도록 설정
backButton.setBounds(20, 50, 60, 60);
backButton.setBorderPainted(false);
backButton.setContentAreaFilled(false);
backButton.setFocusPainted(false);
backButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
super.mouseEntered(e);
backButton.setIcon(backButtonEnteredImage); //마우스 눌렸을 때 이미지 교체
backButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); //마우스 올라갔을 때 손가락 모양으로 바뀌고
}
@Override
public void mouseExited(MouseEvent e) {
super.mouseExited(e);
backButton.setIcon(backButtonBasicImage);
backButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));//마우스 나왔을 때 원래 상태로 바뀜
}
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
backMain();
}
});
add(backButton);
//menuBar 버튼
menuBar.setBounds(0,0,1280,30);
menuBar.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
super.mousePressed(e);
mouseX = e.getX();
mouseY = e.getY();
}
});
menuBar.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
super.mouseDragged(e);
int x = e.getXOnScreen();
int y = e.getYOnScreen();
setLocation(x - mouseX, y - mouseY);
}
});
add(menuBar);
}
//그림 그리는 메소드
public void paint(Graphics g) { //처음 그려줄 때 paint 메소드 재정의
screenImage = createImage(Main.SCREEN_WIDTH, Main.SCREEN_HEIGHT); //780X1280크기만큼의 이미지를 받은 다음에 그것을 다시 screenImage에 답는다
screenGraphic = screenImage.getGraphics();
screenDraw((Graphics2D) screenGraphic);
g.drawImage(screenImage, 0, 0, null);
}
public void screenDraw(Graphics2D g) {
g.drawImage(background, 0, 0, null);
if(isMainScreen) { //isMainScreen == True값일 때에 한해서
g.drawImage(selectedImage, 340, 100, null); //윈도우 창의 위치에 selectedImage 그려줌
g.drawImage(titleImage, 340,70, null); //음악 이름 이미지 띄우기
}
if(isGameScreen) {
game.screenDraw(g);//game 클래스의 screenDraw() 호출
}
paintComponents(g); //paintComponent() 에 의해서 add로 추가한 부분이 보여지는 것
try {
Thread.sleep(5);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
this.repaint();//사용자가 다시그릴 때 호출
}
public void selectTrack(int nowSelected) { //선택된 곡 인덱스 번호 인수로 받고
if(selectedMusic != null) {
selectedMusic.close();//일단 실행중인 음악 종료시켜놓고
}
titleImage = new ImageIcon(Main.class.getResource("/Images/" + trackList.get(nowSelected).getTitleImage())).getImage();
selectedImage = new ImageIcon(Main.class.getResource("/Images/" + trackList.get(nowSelected).getStartImage())).getImage();
selectedMusic = new Music(trackList.get(nowSelected).getStartMusic(), true);
selectedMusic.start();//새로 시작된 음악 시작
}
//왼쪽 누르면 --
public void selectLeft() {
if(nowSelected == 0 )
nowSelected = trackList.size() - 1;
else
nowSelected--;
selectTrack(nowSelected);
}
//오른쪽 누르면 ++
public void selectRight() {
if(nowSelected == trackList.size() - 1 )
nowSelected = 0;
else
nowSelected++;
selectTrack(nowSelected);
}
//(선택곡, 난이도) 주고 게임 시작
public void gameStart(int nowSelected, String difficulty) {
if(selectedMusic != null) selectedMusic.close();
isMainScreen = false;
leftButton.setVisible(false);
rightButton.setVisible(false);
easyButton.setVisible(false);
hardButton.setVisible(false);
background = new ImageIcon(Main.class.getResource("/Images/"+ trackList.get(nowSelected).getGameImage())).getImage();
backButton.setVisible(true);
isGameScreen = true;
game = new Game(trackList.get(nowSelected).getTitleName(), difficulty, trackList.get(nowSelected).getStartMusic());
game.start(); // game클래스의 run() 실행
setFocusable(true); //게임창키보드포커스 설정
}
public void backMain() {
isMainScreen = true;
leftButton.setVisible(true);
rightButton.setVisible(true);
easyButton.setVisible(true);
hardButton.setVisible(true);
background = new ImageIcon(Main.class.getResource("/Images/startBackground.jpg")).getImage();
backButton.setVisible(false);
selectTrack(nowSelected);
isGameScreen = false;
game.close();
}
public void enterMain() {
startButton.setVisible(false);
quitButton.setVisible(false);
background = new ImageIcon(Main.class.getResource("/Images/startBackground.jpg")).getImage();//게임 화면 전환
isMainScreen = true; //start 버튼이 눌렸을 경우에 화면 스크린을 true값 주어서 나타나게 만들어둠
leftButton.setVisible(true);
rightButton.setVisible(true);
easyButton.setVisible(true);
hardButton.setVisible(true);
introMusic.close();
selectTrack(0); //Track리스트의 0번 호출
}
}
728x90
'Java > [학교] Java_GUI' 카테고리의 다른 글
[과제] 자바_GUI_ 소수 판별 및 출력 (0) | 2021.12.12 |
---|---|
[과제] 자바_연결리스트_구현 (0) | 2021.12.12 |
ch12. 스윙 컴포넌트들 (0) | 2021.10.05 |
ch11. 그래픽 프로그래밍 (0) | 2021.09.28 |
ch10. 사용자 이벤트 처리 (0) | 2021.09.14 |