Exemplo n.º 1
0
 @Override
 protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   canvas.save();
   int itemWidth = getWidth() / targetNum;
   int itemHeight = getHeight() / (showdesc ? 2 : 1);
   ArrayList<CirclePoint> circlePoints = new ArrayList<>();
   for (int i = 0; i < targetNum; i++) {
     CirclePoint circlePoint = new CirclePoint();
     circlePoint.cx = (itemWidth / 2 + i * itemWidth);
     circlePoint.cy = itemHeight / 2;
     circlePoint.radius = itemHeight / 5;
     circlePoints.add(circlePoint);
   }
   for (int i = 0; i < targetNum; i++) {
     CirclePoint circlePoint1 = circlePoints.get(i);
     if (i == targetNum - 1) {
       drawCircle(canvas, circlePoint1, i);
       drawText(canvas, String.valueOf(1 + i), circlePoint1);
       drawDesc(canvas, circlePoint1, i, itemHeight);
       break;
     }
     CirclePoint circlePoint2 = circlePoints.get(i + 1);
     canvas.drawLine(
         circlePoint1.cx,
         circlePoint1.cy,
         circlePoint2.cx,
         circlePoint2.cy,
         i <= currentStep - 2 ? linePickedPaint : lineUnPickPaint);
     drawCircle(canvas, circlePoint1, i);
     drawText(canvas, String.valueOf(1 + i), circlePoint1);
     drawDesc(canvas, circlePoint1, i, itemHeight);
   }
   canvas.restore();
 }
Exemplo n.º 2
0
  public void drawRedraw(Graphics2D graphics) {

    if (running) {

      this.randomPoint.drawPoint(graphics);

      if (this.snake1.isWithinLimits() && this.snake1.canPlay()) {

        this.snake1.updateMovement();
        this.snake1.drawPoints(graphics);

        if (this.snake1.interact(randomPoint)) {
          randomPoint.setCenter(Point.randomPoint(1, 49, 1, 49));
        }

        this.snake1.crashWithOther(this.snake2.getPointList());

      } else {
        this.snake1.setCanPlay(false);
        this.snake1.setColorAll(graphics, Color.RED);
        // Write Game Over Screen
      }

      if (this.snake2.isWithinLimits() && this.snake2.canPlay()) {

        this.snake2.updateMovement();
        this.snake2.drawPoints(graphics);

        if (this.snake2.interact(randomPoint)) {
          randomPoint.setCenter(Point.randomPoint(1, 49, 1, 49));
        }

        this.snake2.crashWithOther(this.snake1.getPointList());

      } else {
        this.snake2.setCanPlay(false);
        this.snake2.setColorAll(graphics, Color.BLUE);
        // Write Game Over Screen
      }

      if (!this.snake1.canPlay() && !this.snake2.canPlay()) {
        this.running = false;
      }

    } else {

      // graphics.

    }
  }
Exemplo n.º 3
0
  public static Direction getAdjacentPoint(CirclePoint point1, CirclePoint secondPoint) {

    if (secondPoint.getCenter().getX() > point1.getCenter().getX()) {
      return Direction.LEFT;
    } else if (secondPoint.getCenter().getX() < point1.getCenter().getX()) {
      return Direction.RIGHT;
    } else if (secondPoint.getCenter().getY() < point1.getCenter().getY()) {
      return Direction.DOWN;
    } else {
      return Direction.UP;
    }
  }