Package miniGame.minesweeper
Class MineSweeper
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
miniGame.minesweeper.MineSweeper
- All Implemented Interfaces:
java.awt.event.MouseListener,java.awt.image.ImageObserver,java.awt.MenuContainer,java.io.Serializable,java.util.EventListener,javax.accessibility.Accessible,MineSweeperContents,MiniGame
public class MineSweeper extends javax.swing.JPanel implements MiniGame, java.awt.event.MouseListener, MineSweeperContents
- Author:
- miri MineSweeper (지뢰찾기) 게임 클래스
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy -
Field Summary
Fields Modifier and Type Field Description private MyButton[][]buttonprivate java.awt.ImagechangeImageprivate intflagprivate MyButtonflagButtonprivate intGAME_COLprivate intGAME_ROWprivate booleangameOverprivate java.awt.Imageimageprivate javax.swing.ImageIconimageIconprivate int[][]mineArrayprivate MainPanel_MineSweeperparentsprivate booleansuccessprivate inttimeprivate javax.swing.Timertimerprotected MyButtontimerButtonprivate booleantimerRunprivate inttotalClickprivate inttotalFlagprivate intTOTALMINEFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface miniGame.minesweeper.MineSweeperContents
BACKGROUND_COLOR, BOOM, BOOM_BACKGROUND_COLOR, BUTTON_FONT, COLOR0, COLOR1, COLOR2, COLOR3, COLOR4, COLOR5, COLOR6, COLOR7, COLOR8, GAME_BUTTON_COLORFields inherited from interface miniGame.MiniGame
BEST_SCORE, BUTTON_RULE, BUTTON_START, COL, FONT, PATH_2048, PATH_HAMBURGER, PATH_MINESWEEPER, PATH_MINGAME, PATH_PINPON, PATH_SNAKE, PATH_TETRIS, ROW, SCORE, TITLE_2048, TITLE_HAMBURGER, TITLE_MINESWEEPER, TITLE_PINPON, TITLE_SNAKE, TITLE_TETRIS -
Constructor Summary
Constructors Constructor Description MineSweeper(MainPanel_MineSweeper parents, int row, int col, int totalMine)메인 클래스 생성자 -
Method Summary
Modifier and Type Method Description voidaddButtonImage(MyButton myButton)버튼에 이미지 붙이기 switch문을 사용하여 게임 난이도별로 나누고(난이도마다 버튼의 크기가 달라 크기 지정하기 위함), 게임 버튼에 이미지를 추가한다.voidclickTheBOOM(MyButton[][] myButton, int row, int col)지뢰를 눌렀을 때 모든 판이 오픈되도록 설정한다voidclickTheButtonColor(MyButton[][] myButton, int row, int col)숫자별 색상 설정하는 메소드 오버로드 true일때는 굳이 변수로 설정하지 않아도 되도록voidclickTheButtonColor(MyButton[][] myButton, int row, int col, boolean isGameover)숫자별 색상 설정하기 지뢰를 유추하는 범위가 3x3이므로 최대 지뢰를 표시하는 8까지 나올 수 있다.voidclickToZero(MyButton[][] myButton, int row, int col)눌렀는데 0번이면 주변 3X3 부분 자동으로 열리게 만들기voidfindAllMine(MyButton[][] myButton)지뢰를 유추하여 지뢰를 제외한 모든 판에 클릭해서 숫자가 뜨게 한 후 빈화면에 깃발까지 다 꽂혀있을때 최종적으로 게임이 끝나도록 설정한다voidGameOver()게임이 종료 되었을 때 게임 성공 / 실패 별 메세지 지정javax.swing.JPanelmainPanel()메인 패널 만들기 레이아웃 설정하여 각각의 패널을 추가한다.javax.swing.JPanelmenuPanel()메뉴 패널 만들기 다시 시작 / 타이머 / 깃발 수 / 이전으로 버튼을 넣는다.voidmineArray()정답 배열 만들기 정답을 담은 배열을 만든다.voidmouseClicked(java.awt.event.MouseEvent e)마우스 클릭시에 발생하는 이벤트 설정voidmouseEntered(java.awt.event.MouseEvent e)voidmouseExited(java.awt.event.MouseEvent e)voidmousePressed(java.awt.event.MouseEvent e)voidmouseReleased(java.awt.event.MouseEvent e)voidsetArrayExceptMine(int[][] arrays, int row, int col)지뢰 제외하고 숫자 배정하는 메서드voidsetCountFlag(MyButton[][] myButton)게임 사용자가 플래그로 표시한 총 갯수 세기javax.swing.JPanelsetMineSweeper()게임 패널 만들기 레이아웃으로 게임 판 (지뢰 판)을 만들고 버튼을 추가한다.voidsetMyButton(javax.swing.JPanel panel)게임판의 버튼 배열 만들기 버튼을 배열로 만들어 생성하고 글씨체 등을 세팅한다.voidsetTimer()타이머 생성하기Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
parents
-
button
-
mineArray
private int[][] mineArray -
GAME_ROW
private final int GAME_ROW -
GAME_COL
private final int GAME_COL -
TOTALMINE
private final int TOTALMINE -
imageIcon
private javax.swing.ImageIcon imageIcon -
image
private java.awt.Image image -
changeImage
private java.awt.Image changeImage -
flag
private int flag -
flagButton
-
totalClick
private int totalClick -
totalFlag
private int totalFlag -
gameOver
private boolean gameOver -
success
private boolean success -
timer
private javax.swing.Timer timer -
timerButton
-
timerRun
private boolean timerRun -
time
private int time
-
-
Constructor Details
-
MineSweeper
MineSweeper(MainPanel_MineSweeper parents, int row, int col, int totalMine)메인 클래스 생성자- Parameters:
parents- 이전 화면에서 해당 패널을 불러올 때 연동하기 위해 사용row- 행의 숫자 (게임난이도를 위해 지정)col- 열의 숫자 (게임난이도를 위해 지정)totalMine- 총 지뢰의 숫자 (게임난이도를 위해 지정)
-
-
Method Details
-
mainPanel
public javax.swing.JPanel mainPanel()메인 패널 만들기 레이아웃 설정하여 각각의 패널을 추가한다.- Returns:
- 메인 패널
-
setMineSweeper
public javax.swing.JPanel setMineSweeper()게임 패널 만들기 레이아웃으로 게임 판 (지뢰 판)을 만들고 버튼을 추가한다.- Returns:
- 게임패널
-
setMyButton
public void setMyButton(javax.swing.JPanel panel)게임판의 버튼 배열 만들기 버튼을 배열로 만들어 생성하고 글씨체 등을 세팅한다.- Parameters:
panel- 버튼을 추가할 패널 지정
-
mineArray
public void mineArray()정답 배열 만들기 정답을 담은 배열을 만든다. 지뢰 설정은 상수 BOOM 이용 -
setArrayExceptMine
public void setArrayExceptMine(int[][] arrays, int row, int col)지뢰 제외하고 숫자 배정하는 메서드- Parameters:
arrays- 지정할 배열row- 지정할 행col- 지정할 열
-
clickToZero
눌렀는데 0번이면 주변 3X3 부분 자동으로 열리게 만들기- Parameters:
myButton- 지정할 버튼 배열row- 지정할 행col- 지정할 열
-
clickTheButtonColor
숫자별 색상 설정하는 메소드 오버로드 true일때는 굳이 변수로 설정하지 않아도 되도록- Parameters:
myButton- 지정할 버튼 배열row- 지정할 행col- 지정할 열
-
clickTheButtonColor
숫자별 색상 설정하기 지뢰를 유추하는 범위가 3x3이므로 최대 지뢰를 표시하는 8까지 나올 수 있다. 숫자 8까지의 각각의 색상을 지정하고, 지뢰를 눌렀을 때에는 지뢰의 이미지가 표시되게 한다.- Parameters:
myButton- 지정할 버튼 배열row- 지정할 행col- 지정할 열isGameover- 게임오버인지 여부
-
addButtonImage
버튼에 이미지 붙이기 switch문을 사용하여 게임 난이도별로 나누고(난이도마다 버튼의 크기가 달라 크기 지정하기 위함), 게임 버튼에 이미지를 추가한다.- Parameters:
myButton- 지정할 버튼 배열
-
clickTheBOOM
지뢰를 눌렀을 때 모든 판이 오픈되도록 설정한다- Parameters:
myButton- 지정할 버튼 배열row- 지정할 행col- 지정할 열
-
findAllMine
지뢰를 유추하여 지뢰를 제외한 모든 판에 클릭해서 숫자가 뜨게 한 후 빈화면에 깃발까지 다 꽂혀있을때 최종적으로 게임이 끝나도록 설정한다- Parameters:
myButton- 지정할 버튼 배열
-
GameOver
public void GameOver()게임이 종료 되었을 때 게임 성공 / 실패 별 메세지 지정 -
setTimer
public void setTimer()타이머 생성하기 -
setCountFlag
게임 사용자가 플래그로 표시한 총 갯수 세기- Parameters:
myButton- 지정할 버튼 배열
-
mouseClicked
public void mouseClicked(java.awt.event.MouseEvent e)마우스 클릭시에 발생하는 이벤트 설정- Specified by:
mouseClickedin interfacejava.awt.event.MouseListener
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent e)- Specified by:
mousePressedin interfacejava.awt.event.MouseListener
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent e)- Specified by:
mouseReleasedin interfacejava.awt.event.MouseListener
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent e)- Specified by:
mouseEnteredin interfacejava.awt.event.MouseListener
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent e)- Specified by:
mouseExitedin interfacejava.awt.event.MouseListener
-