-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
1397 lines (1346 loc) · 71.7 KB
/
Client.java
File metadata and controls
1397 lines (1346 loc) · 71.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Final Game Client Class
* @Author Ilya Kononov
* @Date = January 22 2023
* This is the main file of the client and where the game actually happens
*/
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
public class Client {
private static JFrame window;
private JPanel cards;
// The different screens.
private MenuPanel menuScreen;
private LobbySelectPanel lobbySelectScreen;
private AbilitySelectPanel abilitySelectScreen;
private LobbyPanel lobbyScreen;
private GamePanel gameScreen;
private JPanel pauseScreen;
private JPanel howToPlayScreen;
private GameOverPanel gameOverScreen;
public final static String MENU_PANEL = "main menu screen";
public final static String LOBBY_SELECT_PANEL = "lobby select screen";
public final static String ABILITY_SELECT_PANEL = "ability select screen";
public final static String LOBBY_PANEL = "lobby screen";
public final static String HOW_TO_PLAY_PANEL = "how to play screen";
public final static String GAME_PANEL = "game screen";
public final static String PAUSE_PANEL = "pause screen";
public final static String GAME_OVER_PANEL = "game over screen";
private PrintWriter output;
private BufferedReader input;
private static ServerHandler server;
private Socket clientSocket;
private final String HOST = "localhost";
private final int PORT = 5001;
protected static boolean playing;
private boolean lost;
private String lobbyName;
public static void main(String[] args) throws IOException{
Client client = new Client();
client.setup();
server.start();
while(true){
try {
Thread.sleep(10);
} catch (Exception e) {}
}
}
//-------------------------------------------------
private void setup() throws IOException{
window = new JFrame("Dungeon Runner");
window.setPreferredSize(new Dimension(Const.WIDTH + Const.ADJUST_WIDTH, Const.HEIGHT + Const.ADJUST_HEIGHT));// adding because of window problems
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setResizable(false);
window.setSize(Const.WIDTH, Const.HEIGHT);
this.cards = new JPanel(new CardLayout());
clientSocket = new Socket(HOST, PORT);
output = new PrintWriter(clientSocket.getOutputStream());
input = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
server = new ServerHandler(this);
//Initialize the screens.
this.menuScreen = new MenuPanel(Const.MENU_BACKGROUND);
this.lobbySelectScreen = new LobbySelectPanel(Const.WALL_BACKGROUND);
this.abilitySelectScreen = new AbilitySelectPanel(Const.ABILITY_SELECT_BACKGROUND);
this.lobbyScreen = new LobbyPanel(Const.WALL_BACKGROUND);
this.gameScreen = new GamePanel(Const.BLANK_BACKGROUND);
this.pauseScreen = new PausePanel(Const.WALL_BACKGROUND);
this.howToPlayScreen = new HowToPlayPanel(Const.CONTROLS_BACKGROUND);
this.gameOverScreen = new GameOverPanel(Const.WALL_BACKGROUND);
// Add the screens to the window manager.
cards.add(menuScreen, MENU_PANEL);
cards.add(lobbySelectScreen, LOBBY_SELECT_PANEL);
cards.add(abilitySelectScreen, ABILITY_SELECT_PANEL);
cards.add(lobbyScreen, LOBBY_PANEL);
cards.add(gameScreen, GAME_PANEL);
cards.add(pauseScreen, PAUSE_PANEL);
cards.add(howToPlayScreen, HOW_TO_PLAY_PANEL);
cards.add(gameOverScreen, GAME_OVER_PANEL);
window.add(cards);
window.setVisible(true);
window.setResizable(false);
window.pack();
playing = false;
lost = false;
lobbyName = "";
window.setVisible(true);
}
public void stop() throws Exception{
input.close();
output.close();
clientSocket.close();
}
class ServerHandler extends Thread{
private Client client;
private Pinger pinger;
ServerHandler(Client client){
this.client = client;
this.pinger = new Pinger(this.client.output);
this.pinger.start();
}
@Override
public void run(){
while(true){
String update = "";
String[] updateInfo = new String[12];
try {
update = input.readLine();
} catch (Exception e) {}
if(update != "" && update != null){
updateInfo = update.split(" ", 12);
if(!(updateInfo[0].equals(Const.UPDATE_MAP) || updateInfo[0].equals(Const.PLAYER) || updateInfo[0].equals(Const.DRAW_MAP) || updateInfo[0].equals(Const.ENEMY))){System.out.println(update);}
// From server
if(updateInfo[0].equals(Const.LOBBY)){ // LOBBY lobbyName lobbySize
String lobbyName = updateInfo[1] + " Lobby";
String lobbySize = "Players = " + updateInfo[2] + "/4";
lobbySelectScreen.newLobbyBanner(lobbyName, lobbySize, Const.LOBBY_BANNER_START_Y + lobbySelectScreen.lobbies().size() * Const.SPACE_BETWEEN_LOBBIES);
}
else if(updateInfo[0].equals(Const.LOBBY_SELECT)){ // LOBBY_SELECT
Client.ScreenSwapper swapper = new Client.ScreenSwapper(cards, LOBBY_SELECT_PANEL);
swapper.swap();
}
else if(updateInfo[0].equals(Const.CLEAR_LOBBIES)){ // CLEAR_LOBBIES
this.client.lobbySelectScreen.lobbies.clear();
}
else if(updateInfo[0].equals(Const.NAME)){ // NAME newlobby/joinlobby, lobbyName
String secondaryCommand = updateInfo[1];
Client.ServerWriter writer = new Client.ServerWriter(output);
if(secondaryCommand.equals(Const.NEW_LOBBY)){
writer.print(Const.NAME + " " + this.client.lobbySelectScreen.name());
}else if(secondaryCommand.equals(Const.JOIN_LOBBY)){
String lobbyName = updateInfo[2];
writer.print(Const.NAME + " " + lobbyName + " " + this.client.lobbySelectScreen.name());
}
}
else if(updateInfo[0].equals(Const.JOINED)){ // JOINED
lobbyName = updateInfo[1];
}
// From lobby
else if(updateInfo[0].equals(Const.NEW_PLAYER)){ // NEWP playerName playerColor
String newPlayerName = updateInfo[1];
String playerColor = updateInfo[2];
lobbyScreen.newPlayerBanner(newPlayerName, playerColor);
gameScreen.addPlayer(newPlayerName, playerColor, 0, 0);
if(newPlayerName.equals(lobbySelectScreen.name())){
Client.ScreenSwapper swapper = new Client.ScreenSwapper(cards, ABILITY_SELECT_PANEL);
swapper.swap();
}
}
else if(updateInfo[0].equals(Const.LEAVE)){ // LEAVE
abilitySelectScreen.resetButtons();
lobbyScreen.clearBanners();
gameScreen.clearGame();
if(!(lost)){
Client.ScreenSwapper swapper = new Client.ScreenSwapper(cards, MENU_PANEL); // After player leaves lobby they can swap to main menu right away since the lobbyName will always be correct
swapper.swap();
}else{ // Once the game ends all players get sent this command however they don't need to swap screenskey just yet
lost = false;
}
}
else if(updateInfo[0].equals(Const.REMOVE_PLAYER)){ // REMOVEP playerName
String playerName = updateInfo[1];
lobbyScreen.removePlayerBanner(playerName);
gameScreen.removePlayer(playerName);
}
else if(updateInfo[0].equals(Const.RESELECT)){ // RESELECT playerName
String playerName = updateInfo[1];
Client.ScreenSwapper swapper = new Client.ScreenSwapper(cards, ABILITY_SELECT_PANEL);
swapper.swap();
lobbyScreen.updatePlayerBanner(playerName, false);
}
else if(updateInfo[0].equals(Const.MY_ABILITIES)){ // MY_ABILITIES
Client.ServerWriter writer = new Client.ServerWriter(output);
writer.print(Const.MY_ABILITIES + " " + abilitySelectScreen.abilities());
}
else if(updateInfo[0].equals(Const.ABILITIES)){ // ABILITIES playerName passiveName abilityName ultimateName
String playerName = updateInfo[1];
String passive = updateInfo[2];
String ability = updateInfo[3];
String ultimate = updateInfo[4];
lobbyScreen.updatePlayerBanner(playerName, passive, ability, ultimate);
if(updateInfo.length > 5 && updateInfo[5].equals("ME")){ // This is done so that the player cant swap screens until they have chosen all of their abilities
lobbyScreen.updateLobbyTitle();
gameScreen.setAbilities(passive, ability, ultimate);
Client.ScreenSwapper swapper = new Client.ScreenSwapper(cards, LOBBY_PANEL);
swapper.swap();
}
}
else if(updateInfo[0].equals(Const.READY)){ // READY
String playerName = updateInfo[1];
lobbyScreen.updatePlayerBanner(playerName, true);
}
else if(updateInfo[0].equals(Const.UNREADY)){ // UNREADY
String playerName = updateInfo[1];
lobbyScreen.updatePlayerBanner(playerName, false);
}
else if(updateInfo[0].equals(Const.GAME_START)){ // GAME_START clientsName
String myName = updateInfo[1]; // This is done to set make the player see their players field of view first
gameScreen.setCurrentPlayer(myName);
Client.ScreenSwapper swapper = new Client.ScreenSwapper(cards, GAME_PANEL);
swapper.swap();
lobbyScreen.resetBanners();
}
else if(updateInfo[0].equals(Const.PLAYER)){ // PLAYER playerName playerX playerY direction currentHealth
String playerName = updateInfo[1];
int playerX = Integer.parseInt(updateInfo[2]);
int playerY = Integer.parseInt(updateInfo[3]);
int direction = Integer.parseInt(updateInfo[4]);
int health = Integer.parseInt(updateInfo[5]);
gameScreen.updatePlayer(playerName, playerX, playerY, direction, health);
}
else if(updateInfo[0].equals(Const.ABILITY)){ // ABILITY, this command is telling their ability was succesfully used so now its on cooldown
gameScreen.updateAbilityState(false);
}
else if(updateInfo[0].equals(Const.ABILITY_READY)){ // ABILITY_READY, this command is telling their ability is off cooldown
gameScreen.updateAbilityState(true);
}
else if(updateInfo[0].equals(Const.ULTIMATE)){ // ULTIMATE, this command is telling their ultimate was succesfully used so now its on cooldown
gameScreen.updateUltimateState(false);
}
else if(updateInfo[0].equals(Const.ULTIMATE_READY)){ // ULTIMATE_READY, this command is telling their ultimate is off cooldown
gameScreen.updateUltimateState(true);
}
else if(updateInfo[0].equals(Const.NEWE)){ // NEWE enemyX enemyY health
int enemyX = Integer.parseInt(updateInfo[1]);
int enemyY = Integer.parseInt(updateInfo[2]);
int health = Integer.parseInt(updateInfo[3]);
gameScreen.addEnemy(enemyX, enemyY, health);
}
else if(updateInfo[0].equals(Const.ENEMY)){ // ENEMY enemyID enemyX enemyY currentHealth
int enemyID = Integer.parseInt(updateInfo[1]);
int enemyX = Integer.parseInt(updateInfo[2]);
int enemyY = Integer.parseInt(updateInfo[3]);
int health = Integer.parseInt(updateInfo[4]);
gameScreen.updateEnemy(enemyX, enemyY, enemyID, health);
}
else if(updateInfo[0].equals(Const.KILLEDE)){ // KILLEDE enemyID
int enemyID = Integer.parseInt(updateInfo[1]);
gameScreen.removeEnemy(enemyID);
}
else if(updateInfo[0].equals(Const.UPDATE_MAP)){ // UPDATE_MAP rowNum col1 col2 col2...
int rowNum = Integer.parseInt(updateInfo[1]);
char[] row = new char[updateInfo.length - 2];
String msg = "";
for(int i = 1; i <= row.length && i < updateInfo.length - 1 && updateInfo[i + 1] != null; i++){ // the row length will always have a maximum of 7 with 1200x1000 screen dimensions (1200 / 150) + 1 =7
row[i-1] = updateInfo[i + 1].charAt(0);
msg = msg + " " + row[i-1];
}
gameScreen.modifyFOV(rowNum, row);
}
else if(updateInfo[0].equals(Const.DRAW_MAP)){ // DRAW_MAP rowsInFov colsInFov topLeftTileX topLeftTileY
int rowCount = Integer.parseInt(updateInfo[1]);
int colCount = Integer.parseInt(updateInfo[2]);
int mapX = Integer.parseInt(updateInfo[3]) * Const.TILE_DIMENSIONS;
int mapY = Integer.parseInt(updateInfo[4]) * Const.TILE_DIMENSIONS;
gameScreen.updateFOV();
gameScreen.newFOVDimensions(rowCount, colCount, mapX, mapY);
}
else if(updateInfo[0].equals(Const.DIED)){ // DIED playerName
String playerName = updateInfo[1];
gameScreen.killPlayer(playerName);
}
else if(updateInfo[0].equals(Const.DOWNED)){ // DOWNED playerName
String playerName = updateInfo[1];
gameScreen.downPlayer(playerName);
}
else if(updateInfo[0].equals(Const.REVIVED)){ // REVIVED playerName
String playerName = updateInfo[1];
gameScreen.revivePlayer(playerName);
}
else if(updateInfo[0].equals(Const.DIE)){ // DIE, this command is saying the clients player died so they can now start spectating players
gameScreen.die();
}
else if(updateInfo[0].equals(Const.WIN)){ // WIN
Client.ScreenSwapper swapper = new Client.ScreenSwapper(cards, LOBBY_PANEL);
swapper.swap();
gameScreen.resetGame();
}
else if(updateInfo[0].equals(Const.LOSE)){ // LOSE
String rounds = updateInfo[1];
lost = true;
gameOverScreen.updateRounds(rounds);
Client.ScreenSwapper swapper = new Client.ScreenSwapper(cards, GAME_OVER_PANEL);
swapper.swap();
abilitySelectScreen.resetButtons();
lobbyScreen.clearBanners();
gameScreen.clearGame();
}
}
}
}
private class Pinger extends Thread{ // This class maintains a connection with the server during the runtime of the program
PrintWriter output;
Pinger(PrintWriter output){
this.output = output;
}
@Override
public void run(){
while(true){
output.println(Const.PING);
output.flush();
try {
Thread.sleep(20000);
} catch (Exception e){}
}
}
}
}
// Static class that prints a message in the server. Static class was used so that other classes can also talk to the server when neccesary, see ServerButton for an example
public static class ServerWriter{
private PrintWriter output;
/*
* Constructs a ServerWriter object with the command to write to the server.
* @param output PrintWriter that is connected to the server
*/
public ServerWriter(PrintWriter output) {
this.output = output;
}
public void print(String text){
output.println(text);
output.flush();
}
}
public static class ScreenSwapper implements ActionListener {
private String nextPanel;
private JPanel cards;
/*
* Constructs a ScreenSwapper object with the screen to switch to.
* @param cards The JPanel that stores the different screens.
* @param nextPanel The screen to switch to.
*/
public ScreenSwapper(JPanel cards, String nextPanel) {
this.nextPanel = nextPanel;
this.cards = cards;
}
@Override
public void actionPerformed(ActionEvent event) {
this.swap();
}
/**
* This method swaps the current screen to the set screen.
*/
public void swap() {
System.out.println("Switching to " + this.nextPanel);
// Switch to the specified panel.
CardLayout layout = (CardLayout) this.cards.getLayout();
layout.show(this.cards, this.nextPanel);
}
}
public class MenuPanel extends ScreenPanel {
private ServerButton playButton;
private TextButton howToPlayButton;
public MenuPanel(Image backgroundSprite) {
super(backgroundSprite);
// Initialize the buttons.
Text playButtonText = new Text("Play", Const.MENU_BUTTON_FONT, Const.LARGE_BUTTON_FONT_COLOR, Const.HALF_WIDTH, 300);
this.playButton = new ServerButton(window, output, playButtonText, Const.LOBBIES_LIST, Const.LARGE_BUTTON_IN_COLOR, Const.LARGE_BUTTON_BORDER_COLOR,
Const.LARGE_BUTTON_HOVER_COLOR, Const.HALF_WIDTH, 300, Const.RADIUS);
Text howToPlayButtonText = new Text("How To Play", Const.MENU_BUTTON_FONT, Const.LARGE_BUTTON_FONT_COLOR, Const.HALF_WIDTH, 470);
this.howToPlayButton = new TextButton(window, cards, HOW_TO_PLAY_PANEL, howToPlayButtonText, Const.LARGE_BUTTON_IN_COLOR, Const.LARGE_BUTTON_BORDER_COLOR,
Const.LARGE_BUTTON_HOVER_COLOR, Const.HALF_WIDTH, 470, Const.RADIUS);
// Add the listeners for the screens.
this.addMouseListener(playButton.new BasicMouseListener());
this.addMouseMotionListener(playButton.new InsideButtonMotionListener());
this.addMouseListener(howToPlayButton.new BasicMouseListener());
this.addMouseMotionListener(howToPlayButton.new InsideButtonMotionListener());
this.setFocusable(true);
this.addComponentListener(this.FOCUS_WHEN_SHOWN);
}
public void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
this.playButton.draw(graphics);
this.howToPlayButton.draw(graphics);
}
public final ComponentAdapter FOCUS_WHEN_SHOWN = new ComponentAdapter(){
public void componentShown(ComponentEvent event){
requestFocusInWindow();
}
};
}
public class LobbySelectPanel extends ScreenPanel {
private ServerButton newlobbyButton;
private TextButton backButton;
private TextButton nameField;
private Text playerName;
private ArrayList<LobbyBanner> lobbies;
public LobbySelectPanel(Image backgroundSprite) {
super(backgroundSprite);
// Initialize the buttons.
Text newlobbyText = new Text("New Lobby", Const.SMALL_BUTTON_FONT, Const.LARGE_BUTTON_FONT_COLOR, Const.CONTINUE_X, Const.GO_BACK_Y);
this.newlobbyButton = new ServerButton(window, output, newlobbyText, Const.NEW_LOBBY ,Const.SMALL_BUTTON_IN_COLOR, Const.LARGE_BUTTON_BORDER_COLOR,
Const.SMALL_BUTTON_HOVER_COLOR, Const.CONTINUE_X, Const.GO_BACK_Y, Const.RADIUS);
Text backText = new Text("Go back", Const.SMALL_BUTTON_FONT, Const.LARGE_BUTTON_FONT_COLOR, Const.GO_BACK_X, Const.GO_BACK_Y);
this.backButton = new TextButton(window, cards, MENU_PANEL, backText, Const.SMALL_BUTTON_IN_COLOR, Const.LARGE_BUTTON_BORDER_COLOR,
Const.SMALL_BUTTON_HOVER_COLOR, Const.GO_BACK_X, Const.GO_BACK_Y, Const.RADIUS);
int nameY = 170;
this.playerName = new Text("Player", Const.TEXT_FONT, Const.LARGE_BUTTON_FONT_COLOR, Const.HALF_WIDTH, nameY);
Text nameFieldText = new Text(" ", Const.TEXT_FONT, Color.WHITE, Const.HALF_WIDTH, nameY);
this.nameField = new TextButton(window, null, null, nameFieldText, Const.LARGE_BUTTON_IN_COLOR, Const.LARGE_BUTTON_BORDER_COLOR,
Const.LARGE_BUTTON_HOVER_COLOR, Const.HALF_WIDTH, nameY, Const.RADIUS);
lobbies = new ArrayList<LobbyBanner>();
// Add the listeners for the screens.
this.addMouseListener(newlobbyButton.new BasicMouseListener());
this.addMouseMotionListener(newlobbyButton.new InsideButtonMotionListener());
this.addMouseListener(backButton.new BasicMouseListener());
this.addMouseMotionListener(backButton.new InsideButtonMotionListener());
this.addMouseListener(nameField.new BasicMouseListener());
this.addMouseMotionListener(nameField.new InsideButtonMotionListener());
this.addKeyListener(new NameKeyListener());
this.setFocusable(true);
this.addComponentListener(this.FOCUS_WHEN_SHOWN);
}
public void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
this.newlobbyButton.draw(graphics);
this.backButton.draw(graphics);
this.nameField.draw(graphics);
this.playerName.draw(graphics);
for (LobbyBanner lobbyBanner: lobbies) {
lobbyBanner.draw(graphics);
}
}
public ArrayList<LobbyBanner> lobbies() {
return this.lobbies;
}
public String name(){
return this.playerName.getText();
}
public void newLobbyBanner(String lobbyName, String playerCount, int y) {
LobbyBanner lobbyBanner = new LobbyBanner(lobbyName, playerCount, y, this.playerName.getText());
this.addMouseListener(lobbyBanner.joinButton().new BasicMouseListener());
this.addMouseMotionListener(lobbyBanner.joinButton().new InsideButtonMotionListener());
lobbies.add(lobbyBanner);
}
public final ComponentAdapter FOCUS_WHEN_SHOWN = new ComponentAdapter(){
public void componentShown(ComponentEvent event){
requestFocusInWindow();
}
};
private class LobbyBanner{
private Text name;
private Text playerCount;
private ServerButton joinButton;
private int y;
LobbyBanner(String name, String playerCount, int y, String playerName){
this.name = new Text(name, Const.LOBBY_BANNER_BUTTON_FONT, Const.LARGE_BUTTON_FONT_COLOR, 0, y);
this.name.setX(Const.LOBBY_INFO_X); // Setting x's after so that they always line up no matter how long the name is
this.playerCount = new Text(playerCount, Const.LOBBY_BANNER_BUTTON_FONT, Const.LARGE_BUTTON_FONT_COLOR, 0, y + Const.LOBBY_COUNT_Y_DIFFERENCE);
this.playerCount.setX(Const.LOBBY_INFO_X); // Setting x's after so that they always line up no matter how long the name is
this.y = y;
Text joinText = new Text("Join", Const.LOBBY_BANNER_BUTTON_FONT, Const.LARGE_BUTTON_FONT_COLOR, Const.LOBBY_JOIN_X, y + Const.LOBBY_JOIN_Y_DIFFERENCE);
String joinCommand = Const.JOIN_LOBBY + " " + name;
this.joinButton = new ServerButton(window, output, joinText, joinCommand, Const.SMALL_BUTTON_IN_COLOR, Const.LARGE_BUTTON_BORDER_COLOR,
Const.SMALL_BUTTON_HOVER_COLOR, Const.LOBBY_JOIN_X, y + Const.LOBBY_JOIN_Y_DIFFERENCE, Const.RADIUS - 5);
}
public void draw(Graphics graphics){
graphics.setColor(Const.LARGE_BUTTON_IN_COLOR);
graphics.fillRoundRect(Const.LOBBY_BANNER_X, y, Const.LOBBY_BANNER_WIDTH, Const.LOBBY_BANNER_HEIGHT, Const.RADIUS, Const.RADIUS);
graphics.setColor(Const.LARGE_BUTTON_BORDER_COLOR);
graphics.drawRoundRect(Const.LOBBY_BANNER_X, y, Const.LOBBY_BANNER_WIDTH, Const.LOBBY_BANNER_HEIGHT, Const.RADIUS, Const.RADIUS);
name.draw(graphics);
playerCount.draw(graphics);
joinButton.draw(graphics);
}
public ServerButton joinButton(){
return this.joinButton;
}
}
public class NameKeyListener implements KeyListener {
public void keyPressed(KeyEvent event) {
int key = event.getKeyCode();
String newChar = Character.toString((char)key);
if (nameField.getStayHeld() == true){
String name = (playerName.getText());
if (name.length() <= Const.PLAYER_NAME_MAX_LENGTH && key != 8 && key != 32){ //8 is backspace, 32 is space, no spaces in name to not mess up networking
playerName.setText(name + newChar);
}
else if (key == 8 && playerName.getText().length() > 0){
playerName.setText(name.substring(0, (name.length() - 1)));
}
}
window.repaint();
}
public void keyReleased(KeyEvent event) {}
public void keyTyped(KeyEvent event) {}
}
}
public class AbilitySelectPanel extends ScreenPanel {
private ServerButton continueButton;
private ServerButton backButton;
// Button, Ability name
private AbilityButton passiveButton;
private AbilityButton abilityButton;
private AbilityButton ultimateButton;
private int currentAbility;
private ArrayList<AbilityButton> passiveBank;
private ArrayList<AbilityButton> abilityBank;
private ArrayList<AbilityButton> ultimateBank;
private ArrayList<ArrayList<AbilityButton>> banks;
private AbilityButton[] selectedAbilities;
public AbilitySelectPanel(Image backgroundSprite) {
super(backgroundSprite);
// Initialize the buttons.
Text continueText = new Text("Continue", Const.SMALL_BUTTON_FONT, Const.LARGE_BUTTON_FONT_COLOR, Const.CONTINUE_X, Const.GO_BACK_Y);
this.continueButton = new ServerButton(window, output, continueText, Const.SELECTED ,Const.SMALL_BUTTON_IN_COLOR, Const.LARGE_BUTTON_BORDER_COLOR,
Const.SMALL_BUTTON_HOVER_COLOR, Const.CONTINUE_X, Const.GO_BACK_Y, Const.RADIUS);
Text backText = new Text("Go back", Const.SMALL_BUTTON_FONT, Const.LARGE_BUTTON_FONT_COLOR, Const.GO_BACK_X, Const.GO_BACK_Y);
this.backButton = new ServerButton(window, output, backText, Const.LEAVE, Const.SMALL_BUTTON_IN_COLOR, Const.LARGE_BUTTON_BORDER_COLOR,
Const.SMALL_BUTTON_HOVER_COLOR, Const.GO_BACK_X, Const.GO_BACK_Y, Const.RADIUS);
this.passiveButton = new AbilityButton(window, Const.BLANK_ABILITY_IMAGE, Const.LARGE_BUTTON_BORDER_COLOR, "", null, Const.SELECTED_ABILITY_CENTER_X, 330, true);
this.abilityButton = new AbilityButton(window, Const.BLANK_ABILITY_IMAGE, Const.LARGE_BUTTON_BORDER_COLOR, "", null, Const.SELECTED_ABILITY_CENTER_X, 515, true);
this.ultimateButton = new AbilityButton(window, Const.BLANK_ABILITY_IMAGE, Const.LARGE_BUTTON_BORDER_COLOR, "", null, Const.SELECTED_ABILITY_CENTER_X, 710, true);
this.currentAbility = -1;
selectedAbilities = new AbilityButton[3];
selectedAbilities[0] = passiveButton; selectedAbilities[1] = abilityButton; selectedAbilities[2] = ultimateButton;
// Initializing the ability banks
int row = 0;
int column = 0;
this.passiveBank = new ArrayList<AbilityButton>();
for (String abilityName : Const.PASSIVE_IMAGES.keySet()) { // Adding all of the basic ability buttons
if(column == Const.MAX_ABILITES_PER_ROW){
column = 0;
row++;
}
Image passiveImage = Const.PASSIVE_IMAGES.get(abilityName);
Image passiveDescription = Const.PASSIVE_DESCRIPTIONS.get(abilityName);
AbilityButton button = new AbilityButton(window, passiveImage, Const.LARGE_BUTTON_BORDER_COLOR, abilityName, passiveDescription,
Const.ABILITY_BANK_X + (column * Const.ABILITY_X_DIFFERENCE), Const.PASSIVE_BANK_Y + (row * Const.ABILITY_Y_DIFFERENCE), false);
passiveBank.add(button);
this.addMouseListener(button.new BasicMouseListener());
this.addMouseMotionListener(button.new InsideButtonMotionListener());
column++;
}
this.abilityBank = new ArrayList<AbilityButton>();
row = 0;
column = 0;
for (String abilityName : Const.ABILITY_IMAGES.keySet()) { // Adding all of the basic ability buttons
if(column == Const.MAX_ABILITES_PER_ROW){
column = 0;
row++;
}
Image abilityImage = Const.ABILITY_IMAGES.get(abilityName);
Image abilityDescription = Const.ABILITY_DESCRIPTIONS.get(abilityName);
AbilityButton button = new AbilityButton(window, abilityImage, Const.LARGE_BUTTON_BORDER_COLOR, abilityName, abilityDescription,
Const.ABILITY_BANK_X + (column * Const.ABILITY_X_DIFFERENCE), Const.ABILITY_BANK_Y + (row * Const.ABILITY_Y_DIFFERENCE), false);
abilityBank.add(button);
this.addMouseListener(button.new BasicMouseListener());
this.addMouseMotionListener(button.new InsideButtonMotionListener());
column++;
}
this.ultimateBank = new ArrayList<AbilityButton>();
row = 0;
column = 0;
for (String ultimateName : Const.ULTIMATE_IMAGES.keySet()) { // Adding all of the ultimate ability buttons
if(column == Const.MAX_ABILITES_PER_ROW){
column = 0;
row++;
}
Image ultimateImage = Const.ULTIMATE_IMAGES.get(ultimateName);
Image ultimateDescription = Const.ULTIMATE_DESCRIPTIONS.get(ultimateName);
AbilityButton button = new AbilityButton(window, ultimateImage, Const.LARGE_BUTTON_BORDER_COLOR, ultimateName, ultimateDescription,
Const.ABILITY_BANK_X + (column * Const.ABILITY_X_DIFFERENCE), Const.ULTIMATE_BANK_Y + (row * Const.ABILITY_Y_DIFFERENCE), false);
ultimateBank.add(button);
this.addMouseListener(button.new BasicMouseListener());
this.addMouseMotionListener(button.new InsideButtonMotionListener());
column++;
}
banks = new ArrayList<ArrayList<AbilityButton>>(3);
banks.add(passiveBank); banks.add(abilityBank); banks.add(ultimateBank);
// Add the listeners for the screens.
this.addMouseListener(new SelectMouseListener());
this.addMouseListener(backButton.new BasicMouseListener());
this.addMouseMotionListener(backButton.new InsideButtonMotionListener());
this.addMouseListener(continueButton.new BasicMouseListener());
this.addMouseMotionListener(continueButton.new InsideButtonMotionListener());
this.addMouseListener(passiveButton.new BasicMouseListener());
this.addMouseMotionListener(passiveButton.new InsideButtonMotionListener());
this.addMouseListener(abilityButton.new BasicMouseListener());
this.addMouseMotionListener(abilityButton.new InsideButtonMotionListener());
this.addMouseListener(ultimateButton.new BasicMouseListener());
this.addMouseMotionListener(ultimateButton.new InsideButtonMotionListener());
this.setFocusable(true);
this.addComponentListener(this.FOCUS_WHEN_SHOWN);
}
public void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
this.backButton.draw(graphics);
this.continueButton.draw(graphics);
this.passiveButton.draw(graphics);
this.abilityButton.draw(graphics);
this.ultimateButton.draw(graphics);
for (AbilityButton button:passiveBank){
button.draw(graphics);
}
for (AbilityButton button:abilityBank){
button.draw(graphics);
}
for (AbilityButton button:ultimateBank){
button.draw(graphics);
}
// Only drawing description if an ability is selected
if(currentAbility != -1 && selectedAbilities[currentAbility].getDescription() != null){selectedAbilities[currentAbility].getDescription().draw(graphics, 851, 273);}
}
public final ComponentAdapter FOCUS_WHEN_SHOWN = new ComponentAdapter(){
public void componentShown(ComponentEvent event){
requestFocusInWindow();
}
};
public String abilities(){
return this.passiveButton.getName() + " " + this.abilityButton.getName() + " " + this.ultimateButton.getName();
}
private void switchSelectedAbility(int x, int y){
boolean switched = false;
for(int i = 0; i < selectedAbilities.length && !(switched); i++){
if(selectedAbilities[i].contains(x,y) && currentAbility != i){
if(i != currentAbility){
for(AbilityButton button: banks.get(i)){
button.setEnabled(true);
}
if(currentAbility != -1){
for(AbilityButton button: banks.get(currentAbility)){
button.setEnabled(false);
}
}
}
if (currentAbility != - 1){selectedAbilities[currentAbility].resetStayHeld();}
currentAbility = i;
switched = true;
}else if(selectedAbilities[i].contains(x,y) && currentAbility == i){
currentAbility = -1;
if (i == 2){
for (AbilityButton button:ultimateBank) {
button.setEnabled(false);
}
}
else{
for (AbilityButton button:abilityBank) {
button.setEnabled(false);
}
}
}
}
}
public void resetButtons(){ // To make sure if you hop inbetween lobbies mid ability selection old selections don't stay
for (AbilityButton button: passiveBank) {
button.setEnabled(false);
}
for (AbilityButton button: abilityBank) {
button.setEnabled(false);
}
for (AbilityButton button: ultimateBank) {
button.setEnabled(false);
}
for(AbilityButton button: selectedAbilities){
button.setImage(Const.BLANK_ABILITY_IMAGE);
button.setName("");
button.setDescription(null);
}
if(currentAbility != -1){
selectedAbilities[currentAbility].resetStayHeld();
currentAbility = -1;
}
}
public class SelectMouseListener implements MouseListener {
public void mouseClicked(MouseEvent event) {
int mouseX = event.getX();
int mouseY = event.getY();
// If mouse was pressed within selected abilities box
if (Const.SELECTED_ABILITES_BOX.contains(mouseX,mouseY)) {
switchSelectedAbility(mouseX, mouseY);
// If mouse was pressed within ability bank box
}else if (Const.PASSIVE_BANK_BOX.contains(mouseX,mouseY)) {
if(currentAbility == 0){
boolean swapped = false;
for (AbilityButton button: passiveBank) {
if(button.contains(mouseX, mouseY) && !(passiveButton.getName().equals(button.getName()))){ // Swapping selections
swapped = true;
passiveButton.setImage(button.getImage());
passiveButton.setName(button.getName());
passiveButton.setDescription(button.getDescription());
break;
}
}
if (swapped){ // Unselecting the other ability
for (AbilityButton button: passiveBank) {
if(!(passiveButton.getName().equals(button.getName()))){ // Swapping selections
button.resetStayHeld();
}
}
}
}
// If mouse was pressed within ultimate bank box
}else if (Const.ABILITY_BANK_BOX.contains(mouseX,mouseY)) {
if(currentAbility == 1){
boolean swapped = false;
for (AbilityButton button:abilityBank) {
if(button.contains(mouseX, mouseY) && !(abilityButton.getName().equals(button.getName()))){ // Swapping selections
swapped = true;
abilityButton.setImage(button.getImage());
abilityButton.setName(button.getName());
abilityButton.setDescription(button.getDescription());
break;
}
}
if (swapped){ // Unselecting the other ability
for (AbilityButton button:abilityBank) {
if(!(abilityButton.getName().equals(button.getName()))){ // Swapping selections
button.resetStayHeld();
}
}
}
}
// If mouse was pressed within ultimate bank box
}else if (Const.ULTIMATE_BANK_BOX.contains(mouseX,mouseY)) {
if(currentAbility == 2){
boolean swapped = false;
for (AbilityButton button:ultimateBank) {
if(button.contains(mouseX, mouseY) && !(ultimateButton.getName().equals(button.getName()))){ // Swapping selections
swapped = true;
ultimateButton.setImage(button.getImage());
ultimateButton.setName(button.getName());
ultimateButton.setDescription(button.getDescription());
break;
}
}
if (swapped){ // Unselecting the other ability
for (AbilityButton button:ultimateBank) {
if(!(ultimateButton.getName().equals(button.getName()))){ // Swapping selections
button.resetStayHeld();
}
}
}
}
}
}
public void mousePressed(MouseEvent event){}
public void mouseReleased(MouseEvent event){}
public void mouseEntered(MouseEvent event){}
public void mouseExited(MouseEvent event){}
}
}
public class LobbyPanel extends ScreenPanel {
private Text lobbyTitle;
private ServerButton readyButton;
private ServerButton backButton;
private ArrayList<PlayerBanner> playerBanners;
public LobbyPanel(Image backgroundSprite) {
super(backgroundSprite);
this.lobbyTitle = new Text("", Const.MENU_BUTTON_FONT, Const.LARGE_BUTTON_FONT_COLOR, Const.HALF_WIDTH, 125);
// Initialize the buttons.
Text readyText = new Text("Ready", Const.SMALL_BUTTON_FONT, Const.LARGE_BUTTON_FONT_COLOR, Const.CONTINUE_X, Const.GO_BACK_Y);
this.readyButton = new ServerButton(window, output, readyText, Const.READY ,Const.SMALL_BUTTON_IN_COLOR, Const.LARGE_BUTTON_BORDER_COLOR,
Const.SMALL_BUTTON_HOVER_COLOR, Const.CONTINUE_X, Const.GO_BACK_Y, Const.RADIUS);
Text backText = new Text("Go back", Const.SMALL_BUTTON_FONT, Const.LARGE_BUTTON_FONT_COLOR, Const.GO_BACK_X, Const.GO_BACK_Y);
this.backButton = new ServerButton(window, output, backText, Const.RESELECT, Const.SMALL_BUTTON_IN_COLOR, Const.LARGE_BUTTON_BORDER_COLOR,
Const.SMALL_BUTTON_HOVER_COLOR, Const.GO_BACK_X, Const.GO_BACK_Y, Const.RADIUS);
playerBanners = new ArrayList<PlayerBanner>();
// Add the listeners for the screens.
this.addMouseListener(readyButton.new BasicMouseListener());
this.addMouseMotionListener(readyButton.new InsideButtonMotionListener());
this.addMouseListener(backButton.new BasicMouseListener());
this.addMouseMotionListener(backButton.new InsideButtonMotionListener());
this.setFocusable(true);
this.addComponentListener(this.FOCUS_WHEN_SHOWN);
}
public void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
lobbyTitle.draw(graphics);
this.readyButton.draw(graphics);
this.backButton.draw(graphics);
for(int i = 0; i < playerBanners.size(); i++){
playerBanners.get(i).draw(graphics, Const.PLAYER_BANNER_START_X + (Const.PLAYER_BANNER_X_DIFFERENCE * i));
}
}
// Modifying playerBanners
public void newPlayerBanner(String playerName, String color) {
PlayerBanner playerBanner = new PlayerBanner(playerName, color);
playerBanners.add(playerBanner);
window.repaint();
}
public void updatePlayerBanner(String playerName, String passive, String ability, String ultimate) {
for (PlayerBanner playerBanner: playerBanners){
if(playerBanner.name().equals(playerName)){
playerBanner.updateAbilities(passive, ability, ultimate);
break;
}
}
window.repaint();
}
public void updatePlayerBanner(String playerName, boolean ready) {
for (PlayerBanner playerBanner: playerBanners){
if(playerBanner.name().equals(playerName)){
playerBanner.updateReady(ready);
break;
}
}
window.repaint();
}
public void removePlayerBanner(String playerName) {
for (PlayerBanner player: playerBanners){
if(player.name().equals(playerName)){
playerBanners.remove(player);
break;
}
}
window.repaint();
}
public void resetBanners() {
for (PlayerBanner player: playerBanners){
player.updateReady(false);
}
}
public void clearBanners() {
playerBanners.clear();
}
public void updateLobbyTitle() {
this.lobbyTitle.setText(lobbyName + " lobby");
}
public final ComponentAdapter FOCUS_WHEN_SHOWN = new ComponentAdapter(){
public void componentShown(ComponentEvent event){
requestFocusInWindow();
}
};
private class PlayerBanner{
private Text name;
private Image playerImage;
private Image passive;
private Image ability;
private Image ultimate;
private boolean ready;
PlayerBanner(String name, String color){
this.name = new Text(name, Const.LOBBY_BANNER_BUTTON_FONT, Const.LARGE_BUTTON_FONT_COLOR, 0, Const.PLAYER_BANNER_Y + 20);
this.playerImage = Const.PLAYER_ICONS.get(color);
this.passive = Const.BLANK_ABILITY_IMAGE;
this.ability = Const.BLANK_ABILITY_IMAGE;
this.ultimate = Const.BLANK_ABILITY_IMAGE;
}
public void draw(Graphics graphics, int centerX){
graphics.setColor(Const.LARGE_BUTTON_BORDER_COLOR);
graphics.fillRoundRect(centerX - Const.PLAYER_BANNER_WIDTH/2, Const.PLAYER_BANNER_Y, Const.PLAYER_BANNER_WIDTH, Const.PLAYER_BANNER_HEIGHT, Const.RADIUS, Const.RADIUS);
name.setCenterX(centerX);
name.draw(graphics);
playerImage.draw(graphics, centerX - playerImage.getWidth()/2, Const.PLAYER_BANNER_IMAGE_Y);
passive.draw(graphics, centerX - passive.getWidth()/2, Const.PLAYER_BANNER_ABILITY1_Y);
ability.draw(graphics, centerX - ability.getWidth()/2, Const.PLAYER_BANNER_ABILITY2_Y);
ultimate.draw(graphics, centerX - ultimate.getWidth()/2, Const.PLAYER_BANNER_ULTIMATE_Y);
Text readyText;
if(ready){
readyText = new Text("Ready", Const.SMALL_BUTTON_FONT, Color.GREEN, centerX, Const.READY_TEXT_Y);
readyText.draw(graphics);
}
else if (!(ready)){
readyText = new Text("Not Ready", Const.SMALL_BUTTON_FONT, Color.RED, centerX, Const.READY_TEXT_Y);
readyText.draw(graphics);
}
}
public String name(){
return this.name.getText();
}
public void updateAbilities(String passive, String ability, String ultimate){
this.passive = Const.PASSIVE_IMAGES.get(passive);
this.ability = Const.ABILITY_IMAGES.get(ability);
this.ultimate = Const.ULTIMATE_IMAGES.get(ultimate);
}
public void updateReady(boolean ready){
this.ready = ready;
}
}
}
public class GamePanel extends ScreenPanel {
private String passive;
private String ability;
private String ultimate;
private String[] abilities = new String[3];
private HashMap<String, Image> abilityImages;
private HashMap<String, Boolean> abilitiesReady;
private ArrayList<Player> players;
private ArrayList<Enemy> enemies;
private char[][] currentFov;
private char[][] newFov;
private String myName;
private Player currentPlayer; // Player that is currently being spectated
private int mapX; // X coordinate of top left tile of map that is being drawn on screen
private int mapY; // Y coordinate of top left tile of map that is being drawn on screen
private boolean alive; // If the clients player is alive
public GamePanel(Image backgroundSprite) {
super(backgroundSprite);
passive = Const.PASSIVE; ability = Const.ABILITY; ultimate = Const.ULTIMATE;
abilities[0] = passive; abilities[1] = ability; abilities[2] = ultimate;
abilityImages = new HashMap<String, Image>();
players = new ArrayList<Player>();
enemies = new ArrayList<Enemy>();
abilityImages.put(passive, Const.BLANK_ABILITY_IMAGE); abilityImages.put(ability, Const.BLANK_ABILITY_IMAGE); abilityImages.put(ultimate, Const.BLANK_ABILITY_IMAGE);
abilitiesReady = new HashMap<String, Boolean>();
abilitiesReady.put(passive, true); abilitiesReady.put(ability, true); abilitiesReady.put(ultimate, true);
alive = true;
// Add the listeners for the screens.
this.addKeyListener(new GameKeyListener());
this.addMouseListener(new GameMouseListener());
this.setFocusable(true);
this.addComponentListener(this.FOCUS_WHEN_SHOWN);
}
public void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
// Drawing player info bar on bottom middle of screen
drawMap(graphics);
drawPlayers(graphics);
drawEnemies(graphics);
if(alive){ // If client is alive draw the ability UI
graphics.setColor(Const.LARGE_BUTTON_BORDER_COLOR);
graphics.fillRoundRect((int)Const.PLAYER_INFO_RECT.getX(), (int)Const.PLAYER_INFO_RECT.getY(), (int)Const.PLAYER_INFO_RECT.getWidth(), (int)Const.PLAYER_INFO_RECT.getHeight(), Const.RADIUS, Const.RADIUS);
int counter = 0;
Const.PLAYER_ICONS.get(currentPlayer.color).draw(graphics, Const.HALF_WIDTH - 210, Const.ABILITIES_Y);
for(String ability: abilities){
if(abilitiesReady.get(ability)){
abilityImages.get(ability).draw(graphics, Const.ABILITY_1_X + (counter * Const.ABILITIES_X_DIFFERENCE), Const.ABILITIES_Y);
}else{
Const.BLANK_ABILITY_IMAGE.draw(graphics, Const.ABILITY_1_X + (counter * Const.ABILITIES_X_DIFFERENCE), Const.ABILITIES_Y);
}
counter++;
}
}
Const.GAME_TITLE.draw(graphics, 0, 0);
}
public void updateAbilityState(boolean abilityState){
this.abilitiesReady.replace(ability, !abilityState, abilityState);
}
public void updateUltimateState(boolean ultimateState){
this.abilitiesReady.replace(ultimate, !ultimateState, ultimateState);
}
public void setCurrentPlayer(String playerName){
this.myName = playerName;
for(Player player: players){
if(playerName.equals(player.name())){
currentPlayer = player;
break;
}
}
}
public void setAbilities(String passiveName, String abilityName, String ultimateName){
abilityImages.replace(passive, Const.PASSIVE_IMAGES.get(passiveName));
abilityImages.replace(ability, Const.ABILITY_IMAGES.get(abilityName));
abilityImages.replace(ultimate, Const.ULTIMATE_IMAGES.get(ultimateName));
}
private void drawMap(Graphics graphics){
if(currentFov != null){
for(int y = 0; y < currentFov.length; y++){
for(int x = 0; x < currentFov[y].length; x++){
Image tileImage = Const.TILE_IMAGES.get(currentFov[y][x]);
tileImage.draw(graphics, Const.HALF_WIDTH + mapX + (x * Const.TILE_DIMENSIONS) - currentPlayer.getX() - Const.PLAYER_DIMENSIONS/2,
Const.HALF_HEIGHT + mapY + (y * Const.TILE_DIMENSIONS) - currentPlayer.getY() - Const.PLAYER_DIMENSIONS/2);
}
}
}
Client.ServerWriter writer = new Client.ServerWriter(output);
writer.print(Const.DRAWN);
}