GUI란? "Graphical User Interface (그래픽 유저 인터페이스)"의 약자입니다. 흔히 "구이,규이"라고 발음합니다.
마우스로 아이콘을 클릭하며 프로그램을 작동시키는 컴퓨팅 환경을 말합니다. 요즘 컴퓨터 환경은 거의 다 GUI입니다. GUI가 아닌 프로그램은 거의 없습니다. 윈도우를 부팅하여 바탕화면이 나오면 그 자체가 전부 다 GUI입니다.
그래서 GUI의 반대되는 개념이 무엇인가가 중요합니다.
규이의 반댓말은 CLI(Command-Line Interface)입니다. 이것은 키보드로 명령어를 일일이 타이핑하여 프로그램을 사용하는 원시적인 방식입니다. GUI와 달리 CLI는 명령어를 모두 외워야 하기에 상당히 불편합니다. 다만 전문가에게는 CLI가 더 편리할 수도 있습니다. 반복되는 작업을 할 때에는 같은 곳을 마우스로 계속 클릭하는 것이 "노가다"이기에, 명령어들을 배치파일 같은 스크립트로 만들어서 CLI에서 일괄적으로 한꺼번에 처리하는 것이 더 편리합니다.
아래 그림은 맥북 바탕화면인데 이 자체가 GUI입니다. 그런데 검은 창이 있습니다. terminal(or cmd) 즉 도스창(명령 프롬프트)입니다. 그것이 CLI입니다. 이 검은 창에서 키보드로 도스 명령어들을 타이핑할 수 있습니다.
GUI Game (구현 안된 패키지나 클래스를 작성 안해도 게임은 실행 됩니다 ~! ~!)
Navigator(패키징이 효율적이지 못하다. 다음부터 패키징을 할때엔, DAO 와 DTO를 따로 나누고 io.GUIGame.DAO이런식으로 나누주기.)
dBUtil (package)
package dBUtil;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DBUtil {
// 리턴으로 커넥션을 받아와야 한다.
static String URL = "jdbc:mysql://localhost:3306/GUIgame?serverTimezone=UTC";
static String USER = "joe";
static String PASSWORD = "1234";
static String DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
// 접속
public static Connection getConnection() throws Exception{
Connection conn = null;
Class.forName(DRIVER_NAME);
conn = DriverManager.getConnection(URL, USER, PASSWORD);
return conn;
}
// 접속종료
public static void close(Connection conn) {
if(conn != null) {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void close(Connection conn, PreparedStatement ps) {
if(ps != null) {
try {
ps.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
close(conn);
}
public static void close(Connection conn, PreparedStatement ps, ResultSet rs) {
if(rs!=null) {
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
close(conn,ps);
}
}
}
gameStarter (package)
package gameStarter;
import jFrameWithjPanel.GameFrame;
import jFrameWithjPanel.LoginFrame;
import user.UserService;
public class Starter {
public static void main(String[] args) {
// 이부분이 메인 실행 클래스라고 보면된다.
UserService user = new UserService();
}
}
images (package) 참고만 하세요.
jFrameWithjPanel (package)
package jFrameWithjPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import ranking.RankDAO;
import ranking.RankDTO;
import ranking.StopWatch;
import stage.StageDAO;
import stage.StageDTO;
import store.WeaponStoreDAO;
import store.WeaponStoreDTO;
import town.TownDAO;
import town.TownDTO;
import user.UserDAO;
import user.UserDTO;
import worrior.WorriorDAO;
import worrior.WorriorDTO;
public class GameFrame extends JFrame {
// GUI를 담당하는 클래스라고 보면된다. 나름 자세하게 설명을 주석으로 달아뒀다. 모르는 부분은 댓글로 욕해주세요 ㅎㅎ
// 생성자를 사용해서 따로 구현된 클래스를 가져와서 메모리에 올린다.
StageDAO stageDAO = new StageDAO();
StageDTO stageDTO = new StageDTO();
WeaponStoreDAO weaponStoreDAO = new WeaponStoreDAO();
WeaponStoreDTO weaponStoreDTO = new WeaponStoreDTO();
TownDAO townDAO = new TownDAO();
TownDTO townDTO = new TownDTO();
WorriorDAO worriorDAO = new WorriorDAO();
WorriorDTO worriorDTO = new WorriorDTO();
UserDAO userDAO = new UserDAO();
UserDTO userDTO = new UserDTO();
RankDAO rankDAO = new RankDAO();
RankDTO rankDTO = new RankDTO();
StopWatch stopwatch = new StopWatch();
// 패키지내에 변수 선언.
protected int number;
protected int time;
protected String userid;
protected int stageNum;
protected boolean haveBat;
protected boolean haveKatana;
protected boolean haveAx;
protected int townLV;
protected int townHP;
protected int townFHP;
protected int charLV;
protected int charPower;
protected int charHP;
protected int charFHP;
protected int charExp;
protected int charFexp;
protected int charMoney;
private static final long serialVersionUID = 1L;
GamePanel panel;
GameThread gThread = new GameThread();
int keyPressed = 0;
int mouseX = 0, mouseY = 0;
// music 부분은 전체적으로 무시하면 된다. 이유 : 구현하려다가 프로젝트 기간이 부족해서 안 넣음. 블로그 내에 다른 프로젝트 글을 살펴보면 나와있있다.
// Music stageOneMusic = new Music("stageOneMusic.mp3", true);
// 메인 프레임에 키리스너만 붙여둔 상태이다. 추가로 메인 프레임에 게임 쓰레드를 넣어서 동작 시켰다.
public GameFrame(StageDTO stageDTO, WeaponStoreDTO weaponStoreDTO, TownDTO townDTO, WorriorDTO worriorDTO,
UserDTO userDTO, RankDTO rankDTO) {
stageNum = stageDTO.getStageNumber();
if (weaponStoreDTO.getBat() == 1) {
haveBat = true;
} else {
haveBat = false;
}
if (weaponStoreDTO.getKatana() == 1) {
haveKatana = true;
} else {
haveKatana = false;
}
if (weaponStoreDTO.getAx() == 1) {
haveAx = true;
} else {
haveAx = false;
}
townLV = townDTO.getTownLV();
townHP = townDTO.getTownHP();
townFHP = townDTO.getTownFHP();
charLV = worriorDTO.getLv();
charPower = worriorDTO.getPower();
charHP = worriorDTO.getHp();
charFHP = worriorDTO.getFhp();
charExp = worriorDTO.getExp();
charFexp = worriorDTO.getFexp();
charMoney = worriorDTO.getMoney();
userid = userDTO.getId();
// 타이머
rankDAO.getRankData(userDTO);
// 시간변수에 저장
time = rankDTO.getRankTime();
number = rankDTO.getNumber();
// 시간측정 시작.
stopwatch.measureTime(true);
// Frame 설정하는 부분.
setTitle("지구를 지켜라!!");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setBounds(0, 0, 1600, 1000);
setResizable(false);
setLocationRelativeTo(null);// 창이 가운데 나오게
// ----------------------------
panel = new GamePanel();
add(panel, BorderLayout.CENTER);
setVisible(true);
// 게임 진행시키는 스레드 객체 생성 및 스타트
gThread = new GameThread();
gThread.start(); // run() 메소드 자동실행!!
// 프레임에 키보드 입력에 반응하는 keyListner 등록
addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent e) {
// 눌러진 키가 무엇인지 알아내기
int keyCode = e.getKeyCode();
switch (keyCode) {
case KeyEvent.VK_LEFT:
panel.dx = 0; // 원랜 getsetter 만들어야함
break;
case KeyEvent.VK_RIGHT:
panel.dx = 0;
break;
case KeyEvent.VK_UP:
panel.dy = 0;
break;
case KeyEvent.VK_DOWN:
panel.dy = 0;
break;
}
// 방향키 4개 구분
}
@Override
public void keyPressed(KeyEvent e) {
// 눌러진 키가 무엇인지 알아내기
int keyCode = e.getKeyCode();
switch (keyCode) {
case KeyEvent.VK_LEFT:
keyPressed = 3;
panel.dx = -8; // 원랜 getsetter 만들어야함
break;
case KeyEvent.VK_RIGHT:
keyPressed = 1;
panel.dx = 8;
break;
case KeyEvent.VK_UP:
keyPressed = 0;
panel.dy = -8;
break;
case KeyEvent.VK_DOWN:
keyPressed = 2;
panel.dy = 8;
break;
}
// 방향키 4개 구분
}
});
}
//---------------------------------------------------------------------------------------------------------------------
// 게임화면 그려낼 Panel
// 화가 객체라고생각하면 된다.
class GamePanel extends JPanel {
// 화면에 보여질 이미지 객체 참조변수 - 멤버변수
Image imgGameBackStage1;
Image imgGameBackStage2;
Image imgGameBackStage3;
Image imgGameLeftSteel;
Image imgGameRightSteel;
Image imgGameSteelDoor;
Image imgBack;
Image imgStageOneEnemy;
Image imgStageTwoEnemy;
Image imgStageThreeEnemy;
Image imgStage2Door;
Image imgStage2FenceRight;
Image imgStage2FenceLeft;
Image imgHouseFixer;
Image imgWeaponStore;
Image imgSaveHouse;
Image imgLab;
Image imgHospital;
Image imgDevelopmentTown;
Image imgCharUp;
Image imgCharDown;
Image imgCharRight;
Image imgCharLeft;
Image imgCharRightUp;
Image imgCharRigthDown;
Image imgCharLeftUp;
Image imgCharLeftDown;
Image imgChar[] = new Image[8];
Image imgInWeaponStore;
Image imgWeaponSmith;
Image imgWeaponBox;
Image imgBat;
Image imgKatana;
Image imgAx;
Image imgBatOn;
Image imgKatanaOn;
Image imgAxOn;
Image imgWeaponOn;
Image imgInWeaponBox;
Image imgSmithClicked;
Image smithCheckedToBuy;
Image treeForOneStage;
Image treeForTwoStage;
Image imgPlayer;
int width;
int height;// 패널 사이즈 가져오기
int x, y, w, h;// xy : 플레이어의 중심 좌표 / wh : 이미지 절반폭;
int dx = 0, dy = 0;// 플레이어 이미지의 이동속도, 이동방향
// 적군 객체 참조변수, 여러마리일수있으므로 ArrayList(유동적 배열) 활용
ArrayList<StageOneEnemy> stageOneEnemies = new ArrayList<StageOneEnemy>();
ArrayList<StageTwoEnemy> stageTwoEnemies = new ArrayList<StageTwoEnemy>();
ArrayList<StageThreeEnemy> stageThreeEnemies = new ArrayList<StageThreeEnemy>();
//
// protected int stageNum;
// protected int haveBat;
// protected int haveKatana;
// protected int haveAx;
// protected int townLV;
// protected int townHP;
// protected int townFHP;
// protected int charLV;
// protected int charPower;
// protected int charHP;
// protected int charFHP;
// protected int charExp;
// protected int charFexp;
// protected int charMoney;
// 프레임에 적용될 변수들
protected int gameStage = stageNum;
protected int TownLV = townLV;
protected int TownHP = townHP;
protected int TownFHP = townFHP;
protected boolean 야구방망이 = haveBat;
protected boolean 카타나 = haveKatana;
protected boolean 도끼 = haveAx;
protected int LV = charLV;
protected int Power = charPower;
protected int HP = charHP;
protected int FHP = charFHP;
protected int EXP = charExp;
protected int needEXP = 1;
protected int FEXP = charFexp;
protected int Money = charMoney;
int numberOfZombie = 0;
int StageOneMonsterHP;
int StageTwoMonsterHP;
int StageThreeMonsterHP;
int StageOneMonsterPower;
int StageTwoMonsterPower;
int StageThreeMonsterPower;
boolean isDead = false;
boolean stageOneClear = false;
boolean stageTwoClear = false;
boolean stageThreeClear = false;
boolean clickedHospital = false;
boolean clickedLab = false;
boolean clickedWeaponStore = false;
boolean clickedTownCenter = false;
boolean clickedTownStation = false;
boolean clickedSaveHouse = false;
boolean InWeaponStore = false;
boolean clickedWeaponSmith = false;
boolean clickedWeaponBox = false;
boolean clickedBat = false;
boolean clickedKatana = false;
boolean clickedAx = false;
boolean clickedBuyBat = false;
boolean clickedBuyKatana = false;
boolean clickedBuyAx = false;
boolean clickedYes = false;
boolean clickedYesButMoney = false;
boolean clickedNo = false;
int 야구방망이공격력 = 100;
int 카타나공격력 = 1000;
int 도끼공격력 = 10000;
int 야구방망이가격 = 100;
int 카타나가격 = 1000;
int 도끼가격 = 10000;
boolean selectedBat = false;
boolean selectedKatana = false;
boolean selectedAx = false;
boolean clickedYesToWearBat = false;
boolean clickedYesToWearKatana = false;
boolean clickedYesToWearAx = false;
boolean equippedBat = false;
boolean equippedKatana = false;
boolean equippedAx = false;
int 공격력 = 0;
String 착용무기 = "없음";
ArrayList<String> weapon = new ArrayList<>(0);
int Timer;
// 게임 판넬에는 이미지를 넣었다. 패널 사이즈와 플레이어의 좌표를 넣었고, 리스트를 사용해서 몬스터가 여러마리가 생길수 있도록 했다.
// 그리고 이미지들이 어떻게 움직일지에 대한 수식을 넣었다. 화가가 있어서 판넬에 그릴 그림은 여기에서 수정하면 된다.
public GamePanel() {
// 생성자에서 사이즈를 구하려하면 무조건 0임, 아직 패널이 안붙어서 사이즈를 모르기때문에,
// width = getWidth();
// height = getHeight();
// 스테이지 1 이미지
imgGameBackStage1 = new ImageIcon(GameFrame.class.getResource("../images/게임배경화면이미지.jpg"))
.getImage();
// 스테이지 2 이미지
imgGameBackStage2 = new ImageIcon(GameFrame.class.getResource("../images/게임배경화면이미지2.jpg")).getImage();
// 스테이지 3 이미지
imgGameBackStage3 = new ImageIcon(GameFrame.class.getResource("../images/바탕화면이미지3.jpg"))
.getImage();
imgStage2Door = new ImageIcon(GameFrame.class.getResource("../images/StageTwoDoor.png")).getImage();
imgStage2FenceRight = new ImageIcon(GameFrame.class.getResource("../images/울타리.png")).getImage();
imgStage2FenceLeft = new ImageIcon(GameFrame.class.getResource("../images/울타리.png")).getImage();
imgGameSteelDoor = new ImageIcon(GameFrame.class.getResource("../images/철장문이미지.png")).getImage();
imgGameRightSteel = new ImageIcon(GameFrame.class.getResource("../images/마을철창이미지.jpg"))
.getImage();
imgGameLeftSteel = new ImageIcon(GameFrame.class.getResource("../images/마을철창이미지.jpg")).getImage();
// 건물 이미지 불러오기.
imgHouseFixer = new ImageIcon(GameFrame.class.getResource("../images/HouseFixer.png")).getImage();
imgWeaponStore = new ImageIcon(GameFrame.class.getResource("../images/무기상점이미지.png")).getImage();
imgSaveHouse = new ImageIcon(GameFrame.class.getResource("../images/저장소.png")).getImage();
imgLab = new ImageIcon(GameFrame.class.getResource("../images/인체공학소이미지.png")).getImage();
imgHospital = new ImageIcon(GameFrame.class.getResource("../images/병원이미지.png")).getImage();
imgDevelopmentTown = new ImageIcon(GameFrame.class.getResource("../images/마을발전소.png")).getImage();
imgBack = new ImageIcon(GameFrame.class.getResource("../images/바닥배경화면이미지.jpg")).getImage();
imgStageOneEnemy = new ImageIcon(GameFrame.class.getResource("../images/좀비.png")).getImage();
imgStageTwoEnemy = new ImageIcon(GameFrame.class.getResource("../images/좀비2.png")).getImage();
imgStageThreeEnemy = new ImageIcon(GameFrame.class.getResource("../images/좀비3.png")).getImage();
imgInWeaponStore = new ImageIcon(GameFrame.class.getResource("../images/무기상점내부.jpg")).getImage();
imgWeaponSmith = new ImageIcon(GameFrame.class.getResource("../images/무기대장장이.png")).getImage();
imgWeaponBox = new ImageIcon(GameFrame.class.getResource("../images/무기보관함.png")).getImage();
imgWeaponOn = new ImageIcon(GameFrame.class.getResource("../images/착용무기틀.png")).getImage();
imgInWeaponBox = new ImageIcon(GameFrame.class.getResource("../images/무기보관함내부.png")).getImage();
imgSmithClicked = new ImageIcon(GameFrame.class.getResource("../images/무기대장장이클릭.png"))
.getImage();
imgBat = new ImageIcon(GameFrame.class.getResource("../images/야구방망이.png")).getImage();
imgKatana = new ImageIcon(GameFrame.class.getResource("../images/카타나.png")).getImage();
imgAx = new ImageIcon(GameFrame.class.getResource("../images/도끼.png")).getImage();
//
smithCheckedToBuy = new ImageIcon(GameFrame.class.getResource("../images/대장장이의말문.png"))
.getImage();
treeForOneStage = new ImageIcon(GameFrame.class.getResource("../images/1단계나무.png")).getImage();
treeForTwoStage = new ImageIcon(GameFrame.class.getResource("../images/2단계나무.png")).getImage();
// addMouseListener(this); //더블 버퍼링 알아보기.
// imgCharUp = new ImageIcon(Main.class.getResource("../images/캐릭터위쪽방향.png")).getImage();
// imgCharRight = new ImageIcon(Main.class.getResource("../images/캐릭터오른쪽방향.png")).getImage();
// imgCharDown = new ImageIcon(Main.class.getResource("../images/캐릭터아래쪽방향.png")).getImage();
// imgCharLeft = new ImageIcon(Main.class.getResource("../images/캐릭터왼쪽방향.png")).getImage();
// imgCharRightUp = new ImageIcon(Main.class.getResource("../images/캐릭터오른위쪽방향.png")).getImage();
// imgCharRigthDown = new ImageIcon(Main.class.getResource("../images/캐릭터오른아래쪽방향.png")).getImage();
// imgCharLeftDown = new ImageIcon(Main.class.getResource("../images/캐릭터왼아래쪽방향.png")).getImage();
// imgCharLeftUp = new ImageIcon(Main.class.getResource("../images/캐릭터왼위쪽방향.png")).getImage();
//
// imgChar[0] = imgCharUp;
// imgChar[1] = imgCharRight;
// imgChar[2] = imgCharDown;
// imgChar[3] = imgCharLeft;
// imgChar[4] = imgCharRightUp;
// imgChar[5] = imgCharRigthDown;
// imgChar[6] = imgCharLeftDown;
// imgChar[7] = imgCharLeftUp;
imgPlayer = new ImageIcon(GameFrame.class.getResource("../images/주인공캐릭터.png")).getImage();
}
public void stopwatch() {
while (true) {
try {
Thread.sleep(1000);
Timer += 1;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// 화면에 보여질때 보여질 내용물 작업을 수행하는 메소드 : 자동 실행(콜백 메소드)
@Override
protected void paintComponent(Graphics g) {
// 화면에 보여질 작업 코딩
if (width == 0 || height == 0) { // 처음 호출시엔 느려서 안보이다 이후 보임
width = getWidth() - 290; // 화면의 오른쪽 부분에 접근 못하게 만듦.
height = getHeight() - 120;
// 리사이징
imgGameBackStage1 = imgGameBackStage1.getScaledInstance(1300, 950, Image.SCALE_SMOOTH); // 사진의 크기를 정해준다.
imgGameBackStage2 = imgGameBackStage2.getScaledInstance(1300, 950, Image.SCALE_SMOOTH); // 사진의 크기를 정해준다.
imgGameBackStage3 = imgGameBackStage3.getScaledInstance(1300, 950, Image.SCALE_SMOOTH); // 사진의 크기를 정해준다.
imgWeaponStore = imgWeaponStore.getScaledInstance(50, 50, Image.SCALE_SMOOTH);
imgLab = imgLab.getScaledInstance(50, 50, Image.SCALE_SMOOTH);
imgHospital = imgHospital.getScaledInstance(50, 50, Image.SCALE_SMOOTH);
imgHouseFixer = imgHouseFixer.getScaledInstance(50, 50, Image.SCALE_SMOOTH);
imgStage2Door = imgStage2Door.getScaledInstance(50, 50, Image.SCALE_SMOOTH);
imgGameSteelDoor = imgGameSteelDoor.getScaledInstance(100, 40, Image.SCALE_SMOOTH);
imgGameRightSteel = imgGameRightSteel.getScaledInstance(600, 20, Image.SCALE_SMOOTH); // 사진의 크기를 정해준다.
imgGameLeftSteel = imgGameLeftSteel.getScaledInstance(600, 20, Image.SCALE_SMOOTH); // 사진의 크기를 정해준다.
imgBack = imgBack.getScaledInstance(300, 1000, Image.SCALE_SMOOTH);
imgDevelopmentTown = imgDevelopmentTown.getScaledInstance(50, 50, Image.SCALE_SMOOTH);
imgInWeaponStore = imgInWeaponStore.getScaledInstance(1300, 950, Image.SCALE_SMOOTH);
imgSaveHouse = imgSaveHouse.getScaledInstance(50, 50, Image.SCALE_SMOOTH);
imgWeaponSmith = imgWeaponSmith.getScaledInstance(100, 100, Image.SCALE_SMOOTH);
imgWeaponBox = imgWeaponBox.getScaledInstance(100, 100, Image.SCALE_SMOOTH);
imgWeaponOn = imgWeaponOn.getScaledInstance(30, 30, Image.SCALE_SMOOTH);
imgInWeaponBox = imgInWeaponBox.getScaledInstance(1000, 800, Image.SCALE_SMOOTH);
imgSmithClicked = imgSmithClicked.getScaledInstance(1000, 700, Image.SCALE_SMOOTH);
imgBat = imgBat.getScaledInstance(200, 200, Image.SCALE_SMOOTH);
imgKatana = imgKatana.getScaledInstance(200, 200, Image.SCALE_SMOOTH);
imgAx = imgAx.getScaledInstance(200, 200, Image.SCALE_SMOOTH);
imgBatOn = imgBat.getScaledInstance(20, 20, Image.SCALE_SMOOTH);
imgKatanaOn = imgKatana.getScaledInstance(20, 20, Image.SCALE_SMOOTH);
imgAxOn = imgAx.getScaledInstance(20, 20, Image.SCALE_SMOOTH);
smithCheckedToBuy = smithCheckedToBuy.getScaledInstance(500, 500, Image.SCALE_SMOOTH);
treeForOneStage = treeForOneStage.getScaledInstance(50, 50, Image.SCALE_SMOOTH);
treeForTwoStage = treeForTwoStage.getScaledInstance(50, 50, Image.SCALE_SMOOTH);
imgPlayer = imgPlayer.getScaledInstance(64, 64, Image.SCALE_SMOOTH);
x = width / 2;// 플레이어의 좌표 계산
y = height - 300;
w = 32;
h = 32;
}
// 이곳에 화가객체가 있으므로 그림 그리는 작업은 무조건 여기서
// 스테이지 나누기
if (equippedBat == false && equippedKatana == false && equippedAx == false) {
공격력 = Power;
}
if (gameStage == 1) {
// stageOneMusic.start();
g.drawImage(imgGameBackStage1, 0, 50, this);// 배경 그리기
g.drawImage(imgBack, 1300, 0, this);// 캐릭터창 배경 그리기
g.drawImage(treeForOneStage, 0, 100, this);// 캐릭터창 배경 그리기
g.drawImage(treeForOneStage, 100, 120, this);// 캐릭터창 배경 그리기
g.drawImage(treeForOneStage, 230, 310, this);// 캐릭터창 배경 그리기
g.drawImage(treeForOneStage, 300, 425, this);// 캐릭터창 배경 그리기
g.drawImage(treeForOneStage, 410, 508, this);// 캐릭터창 배경 그리기
g.drawImage(treeForOneStage, 560, 215, this);// 캐릭터창 배경 그리기
g.drawImage(treeForOneStage, 600, 324, this);// 캐릭터창 배경 그리기
g.drawImage(treeForOneStage, 710, 112, this);// 캐릭터창 배경 그리기
g.drawImage(treeForOneStage, 800, 403, this);// 캐릭터창 배경 그리기
g.drawImage(treeForOneStage, 970, 209, this);// 캐릭터창 배경 그리기
g.drawImage(treeForOneStage, 1060, 330, this);// 캐릭터창 배경 그리기
g.drawImage(treeForOneStage, 1100, 120, this);// 캐릭터창 배경 그리기
g.drawImage(treeForOneStage, 1210, 516, this);// 캐릭터창 배경 그리기
g.drawImage(treeForOneStage, 1250, 332, this);// 캐릭터창 배경 그리기
g.drawImage(treeForOneStage, 150, 218, this);// 캐릭터창 배경 그리기
g.drawImage(imgGameSteelDoor, 600, 545, this);
g.drawImage(imgGameRightSteel, 700, 560, this);
g.drawImage(imgGameLeftSteel, 0, 560, this);
g.setFont(new Font(null, Font.BOLD, 110));// 점수 표시하기
if (0 * gameStage <= numberOfZombie && numberOfZombie < 5 * gameStage) {
g.drawString("□□□□□□□□□□□□□□□□□□□□", 113, 59);
} else if (5 * gameStage <= numberOfZombie && numberOfZombie < 10 * gameStage) {
g.drawString("■□□□□□□□□□□□□□□□□□□□", 113, 59);
} else if (10 * gameStage <= numberOfZombie && numberOfZombie < 15 * gameStage) {
g.drawString("■■□□□□□□□□□□□□□□□□□□", 113, 59);
} else if (15 * gameStage <= numberOfZombie && numberOfZombie < 20 * gameStage) {
g.drawString("■■■□□□□□□□□□□□□□□□□□", 113, 59);
} else if (20 * gameStage <= numberOfZombie && numberOfZombie < 25 * gameStage) {
g.drawString("■■■■□□□□□□□□□□□□□□□□", 113, 59);
} else if (25 * gameStage <= numberOfZombie && numberOfZombie < 30 * gameStage) {
g.drawString("■■■■■□□□□□□□□□□□□□□□", 113, 59);
} else if (30 * gameStage <= numberOfZombie && numberOfZombie < 35 * gameStage) {
g.drawString("■■■■■■□□□□□□□□□□□□□□", 113, 59);
} else if (35 * gameStage <= numberOfZombie && numberOfZombie < 40 * gameStage) {
g.drawString("■■■■■■■□□□□□□□□□□□□□", 113, 59);
} else if (40 * gameStage <= numberOfZombie && numberOfZombie < 45 * gameStage) {
g.drawString("■■■■■■■■□□□□□□□□□□□□", 113, 59);
} else if (45 * gameStage <= numberOfZombie && numberOfZombie < 50 * gameStage) {
g.drawString("■■■■■■■■■□□□□□□□□□□□", 113, 59);
} else if (50 * gameStage <= numberOfZombie && numberOfZombie < 55 * gameStage) {
g.drawString("■■■■■■■■■■□□□□□□□□□□", 113, 59);
} else if (55 * gameStage <= numberOfZombie && numberOfZombie < 60 * gameStage) {
g.drawString("■■■■■■■■■■■□□□□□□□□□", 113, 59);
} else if (60 * gameStage <= numberOfZombie && numberOfZombie < 65 * gameStage) {
g.drawString("■■■■■■■■■■■■□□□□□□□□", 113, 59);
} else if (65 * gameStage <= numberOfZombie && numberOfZombie < 70 * gameStage) {
g.drawString("■■■■■■■■■■■■■□□□□□□□", 113, 59);
} else if (70 * gameStage <= numberOfZombie && numberOfZombie < 75 * gameStage) {
g.drawString("■■■■■■■■■■■■■■□□□□□□", 113, 59);
} else if (75 * gameStage <= numberOfZombie && numberOfZombie < 80 * gameStage) {
g.drawString("■■■■■■■■■■■■■■■□□□□□", 113, 59);
} else if (80 * gameStage <= numberOfZombie && numberOfZombie < 85 * gameStage) {
g.drawString("■■■■■■■■■■■■■■■■□□□□", 113, 59);
} else if (85 * gameStage <= numberOfZombie && numberOfZombie < 90 * gameStage) {
g.drawString("■■■■■■■■■■■■■■■■■□□□", 113, 59);
} else if (90 * gameStage <= numberOfZombie && numberOfZombie < 95 * gameStage) {
g.drawString("■■■■■■■■■■■■■■■■■■□□", 113, 59);
} else if (95 * gameStage <= numberOfZombie && numberOfZombie < 100 * gameStage) {
g.drawString("■■■■■■■■■■■■■■■■■■■□", 113, 59);
} else if (100 * gameStage <= numberOfZombie) {
g.drawString("■■■■■■■■■■■■■■■■■■■■", 113, 59);
g.drawImage(imgStage2Door, 1225, 150, this);
g.setFont(new Font(null, Font.BOLD, 15));// 점수 표시하기
g.drawString("첫 번째 감염 지역을 클리어 했습니다.", 1300, 680);
g.drawString("다음 지역으로 이동해주세요.", 1300, 700);
stageOneClear = true;
// stageOneMusic.close();
}
for (StageOneEnemy t : stageOneEnemies) {
g.drawImage(t.imgOneEnemy, t.x - t.w, t.y + 120 - t.h, this);
}
}
if (gameStage == 2) {
g.drawImage(imgGameBackStage2, 0, 50, this);// 배경 그리기
g.drawImage(imgBack, 1300, 0, this);// 캐릭터창 배경 그리기
g.drawImage(treeForTwoStage, 0, 100, this);// 캐릭터창 배경 그리기
g.drawImage(treeForTwoStage, 100, 120, this);// 캐릭터창 배경 그리기
g.drawImage(treeForTwoStage, 230, 110, this);// 캐릭터창 배경 그리기
g.drawImage(treeForTwoStage, 300, 125, this);// 캐릭터창 배경 그리기
g.drawImage(treeForTwoStage, 410, 108, this);// 캐릭터창 배경 그리기
g.drawImage(treeForTwoStage, 560, 115, this);// 캐릭터창 배경 그리기
g.drawImage(treeForTwoStage, 600, 124, this);// 캐릭터창 배경 그리기
g.drawImage(treeForTwoStage, 710, 112, this);// 캐릭터창 배경 그리기
g.drawImage(treeForTwoStage, 800, 103, this);// 캐릭터창 배경 그리기
g.drawImage(treeForTwoStage, 970, 109, this);// 캐릭터창 배경 그리기
g.drawImage(treeForTwoStage, 1060, 130, this);// 캐릭터창 배경 그리기
g.drawImage(treeForTwoStage, 1100, 120, this);// 캐릭터창 배경 그리기
g.drawImage(treeForTwoStage, 1210, 116, this);// 캐릭터창 배경 그리기
g.drawImage(treeForTwoStage, 1250, 132, this);// 캐릭터창 배경 그리기
g.drawImage(treeForTwoStage, 150, 118, this);// 캐릭터창 배경 그리기
g.drawImage(imgGameSteelDoor, 600, 545, this);
g.drawImage(imgGameRightSteel, 700, 560, this);
g.drawImage(imgGameLeftSteel, 0, 560, this);
g.setFont(new Font(null, Font.BOLD, 110));// 점수 표시하기
if (0 * gameStage <= numberOfZombie && numberOfZombie < 5 * gameStage) {
g.drawString("□□□□□□□□□□□□□□□□□□□□", 113, 59);
} else if (5 * gameStage <= numberOfZombie && numberOfZombie < 10 * gameStage) {
g.drawString("■□□□□□□□□□□□□□□□□□□□", 113, 59);
} else if (10 * gameStage <= numberOfZombie && numberOfZombie < 15 * gameStage) {
g.drawString("■■□□□□□□□□□□□□□□□□□□", 113, 59);
} else if (15 * gameStage <= numberOfZombie && numberOfZombie < 20 * gameStage) {
g.drawString("■■■□□□□□□□□□□□□□□□□□", 113, 59);
} else if (20 * gameStage <= numberOfZombie && numberOfZombie < 25 * gameStage) {
g.drawString("■■■■□□□□□□□□□□□□□□□□", 113, 59);
} else if (25 * gameStage <= numberOfZombie && numberOfZombie < 30 * gameStage) {
g.drawString("■■■■■□□□□□□□□□□□□□□□", 113, 59);
} else if (30 * gameStage <= numberOfZombie && numberOfZombie < 35 * gameStage) {
g.drawString("■■■■■■□□□□□□□□□□□□□□", 113, 59);
} else if (35 * gameStage <= numberOfZombie && numberOfZombie < 40 * gameStage) {
g.drawString("■■■■■■■□□□□□□□□□□□□□", 113, 59);
} else if (40 * gameStage <= numberOfZombie && numberOfZombie < 45 * gameStage) {
g.drawString("■■■■■■■■□□□□□□□□□□□□", 113, 59);
} else if (45 * gameStage <= numberOfZombie && numberOfZombie < 50 * gameStage) {
g.drawString("■■■■■■■■■□□□□□□□□□□□", 113, 59);
} else if (50 * gameStage <= numberOfZombie && numberOfZombie < 55 * gameStage) {
g.drawString("■■■■■■■■■■□□□□□□□□□□", 113, 59);
} else if (55 * gameStage <= numberOfZombie && numberOfZombie < 60 * gameStage) {
g.drawString("■■■■■■■■■■■□□□□□□□□□", 113, 59);
} else if (60 * gameStage <= numberOfZombie && numberOfZombie < 65 * gameStage) {
g.drawString("■■■■■■■■■■■■□□□□□□□□", 113, 59);
} else if (65 * gameStage <= numberOfZombie && numberOfZombie < 70 * gameStage) {
g.drawString("■■■■■■■■■■■■■□□□□□□□", 113, 59);
} else if (70 * gameStage <= numberOfZombie && numberOfZombie < 75 * gameStage) {
g.drawString("■■■■■■■■■■■■■■□□□□□□", 113, 59);
} else if (75 * gameStage <= numberOfZombie && numberOfZombie < 80 * gameStage) {
g.drawString("■■■■■■■■■■■■■■■□□□□□", 113, 59);
} else if (80 * gameStage <= numberOfZombie && numberOfZombie < 85 * gameStage) {
g.drawString("■■■■■■■■■■■■■■■■□□□□", 113, 59);
} else if (85 * gameStage <= numberOfZombie && numberOfZombie < 90 * gameStage) {
g.drawString("■■■■■■■■■■■■■■■■■□□□", 113, 59);
} else if (90 * gameStage <= numberOfZombie && numberOfZombie < 95 * gameStage) {
g.drawString("■■■■■■■■■■■■■■■■■■□□", 113, 59);
} else if (95 * gameStage <= numberOfZombie && numberOfZombie < 100 * gameStage) {
g.drawString("■■■■■■■■■■■■■■■■■■■□", 113, 59);
} else if (100 * gameStage <= numberOfZombie) {
g.drawString("■■■■■■■■■■■■■■■■■■■■", 113, 59);
g.drawImage(imgStage2Door, 1225, 150, this);
g.setFont(new Font(null, Font.BOLD, 15));// 점수 표시하기
g.drawString("두 번째 감염 지역을 클리어 했습니다.", 1300, 680);
g.drawString("다음 지역은 숙주 좀비들이 있는 지역입니다. ", 1300, 700);
g.drawString("충분한 정비시간을 갖고", 1300, 720);
g.drawString("다음 지역으로 이동해주세요.", 1300, 740);
stageTwoClear = true;
}
for (StageTwoEnemy t : stageTwoEnemies) {
g.drawImage(t.imgTwoEnemy, t.x - t.w, t.y + 120 - t.h, this);
}
}
if (gameStage == 3) {
g.drawImage(imgGameBackStage3, 0, 50, this);// 배경 그리기
g.drawImage(imgBack, 1300, 0, this);// 캐릭터창 배경 그리기
g.drawImage(imgGameSteelDoor, 600, 545, this);
g.drawImage(imgGameRightSteel, 700, 560, this);
g.drawImage(imgGameLeftSteel, 0, 560, this);
g.setFont(new Font(null, Font.BOLD, 110));// 점수 표시하기
if (0 * gameStage <= numberOfZombie && numberOfZombie < 5 * gameStage) {
g.drawString("□□□□□□□□□□□□□□□□□□□□", 113, 59);
} else if (5 * gameStage <= numberOfZombie && numberOfZombie < 10 * gameStage) {
g.drawString("■□□□□□□□□□□□□□□□□□□□", 113, 59);
} else if (10 * gameStage <= numberOfZombie && numberOfZombie < 15 * gameStage) {
g.drawString("■■□□□□□□□□□□□□□□□□□□", 113, 59);
} else if (15 * gameStage <= numberOfZombie && numberOfZombie < 20 * gameStage) {
g.drawString("■■■□□□□□□□□□□□□□□□□□", 113, 59);
} else if (20 * gameStage <= numberOfZombie && numberOfZombie < 25 * gameStage) {
g.drawString("■■■■□□□□□□□□□□□□□□□□", 113, 59);
} else if (25 * gameStage <= numberOfZombie && numberOfZombie < 30 * gameStage) {
g.drawString("■■■■■□□□□□□□□□□□□□□□", 113, 59);
} else if (30 * gameStage <= numberOfZombie && numberOfZombie < 35 * gameStage) {
g.drawString("■■■■■■□□□□□□□□□□□□□□", 113, 59);
} else if (35 * gameStage <= numberOfZombie && numberOfZombie < 40 * gameStage) {
g.drawString("■■■■■■■□□□□□□□□□□□□□", 113, 59);
} else if (40 * gameStage <= numberOfZombie && numberOfZombie < 45 * gameStage) {
g.drawString("■■■■■■■■□□□□□□□□□□□□", 113, 59);
} else if (45 * gameStage <= numberOfZombie && numberOfZombie < 50 * gameStage) {
g.drawString("■■■■■■■■■□□□□□□□□□□□", 113, 59);
} else if (50 * gameStage <= numberOfZombie && numberOfZombie < 55 * gameStage) {
g.drawString("■■■■■■■■■■□□□□□□□□□□", 113, 59);
} else if (55 * gameStage <= numberOfZombie && numberOfZombie < 60 * gameStage) {
g.drawString("■■■■■■■■■■■□□□□□□□□□", 113, 59);
} else if (60 * gameStage <= numberOfZombie && numberOfZombie < 65 * gameStage) {
g.drawString("■■■■■■■■■■■■□□□□□□□□", 113, 59);
} else if (65 * gameStage <= numberOfZombie && numberOfZombie < 70 * gameStage) {
g.drawString("■■■■■■■■■■■■■□□□□□□□", 113, 59);
} else if (70 * gameStage <= numberOfZombie && numberOfZombie < 75 * gameStage) {
g.drawString("■■■■■■■■■■■■■■□□□□□□", 113, 59);
} else if (75 * gameStage <= numberOfZombie && numberOfZombie < 80 * gameStage) {
g.drawString("■■■■■■■■■■■■■■■□□□□□", 113, 59);
} else if (80 * gameStage <= numberOfZombie && numberOfZombie < 85 * gameStage) {
g.drawString("■■■■■■■■■■■■■■■■□□□□", 113, 59);
} else if (85 * gameStage <= numberOfZombie && numberOfZombie < 90 * gameStage) {
g.drawString("■■■■■■■■■■■■■■■■■□□□", 113, 59);
} else if (90 * gameStage <= numberOfZombie && numberOfZombie < 95 * gameStage) {
g.drawString("■■■■■■■■■■■■■■■■■■□□", 113, 59);
} else if (95 * gameStage <= numberOfZombie && numberOfZombie < 100 * gameStage) {
g.drawString("■■■■■■■■■■■■■■■■■■■□", 113, 59);
} else if (100 * gameStage <= numberOfZombie) {
g.drawString("■■■■■■■■■■■■■■■■■■■■", 113, 59);
g.setFont(new Font(null, Font.BOLD, 25));// 점수 표시하기
g.drawString("지구에 있는 모든 좀비를 제거했습니다 ~!!", 1300 / 2, 400);
g.drawString("수고하셨습니다 ~!", 1300 / 2, 430);
stageThreeClear = true;
}
for (StageThreeEnemy t : stageThreeEnemies) {
g.drawImage(t.imgThreeEnemy, t.x - t.w, t.y + 120 - t.h, this);
if (stageThreeClear == true) {
stageThreeEnemies.clear();
}
}
}
g.setFont(new Font(null, Font.BOLD, 20));// 점수 표시하기
g.drawImage(imgHouseFixer, 125, 660, this);
g.drawImage(imgDevelopmentTown, 250, 660, this);
g.drawImage(imgWeaponStore, 125, 850, this);
g.drawImage(imgLab, 625, 850, this);
g.drawImage(imgHospital, 1125, 850, this);
g.drawImage(imgSaveHouse, 1125, 660, this);
g.drawImage(imgPlayer, x - w, y + 120 - h, this);// 플레이어
g.setFont(new Font(null, Font.BOLD, 20));// 점수 표시하기
g.drawString("-------[ 캐릭터 정보 ]-------", 1300, 40); // + PlayerName 추가하기.
g.drawString("레벨 : " + LV, 1325, 80);
g.drawString("공격력 : " + 공격력, 1325, 120);
g.drawString("(착용무기 : " + 착용무기 + ")", 1325, 140);
g.drawString("체력 : " + HP, 1325, 180);
g.drawString("(최대 체력 : " + FHP + ")", 1325, 200);
// if (HP <= (HP/FHP)*100 && numberOfZombie < 5 * gameStage) {
// g.drawString("□□□□□□□□□□□□□□□□□□□□", 1325, 220);
// } else if (5 * gameStage <= numberOfZombie && numberOfZombie < 10 * gameStage) {
// g.drawString("■□□□□□□□□□□□□□□□□□□□", 1325, 220);
// } else if (10 * gameStage <= numberOfZombie && numberOfZombie < 15 * gameStage) {
// g.drawString("■■□□□□□□□□□□□□□□□□□□", 1325, 220);
// } else if (15 * gameStage <= numberOfZombie && numberOfZombie < 20 * gameStage) {
// g.drawString("■■■□□□□□□□□□□□□□□□□□", 1325, 220);
// } else if (20 * gameStage <= numberOfZombie && numberOfZombie < 25 * gameStage) {
// g.drawString("■■■■□□□□□□□□□□□□□□□□", 1325, 220);
// } else if (25 * gameStage <= numberOfZombie && numberOfZombie < 30 * gameStage) {
// g.drawString("■■■■■□□□□□□□□□□□□□□□", 1325, 220);
// } else if (30 * gameStage <= numberOfZombie && numberOfZombie < 35 * gameStage) {
// g.drawString("■■■■■■□□□□□□□□□□□□□□", 1325, 220);
// } else if (35 * gameStage <= numberOfZombie && numberOfZombie < 40 * gameStage) {
// g.drawString("■■■■■■■□□□□□□□□□□□□□", 1325, 220);
// } else if (40 * gameStage <= numberOfZombie && numberOfZombie < 45 * gameStage) {
// g.drawString("■■■■■■■■□□□□□□□□□□□□", 1325, 220);
// } else if (45 * gameStage <= numberOfZombie && numberOfZombie < 50 * gameStage) {
// g.drawString("■■■■■■■■■□□□□□□□□□□□", 1325, 220);
// } else if (50 * gameStage <= numberOfZombie && numberOfZombie < 55 * gameStage) {
// g.drawString("■■■■■■■■■■□□□□□□□□□□", 1325, 220);
// } else if (55 * gameStage <= numberOfZombie && numberOfZombie < 60 * gameStage) {
// g.drawString("■■■■■■■■■■■□□□□□□□□□", 1325, 220);
// } else if (60 * gameStage <= numberOfZombie && numberOfZombie < 65 * gameStage) {
// g.drawString("■■■■■■■■■■■■□□□□□□□□", 1325, 220);
// } else if (65 * gameStage <= numberOfZombie && numberOfZombie < 70 * gameStage) {
// g.drawString("■■■■■■■■■■■■■□□□□□□□", 1325, 220);
// } else if (70 * gameStage <= numberOfZombie && numberOfZombie < 75 * gameStage) {
// g.drawString("■■■■■■■■■■■■■■□□□□□□", 1325, 220);
// } else if (75 * gameStage <= numberOfZombie && numberOfZombie < 80 * gameStage) {
// g.drawString("■■■■■■■■■■■■■■■□□□□□", 1325, 220);
// } else if (80 * gameStage <= numberOfZombie && numberOfZombie < 85 * gameStage) {
// g.drawString("■■■■■■■■■■■■■■■■□□□□", 1325, 220);
// } else if (85 * gameStage <= numberOfZombie && numberOfZombie < 90 * gameStage) {
// g.drawString("■■■■■■■■■■■■■■■■■□□□", 1325, 220);
// } else if (90 * gameStage <= numberOfZombie && numberOfZombie < 95 * gameStage) {
// g.drawString("■■■■■■■■■■■■■■■■■■□□", 1325, 220);
// } else if (95 * gameStage <= numberOfZombie && numberOfZombie < 100 * gameStage) {
// g.drawString("■■■■■■■■■■■■■■■■■■■□", 1325, 220);
// } else if (100 * gameStage <= numberOfZombie) {
// g.drawString("■■■■■■■■■■■■■■■■■■■■", 113, 59);
// }
g.drawString("경험치 : " + EXP, 1325, 240);
g.drawString("(필요한 경험치 : " + needEXP + ")", 1325, 260);
if (Money <= 0) {
Money = 0;
}
g.drawString("돈 : " + Money, 1325, 300);
g.drawString("-------[ 마을 정보 ]-------", 1300, 360); // +
// PlayerName
// 추가하기.
g.drawString("마을 레벨 : " + TownLV, 1325, 400);
g.drawString("성벽 체력 : " + TownHP, 1325, 440);
g.drawString("(성벽 최대체력 : " + TownFHP + ")", 1325, 460);
g.drawString("------[ 몬스터 정보 ]------", 1305, 520);
if (gameStage == 1) {
if (StageOneMonsterHP <= 0) {
StageOneMonsterHP = 0;
}
g.drawString("몬스터 체력 : " + StageOneMonsterHP, 1325, 560);
g.drawString("몬스터 공격력 : " + StageOneMonsterPower, 1325, 600);
} else if (gameStage == 2) {
if (StageTwoMonsterHP <= 0) {
StageTwoMonsterHP = 0;
}
g.drawString("몬스터 체력 : " + StageTwoMonsterHP, 1325, 560);
g.drawString("몬스터 공격력 : " + StageTwoMonsterPower, 1325, 600);
} else if (gameStage == 3) {
if (StageThreeMonsterHP <= 0) {
StageThreeMonsterHP = 0;
}
g.drawString("몬스터 체력 : " + StageThreeMonsterHP, 1325, 560);
g.drawString("몬스터 공격력 : " + StageThreeMonsterPower, 1325, 600);
}
g.drawString("-------[ 게임 정보 ]-------", 1300, 640); // + PlayerName 추가하기.
g.drawString("[ 스테 이지 ]", 10, 20); // +
g.drawString("{ " + gameStage + " }", 39, 40); // + PlayerName 추가하기.
// g.setFont(new Font(null, Font.BOLD, 15));// 점수 표시하기
// g.drawString("마우스 정보", 1450, 900); // + PlayerName 추가하기.
// g.drawString("mouseX : " + mouseX, 1450, 920); // + PlayerName 추가하기.
// g.drawString("mouseY : " + mouseY, 1450, 940); // + PlayerName 추가하기.
if (clickedHospital == true) {
g.setFont(new Font(null, Font.BOLD, 15));// 점수 표시하기
g.drawString("병원입니다.", 1300, 700);
g.drawString("캐릭터의 체력을 회복 시켜줍니다.", 1300, 720);
g.drawString("LV 1 = 1원 (체력회복량 = 1)", 1300, 740);
g.drawString("LV 2 = 5원 (체력회복량 = 5)", 1300, 760);
g.drawString("LV 3 = 10원 (체력회복량 = 10)", 1300, 780);
g.drawString("LV 4 이상 = 50원 (체력회복량 = 50)", 1300, 800);
}
if (clickedLab == true) {
g.setFont(new Font(null, Font.BOLD, 15));// 점수 표시하기
g.drawString("인체공학소 입니다.", 1300, 700);
g.drawString("캐릭터의 최대체력을 증강 시켜줍니다.", 1300, 720);
g.drawString("비용 : 1원 (최대체력 = 1 증강)", 1300, 740);
}
if (clickedWeaponStore == true) {
g.setFont(new Font(null, Font.BOLD, 15));// 점수 표시하기
g.drawString("무기상점 입니다.", 1300, 700);
g.drawString("무기를 구매 할 수 있습니다.", 1300, 720);
g.drawString("1. 야구 방망이 = 100원 (공격력 100)", 1300, 740);
g.drawString("2. 카타나 = 1000원 (공격력 1000)", 1300, 760);
g.drawString("3. 양손도끼 = 10000원 (공격력 10000)", 1300, 780);
}
if (clickedTownCenter == true) {
g.setFont(new Font(null, Font.BOLD, 15));// 점수 표시하기
g.drawString("마을 수리소 입니다.", 1300, 700);
g.drawString("좀비로 인해 피해입은 성벽을 수리해 줍니다. ", 1300, 720);
g.drawString("마을레벨 1 = 1원 (회복량 = 1)", 1300, 740);
g.drawString("마을레벨 2 = 10원 (회복량 = 10)", 1300, 760);
g.drawString("마을레벨 3 이상 = 100원 (회복량 = 100)", 1300, 780);
g.drawString("마을레벨 4 이상 = 1000원 (회복량 = 1000)", 1300, 800);
}
if (clickedTownStation == true) {
g.setFont(new Font(null, Font.BOLD, 15));// 점수 표시하기
g.drawString("마을 발전소 입니다.", 1300, 700);
g.drawString("마을의 레벨을 올려줍니다.", 1300, 720);
g.drawString("마을의 레벨이 오르면,", 1300, 740);
g.drawString("성벽의 최대체력이 오르게 됩니다.", 1300, 760);
g.drawString("비용 : 1000원 (최대체력 1000증가)", 1300, 780);
}
if (clickedSaveHouse == true) {
g.setFont(new Font(null, Font.BOLD, 15));// 점수 표시하기
g.drawString("데이터를 저장할 수 있는 집 입니다", 1300, 700);
g.drawString("캐릭터가 집에있으면 데이터가 저장됩니다.", 1300, 720);
}
// if(clickedWeaponBox == true) {
// g.drawImage(, 125, 850, this);
// }
//
// if(clickedWeaponBox == true) {
// g.drawImage(, 125, 850, this);
// }
needEXP = FEXP - EXP;
if (needEXP <= 0) {
LV += 1;
EXP = 0;
FEXP *= LV;
FHP *= LV;
Power += 10;
}
// 스테이지문의 위치와 조건 설정 1125, 660 - 120 하면,
if (x >= 1225 && x <= 1300 && y >= 30 && y <= 105) {
if (stageOneClear == true && gameStage == 1) {
stageOneEnemies.clear();
gameStage = 2;
numberOfZombie = 0;
x = 1300 / 2;
y = 610;
} else if (stageOneClear == false) {
g.drawString("스테이지를 진행 하려면", 1330, 760);
g.drawString("좀비를 더 죽여야 합니다.", 1330, 780);
y = 110;
}
if (stageTwoClear == true && gameStage == 2) {
stageTwoEnemies.clear();
gameStage = 3;
numberOfZombie = 0;
x = 1300 / 2;
y = 610;
} else if (stageOneClear == false) {
g.drawString("스테이지를 진행 하려면", 1330, 760);
g.drawString("좀비를 더 죽여야 합니다.", 1330, 780);
y = 110;
}
if (stageThreeClear == true && gameStage == 3) {
stageThreeEnemies.clear();
gameStage = 4;
x = 1150;
y = 610;
} else if (stageThreeClear == false) {
g.drawString("보스 몬스터를 공격하려면", 1330, 760);
g.drawString("좀비를 더 죽여야 합니다.", 1330, 780);
y = 610;
}
}
// 병원의 위치와 조건 설정
if (x >= 1125 && x <= 1200 && y >= 700 && y <= 775) {
if (LV == 1) {
if (HP < FHP - 1 && Money >= 1) {
HP += 1;
Money -= 1;
g.drawString("회복 중 입니다.", 1330, 780);
} else if (HP < FHP && Money < 1) {
g.drawString("돈이 부족합니다.", 1330, 780);
} else if (HP == FHP) {
g.drawString("체력이 가득 차 있습니다.", 1330, 780);
}
}
if (LV == 2) {
if (HP < FHP - 5 && Money >= 5) {
HP += 5;
Money -= 5;
g.drawString("회복 중 입니다.", 1330, 780);
} else if (HP < FHP && Money < 5) {
g.drawString("돈이 부족합니다.", 1330, 780);
} else if (HP == FHP) {
g.drawString("체력이 가득 차 있습니다.", 1330, 780);
}
}
if (LV == 3) {
if (HP < FHP - 10 && Money >= 10) {
HP += 10;
Money -= 10;
g.drawString("회복 중 입니다.", 1330, 780);
} else if (HP < FHP && Money < 10) {
g.drawString("돈이 부족합니다.", 1330, 780);
} else if (HP == FHP) {
g.drawString("체력이 가득 차 있습니다.", 1330, 780);
}
}
if (LV == 4) {
if (HP < FHP - 50 && Money >= 50) {
HP += 50;
Money -= 50;
g.drawString("회복 중 입니다.", 1330, 780);
} else if (HP < FHP && Money < 50) {
g.drawString("돈이 부족합니다.", 1330, 780);
} else if (HP == FHP) {
g.drawString("체력이 가득 차 있습니다.", 1330, 780);
}
}
if (LV == 5) {
if (HP < FHP - 100 && Money >= 100) {
HP += 100;
Money -= 100;
g.drawString("회복 중 입니다.", 1330, 780);
} else if (HP < FHP && Money < 100) {
g.drawString("돈이 부족합니다.", 1330, 780);
} else if (HP == FHP) {
g.drawString("체력이 가득 차 있습니다.", 1330, 780);
}
}
if (LV == 6) {
if (HP < FHP - 500 && Money >= 500) {
HP += 500;
Money -= 500;
g.drawString("회복 중 입니다.", 1330, 780);
} else if (HP < FHP && Money < 500) {
g.drawString("돈이 부족합니다.", 1330, 780);
} else if (HP == FHP) {
g.drawString("체력이 가득 차 있습니다.", 1330, 780);
}
}
if (LV >= 7) {
if (HP < FHP - 1000 && Money >= 1000) {
HP += 1000;
Money -= 1000;
g.drawString("회복 중 입니다.", 1330, 780);
} else if (HP < FHP && Money < 1000) {
g.drawString("돈이 부족합니다.", 1330, 780);
} else if (HP == FHP) {
g.drawString("체력이 가득 차 있습니다.", 1330, 780);
}
}
}
//
// this.야구방망이 = 야구방망이;
// this.카타나 = 카타나;
// this.도끼 = 도끼;
// 무기상점의 위치와 조건 설정
if (x >= 125 && x <= 200 && y >= 700 && y <= 775) {
InWeaponStore = true;
// 들어 와 있을때에만 대장장이와 보관함이 클릭 가능 하도록 설정할것.
if (InWeaponStore == true) {
g.drawImage(imgInWeaponStore, 0, 50, this);
g.drawImage(imgWeaponSmith, 1300 / 2, 100, this);
g.drawImage(imgWeaponBox, 100, 100, this);
if (clickedWeaponBox == true) {
g.drawImage(imgInWeaponBox, 150, 250, this);
if (야구방망이 == true) {
g.drawImage(imgBat, 230, 420, this);
}
if (카타나 == true) {
g.drawImage(imgKatana, 500, 420, this);
}
if (도끼 == true) {
g.drawImage(imgAx, 230, 690, this);
}
if (selectedBat == true) {
g.drawImage(smithCheckedToBuy, 445, 230, this);
g.drawImage(imgBat, 580, 370, this);
g.setFont(new Font(null, Font.BOLD, 20));// 점수 표시하기
g.drawString("해당 무기를 착용하시겠습니까?", 575, 600);
g.setFont(new Font(null, Font.BOLD, 40));// 점수 표시하기
g.drawString("예", 515, 650);
g.drawString("아니오", 640, 650);
g.drawString("판매", 835, 650);
}
if (selectedKatana == true) {
g.drawImage(smithCheckedToBuy, 445, 230, this);
g.drawImage(imgKatana, 580, 370, this);
g.setFont(new Font(null, Font.BOLD, 20));// 점수 표시하기
g.drawString("해당 무기를 착용하시겠습니까?", 575, 600);
g.setFont(new Font(null, Font.BOLD, 40));// 점수 표시하기
g.drawString("예", 515, 650);
g.drawString("아니오", 640, 650);
g.drawString("판매", 835, 650);
}
if (selectedAx == true) {
g.drawImage(smithCheckedToBuy, 445, 230, this);
g.drawImage(imgAx, 580, 370, this);
g.setFont(new Font(null, Font.BOLD, 20));// 점수 표시하기
g.drawString("해당 무기를 착용하시겠습니까?", 575, 600);
g.setFont(new Font(null, Font.BOLD, 40));// 점수 표시하기
g.drawString("예", 515, 650);
g.drawString("아니오", 640, 650);
g.drawString("판매", 835, 650);
}
}
if (clickedWeaponSmith == true) {
g.drawImage(imgSmithClicked, 150, 250, this);
g.drawImage(imgBat, 1300 * 2 / 5 - 225, 500, this);
g.drawString("공격력 : " + 야구방망이공격력, 400, 740);
g.drawString("가격 : " + 야구방망이가격, 405, 760);
g.drawImage(imgKatana, 1300 * 3 / 5 - 225, 500, this);
g.drawString("공격력 : " + 카타나공격력, 650, 740);
g.drawString("가격 : " + 카타나가격, 655, 760);
g.drawImage(imgAx, 1300 * 4 / 5 - 225, 500, this);
g.drawString("공격력 : " + 도끼공격력, 900, 740);
g.drawString("가격 : " + 도끼가격, 905, 760);
if (clickedBat == true) {
g.drawImage(smithCheckedToBuy, 445, 230, this);
g.drawImage(imgBat, 580, 370, this);
g.setFont(new Font(null, Font.BOLD, 20));// 점수 표시하기
g.drawString("해당 무기를 구매하시겠습니까?", 575, 600);
g.setFont(new Font(null, Font.BOLD, 40));// 점수 표시하기
g.drawString("예", 515, 650);
g.drawString("아니오", 765, 650);
if (clickedYes == true) {
// g.drawString("무기가 구매되었습니다.", 1330, 780);
clickedYes = false;
} else if (clickedYes == true) {
// 이미 구매된 상
clickedYes = false;
} else if (clickedYesButMoney == true) {
// g.drawString("무기를 구매하려면 " + (100 - Money) + "의 돈이 더 필요 합니다.", 1330, 780);
clickedYesButMoney = false;
} else if (clickedNo == true) {
// g.drawString("구매가 취소되었습니다.", 1330, 780);
clickedNo = false;
}
}
if (clickedKatana == true) {
g.drawImage(smithCheckedToBuy, 445, 230, this);
g.drawImage(imgKatana, 580, 370, this);
g.setFont(new Font(null, Font.BOLD, 20));// 점수 표시하기
g.drawString("해당 무기를 구매하시겠습니까?", 575, 600);
g.setFont(new Font(null, Font.BOLD, 40));// 점수 표시하기
g.drawString("예", 515, 650);
g.drawString("아니오", 765, 650);
if (clickedYes == true) {
// g.drawString("무기가 구매되었습니다.", 1330, 780);
clickedYes = false;
} else if (clickedYes == true) {
// 이미 구매된 상
clickedYes = false;
} else if (clickedYesButMoney == true) {
// g.drawString("무기를 구매하려면 " + (100 - Money) + "의 돈이 더 필요 합니다.", 1330, 780);
clickedYesButMoney = false;
} else if (clickedNo == true) {
// g.drawString("구매가 취소되었습니다.", 1330, 780);
clickedNo = false;
}
}
if (clickedAx == true) {
g.drawImage(smithCheckedToBuy, 445, 230, this);
g.drawImage(imgAx, 580, 370, this);
g.setFont(new Font(null, Font.BOLD, 20));// 점수 표시하기
g.drawString("해당 무기를 구매하시겠습니까?", 575, 600);
g.setFont(new Font(null, Font.BOLD, 40));// 점수 표시하기
g.drawString("예", 515, 650);
g.drawString("아니오", 765, 650);
if (clickedYes == true) {
// g.drawString("무기가 구매되었습니다.", 1330, 780);
clickedYes = false;
} else if (clickedYes == true) {
// 이미 구매된 상
clickedYes = false;
} else if (clickedYesButMoney == true) {
// g.drawString("무기를 구매하려면 " + (100 - Money) + "의 돈이 더 필요 합니다.", 1330, 780);
clickedYesButMoney = false;
} else if (clickedNo == true) {
// g.drawString("구매가 취소되었습니다.", 1330, 780);
clickedNo = false;
}
}
}
}
}
// 집의 위치와 조건 설정
if (x >= 1125 && x <= 1200 && y >= 500 && y <= 575) {
g.drawString("데이터가 저장됬습니다.", 1330, 780);
UserDAO userDAO = new UserDAO();
/*
* TODO 이곳에 저장 하는 메서드 불러오기.
*/
// int gameStage = stageNum;
// int TownLV = townLV;
// int TownHP = townHP;
// int TownFHP = townFHP;
//
// boolean 야구방망이 = haveBat;
// boolean 카타나 = haveKatana;
// boolean 도끼 = haveAx;
//
// int LV = charLV;
// int Power = charPower;
// int HP = charHP;
// int FHP = charFHP;
// int EXP = charExp;
// int needEXP = 1;
// int FEXP = charFexp;
// int Money = charMoney;
if (야구방망이 == true) {
weaponStoreDTO.setBat(1);
} else {
weaponStoreDTO.setBat(0);
}
if (카타나 == true) {
weaponStoreDTO.setKatana(1);
} else {
weaponStoreDTO.setKatana(0);
}
if (도끼 == true) {
weaponStoreDTO.setAx(1);
} else {
weaponStoreDTO.setAx(0);
}
stageDTO.setStageNumber(gameStage);
townDTO.setTownLV(TownLV);
townDTO.setTownHP(TownHP);
townDTO.setTownFHP(TownFHP);
worriorDTO.setLv(LV);
worriorDTO.setPower(Power);
worriorDTO.setHp(HP);
worriorDTO.setFhp(FHP);
worriorDTO.setExp(EXP);
worriorDTO.setFexp(FEXP);
worriorDTO.setMoney(Money);
userDTO.setId(userDTO.getId());
userDAO.saveData(stageDTO, weaponStoreDTO, townDTO, worriorDTO, userid);
// 결합한 시간을 SQL 에 저장한다.
// + stopwatch.currentTime()
// System.out.println(stopwatch.currentTime());
// System.out.println(time);
// System.out.println(userDTO.getId());
// System.out.println(number);
// System.out.println(rankDTO.getId());
// System.out.println(rankDTO.getId());
// System.out.println(rankDTO.getId());
//
// System.out.println(gameStage);
// System.out.println(stageNum);
// rankDTO.setRankTime(time);
// rankDTO.setId(userDTO.getId());
// rankDTO.setNumber(number);
// rankDAO.saveData(rankDTO);
}
// 인체공학소의 위치와 조건 설정
if (x >= 625 && x <= 700 && y >= 700 && y <= 775) {
if (Money >= 1) {
FHP += 1;
Money -= 1;
y = 699;
} else if (Money < 1) {
g.drawString("돈이 부족합니다.", 1330, 780);
}
}
// 마을정비소 위치와 조건 설정
if (x >= 125 && x <= 200 && y >= 500 && y <= 575) {
if (TownHP < TownFHP - 100 && Money >= 10) { // HP를 한번에 채워주고 1000을 넘게 하지 않기 위해서 -100을 넘어줌
if (TownLV == 1) {
Money -= 1;
TownHP += 1;
}
if (TownLV == 2) {
Money -= 10;
TownHP += 10;
}
if (TownLV == 3) {
Money -= 100;
TownHP += 100;
}
if (TownLV >= 4) {
Money -= 1000;
TownHP += 1000;
}
y = 499;
} else if (TownHP < TownFHP && Money < 1) {
g.drawString("돈이 부족합니다.", 1330, 780);
} else if (TownHP == TownFHP) {
g.drawString("성벽이 수리되었습니다.", 1330, 780);
}
}
// 마을발전소
if (x >= 250 && x <= 325 && y >= 500 && y <= 575) {
if (Money >= 1000) { // HP를 한번에 채워주고 1000을 넘게 하지 않기 위해서 -100을 넘어줌
Money -= 1000;
TownLV += 1;
TownFHP += 1000;
x = 650;
y = 600;
} else if (TownHP < TownFHP && Money < 1) {
g.drawString("돈이 부족합니다.", 1330, 780);
} else if (TownHP == TownFHP) {
g.drawString("성벽이 수리되었습니다.", 1330, 780);
}
}
// 성문 설정
// 안쪽 벽 설정
if (x >= 601 && x <= 700 && y >= 460 && y <= 480) {
y = 399;
}
// 바깥 벽 설정
if (x >= 601 && x <= 700 && y >= 400 && y <= 420) {
y = 481;
}
// 왼쪽 벽 설정
// 안쪽 벽 설정
if (x >= 1 && x <= 599 && y >= 460 && y <= 480) {
y = 481;
}
// 바깥 벽 설정
if (x >= 0 && x <= 600 && y >= 400 && y <= 420) {
x = width - 1200; // 플레이어의 좌표 계산
y = height - 950;
}
// 오른쪽 벽 설정
// 안쪽 벽 설정
if (x >= 701 && x <= 1300 && y >= 460 && y <= 480) {
y = 481;
}
// 바깥 벽 설정
if (x >= 701 && x <= 1300 && y >= 400 && y <= 420) {
x = width - 100; // 플레이어의 좌표 계산
y = height - 950;
}
// 캐릭터 정보 창
if (HP <= 20) {
g.setFont(new Font(null, Font.BOLD, 40));// 점수 표시하기
g.drawString("캐릭터의 체력이 부족합니다.", 500, 300);
}
if (TownHP <= 100) {
stopwatch.measureTime(false);
g.drawString("마을이 감염 되기전 입니다.", 1300 / 2, 100);
}
if (TownHP <= 0) {
// try {
//// g.drawString("걸린 시간 : " + timerBuffer , 1300 / 2, 430);
//// System.out.format("Timer OFF! 경과 시간: [%s]%n", timerBuffer); // 경과 시간 화면에 출력
// System.in.read();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
try {
stopwatch.measureTime(false);
Thread.sleep(5000);
System.exit(0);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// 여러장면 만들기
// 위해 일정시간마다
// 다시 그리기(re
// painting)
if (HP <= 10) {
g.drawString("캐릭터가 죽기 직전입니다.", 400, 230);
if (HP <= 0) {
// g.drawString("걸린 시간 : " + timerBuffer , 1300 / 2, 430);
// System.out.format("Timer OFF! 경과 시간: [%s]%n", timerBuffer); // 경과 시간 화면에 출력
// try {
//// g.drawString("걸린 시간 : " + timerBuffer , 1300 / 2, 430);
//// System.out.format("Timer OFF! 경과 시간: [%s]%n", timerBuffer); // 경과 시간 화면에 출력
// System.in.read();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
try {
stopwatch.measureTime(false);
Thread.sleep(5000);
System.exit(0);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}// paintComponent method
public void Mouse() {
// TODO Auto-generated method stub
panel.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
// mouseX = e.getX(); // 마우스 포인터의 X좌표
// mouseY = e.getY(); // 마우스 포인터의 Y좌표
}
@Override
public void mouseClicked(MouseEvent e) {
mouseX = e.getX(); // 마우스 포인터의 X좌표
mouseY = e.getY(); // 마우스 포인터의 Y좌표
if (mouseX >= 1125 && mouseX <= 1175 && mouseY >= 860 && mouseY <= 900) {
clickedHospital = true;
} else {
clickedHospital = false;
}
if (mouseX >= 630 && mouseX <= 675 && mouseY >= 860 && mouseY <= 900) {
clickedLab = true;
} else {
clickedLab = false;
}
if (mouseX >= 130 && mouseX <= 175 && mouseY >= 860 && mouseY <= 900) {
clickedWeaponStore = true;
} else {
clickedWeaponStore = false;
}
if (mouseX >= 130 && mouseX <= 175 && mouseY >= 660 && mouseY <= 715) {
clickedTownCenter = true;
} else {
clickedTownCenter = false;
}
if (mouseX >= 260 && mouseX <= 300 && mouseY >= 660 && mouseY <= 715) {
clickedTownStation = true;
} else {
clickedTownStation = false;
}
if (mouseX >= 1125 && mouseX <= 1175 && mouseY >= 660 && mouseY <= 715) {
clickedSaveHouse = true;
} else {
clickedSaveHouse = false;
}
if (InWeaponStore == true) {
// 보관함
if (mouseX >= 100 && mouseX <= 200 && mouseY >= 100 && mouseY <= 200) {
clickedWeaponBox = true;
} else if (mouseX <= 150 || mouseX >= 1150 || mouseY <= 340 || mouseY >= 950) {
clickedWeaponBox = false;
}
if (clickedWeaponBox == true) {
if (야구방망이 == true && mouseX >= 240 && mouseX <= 425 && mouseY >= 430 && mouseY <= 600) {
selectedBat = true;
} else if (야구방망이 == false && mouseX >= 240 && mouseX <= 425 && mouseY >= 430
&& mouseY <= 600) {
System.out.println("보관함 야구방망이 x");
}
if (카타나 == true && mouseX >= 510 && mouseX <= 690 && mouseY >= 430 && mouseY <= 600) {
selectedKatana = true;
} else if (카타나 == false && mouseX >= 240 && mouseX <= 425 && mouseY >= 430
&& mouseY <= 600) {
System.out.println("보관함 카타나 x");
}
if (도끼 == true && mouseX >= 240 && mouseX <= 425 && mouseY >= 700 && mouseY <= 870) {
selectedAx = true;
} else if (도끼 == false && mouseX >= 240 && mouseX <= 425 && mouseY >= 430
&& mouseY <= 600) {
System.out.println("보관함 도끼 x");
}
}
if (selectedBat == true && 야구방망이 == true) {
// 예
if (mouseX >= 515 && mouseX <= 550 && mouseY >= 620 && mouseY <= 660) {
clickedYesToWearBat = true; // weapon.add(0,"없음");
공격력 = Power + 야구방망이공격력;
착용무기 = "야구방망이";
equippedBat = true;
selectedBat = false;
}
// 아니오
if (mouseX >= 630 && mouseX <= 780 && mouseY >= 620 && mouseY <= 660) {
공격력 = Power;
착용무기 = "없음";
equippedBat = false;
selectedBat = false;
}
// 판매
if (mouseX >= 835 && mouseX <= 900 && mouseY >= 620 && mouseY <= 660) {
공격력 = Power;
착용무기 = "없음";
equippedBat = false;
야구방망이 = false;
Money += 야구방망이가격 / 2;
selectedBat = false;
}
}
if (selectedKatana == true && 카타나 == true) {
// 예
if (mouseX >= 515 && mouseX <= 550 && mouseY >= 620 && mouseY <= 660) {
clickedYesToWearKatana = true; // weapon.add(0,"없음");
공격력 = Power + 카타나공격력;
착용무기 = "카타나";
equippedKatana = true;
selectedKatana = false;
}
// 아니오
if (mouseX >= 630 && mouseX <= 780 && mouseY >= 620 && mouseY <= 660) {
착용무기 = "없음";
공격력 = Power;
equippedKatana = false;
selectedKatana = false;
}
// 판매
if (mouseX >= 835 && mouseX <= 900 && mouseY >= 620 && mouseY <= 660) {
착용무기 = "없음";
공격력 = Power;
equippedKatana = false;
카타나 = false;
Money += 카타나가격 / 2;
selectedKatana = false;
}
}
if (selectedAx == true && 도끼 == true) {
// 예
if (mouseX >= 515 && mouseX <= 550 && mouseY >= 620 && mouseY <= 660) {
clickedYesToWearAx = true; // weapon.add(0,"없음");
공격력 = Power + 도끼공격력;
착용무기 = "도끼";
equippedAx = true;
selectedAx = false;
}
// 아니오
if (mouseX >= 630 && mouseX <= 780 && mouseY >= 620 && mouseY <= 660) {
착용무기 = "없음";
공격력 = Power;
equippedAx = false;
selectedAx = false;
}
// 판매
if (mouseX >= 835 && mouseX <= 900 && mouseY >= 620 && mouseY <= 660) {
착용무기 = "없음";
공격력 = Power;
equippedAx = false;
도끼 = false;
Money += 도끼가격 / 2;
selectedAx = false;
}
}
// 상인
if (mouseX >= 650 && mouseX <= 750 && mouseY >= 100 && mouseY <= 200) {
clickedWeaponSmith = true;
} else if (mouseX <= 150 || mouseX >= 1150 || mouseY <= 340 || mouseY >= 870) {
clickedWeaponSmith = false;
}
if (clickedWeaponSmith == true) {
if (mouseX >= 300 && mouseX <= 500 && mouseY >= 500 && mouseY <= 700) {
clickedBat = true;
} else if (mouseX <= 150 || mouseX >= 1150 || mouseY <= 340 || mouseY >= 870) {
clickedBat = false;
}
if (mouseX >= 550 && mouseX <= 750 && mouseY >= 500 && mouseY <= 700) {
clickedKatana = true;
} else if (mouseX <= 150 || mouseX >= 1150 || mouseY <= 340 || mouseY >= 870) {
clickedKatana = false;
}
if (mouseX >= 800 && mouseX <= 1000 && mouseY >= 500 && mouseY <= 700) {
clickedAx = true;
} else if (mouseX <= 150 || mouseX >= 1150 || mouseY <= 340 || mouseY >= 870) {
clickedAx = false;
}
}
if (clickedBat == true && 야구방망이 == false) {
if (mouseX >= 515 && mouseX <= 550 && mouseY >= 620 && mouseY <= 660 && Money >= 100) {
clickedBuyBat = true;
Money -= 100;
야구방망이 = true;
System.out.println("방망이 구매됨");
clickedBat = false;
clickedYes = true;
}
else if (mouseX >= 515 && mouseX <= 550 && mouseY >= 620 && mouseY <= 660 && Money < 100) {
clickedBuyBat = false;
System.out.println("돈이 부족함. 방망이 구매안됨");
clickedBat = false;
clickedYesButMoney = true;
}
if (mouseX >= 720 && mouseX <= 870 && mouseY >= 620 && mouseY <= 660) {
clickedBuyBat = false;
System.out.println("방망이 구매안됨");
clickedBat = false;
clickedNo = true;
}
}
if (clickedKatana == true && 카타나 == false) {
if (mouseX >= 515 && mouseX <= 550 && mouseY >= 620 && mouseY <= 660 && Money >= 1000) {
clickedBuyKatana = true;
Money -= 1000;
카타나 = true;
clickedKatana = false;
clickedYes = true;
} else if (mouseX >= 515 && mouseX <= 550 && mouseY >= 620 && mouseY <= 660
&& Money < 1000) {
clickedBuyKatana = false;
clickedKatana = false;
clickedYesButMoney = true;
// 돈 부족 구매 x
}
if (mouseX >= 720 && mouseX <= 870 && mouseY >= 620 && mouseY <= 660) {
clickedBuyKatana = false;
clickedKatana = false;
clickedNo = true;
}
}
if (clickedAx == true && 도끼 == false) {
if (mouseX >= 515 && mouseX <= 550 && mouseY >= 620 && mouseY <= 660 && Money >= 10000) {
Money -= 10000;
도끼 = true;
clickedBuyAx = true;
clickedAx = false;
clickedYes = true;
} else if (mouseX >= 515 && mouseX <= 550 && mouseY >= 620 && mouseY <= 660
&& Money < 10000) {
clickedBuyAx = false;
clickedAx = false;
clickedYesButMoney = true;
}
if (mouseX >= 720 && mouseX <= 870 && mouseY >= 620 && mouseY <= 660) {
clickedBuyAx = false;
clickedAx = false;
clickedNo = true;
}
}
}
}
});
}
void move() { // 플레이어 움직이기(좌표 변경)
// 적군들 움직이기
// 중간에 배열의 개수 변경될 여지가 있다면
// 맨 마지막 요소부터 거꾸로 0번 요소까지 역으로 처리해야함.
if (gameStage == 1) {
for (int i = stageOneEnemies.size() - 1; i >= 0; i--) {
StageOneEnemy t = stageOneEnemies.get(i);
t.move();
if (t.isDead) { // ArrayList에서 제거
stageOneEnemies.remove(i);
TownHP -= t.monsterPower;
}
}
} else if (gameStage == 2) {
for (int i = stageTwoEnemies.size() - 1; i >= 0; i--) {
StageTwoEnemy t = stageTwoEnemies.get(i);
t.move();
if (t.isDead) { // ArrayList에서 제거
stageTwoEnemies.remove(i);
TownHP -= t.monsterPower;
}
}
} else if (gameStage == 3) {
for (int i = stageThreeEnemies.size() - 1; i >= 0; i--) {
StageThreeEnemy t = stageThreeEnemies.get(i);
t.move();
if (t.isDead) { // ArrayList에서 제거
stageThreeEnemies.remove(i);
TownHP -= t.monsterPower;
}
}
}
// for(Enemy t : enemies) { //foreach문으론 불가 }
x += dx;
y += dy;
// 플레이어 좌표가 화면 밖으로 나가지 않도록
if (x < w)
x = w;
if (x > width - w)
x = width - w;
if (y < h)
y = h;
if (y > height - h)
y = height - h;
}
void makeEnemy() { // 적군 생성 메소드
if (width == 0 || height == 0)
return;
Random rnd = new Random();// 50번에 한번꼴로 만들기
int Num = rnd.nextInt(10);
if (gameStage == 1) {
if (Num == 0) {
stageOneEnemies.add(new StageOneEnemy(imgStageOneEnemy, width, height)); // 몬스터의 특징 수정
}
} else if (gameStage == 2) {
if (Num == 0) {
stageTwoEnemies.add(new StageTwoEnemy(imgStageOneEnemy, width, height)); // 몬스터의 특징 수정
stageTwoEnemies.add(new StageTwoEnemy(imgStageTwoEnemy, width, height)); // 몬스터의 특징 수정
}
} else if (gameStage == 3) {
if (Num == 0) {
stageThreeEnemies.add(new StageThreeEnemy(imgStageOneEnemy, width, height)); // 몬스터의 특징 수정
stageThreeEnemies.add(new StageThreeEnemy(imgStageTwoEnemy, width, height)); // 몬스터의 특징 수정
stageThreeEnemies.add(new StageThreeEnemy(imgStageThreeEnemy, width, height)); // 몬스터의 특징 수정
}
}
}
// 충돌체크 작업 계산 메소드
// 몬스터 생성되고, 몬스터가 캐릭터에 닿으면 죽음.
void checkCollision() { // 플레이어와 적군의 충돌
if (gameStage == 1) {
for (StageOneEnemy t : stageOneEnemies) {
int left = t.x - t.w;
int right = t.x + t.w;
int top = t.y - t.h;
int bottom = t.y + t.h;
if (x > left && x < right && y > top && y < bottom) {
t.HP -= 공격력;
StageOneMonsterHP = t.HP;
StageOneMonsterPower = t.monsterPower;
HP -= t.monsterPower;
if (t.HP <= 0) {
t.isDead = true;
Money += 10;
EXP += 5;
numberOfZombie += 10;
TownHP += t.monsterPower;
}
// t.isDead = true; // 충돌했음
// HP -= 5;
// Money += 10;
// EXP += 5;
}
// 여기에 성의 위치를 넣고 부딛치면 죽는걸로 설정할 것.
}
} else if (gameStage == 2) {
for (StageTwoEnemy t : stageTwoEnemies) {
int left = t.x - t.w;
int right = t.x + t.w;
int top = t.y - t.h;
int bottom = t.y + t.h;
if (x > left && x < right && y > top && y < bottom) {
t.HP -= 공격력;
StageTwoMonsterHP = t.HP;
StageTwoMonsterPower = t.monsterPower;
HP -= t.monsterPower;
if (t.HP <= 0) {
t.isDead = true;
Money += 200;
EXP += 5;
numberOfZombie += 10;
TownHP += t.monsterPower;
}
// t.isDead = true; // 충돌했음
// HP -= 5;
// Money += 10;
// EXP += 5;
}
// 여기에 성의 위치를 넣고 부딛치면 죽는걸로 설정할 것.
}
} else if (gameStage == 3) {
for (StageThreeEnemy t : stageThreeEnemies) {
int left = t.x - t.w;
int right = t.x + t.w;
int top = t.y - t.h;
int bottom = t.y + t.h;
if (x > left && x < right && y > top && y < bottom) {
t.HP -= 공격력;
StageThreeMonsterHP = t.HP;
StageThreeMonsterPower = t.monsterPower;
HP -= t.monsterPower;
if (t.HP <= 0) {
t.isDead = true;
Money += 1000;
EXP += 5;
numberOfZombie += 10;
TownHP += t.monsterPower;
}
// t.isDead = true; // 충돌했음
// HP -= 5;
// Money += 10;
// EXP += 5;
}
// 여기에 성의 위치를 넣고 부딛치면 죽는걸로 설정할 것.
}
}
if (FEXP <= 0) {
LV += 1;
EXP = 0;
}
}
// // 마우스 버튼을 클릭했을 때의 동작 정의
//
// public void mouseClicked(MouseEvent e) {
//
// }
//
// // 마우스 포인터가 컨테이너/컴포넌트 영역 안에 있을 때의 동작 정의
//
// public void mouseEntered(MouseEvent e) {
// panel.setBounds(mouseX, mouseY, 50, 50);
// panel.setBackground(Color.RED);
// }
//
// // 마우스 포인터가 컨테이너/컴포넌트 영역 밖에 있을 때의 동작 정의
//
// public void mouseExited(MouseEvent e) {
// panel.setBounds((600 - 200) / 2, (600 - 200) / 2, 200, 200);
// panel.setBackground(Color.blue);
// }
//
// // 마우스 버튼을 누르고 있을 때의 동작 정의
// public void mousePressed(MouseEvent e) {
// mouseX = e.getX(); // 마우스 포인터의 X좌표
// mouseY = e.getY(); // 마우스 포인터의 Y좌표
//
// panel.setLocation(mouseX, mouseY);
// panel.setBackground(Color.green);
//
// }
//
// // 마우스 버튼을 눌렀다가 떼었을 때의 동작 정의
//
// public void mouseReleased(MouseEvent e) {
//
// }
}
//---------------------------------------------------------------------------------------------------------------------
public class StageOneEnemy {
Image imgOneEnemy; // 이미지 참조변수 // 좀비 이미지 추가할것.
int x, y; // 이미지 중심 좌표
int w, h; // 이미지 절반폭, 절반높이
int monsterMove; // 적군의 변화량
int monsterPower = 1;
int HP = 100;
int width, height; // 화면(panel)의 사이즈
// 본인 객체가 죽었는지 여부!
boolean isDead = false;
public StageOneEnemy(Image imgStageOneEnemy, int width, int height) {
this.width = width;
this.height = height;
// this.HP
// 멤버변수 값 초기화..
imgOneEnemy = imgStageOneEnemy.getScaledInstance(32, 32, Image.SCALE_SMOOTH);
w = 32; // 이미지 절반넓이
h = 32;
Random rnd = new Random();
x = rnd.nextInt(width - w * 2) + w; // w ~ width - w
y = -h;
monsterMove = +1; // 움직이는 속도
// monsterMove =+ rnd.nextInt(5)+1;//떨어지는 속도 랜덤하게
}
void move() { // Enemy의 움직이는 기능 메소드 //랜덤하게 할것 = x y에 랜덤값을 줘서 움직임이 자유롭게 할것 + 생성되는 위치도 랜덤하게 둘것 =
// 생성되는 위치를 화면 안의 x y 값을 넣고 랜덤값을 줄것.
// x y 값을 랜덤하게 둘것.
Random rnd = new Random();
int number = rnd.nextInt(4);
if (number == 0) {
x += monsterMove;
} else if (number == 1) {
x -= monsterMove + 0.01;
} else if (number == 2) {
y += monsterMove;
} else if (number == 3) {
y -= monsterMove;
}
y += monsterMove; // y로 이동하게 만듦
// 만약 화면 밑으로 나가버리면 객체 없애기
if (y > height - 450 + h) { // ArrayList에서 제거
this.isDead = true; // 죽음 표식!
}
}
}
public class StageTwoEnemy {
Image imgTwoEnemy; // 이미지 참조변수 // 좀비 이미지 추가할것.
int x, y; // 이미지 중심 좌표
int w, h; // 이미지 절반폭, 절반높이
int monsterMove; // 적군의 변화량
int monsterPower = 10;
int HP = 1000;
int width, height; // 화면(panel)의 사이즈
// 본인 객체가 죽었는지 여부!
boolean isDead = false;
public StageTwoEnemy(Image imgStageTwoEnemy, int width, int height) {
this.width = width;
this.height = height;
// this.HP
// 멤버변수 값 초기화..
imgTwoEnemy = imgStageTwoEnemy.getScaledInstance(40, 40, Image.SCALE_SMOOTH);
w = 32; // 이미지 절반넓이
h = 32;
Random rnd = new Random();
x = rnd.nextInt(width - w * 2) + w; // w ~ width - w
y = -h;
monsterMove = +1; // 움직이는 속도
// monsterMove =+ rnd.nextInt(5)+1;//떨어지는 속도 랜덤하게
}
void move() { // Enemy의 움직이는 기능 메소드 //랜덤하게 할것 = x y에 랜덤값을 줘서 움직임이 자유롭게 할것 + 생성되는 위치도 랜덤하게 둘것 =
// 생성되는 위치를 화면 안의 x y 값을 넣고 랜덤값을 줄것.
// x y 값을 랜덤하게 둘것.
Random rnd = new Random();
int number = rnd.nextInt(4);
if (number == 0) {
x += monsterMove;
} else if (number == 1) {
x -= monsterMove + 0.01;
} else if (number == 2) {
y += monsterMove;
} else if (number == 3) {
y -= monsterMove;
}
y += monsterMove + 2; // y로 이동하게 만듦
// 만약 화면 밑으로 나가버리면 객체 없애기
if (y > height - 450 + h) { // ArrayList에서 제거
this.isDead = true; // 죽음 표식!
}
}
}
public class StageThreeEnemy {
Image imgThreeEnemy; // 이미지 참조변수 // 좀비 이미지 추가할것.
int x, y; // 이미지 중심 좌표
int w, h; // 이미지 절반폭, 절반높이
int monsterMove; // 적군의 변화량
int monsterPower = 20;
int HP = 10000;
int width, height; // 화면(panel)의 사이즈
// 본인 객체가 죽었는지 여부!
boolean isDead = false;
public StageThreeEnemy(Image imgStageThreeEnemy, int width, int height) {
this.width = width;
this.height = height;
// this.HP
// 멤버변수 값 초기화..
imgThreeEnemy = imgStageThreeEnemy.getScaledInstance(64, 64, Image.SCALE_SMOOTH);
w = 32; // 이미지 절반넓이
h = 32;
Random rnd = new Random();
x = rnd.nextInt(width - w * 2) + w; // w ~ width - w
y = -h;
monsterMove = +1; // 움직이는 속도
// monsterMove =+ rnd.nextInt(5)+1;//떨어지는 속도 랜덤하게
}
void move() { // Enemy의 움직이는 기능 메소드 //랜덤하게 할것 = x y에 랜덤값을 줘서 움직임이 자유롭게 할것 + 생성되는 위치도 랜덤하게 둘것 =
// 생성되는 위치를 화면 안의 x y 값을 넣고 랜덤값을 줄것.
// x y 값을 랜덤하게 둘것.
Random rnd = new Random();
int number = rnd.nextInt(4);
if (number == 0) {
x += monsterMove;
} else if (number == 1) {
x -= monsterMove + 0.01;
} else if (number == 2) {
y += monsterMove;
} else if (number == 3) {
y -= monsterMove;
}
y += monsterMove + 5; // y로 이동하게 만듦
// 만약 화면 밑으로 나가버리면 객체 없애기
if (y > height - 450 + h) { // ArrayList에서 제거
this.isDead = true; // 죽음 표식!
}
}
}
class GameThread extends Thread {
boolean CharInWeaponStore = false;
@Override
public void run() {
while (true) {
// 적군 객체 만들어내는 기능 메소드 호출
panel.makeEnemy();
// GamePanel의 플레이어 좌표 변경
// panel.x += -1;// 객체의 멤버값 변경은
// panel.y += -5;/// 그 객체가 스스로 하도록 하는것이 OOP이 기본 모티브
panel.move();
panel.checkCollision();// 충돌 체크 기능 호출
panel.Mouse();// 무기상점패널 추가.
panel.repaint();// GamePanel의 화면 갱신
try { // 너무 빨리 돌아서 천천히 돌도록
sleep(20);
} catch (InterruptedException e) {
System.out.println(e.getMessage());
}
}
}
}
}
LoginFrame.java > 구현 안 함.
Music.java > 구현 안 함.
ranking (package) {music (package)는 구현 안했습니다}
package ranking;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import dBUtil.DBUtil;
import jFrameWithjPanel.GameFrame;
import stage.StageDTO;
import user.UserDTO;
public class RankDAO {
RankDTO rankDTO = new RankDTO();
/*
* rank는 따로 join 하지 않고 따로 만들어서 등록하기. 이유는 지금 (금)오늘부터 작업해서 병합하다가 오류 날 위험이 있으므로.
*
* [전체적인 랭킹 로직] 1. mysql에서 로그인할때의 해당 id의 pk를 갖은 데이터를 불러온다 - getRankData() 2.
* 데이터를 불러오면, 해당 데이터(time)+시간측정을 시작한다. 3. 사용자가 데이터를 저장하면 위에 측정된 "데이터(time)+시간측정"
* 해당 변수를 insert 메서드에 넣어서 저장한다. 4. 만약, 사용자가 게임을 클리어 하게되면 RankUpdata메서드를 실행해서 최종
* 데이터를 추가한다. 5. 그리고 사용자가 게임을 클리어 하게 되면 해당 아이디와 관련된 모든 정보는 삭제 시킨다. - 오로지 Ranking
* 테이블에만 남아 있게 한다.
*/
// 랭크의 데이터를 가져오는 메서드
public void getRankData(UserDTO dto) {
String sql = "select number, ranktime, id from ranking where id = ?";
try (Connection conn = DBUtil.getConnection(); PreparedStatement ps = conn.prepareStatement(sql);) {
ps.setString(1, dto.getId());
ResultSet rs = ps.executeQuery();
while (rs.next()) {
rankDTO.setNumber(rs.getInt(1));
rankDTO.setRankTime(rs.getInt(2));
rankDTO.setId(rs.getString(3));
}
rs.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
}
// 랭크순위를 계산해서 업데이트 하는 메서드
public void RankUpdata() {
/*
* [로직] 1. 모든 정보를 불러와서 ranktime비교하고, 가장 값이 작은 필드부터 랭크포인트를 순서대로 갖게 구현하기.
*/
}
// 랭크에 데이터를 넣는 메서드
public void saveData(RankDTO dto) {
String sql = "update Ranking set ranktime = ? where number = ?";
try (Connection conn = DBUtil.getConnection(); PreparedStatement ps = conn.prepareStatement(sql);) {
ps.setInt(1, dto.getRankTime());
ps.setInt(2, dto.getNumber());
int count = ps.executeUpdate();
if (count > 0) {
System.out.println("데이터 추가됨");
} else {
System.out.println("데이터 추가 실패");
}
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
package ranking;
public class RankDTO {
private String id;
private int rankTime;
private int number;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getRankTime() {
return rankTime;
}
public void setRankTime(int rankTime) {
this.rankTime = rankTime;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
@Override
public String toString() {
return "RankDTO [id=" + id + ", rankTime=" + rankTime + ", number=" + number + "]";
}
}
package ranking;
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;
public class StopWatch {
Timer t = new Timer();
int count = 0;
public int measureTime(boolean stop) {
TimerTask task = new TimerTask() {
@Override
public void run() {
if (stop) {
count++;
System.out.println(count);
} else {
t.cancel();
}
}
};
t.schedule(task, 1000, 1000); // 1초 뒤에 1초마다 run실행. 한번 취소되면 재 실행 못함.
return count;
}
public int currentTime() {
return count;
}
//테스트용
// public static void main(String[] args) {
// Scanner scan = new Scanner(System.in);
// StopWatch s = new StopWatch();
// while (true) {
// System.out.println("스탑워치 종료 = 1 시작 = 2");
// int num = scan.nextInt();
// if (num == 1) {
// s.measureTime(false);
// System.out.println(s.measureTime(false));
// } else if (num == 2) {
// s.measureTime(true);
// }
// }
//
// }
}
stage (package)
package stage;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import dBUtil.DBUtil;
public class StageDAO {
/*
* 스테이지 추가하기. 스테이지의 기본값은 1이다.
*/
public void insert(StageDTO dto) {
String sql = "insert into stage values (?,?)";
try (Connection conn = DBUtil.getConnection(); PreparedStatement ps = conn.prepareStatement(sql);) {
ps.setString(1, dto.getId());
ps.setInt(2, dto.getStageNumber());
int count = ps.executeUpdate();
if (count > 0) {
System.out.println("데이터 추가됨");
} else {
System.out.println("데이터 추가 실패");
}
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
package stage;
public class StageDTO {
private String id;
private int stageNumber;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getStageNumber() {
return stageNumber;
}
public void setStageNumber(int stageNumber) {
this.stageNumber = stageNumber;
}
@Override
public String toString() {
return "StageDTO [id=" + id + ", stageNumber=" + stageNumber + "]";
}
}
store (package)
package store;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import dBUtil.DBUtil;
public class WeaponStoreDAO {
public void insert(WeaponStoreDTO dto) {
String sql = "insert into weaponStore values (?,?,?,?)";
try (Connection conn = DBUtil.getConnection(); PreparedStatement ps = conn.prepareStatement(sql);) {
ps.setString(1, dto.getId());
ps.setInt(2, dto.getAx());
ps.setInt(3, dto.getKatana());
ps.setInt(4, dto.getAx());
int count = ps.executeUpdate();
if (count > 0) {
System.out.println("데이터 추가됨");
} else {
System.out.println("데이터 추가 실패");
}
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
package store;
public class WeaponStoreDTO {
private String id;
private int bat;
private int katana;
private int ax;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getBat() {
return bat;
}
public void setBat(int bat) {
this.bat = bat;
}
public int getKatana() {
return katana;
}
public void setKatana(int katana) {
this.katana = katana;
}
public int getAx() {
return ax;
}
public void setAx(int ax) {
this.ax = ax;
}
@Override
public String toString() {
return "WeaponStoreDTO [id=" + id + ", bat=" + bat + ", katana=" + katana + ", ax=" + ax + "]";
}
}
town (package)
package town;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import dBUtil.DBUtil;
import store.WeaponStoreDTO;
public class TownDAO {
public void insert(TownDTO dto) {
String sql = "insert into town values (?,?,?,?)";
try (Connection conn = DBUtil.getConnection(); PreparedStatement ps = conn.prepareStatement(sql);) {
ps.setString(1, dto.getId());
ps.setInt(2, dto.getTownLV());
ps.setInt(3, dto.getTownHP());
ps.setInt(4, dto.getTownFHP());
int count = ps.executeUpdate();
if (count > 0) {
System.out.println("데이터 추가됨");
} else {
System.out.println("데이터 추가 실패");
}
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
package town;
public class TownDTO {
private String id;
private int townLV;
private int townHP;
private int townFHP;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getTownLV() {
return townLV;
}
public void setTownLV(int townLV) {
this.townLV = townLV;
}
public int getTownHP() {
return townHP;
}
public void setTownHP(int townHP) {
this.townHP = townHP;
}
public int getTownFHP() {
return townFHP;
}
public void setTownFHP(int townFHP) {
this.townFHP = townFHP;
}
@Override
public String toString() {
return "TownDTO [id=" + id + ", townLV=" + townLV + ", townHP=" + townHP + ", townFHP=" + townFHP + "]";
}
}
user (package)
package user;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;
import dBUtil.DBUtil;
import jFrameWithjPanel.GameFrame;
import ranking.RankDAO;
import ranking.RankDTO;
import stage.StageDAO;
import stage.StageDTO;
import store.WeaponStoreDAO;
import store.WeaponStoreDTO;
import town.TownDAO;
import town.TownDTO;
import worrior.WorriorDAO;
import worrior.WorriorDTO;
public class UserDAO {
Scanner scan = new Scanner(System.in);
StageDAO stageDAO = new StageDAO();
StageDTO stageDTO = new StageDTO();
WeaponStoreDAO weaponStoreDAO = new WeaponStoreDAO();
WeaponStoreDTO weaponStoreDTO = new WeaponStoreDTO();
TownDAO townDAO = new TownDAO();
TownDTO townDTO = new TownDTO();
WorriorDAO worriorDAO = new WorriorDAO();
WorriorDTO worriorDTO = new WorriorDTO();
RankDAO rankDAO = new RankDAO();
RankDTO rankDTO = new RankDTO();
// mysql에 데이터 추가
public void insert(UserDTO dto) {
String sql = "insert into user values (?,?)";
try (Connection conn = DBUtil.getConnection(); PreparedStatement ps = conn.prepareStatement(sql);) {
ps.setString(1, dto.getId());
ps.setString(2, dto.getPw());
int count = ps.executeUpdate();
if (count > 0) {
System.out.println("회원가입을 성공했습니다.");
// TODO : mysql 데이터 기본값으로 설정하기. 각 dao insert만들어서 기본값 추가.
stageDTO.setId(dto.getId());
stageDTO.setStageNumber(1);
weaponStoreDTO.setId(dto.getId());
weaponStoreDTO.setBat(0);
weaponStoreDTO.setKatana(0);
weaponStoreDTO.setAx(0);
townDTO.setId(dto.getId());
townDTO.setTownLV(1);
townDTO.setTownHP(1000);
townDTO.setTownFHP(1000);
worriorDTO.setId(dto.getId());
worriorDTO.setLv(1);
worriorDTO.setPower(10);
worriorDTO.setHp(100);
worriorDTO.setFhp(100);
worriorDTO.setExp(0);
worriorDTO.setFexp(200);
worriorDTO.setMoney(0);
stageDAO.insert(stageDTO);
weaponStoreDAO.insert(weaponStoreDTO);
townDAO.insert(townDTO);
worriorDAO.insert(worriorDTO);
} else {
System.out.println("회원가입을 실패하였습니다.");
}
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
}
// 아이디 중복 확인
public boolean idDup(UserDTO dto) {
boolean result = false;
String sql = "select id from user where id = ?";
try (Connection conn = DBUtil.getConnection(); PreparedStatement ps = conn.prepareStatement(sql);) {
ps.setString(1, dto.getId());
ResultSet rs = ps.executeQuery();
if (rs.next()) {
// 아이디 이미 있음
result = true;
System.out.println("중복된 아이디가 있습니다.");
} else {
// 아이디 없음
insert(dto);
result = false;
}
rs.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
return result;
}
public void login(UserDTO dto) {
String sql = "select id, pw from user where id = ? and pw = ?";
try (Connection conn = DBUtil.getConnection(); PreparedStatement ps = conn.prepareStatement(sql);) {
ps.setString(1, dto.getId());
ps.setString(2, dto.getPw());
ResultSet rs = ps.executeQuery();
if (rs.next()) {
// 로그인 성공
System.out.println("로그인이 되었습니다.");
/*
* TODO mysql에 저장된 데이터를 불러와 GameFrame에 넘겨주기 1.
*/
getData(dto);
running();
} else {
// 로그인 실패
System.out.println("아이디 또는 비밀번호가 일치하지 않습니다.");
}
rs.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
}
public void running() {
System.out.println("게임 실행중...");
scan.nextLine();
}
public void getData(UserDTO dto) {
String sql = "select stageNumber,bat,katana,ax,townLV,townHP,townFHP,LV,power,hp,fhp,exp,fexp,money\n"
+ "from user u\n" + "inner join worrior w on u.id = w.id\n" + "inner join town t on u.id = t.id\n"
+ "inner join stage s on u.id = s.id\n" + "inner join weaponStore ws on u.id = ws.id\n"
+ "where u.id = ?";
try (Connection conn = DBUtil.getConnection(); PreparedStatement ps = conn.prepareStatement(sql);) {
ps.setString(1, dto.getId());
ResultSet rs = ps.executeQuery();
while (rs.next()) {
stageDTO.setStageNumber(rs.getInt(1));
weaponStoreDTO.setBat(rs.getInt(2));
weaponStoreDTO.setKatana(rs.getInt(3));
weaponStoreDTO.setAx(rs.getInt(4));
townDTO.setTownLV(rs.getInt(5));
townDTO.setTownHP(rs.getInt(6));
townDTO.setTownFHP(rs.getInt(7));
worriorDTO.setLv(rs.getInt(8));
worriorDTO.setPower(rs.getInt(9));
worriorDTO.setHp(rs.getInt(10));
worriorDTO.setFhp(rs.getInt(11));
worriorDTO.setExp(rs.getInt(12));
worriorDTO.setFexp(rs.getInt(13));
worriorDTO.setMoney(rs.getInt(14));
}
new GameFrame(stageDTO, weaponStoreDTO, townDTO, worriorDTO, dto, rankDTO);
// getRankData
rs.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
}
public void saveData(StageDTO stageDTO, WeaponStoreDTO weaponStoreDTO, TownDTO townDTO, WorriorDTO worriorDTO,
String userid) {
String sql = "UPDATE user u \n" + "inner join worrior w on u.id = w.id\n" + "inner join town t on u.id = t.id\n"
+ "inner join stage s on u.id = s.id\n" + "inner join weaponStore ws on u.id = ws.id\n"
+ "set stageNumber = ?,bat = ?, katana = ?, ax = ?, townLV = ?, townHP = ?, townFHP = ?, LV = ?, power = ?\n"
+ ", hp = ?, fhp = ?, exp = ?, fexp = ?, money = ?\n" + "where u.id = ?";
try (Connection conn = DBUtil.getConnection(); PreparedStatement ps = conn.prepareStatement(sql);) {
ps.setInt(1, stageDTO.getStageNumber());
ps.setInt(2, weaponStoreDTO.getBat());
ps.setInt(3, weaponStoreDTO.getKatana());
ps.setInt(4, weaponStoreDTO.getAx());
ps.setInt(5, townDTO.getTownLV());
ps.setInt(6, townDTO.getTownHP());
ps.setInt(7, townDTO.getTownFHP());
ps.setInt(8, worriorDTO.getLv());
ps.setInt(9, worriorDTO.getPower());
ps.setInt(10, worriorDTO.getHp());
ps.setInt(11, worriorDTO.getFhp());
ps.setInt(12, worriorDTO.getExp());
ps.setInt(13, worriorDTO.getFexp());
ps.setInt(14, worriorDTO.getMoney());
ps.setString(15, userid);
int count = ps.executeUpdate();
if (count > 0) {
System.out.println("데이터 저장을 성공했습니다.");
} else {
System.out.println("데이터 저장을 실패하였습니다.");
}
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
package user;
public class UserDTO {
private String id;
private String pw;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPw() {
return pw;
}
public void setPw(String pw) {
this.pw = pw;
}
@Override
public String toString() {
return "UserDTO [id=" + id + ", pw=" + pw + "]";
}
}
package user;
import java.util.Scanner;
import com.mysql.cj.xdevapi.Type;
public class UserService {
Scanner scan = new Scanner(System.in);
UserDAO dao = new UserDAO();
UserDTO dto = new UserDTO();
public void loginView() {
System.out.println("로그인");
System.out.print("아이디 :");
String id = scan.next();
System.out.print("\n비밀번호 :");
String pw = scan.next();
// 맞는지 확인.
dto.setId(id);
dto.setPw(pw);
dao.login(dto);
}
public void signupView() {
System.out.println("회원가입");
System.out.print("아이디 :");
String id = scan.next();
System.out.print("\n비밀번호 :");
String pw = scan.next();
dto.setId(id);
dto.setPw(pw);
dao.idDup(dto);
// 맞는지 확인.
// 확인. id가 이미 존재하면, 다시 입력 받을 수 있도록 하기.
}
public UserService() {
while (true) {
System.out.println("1. 로그인");
System.out.println("2. 회원가입");
int num = scan.nextInt();
if (num == 1) {
loginView();
} else if (num == 2) {
signupView();
} else {
System.out.println("잘못 입력된 번호입니다.");
}
}
}
}
worrior (package)
package worrior;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import dBUtil.DBUtil;
public class WorriorDAO {
public void insert(WorriorDTO dto) {
String sql = "insert into worrior values (?,?,?,?,?,?,?,?)";
try (Connection conn = DBUtil.getConnection(); PreparedStatement ps = conn.prepareStatement(sql);) {
ps.setString(1, dto.getId());
ps.setInt(2, dto.getLv());
ps.setInt(3, dto.getPower());
ps.setInt(4, dto.getHp());
ps.setInt(5, dto.getFhp());
ps.setInt(6, dto.getExp());
ps.setInt(7, dto.getFexp());
ps.setInt(8, dto.getMoney());
int count = ps.executeUpdate();
if (count > 0) {
System.out.println("데이터 추가됨");
} else {
System.out.println("데이터 추가 실패");
}
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
package worrior;
public class WorriorDTO {
private String id;
private int lv;
private int power;
private int hp;
private int fhp;
private int exp;
private int fexp;
private int money;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getLv() {
return lv;
}
public void setLv(int lv) {
this.lv = lv;
}
public int getPower() {
return power;
}
public void setPower(int power) {
this.power = power;
}
public int getHp() {
return hp;
}
public void setHp(int hp) {
this.hp = hp;
}
public int getFhp() {
return fhp;
}
public void setFhp(int fhp) {
this.fhp = fhp;
}
public int getExp() {
return exp;
}
public void setExp(int exp) {
this.exp = exp;
}
public int getFexp() {
return fexp;
}
public void setFexp(int fexp) {
this.fexp = fexp;
}
public int getMoney() {
return money;
}
public void setMoney(int money) {
this.money = money;
}
@Override
public String toString() {
return "WorriorDTO [id=" + id + ", lv=" + lv + ", power=" + power + ", hp=" + hp + ", fhp=" + fhp + ", exp="
+ exp + ", fexp=" + fexp + ", money=" + money + "]";
}
}
결과물
마우스로 각 작은 이미지를 클릭하면 게임정보에 클릭한 이미지가 어떤걸 의미하는지와 캐릭터가 들어가면 상태가 어떻게 변하는지에 대해 나옵니다.
만약 왼쪽 아래 Store에 들어가게되면 UI가 아래와 같은 식으로 바뀌면서 아이템을 구매하거나 착용할 수 있는 화면이 보이게 됩니다.
긴글 읽어주셔서 감사합니다~! 추가적인 질문이나 오류 난 부분이 있으면 알려주세요~!
도와 드리겠습니다~!
- 참고 문헌 -
GUI 설명관련 : mwultong.blogspot.com/2007/11/gui.html
GUI 만드는 법 및 사용법 : code-knowledge.com/java-create-game-gui
공홈(추천) : docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html
각종 메서드 사용법 및 설명(블로그 내 연관 글 까지 살펴보기) : raccoonjy.tistory.com/16?category=744507
'workSpace > JAVA' 카테고리의 다른 글
[PHP] basic knowledge (0) | 2021.03.03 |
---|---|
basic info for HTML (0) | 2021.03.03 |
[Java][mysql] 자바와 mysql을 연동한 은행 프로그램 (3) | 2020.12.08 |
[Java][DBUtil][DAO][DTO] 방식 기본 구현법 (0) | 2020.12.07 |
[Java][JDBC][Insert][Update][Delete]자바에 MYSQL(workbench) 데이터베이스에 추가, 수정, 변경 하기 (0) | 2020.12.07 |