Ich möchte im gameOver teil in eine klasse namens gameOver springen da ich hier aber View extende bin ich leider hilflos
Code
package com.example.a223;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.view.MotionEvent;
import android.view.View;
public class GameView extends View {
/*
Farbtabelle
0 = blau
1 = black
2 = red
*/
//Maih
MainActivity mainActivity = new MainActivity();
//Ball
private int blueX;
private int blueY = -40;
int blueSpeed = 15;
private Paint bluePaint = new Paint();
private int zufallzahl;
//Game
public boolean gameOver = false;
private Paint gameOverPaint = new Paint();
private int currColor = 0;
public int currGameColor = 0;
public int score = 0;
private boolean touchflg = false;
private boolean gamenotStart = true;
private boolean starttap = false;
private Paint untenviereckPaint = new Paint();
Paint lvlUpPaint = new Paint();
int currLvl =1;
int currLvlUpScore = 10;
//canvas
int canvasWith;
int canvasHigh;
//Status Check
//Score
private Paint scorePaint = new Paint();
public GameView(Context context) {
super(context);
scorePaint.setColor(Color.BLACK);
scorePaint.setTextSize(55);
scorePaint.setTypeface(Typeface.DEFAULT_BOLD);
scorePaint.setAntiAlias(true);
gameOverPaint.setColor(Color.BLACK);
gameOverPaint.setTextSize(70);
gameOverPaint.setTypeface(Typeface.DEFAULT_BOLD);
gameOverPaint.setAntiAlias(true);
lvlUpPaint.setColor(Color.LTGRAY);
lvlUpPaint.setTextSize(60);
lvlUpPaint.setTypeface(Typeface.SANS_SERIF);
lvlUpPaint.setAntiAlias(true);
//bluePaint.setColor(Color.BLUE);
}
@Override
protected void onDraw(Canvas canvas) {
canvasWith = getWidth();
canvasHigh = getHeight();
//Blue Ball
if(touchflg){
if(currGameColor == 0) untenviereckPaint.setColor(Color.BLUE);
if(currGameColor == 1) untenviereckPaint.setColor(Color.BLACK);
if(currGameColor == 2) untenviereckPaint.setColor(Color.RED);
if(currGameColor ==3) untenviereckPaint.setColor(Color.GREEN);
}
if(gamenotStart){
canvas.drawText("Tap Screen to start Game!",getWidth()/6,getHeight()/2 ,gameOverPaint);
if(starttap){
gamenotStart = false;
}
}
//Game Over
else if(gameOver){
}else{
blueX = canvasWith / 2;
blueY +=blueSpeed;
if(blueY > canvasHigh - 200 ) {
if(score == currLvlUpScore){
currLvl++;
blueSpeed = blueSpeed+1;
currLvlUpScore = currLvlUpScore+currLvlUpScore+currLvl;
}
blueY = -80;
zufallzahl = (int) Math.floor(Math.random() * 4);
if (currColor == currGameColor) {
score++;
} else {
gameOver = true;
}
}
}
if(zufallzahl == 0){
bluePaint.setColor(Color.BLUE);
currColor = 0;
}else if (zufallzahl == 1){
bluePaint.setColor(Color.BLACK);
currColor = 1;
}else if(zufallzahl == 2){
bluePaint.setColor(Color.RED);
currColor = 2;
}else if(zufallzahl == 3){
bluePaint.setColor(Color.GREEN);
currColor = 3;
}
canvas.drawRect(0,canvasHigh,canvasWith,canvasHigh - 200,untenviereckPaint);
canvas.drawCircle(canvasWith/2,canvasHigh-60,50,untenviereckPaint);
canvas.drawCircle(blueX, blueY,30,bluePaint);
canvas.drawText("Score : " + score, 50,100,scorePaint);
canvas.drawText("Level : " + currLvl , canvasWith-300,100,scorePaint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction() == (MotionEvent.ACTION_DOWN)){
if(gamenotStart) starttap = true;
if(gameOver){
score = 0;
gameOver = false;
return true;
}
currGameColor ++;
if(currGameColor == 4) currGameColor =0;
touchflg = true;
}
return true;
}
}
Alles anzeigen