From c7a907335a46e9e5a580ebc69d25ac451089aacb Mon Sep 17 00:00:00 2001 From: Yazan Alaamer Date: Sat, 21 Jan 2023 00:41:01 +0100 Subject: [PATCH] create monster attacking system --- src/main/java/game/StartDarkSoulsGame.java | 43 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/main/java/game/StartDarkSoulsGame.java b/src/main/java/game/StartDarkSoulsGame.java index 55e49ea..2529465 100644 --- a/src/main/java/game/StartDarkSoulsGame.java +++ b/src/main/java/game/StartDarkSoulsGame.java @@ -258,6 +258,20 @@ public class StartDarkSoulsGame { choice4.setText(""); } + public void monsterAttack() { + position = "monsterAttack"; + int monsterDamage = 0; + + monsterDamage = new java.util.Random().nextInt(5); + mainTextArea.setText("Monster attacked you "+ monsterDamage +" Damage"); + playerHP = playerHP - monsterDamage; + hpLabelNumber.setText(" " + playerHP); + choice1.setText(">"); + choice2.setText(""); + choice3.setText(""); + choice4.setText(""); + + } public void win() { position = "win"; mainTextArea.setText("THE SOUl OF CINDER has been defeated.\n" @@ -346,7 +360,7 @@ public class StartDarkSoulsGame { break; case "west": switch(yourChoice) { - case "c1": break; + case "c1": fight(); break; case "c2": crossRoad(); break; } break; @@ -355,6 +369,33 @@ public class StartDarkSoulsGame { case "c1": playerAttack(); break; case "c2": crossRoad(); break; } + break; + case "playerAttack": + switch (yourChoice) { + case "c1": if(monsterHP < 1) { + win(); + } + else { + monsterAttack(); break; + } + + } + break; + case "monsterAttack": + switch (yourChoice) { + case "c1": if (playerHP < 1) { + lose(); + } + else { + fight(); + } + break; + } + break; + case "win": + switch(yourChoice) { + case "c1": crossRoad(); break; + } } }