コード例 #1
0
    public void onTouch(MotionEvent e) {
      if (months != null) {

        switch (e.getAction()) {
          case MotionEvent.ACTION_DOWN:
            // figure out if a ball has been touched
            //
            Point touchCoord =
                new Point(
                    (int) (e.getX() * (bounds.width() * 1.0 / windowBounds.width())),
                    (int) (e.getY() * (bounds.height() * 1.0 / windowBounds.height())));

            for (rectangle month : months) {
              // if the places that we touched happens to be in the area of the ball, then set ball
              // touch to true
              if (month.contains(touchCoord)) {
                month.setPressed(true);
                //                            // add ball pressed to userSequenceTest, so that we
                // can compare with demoSequence
                //                            userSequenceTest.add(ball);
                //
                //                            monthPressedCount++;
              } else // if we didn't touch the ball
              {
                // then set all the months to false
                month.setPressed(false);
              }
            }
            break;

          case MotionEvent.ACTION_UP:
            for (rectangle month : months) {
              if (month.isPressed() == true) {
                // add ball pressed to userSequenceTest, so that we can compare with demoSequence
                java.util.Date date = new java.util.Date();
                pastTime = currentTime;
                currentTime = new Timestamp(date.getTime()).getTime();

                double timeDiff = ((double) currentTime - (double) pastTime) / 1000;
                // float timeDiffF = ((float)currentTime-(float)pastTime)/1000;
                userSequenceTest.add(month);
                userSequenceString.add(month.getMonth() + "  time taken = " + timeDiff);

                monthPressedCount++;
                month.setPressed(false);
              }
            }
            break;
        }
      }
      // if it has, add it to the users sequence
      // if(count<clips.size()&&clips.get(count) instanceof ITouchClip)((ITouchClip)
      // clips.get(count)).onTouch(e);
      // return true;
    }
コード例 #2
0
    public boolean play(Canvas out, Context context) {
      Paint paint = null;
      float aspect = out.getHeight() * 1.0f / out.getWidth();
      int width = 1000;
      Bitmap bitmap = Bitmap.createBitmap(width, Math.round(width * aspect), Bitmap.Config.RGB_565);
      Canvas c = new Canvas(bitmap);
      bounds = c.getClipBounds();
      windowBounds = out.getClipBounds();

      if (!started) {
        started = true;
        months = getMonthVector();

        paint = new Paint();
        paint.setColor(Color.parseColor("#00ff00"));
        paint.setStrokeWidth(5);
      }

      for (rectangle month : months) {
        // ball.Update();  // the months don't need to be updated
        month.Draw(c);
      }

      out.drawBitmap(bitmap, c.getClipBounds(), out.getClipBounds(), paint);

      //                for(int i = 0; i < userSequenceTest.size(); i++)
      //                {
      //                    if(demoSequence.get(i) != userSequenceTest.get(i))
      //                    {
      //                        sequencesMatch = false;
      //                    }
      //
      //                    if(sequencesMatch == false)
      //                    {
      //                        break;
      //                    }
      //
      //                }

      return false;

      //                // if we've pressed more circles than are in the sequence, then we have
      // failed.
      //                if(monthPressedCount > getDemoSequence().size() || sequencesMatch == false)
      //                {
      //                    // return true when finished
      //                    for(rectangle month: months)
      //                    {
      //                        month.setPressed(false);
      //                    }
      //                    setResult(false);
      //                    return true;
      //                }
      //                // if the sequences match and we have pressed the number of months in the
      // demo sequence
      //                else if(sequencesMatch == true && monthPressedCount == demoSequence.size()){
      //                    // then we have succeded and return true because we have finished
      //
      //                    setResult(true);
      //                    return true;
      //                } else {
      //                    return false;
      //                }

    }