while ( snakeSq.hasNext() ) { Point tempPoint = (Point)snakeSq.next(); if( temp.equals( tempPoint ) && snakeSq.hasNext() != false ) { snakeTimer.stop(); stopGame(); JOptionPane.showMessageDialog( null, "Your Score is " + score + "\n\nYou Loss!" ); } } System.out.println( temp.x + " " + temp.y ); if( (temp.x == 0 && direction == 4) || (temp.x == horizontalGrid-1 && direction == 2) || (temp.y == 0 && direction == 1) || (temp.y == verticalGrid-1 && direction == 3) ) { snakeTimer.stop(); stopGame(); JOptionPane.showMessageDialog( null, "Your Score is " + score + "\n\nYou Loss!" ); } if( direction != mainSnake.snakeReDirection ) { moveSnake( direction ); } mainSnake.drawSnake( getGraphics(), singleWidthX, singleHeightY, cooPos ); drawBeanAndEBean( getGraphics() ); } }
public void stopGame() { this.hasStoped = true; this.snakeTimer.stop(); Graphics2D g = (Graphics2D) GameFrame.this.getGraphics(); g.setColor( ColorGroup.COLOR_BACK ); super.paint( g ); configMenu.setVisible( true ); }
public void resetGame() { System.gc(); this.hasStoped = false; Graphics2D g = (Graphics2D) GameFrame.this.getGraphics(); g.setColor( ColorGroup.COLOR_BACK ); super.paint( g ); this.mainSnake = new Snake(); this.createBean( bean ); this.eatedBean.clear(); mainSnake.drawSnake( getGraphics(), singleWidthX, singleHeightY, cooPos ); this.snakeTimer.start(); this.direction = 2; this.score = 0; this.scoreLabel.setText( "Pause[SPACE] - Exit[ESC]" ); }
private void moveSnake( int direction ) { if( mainSnake.checkBeanIn( this.bean ) ) { this.score += 100; this.scoreLabel.setText( this.info + " Current Score:" + this.score ); this.eatedBean.add( new Point(this.bean) ); this.createBean( this.bean ); } mainSnake.changeDirection( (Point) mainSnake.getLast(), direction ); Point temp = (Point) mainSnake.getFirst(); if( eatedBean.size() != 0 ) { if( eatedBean.getFirst().equals( temp ) ) { eatedBean.remove( 0 ); } else { mainSnake.clearEndSnakePiece( getGraphics(), temp.x, temp.y, singleWidthX, singleHeightY, cooPos ); mainSnake.removeTail(); } } else { mainSnake.clearEndSnakePiece( getGraphics(), temp.x, temp.y, singleWidthX, singleHeightY, cooPos ); mainSnake.removeTail(); } }
private void drawBeanAndEBean( Graphics g ) { g.setColor( ColorGroup.COLOR_BEAN ); this.drawPiece( g, this.bean.x, this.bean.y ); g.setColor( ColorGroup.COLOR_EATEDBEAN ); snakeSq = eatedBean.iterator(); while ( snakeSq.hasNext() ) { Point tempPoint = (Point)snakeSq.next(); this.drawPiece( g, tempPoint.x, tempPoint.y ); } }
private void drawPiece( Graphics g, int x, int y ) { |