コード例 #1
0
ファイル: CSnake.java プロジェクト: Nappyd326648/Snake
  public boolean didEatKibble(Kibble kibble) {
    // to get the kibble location
    xx = kibble.getKibbleX();
    yy = kibble.getKibbleY();

    if (kibble.getKibbleX() == snakeHeadX && kibble.getKibbleY() == snakeHeadY) {
      justAteMustGrowThisMuch += growthIncrement;
      return true;
    }
    return false;
  }
コード例 #2
0
  private void displayKibble(Graphics g) {

    // Draw the kibble in green
    g.setColor(Color.RED);

    int x = kibble.getKibbleX() * SnakeGame.squareSize;
    int y = kibble.getKibbleY() * SnakeGame.squareSize;

    g.fillRect(x, y, SnakeGame.squareSize, SnakeGame.squareSize);
    // Removed (magic?)numbers here that originally increased padding to accommodate for the border.
    // With the grid removed, it an be drawn fine with no modification
    // Original code >> g.fillRect(x+1, y+1, SnakeGame.squareSize-1, SnakeGame.squareSize-1);

  }