RuneHive-Game
Loading...
Searching...
No Matches
PuzzleDisplay.java
Go to the documentation of this file.
1package com.runehive.content.puzzle;
2
3import com.runehive.game.world.entity.mob.player.Player;
4import com.runehive.net.packet.out.SendInterfaceWidget;
5import com.runehive.util.Utility;
6
7/**
8 * Handles displaying the puzzle.
9 *
10 * @author Daniel
11 */
12public class PuzzleDisplay {
13 /** The player instance. */
14 private final Player player;
15
16 /** The puzzle data. */
18
19 /** The options array. */
20 private int[] options;
21
22 /** The puzzle type. */
24
25 /** The success count. */
27
28 /** Constructs a new <code>PuzzleDisplay</code>. */
30 this.player = player;
31 }
32
33 /** Randomize the puzzle. */
34 private void randomize() {
35 this.puzzle = PuzzleData.PUZZLES[(int) (Math.random() * PuzzleData.PUZZLES.length)];
36 this.options = Utility.shuffleArray(puzzle.getOptions());
37 }
38
39 /** Opens the puzzle interface. */
40 public void open(PuzzleType puzzleType) {
41 randomize();
42
43 for (int index = 0; index < 3; index++) {
44 int sequenceModel = puzzle.getSequenceModel(index);
45 int optionModel = options[index];
46 player.send(new SendInterfaceWidget(4545 + index, sequenceModel));
47 player.send(new SendInterfaceWidget(4550 + index, optionModel));
48 }
49
50 type = puzzleType;
51 player.interfaceManager.open(4543);
52 }
53
54 /** Checks the puzzle answer. */
55 private boolean checkAnswer(int button) {
56 int index = button - 4550;
57 int model = options[index];
58 return model == puzzle.getAnswer();
59 }
60
61 /** Handles clicking on the puzzle interface. */
62 public boolean click(int button) {
63 switch (button) {
64 case 4550:
65 case 4551:
66 case 4552:
67 if (checkAnswer(button)) {
69 type.onSuccess(player);
70 return true;
71 }
72 successCount = 0;
73 type.onFailure(player);
74 return true;
75 }
76 return false;
77 }
78}
void open(PuzzleType puzzleType)
Opens the puzzle interface.
PuzzleDisplay(Player player)
Constructs a new PuzzleDisplay.
final Player player
The player instance.
void randomize()
Randomize the puzzle.
boolean click(int button)
Handles clicking on the puzzle interface.
boolean checkAnswer(int button)
Checks the puzzle answer.
This class represents a character controlled by a player.
Definition Player.java:125
Handles miscellaneous methods.
Definition Utility.java:27
static int[] shuffleArray(int[] array)
Definition Utility.java:878
static final PuzzleData[] PUZZLES
The difference puzzle types.