Guest User

Untitled

a guest
Sep 26th, 2024
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.81 KB | Source Code | 0 0
  1. the abstract operator class for my dag data structure yet to implement
  2. package InGameEvents.Operators;
  3.  
  4. import javax.swing.JFrame;
  5.  
  6. public abstract class Operator{
  7.     String name;
  8.     public Operator(String name){
  9.         this.name = name;
  10.     }
  11.    
  12. }
  13.  
  14.  
  15.  
  16. the battle mechanics that implement it
  17.  
  18.  
  19.  
  20.  package InGameEvents.Operators;
  21.  
  22. import java.awt.event.KeyEvent;
  23. import java.awt.event.KeyListener;
  24. import java.util.ArrayList;
  25. import java.util.Timer;
  26. import java.util.TimerTask;
  27.  
  28. import Graph.Interactables.Enemies.Enemies;
  29. import Graph.Interactables.Enemies.BOSSES.BodyBlitzCP.BodyBlitzCP;
  30. import Graph.Interactables.InteractablesCommonObjs.Weapons.WeaponsMech;
  31. import Graph.Interactables.InteractablesCommonObjs.Weapons.Fists.Fists;
  32. import Graph.LevelForGame.levels;
  33. import SystemManager.GameScene;
  34. import User.PlayerCharacter.MainCharacter;
  35.  
  36. public class Battles extends Operator{
  37.  
  38.     MainCharacter player;
  39.     WeaponsMech xMech;
  40.     Enemies oppEnemies;
  41.     int countdown;
  42.     int combo = 0;
  43.     String[] PlayerMoves;
  44.     String[] OppMoves;
  45.     int CounterSize;
  46.     GameScene game;
  47.     int pressed = 0;
  48.     boolean startBattle = false;
  49.      
  50.  
  51.     int i = 0;
  52.  
  53.  
  54.     public Battles(String name) {
  55.         super(name);
  56.  
  57.         oppEnemies = new BodyBlitzCP();
  58.         player = new MainCharacter();
  59.         xMech = player.getWeapon();
  60.         game = new GameScene();
  61.         OppMoves = oppEnemies.getMoves();
  62.         for (String arr : OppMoves){
  63.             System.out.println(" " + arr);
  64.  
  65.         }
  66.         System.out.println("\n" + "\n");
  67.         String text = oppEnemies.printKeyPress();
  68.         System.out.println(text);
  69.  
  70.  
  71.         CounterAttack("player");
  72.        
  73.        
  74.  
  75.  
  76.  
  77.  
  78.        
  79.    
  80.        
  81.     }
  82.  
  83.  
  84.  
  85.  
  86.  
  87.     public void CounterAttack(String input) {
  88.     if (input.equals("player") && player != null && xMech != null) {
  89.         PlayerCounterAttack();
  90.     } else if (input.equals("enemy") && oppEnemies != null) {
  91.         // Implement enemy counter-attack logic here
  92.     }
  93.  
  94.  
  95.     }
  96.    
  97.  
  98.     void PlayerCounterAttack() {
  99.         this.countdown = 120; // Start countdown at 10
  100.         this.combo = 0;
  101.         this.i = 0;
  102.         this.pressed = 0;
  103.         Timer time = new Timer(); // Initialize the Timer
  104.    
  105.         TimerTask task = new TimerTask() {
  106.             @Override
  107.             public void run() {
  108.                 if (i < OppMoves.length) {
  109.                     String attack = OppMoves[i];
  110.    
  111.                     if (attack == null || attack.equals("")) {
  112.                         System.out.println("ERROR: ATTACK DOES NOT EXIST");
  113.                     } else {
  114.                         if (countdown > 0) {
  115.                             if (startBattle == false) {
  116.                                 game.GameBattles();
  117.                                 startBattle = true;
  118.                             }
  119.    
  120.                             // Check if player pressed the correct keys
  121.                             game.setFocusable(true);
  122.                             game.requestFocusInWindow();
  123.                             if (game.getPressed()) {
  124.                                 pressed++;
  125.                             }
  126.    
  127.                             if (pressed >= oppEnemies.getKeyPressNeeded(attack)) {
  128.                                 if (startBattle == true) {
  129.                                     game.GameBattles();
  130.                                 }
  131.                                 if (combo >= 3) {
  132.                                     combo = 0;
  133.                                 }
  134.                                 pressed = 0; // Reset pressed
  135.                                 combo++; // Increase combo
  136.                                 i++; // Move to the next enemy attack
  137.                             }
  138.    
  139.                             countdown--; // Decrease countdown each second
  140.                             String text = oppEnemies.printKeyPress();
  141.                             game.text.setText(String.valueOf(countdown) + " pressed: " + pressed + " Press needed: " + oppEnemies.getKeyPressNeeded(attack) + " name of move: " + attack);
  142.                         } else {
  143.                             System.out.println("Counterattack phase completed!");
  144.                             resetCounters();
  145.                             this.cancel();
  146.                         }
  147.                     }
  148.                 } else {
  149.                     System.out.println("ERROR: Attack index out of bounds.");
  150.                     this.cancel();
  151.                 }
  152.             }
  153.         };
  154.    
  155.         // Start the timer to run the task every second
  156.         time.scheduleAtFixedRate(task, 0, 1000); // Execute every second
  157.     }
  158.    
  159.     private void resetCounters() {
  160.         i = 0;
  161.         combo = 0;
  162.         pressed = 0;
  163.         countdown = 0;
  164.     }
  165.  
  166.  
  167.  
Advertisement
Add Comment
Please, Sign In to add comment