画像の色によって得点を変更させたい

package com.example.curling;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Point;
import android.view.Display;
import android.view.WindowManager;

public class MainActivity extends AppCompatActivity {

private ImageView akaStone, yellowStone, pointline2; private float startX, startY, totalSlideDistance; private boolean isAkaTurn = true; // 初めは1Pのターン private boolean akaStoneSlid = false; private boolean yellowStoneSlid = false; private Handler handler = new Handler(); private Runnable moveImageRunnable; // サイズ private int frameHeight; private int boxSize; private int screenWidth; private int screenHeight; private float akaX; private float yellowX; // Screen Size

・・・・・・・・・・・・・

private boolean isInColorRange(ImageView stone, int targetColor) { Bitmap bitmap = getBitmapFromImageView(stone); int x = stone.getWidth() / 2; int y = stone.getHeight() / 2; int pixelColor = bitmap.getPixel(x, y); return pixelColor == targetColor; } private int calculateScore(ImageView stone) { float stoneX = stone.getX() + stone.getWidth() / 2; float stoneY = stone.getY() + stone.getHeight() / 2; float pointlineX = pointline2.getX(); float pointlineY = pointline2.getY(); if (stoneX >= pointlineX && stoneX <= pointlineX + pointline2.getWidth() && stoneY >= pointlineY && stoneY <= pointlineY + pointline2.getHeight()) { // 得点を計算する条件を変更 if (isInColorRange(stone, Color.RED)) { return -50; } else if (isInColorRange(stone, Color.BLACK)) { return 0; } else if (isInColorRange(stone, Color.YELLOW)) { return 30; } } return 0; // 何も該当しない場合は0点 } private void updateScore(ImageView stone, TextView scoreTextView) { int score = calculateScore(stone); // 得点を更新 if (stone == akaStone) { akaStoneScore += score; displayScore(akaStoneScore, scoreTextView); } else if (stone == yellowStone) { yellowStoneScore += score; displayScore(yellowStoneScore, scoreTextView); } } private void displayScore(int score, TextView scoreTextView) { scoreTextView.setText("Score: " + score); } private Bitmap getBitmapFromImageView(ImageView imageView) { return ((BitmapDrawable) imageView.getDrawable()).getBitmap(); }

}

試したこと

画像の中の色によって場合をわけるものを調べても全く出ず、chatGPTにきいてもエラーが出てしまいました。
cannnot resolve symbol ●●

想定しているのはチキンレース的なもので、ピンクなら100点、黒なら0点・・・のようなものをつくりたいと思っています。どなたか助言をお願いします。イメージ説明

コメントを投稿

0 コメント