Browse Source

added function to choices buttons

master
Yazan Alaamer 2 years ago
parent
commit
652b018d24
  1. 29
      src/main/java/game/StartDarkSoulsGame.java

29
src/main/java/game/StartDarkSoulsGame.java

@ -96,6 +96,7 @@ public class StartDarkSoulsGame {
choice1.setFont(normalFont); choice1.setFont(normalFont);
choice1.setFocusPainted(false); choice1.setFocusPainted(false);
choice1.setActionCommand("c1"); choice1.setActionCommand("c1");
choice1.addActionListener(choiceHandler);
choiceButtonPanel.add(choice1); choiceButtonPanel.add(choice1);
choice2 = new JButton("Choice 2"); choice2 = new JButton("Choice 2");
@ -104,6 +105,7 @@ public class StartDarkSoulsGame {
choice2.setFont(normalFont); choice2.setFont(normalFont);
choice2.setFocusPainted(false); choice2.setFocusPainted(false);
choice2.setActionCommand("c2"); choice2.setActionCommand("c2");
choice2.addActionListener(choiceHandler);
choiceButtonPanel.add(choice2); choiceButtonPanel.add(choice2);
choice3 = new JButton("Choice 3"); choice3 = new JButton("Choice 3");
@ -112,6 +114,7 @@ public class StartDarkSoulsGame {
choice3.setFont(normalFont); choice3.setFont(normalFont);
choice3.setFocusPainted(false); choice3.setFocusPainted(false);
choice3.setActionCommand("c3"); choice3.setActionCommand("c3");
choice3.addActionListener(choiceHandler);
choiceButtonPanel.add(choice3); choiceButtonPanel.add(choice3);
choice4 = new JButton("Choice 4"); choice4 = new JButton("Choice 4");
@ -120,6 +123,7 @@ public class StartDarkSoulsGame {
choice4.setFont(normalFont); choice4.setFont(normalFont);
choice4.setFocusPainted(false); choice4.setFocusPainted(false);
choice4.setActionCommand("c4"); choice4.setActionCommand("c4");
choice4.addActionListener(choiceHandler);
choiceButtonPanel.add(choice4); choiceButtonPanel.add(choice4);
playerPanel = new JPanel(); playerPanel = new JPanel();
@ -158,7 +162,7 @@ public class StartDarkSoulsGame {
townGate(); townGate();
} }
public void townGate() { public void townGate() {
position = "twonGate";
position = "townGate";
mainTextArea.setText("You are at the Gate of the town.\n A guard is standing in front of you. WHAT DO YOU DO !?"); mainTextArea.setText("You are at the Gate of the town.\n A guard is standing in front of you. WHAT DO YOU DO !?");
choice1.setText("Talk to the gurad "); choice1.setText("Talk to the gurad ");
choice2.setText("Attack the guard"); choice2.setText("Attack the guard");
@ -173,14 +177,31 @@ public class StartDarkSoulsGame {
choice3.setText(""); choice3.setText("");
choice4.setText(""); choice4.setText("");
} }
public class TitelScreenHandler implements ActionListener{
public void actionPerformed(ActionEvent event) {
createGameScreen();
}
}
public class ChoiceHandler implements ActionListener{ public class ChoiceHandler implements ActionListener{
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
String yourChoice = event.getActionCommand(); String yourChoice = event.getActionCommand();
switch(position) {
case "townGate":
switch(yourChoice) {
case "c1": talkGuard(); break;
case "c2": break;
case "c3": break;
} }
break;
case "talkGuard":
switch(yourChoice) {
case"c1": townGate();break;
}
break;
} }
public class TitelScreenHandler implements ActionListener{
public void actionPerformed(ActionEvent event) {
createGameScreen();
} }
} }

Loading…
Cancel
Save