Package miniGame.snake
Class SnakeGamePanel
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
miniGame.snake.SnakeGamePanel
- All Implemented Interfaces:
java.awt.event.KeyListener,java.awt.image.ImageObserver,java.awt.MenuContainer,java.io.Serializable,java.util.EventListener,javax.accessibility.Accessible,SNAKEGAMEINTERFACE
public class SnakeGamePanel extends javax.swing.JPanel implements SNAKEGAMEINTERFACE, java.awt.event.KeyListener
- Author:
- ChoiMunKyoung
- 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 (package private) intappleX사과의 x 좌표(package private) intappleY사과의 Y 좌표(package private) intbodyLength몸의 길이(package private) int[]bodyX몸의 x 좌표값들의 배열(package private) int[]bodyY몸의 y 좌표값들의 배열(package private) intdirection방향값(package private) inteatenApple먹은 사과의 개수(package private) javax.swing.JPanelmainPanelprivate javax.swing.JPanel[][]panelsstatus 배열에 맞춰서 색이 들어갈 패널들(package private) MainPanel_SnakeGameparentprivate int[][]status사과 몸 값이 들어갈 배열(package private) javax.swing.TimertimerFields 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.snake.SNAKEGAMEINTERFACE
APPLE, APPLECOLOR, BODY, BORADCOLOR, DOWN, EMPTY, GAMEHEIGHT, GAMEWIDTH, LEFT, PANELHEIGHT, PANELWIDTH, RIGHT, SNAKECOLOR, UP -
Constructor Summary
Constructors Constructor Description SnakeGamePanel(MainPanel_SnakeGame parent) -
Method Summary
Modifier and Type Method Description (package private) voidclean()이전의 몸 배열의 값들을 지워주기 위해 redraw() 할때 먼저 모든 status 의 BODY 값을 EMPTY 로 변경(package private) voideatApple()머리부분이 APPLE값이라면 몸의길이를 늘리고 먹은 사과 개수 늘리고 spawnApple()실행voidkeyPressed(java.awt.event.KeyEvent e)voidkeyReleased(java.awt.event.KeyEvent e)voidkeyTyped(java.awt.event.KeyEvent e)(package private) voidloseGame()머리부분이 몸의 좌표값과 같아지면 lose 먹은 사과 개수 출력static voidmain(java.lang.String[] args)(package private) intmoving(int pressedKey)direction 값에 맞춰서 증감식 리턴(package private) voidredraw()몸의 배열을 status에 대입하고 status 배열에 맞춰서 panels에 색을 설정해준다 panels 를 main패널에 add(package private) voidsetBodyXY()머리부분을 몸이 따라가게 보이기위해 머리 부분을 제외하고 몸의 배열을 이전 배열 넣어준다(package private) voidspawnApple()랜덤한 두 정수로 좌표값 설정후 status 배열에 EMPTY면 APPLE 값으로 변경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
-
appleX
int appleX사과의 x 좌표 -
appleY
int appleY사과의 Y 좌표 -
eatenApple
int eatenApple먹은 사과의 개수 -
bodyLength
int bodyLength몸의 길이 -
bodyX
int[] bodyX몸의 x 좌표값들의 배열 -
bodyY
int[] bodyY몸의 y 좌표값들의 배열 -
direction
int direction방향값 -
timer
javax.swing.Timer timer -
panels
private javax.swing.JPanel[][] panelsstatus 배열에 맞춰서 색이 들어갈 패널들 -
status
private int[][] status사과 몸 값이 들어갈 배열 -
mainPanel
javax.swing.JPanel mainPanel -
parent
MainPanel_SnakeGame parent
-
-
Constructor Details
-
SnakeGamePanel
-
-
Method Details
-
keyTyped
public void keyTyped(java.awt.event.KeyEvent e)- Specified by:
keyTypedin interfacejava.awt.event.KeyListener
-
keyPressed
public void keyPressed(java.awt.event.KeyEvent e)- Specified by:
keyPressedin interfacejava.awt.event.KeyListener
-
keyReleased
public void keyReleased(java.awt.event.KeyEvent e)- Specified by:
keyReleasedin interfacejava.awt.event.KeyListener
-
spawnApple
void spawnApple()랜덤한 두 정수로 좌표값 설정후 status 배열에 EMPTY면 APPLE 값으로 변경 -
redraw
void redraw()몸의 배열을 status에 대입하고 status 배열에 맞춰서 panels에 색을 설정해준다 panels 를 main패널에 add -
clean
void clean()이전의 몸 배열의 값들을 지워주기 위해 redraw() 할때 먼저 모든 status 의 BODY 값을 EMPTY 로 변경 -
eatApple
void eatApple()머리부분이 APPLE값이라면 몸의길이를 늘리고 먹은 사과 개수 늘리고 spawnApple()실행 -
moving
int moving(int pressedKey)direction 값에 맞춰서 증감식 리턴 -
loseGame
void loseGame()머리부분이 몸의 좌표값과 같아지면 lose 먹은 사과 개수 출력 -
setBodyXY
void setBodyXY()머리부분을 몸이 따라가게 보이기위해 머리 부분을 제외하고 몸의 배열을 이전 배열 넣어준다 -
main
public static void main(java.lang.String[] args)
-