package jeu;

import engine.GameController;

import java.awt.event.KeyEvent;
import java.util.HashMap;

public class Controller implements GameController{

    private boolean isRightPressed, isLeftPressed, isSpacePressed;
    private boolean isLeftCLickPressed;
    private final HashMap<String,Boolean> cmd = new HashMap<>();
    /*
    * commande en cours
    */

    /*
    * construction du controleur par defaut le controleur n'a pas de commande
    */

    public Controller() {
        isRightPressed = false; isLeftPressed = false; isSpacePressed = false; isLeftCLickPressed = false; // pour attaquer sur clique gauche
        // pour l'instant faut appuyer sur Q mais c'est a changer
    }
    /**
     * getCommand retourne une liste de booleans sous la forme [isRightPressed, isLeftPressed, isSpacePressed]
     */
    @Override
    public HashMap<String,Boolean> getCommand() {
        cmd.put("Right",isRightPressed);
        cmd.put("Left",isLeftPressed);
        cmd.put("Jump",isSpacePressed);
        cmd.put("Attack",isLeftCLickPressed);
        return cmd;
    }
    @Override

    public void keyPressed(KeyEvent e) {

        switch (e.getKeyCode()) {
            // si on appuie sur une touche ci dessous le boolean devient vraie.
            case KeyEvent.VK_RIGHT -> isRightPressed = true;
            case KeyEvent.VK_LEFT -> isLeftPressed = true;
            case KeyEvent.VK_SPACE -> isSpacePressed = true;
            case KeyEvent.VK_Q -> isLeftCLickPressed = true;
        }
    }
    @Override
    public void keyReleased(KeyEvent e) {
        switch (e.getKeyCode()) {
            case KeyEvent.VK_RIGHT -> isRightPressed = false;
            case KeyEvent.VK_LEFT -> isLeftPressed = false;
            case KeyEvent.VK_SPACE -> isSpacePressed = false;
            case KeyEvent.VK_Q -> isLeftCLickPressed = false;
        }
    }
    @Override

    public void keyTyped(KeyEvent e) {

    }

}