Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- the abstract operator class for my dag data structure yet to implement
- package InGameEvents.Operators;
- import javax.swing.JFrame;
- public abstract class Operator{
- String name;
- public Operator(String name){
- this.name = name;
- }
- }
- the battle mechanics that implement it
- package InGameEvents.Operators;
- import java.awt.event.KeyEvent;
- import java.awt.event.KeyListener;
- import java.util.ArrayList;
- import java.util.Timer;
- import java.util.TimerTask;
- import Graph.Interactables.Enemies.Enemies;
- import Graph.Interactables.Enemies.BOSSES.BodyBlitzCP.BodyBlitzCP;
- import Graph.Interactables.InteractablesCommonObjs.Weapons.WeaponsMech;
- import Graph.Interactables.InteractablesCommonObjs.Weapons.Fists.Fists;
- import Graph.LevelForGame.levels;
- import SystemManager.GameScene;
- import User.PlayerCharacter.MainCharacter;
- public class Battles extends Operator{
- MainCharacter player;
- WeaponsMech xMech;
- Enemies oppEnemies;
- int countdown;
- int combo = 0;
- String[] PlayerMoves;
- String[] OppMoves;
- int CounterSize;
- GameScene game;
- int pressed = 0;
- boolean startBattle = false;
- int i = 0;
- public Battles(String name) {
- super(name);
- oppEnemies = new BodyBlitzCP();
- player = new MainCharacter();
- xMech = player.getWeapon();
- game = new GameScene();
- OppMoves = oppEnemies.getMoves();
- for (String arr : OppMoves){
- System.out.println(" " + arr);
- }
- System.out.println("\n" + "\n");
- String text = oppEnemies.printKeyPress();
- System.out.println(text);
- CounterAttack("player");
- }
- public void CounterAttack(String input) {
- if (input.equals("player") && player != null && xMech != null) {
- PlayerCounterAttack();
- } else if (input.equals("enemy") && oppEnemies != null) {
- // Implement enemy counter-attack logic here
- }
- }
- void PlayerCounterAttack() {
- this.countdown = 120; // Start countdown at 10
- this.combo = 0;
- this.i = 0;
- this.pressed = 0;
- Timer time = new Timer(); // Initialize the Timer
- TimerTask task = new TimerTask() {
- @Override
- public void run() {
- if (i < OppMoves.length) {
- String attack = OppMoves[i];
- if (attack == null || attack.equals("")) {
- System.out.println("ERROR: ATTACK DOES NOT EXIST");
- } else {
- if (countdown > 0) {
- if (startBattle == false) {
- game.GameBattles();
- startBattle = true;
- }
- // Check if player pressed the correct keys
- game.setFocusable(true);
- game.requestFocusInWindow();
- if (game.getPressed()) {
- pressed++;
- }
- if (pressed >= oppEnemies.getKeyPressNeeded(attack)) {
- if (startBattle == true) {
- game.GameBattles();
- }
- if (combo >= 3) {
- combo = 0;
- }
- pressed = 0; // Reset pressed
- combo++; // Increase combo
- i++; // Move to the next enemy attack
- }
- countdown--; // Decrease countdown each second
- String text = oppEnemies.printKeyPress();
- game.text.setText(String.valueOf(countdown) + " pressed: " + pressed + " Press needed: " + oppEnemies.getKeyPressNeeded(attack) + " name of move: " + attack);
- } else {
- System.out.println("Counterattack phase completed!");
- resetCounters();
- this.cancel();
- }
- }
- } else {
- System.out.println("ERROR: Attack index out of bounds.");
- this.cancel();
- }
- }
- };
- // Start the timer to run the task every second
- time.scheduleAtFixedRate(task, 0, 1000); // Execute every second
- }
- private void resetCounters() {
- i = 0;
- combo = 0;
- pressed = 0;
- countdown = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment