From 78cd2447f535112350dfe81e8c09377017318da7 Mon Sep 17 00:00:00 2001 From: Amir Daouadi Date: Wed, 12 Apr 2023 00:21:11 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20d'un=20diff=C3=A9rent=20type=20de=20con?= =?UTF-8?q?trolleur=20en=20essaie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controller/HGameController.java | 33 +++++++++++++++++++++++++++++++++ Controller/Player.java | 23 +++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 Controller/HGameController.java create mode 100644 Controller/Player.java diff --git a/Controller/HGameController.java b/Controller/HGameController.java new file mode 100644 index 0000000..dd2733f --- /dev/null +++ b/Controller/HGameController.java @@ -0,0 +1,33 @@ +package Controller; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +public class HGameController implements KeyListener { + private Player player; + + public HGameController(Player player) { + this.player = player; + } + + @Override + public void keyPressed(KeyEvent e) { + int keyCode = e.getKeyCode(); + if (keyCode == KeyEvent.VK_UP) { + player.move(-1, 0); + } else if (keyCode == KeyEvent.VK_DOWN) { + player.move(1, 0); + } else if (keyCode == KeyEvent.VK_LEFT) { + player.move(0, -1); + } else if (keyCode == KeyEvent.VK_RIGHT) { + player.move(0, 1); + } + } + + @Override + public void keyReleased(KeyEvent e) { + } + + @Override + public void keyTyped(KeyEvent e) { + } +} diff --git a/Controller/Player.java b/Controller/Player.java new file mode 100644 index 0000000..3fc280c --- /dev/null +++ b/Controller/Player.java @@ -0,0 +1,23 @@ +package Controller; +public class Player { + private int x; + private int y; + + public Player(int x, int y) { + this.x = x; + this.y = y; + } + + public void move(int dx, int dy) { + x += dx; + y += dy; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } +}