From f74ae35758a92d3316b2a80c34e2c42942e2c874 Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Wed, 7 Feb 2024 23:03:35 +0100 Subject: [PATCH] added funtion Gohst moving in random stage --- src/main/java/pacmanGame/GhostBehaviorRandom.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/pacmanGame/GhostBehaviorRandom.java b/src/main/java/pacmanGame/GhostBehaviorRandom.java index 492892c..d461501 100644 --- a/src/main/java/pacmanGame/GhostBehaviorRandom.java +++ b/src/main/java/pacmanGame/GhostBehaviorRandom.java @@ -4,7 +4,20 @@ public class GhostBehaviorRandom implements GhostBehavior { @Override public Vector2 GetDirection(Ghost ghost) { - + Random random = new Random(); + int direction = random.nextInt(4); + switch(direction) { + case 0: //oben + return new Vector2(0,1); + case 1: //unten + return new Vector2(0,-1); + case 2:// links + return new Vector2(-1,0); + case 3: //rechts + return new Vector2(1,0); + default: + break; + } return null; }