Помогите, не знаю насколько правильно написан код. Использовал нейросеть :)
Ввёл запрос - "Напиши для андроида программу для полноценной игры через геймпад." и выдала это -
```Java
// This program allows for full functionality through a gamepad for Android devices
// Import necessary libraries
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
public class GamepadActivity extends Activity implements View.OnKeyListener, View.OnTouchListener {
// Declare necessary variables
private TextView mTextView;
private Button mButtonUp;
private Button mButtonDown;
private Button mButtonLeft;
private Button mButtonRight;
private Button mButtonA;
private Button mButtonB;
private Button mButtonX;
private Button mButtonY;
// Declare necessary variables for joystick input
private JoystickView mJoystick;
private float mJoystickX;
private float mJoystickY;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set full screen mode
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Set layout
setContentView(R.layout.activity_gamepad);
// Get views
mTextView = findViewById(R.id.text_view);
mButtonUp = findViewById(R.id.button_up);
mButtonDown = findViewById(R.id.button_down);
mButtonLeft = findViewById(R.id.button_left);
mButtonRight = findViewById(R.id.button_right);
mButtonA = findViewById(R.id.button_a);
mButtonB = findViewById(R.id.button_b);
mButtonX = findViewById(R.id.button_x);
mButtonY = findViewById(R.id.button_y);
// Set listeners
mButtonUp.setOnTouchListener(this);
mButtonDown.setOnTouchListener(this);
mButtonLeft.setOnTouchListener(this);
mButtonRight.setOnTouchListener(this);
mButtonA.setOnTouchListener(this);
mButtonB.setOnTouchListener(this);
mButtonX.setOnTouchListener(this);
mButtonY.setOnTouchListener(this);
mJoystick = findViewById(R.id.joystick);
mJoystick.setOnJoystickMoveListener(new JoystickView.OnJoystickMoveListener() {
public void onValueChanged(int angle, int strength) {
mJoystickX = (float) Math.cos(Math.toRadians(angle)) * strength / 100;
mJoystickY = (float) Math.sin(Math.toRadians(angle)) * strength / 100;
}
}, JoystickView.DEFAULT_LOOP_INTERVAL);
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BUTTON_A:
if (event.getAction() == KeyEvent.ACTION_DOWN) {
mTextView.setText("A button pressed");
} else if (event.getAction() == KeyEvent.ACTION_UP) {
mTextView.setText("A button released");
}
return true;
case KeyEvent.KEYCODE_BUTTON_B:
if (event.getAction() == KeyEvent.ACTION_DOWN) {
mTextView.setText("B button pressed");
} else if (event.getAction() == KeyEvent.ACTION_UP) {
mTextView.setText("B button released");
}
return true;
case KeyEvent.KEYCODE_BUTTON_X:
if (event.getAction() == KeyEvent.ACTION_DOWN) {
mTextView.setText("X button pressed");
} else if (event.getAction() == KeyEvent.ACTION_UP) {
mTextView.setText("X button released");
}
return true;
case KeyEvent.KEYCODE_BUTTON_Y:
if (event.getAction() == KeyEvent.ACTION_DOWN) {
mTextView.setText("Y button pressed");
} else if (event.getAction() == KeyEvent.ACTION_UP) {
mTextView.setText("Y button released");
}
return true;
default:
return false;
}
}
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BUTTON_A:
case KeyEvent.KEYCODE_BUTTON_B:
case KeyEvent.KEYCODE_BUTTON_X:
case KeyEvent.KEYCODE_BUTTON_Y:
return true;
default:
return false;
}
}
public boolean onTouch(View v, MotionEvent event) {
switch (v.getId()) {
case R.id.button_up:
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mTextView.setText("Up button pressed");
} else if (event.getAction() == MotionEvent.ACTION_UP) {
mTextView.setText("Up button released");
}
return true;
case R.id.button_down:
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mTextView.setText("Down button pressed");
} else if (event.getAction() == MotionEvent.ACTION_UP) {
mTextView.setText("Down button released");
}
return true;
case R.id.button_left:
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mTextView.setText("Left button pressed");
} else if (event.getAction() == MotionEvent.ACTION_UP) {
mTextView.setText("Left button released");
}
return true;
case R.id.button_right:
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mTextView.setText("Right button pressed");
} else if (event.getAction() == MotionEvent.ACTION_UP) {
mTextView.setText("Right button released");
}
return true;
case R.id.button_a:
case R.id.button_b:
case R.id.button_x:
case R.id.button_y:
return false;
default:
return false;
}
}
public
Понимаю, что это возможно хрень, но узнать насколько верно написан код интересно :P