-
Notifications
You must be signed in to change notification settings - Fork 0
/
magicSquare.java~
2195 lines (2146 loc) · 76.8 KB
/
magicSquare.java~
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
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/**
* <p>Title: CO32018 - Internet Programming - A Magic Square with a Hole</p>
*
* <p>Description: Using all 28 dominoes, form a rectangular array with a
* central hole. The sum of each <br /> of the eight rows and columns and the two
* diagonals must add up to 21. For rows, add whole <br />dominoes; for diagonals,
* add the 6 half dominoes from corner to corner</p>
*
* <p>Copyright: Ray Nimmo(c) 2006</p>
*
* <p>Version 1.8.9</p>
*
* <p>Author Ray Nimmo - 05005802</p>
*/
//complete - all dominoes drawn - all scores add up on horizontal and vertical lines
// - puzzle solve function complete
// - easy start function complete
//todo: screen flickers when moving dominoes - implement paint update function
//todo: implement a snap to position function for dominoes on board
public class magicSquare extends Applet implements MouseListener,MouseMotionListener{
public void init(){
setBackGround(); //call to draw background colour and set applet size
this.addMouseListener(this); //mouse listener added to board
this.addMouseMotionListener(this);//mouse motion listener added to board
initializeDominoes(); //call to initialize all dominoes
}
public void paint(Graphics g){
paintBoard(g); //call to draw all board areas and decorative effects
paintDominoes(g); //call to draw all dominoes to stockpile
puzzleSolved(g); //check for puzzle completion
//checks if user has attempted puzzle - or just clicked solve
if(showAttemptedMessage==true)if(removeAttemptedMessage==false)attemptMessage(g);
if(removeAttemptedMessage==true)resetAttempt();
if(showSolutionText==true)showSolutionClickedText(g);
if(showEasyStartText==true)showEasyStartClickedText(g);
}
// public void update (Graphics g)
// {
// paint(g);
// }
//////////////////////////////////////////////////////////////////////////////////
// DRAW FUNCTIONS FOR PLAYING BOARD
//////////////////////////////////////////////////////////////////////////////////
public void paintBoard(Graphics g){
drawPlayingBoard(g); //call to set background colour and size
drawBorders(g); //call to draw the coloured partition
drawStockpile(g); //call to draw the stockpile
drawAnswerAreas(g); //call to draw answer areas
countLineValues(g); //call to check scores - re-check on every paint
}
public void setBackGround(){
setBackground(Color.cyan); //sets playing board background colour
setSize(620,568); //sets size of applet
}
public void drawPlayingBoard(Graphics g){
/**
* contains all code relating to drawing the playing board
*/
g.setColor(Color.black);
x=15; //set up x to be the first x-co'ords of first box
for(int i=1;i<=4;i++){ //loop four times on the x-axis
y=15; //set up y to be the first y-co'ords of first box
for(int j=1;j<=8;j++){ //loop four times on the y-axis
if(y>183&&y<319&&x>109&&x<208){
//exclusion from drawing the central boxes by setting
//an exlusion zone around their co-ordinates. Initially
//used the drawBlank(g) function to overwrite with
//background colour. Found it works fine with no command
}
else drawPiece(g); //call to draw an 80*45 box on screen
y=y+61; //next loop increase y by 75
//this will loop on y-axis 8 times
}
x=x+96; //only reached after 8 loops on y-axis
//when reached increases x by 150 for next loop
//this moves cursor along then accesses y loop
//again for another 8 boxes on y-axis
}
}
public void drawBlank(Graphics g){ //***function not used at present***
g.setColor(Color.cyan); //draws a space on the board
g.drawRect(x,y,80,45); //set colour same as background so is not seen
}
public void drawPiece(Graphics g){
/**
* draws a domino placeholder area on board
*/
g.setColor(Color.blue);
g.drawRect(x,y,90,55); //draws a blue rectangle as placeholder
g.setColor(Color.red);
g.drawRect(x+1,y+1,88,53); //draws a red inside line to spaceholder
g.setColor(Color.yellow);
g.fillRect(x+2,y+2,86,51); //fills inside of placeholder yellow
}
public void drawAnswerAreas(Graphics g){
/**
* draws white space for scores for vertical,horizontal
* and diagonal scores
*/g.setColor(Color.white);
//answers for horizontal placeholders - shown on left of screen
g.drawRect(400,25,25,25); //first line - at top
g.fillRect(400,25,25,25);
g.drawRect(400,85,25,25); //second line
g.fillRect(400,85,25,25);
g.drawRect(400,148,25,25); //third line
g.fillRect(400,148,25,25);
g.drawRect(400,208,25,25); //fourth line
g.fillRect(400,208,25,25);
g.drawRect(400,270,25,25); //fifth line
g.fillRect(400,270,25,25);
g.drawRect(400,330,25,25); //sixth line
g.fillRect(400,330,25,25);
g.drawRect(400,391,25,25); //seventh line
g.fillRect(400,391,25,25);
g.drawRect(400,452,25,25); //eighth line - at bottom
g.fillRect(400,452,25,25);
//answers for vertical placeholders - shown at bottom of screen
g.drawRect(23,502,24,24); //first line - at left
g.fillRect(23,502,24,24);
g.drawRect(65,502,24,24); //second line
g.fillRect(65,502,24,24);
g.drawRect(120,502,25,25); //third line
g.fillRect(120,502,25,25);
g.drawRect(163,502,25,25); //fourth line
g.fillRect(163,502,25,25);
g.drawRect(216,502,25,25); //fifth line - at right
g.fillRect(216,502,25,25);
g.drawRect(259,502,25,25); //sixth line - at right
g.fillRect(259,502,25,25);
g.drawRect(313,502,25,25); //seventh line - at right
g.fillRect(313,502,25,25);
g.drawRect(354,502,25,25); //eighth line - at right
g.fillRect(354,502,25,25);
//answers for diagonal placeholders - shown in middle of board
g.drawRect(160,213,25,25); //diagonal score area from top left to bottom right
g.fillRect(160,213,25,25);
g.drawRect(216,213,25,25); //diagonal score area from top right to bottom left
g.fillRect(216,213,25,25);
}
public void drawBorders(Graphics g){
/**
* draws the red/yellow partitions around board - decoration only
*/
g.setColor(Color.red); //red line sections
g.drawLine(470,5,470,560); //middle vertical partition
g.drawLine(472,5,472,560);
g.drawLine(614,5,614,560); //right vertical border
g.drawLine(616,3,616,562);
g.drawLine(5,560,614,560); //bottom border
g.drawLine(3,562,616,562);
g.drawLine(3,3,616,3); //top border
g.drawLine(5,5,614,5);
g.drawLine(3,3,3,562); //left vertical border
g.drawLine(5,5,5,560);
g.setColor(Color.yellow); //yellow insets to lines
g.drawLine(471,5,471,561); //middle vertical partition
g.drawLine(615,5,615,561); //right vertical border
g.drawLine(5,561,615,561); //bottom border
g.drawLine(4,4,615,4); //top border
g.drawLine(4,4,4,561); //left vertical border
g.setColor(Color.red);
g.drawLine(156,199,244,315); //diagonal - top left to bottom right
g.drawLine(244,199,156,314); //diagonal top right to bottom left
//diagonal score labels in center of board
g.drawString("Diagonal",127,260);
g.drawString("Line Scores",222,260);
}
public void drawStockpile(Graphics g){
/**
* draws stockpile place on board
* - this is where all dominoes will originate from
*/
g.setColor(Color.red);
g.drawRect(505,225,80,45);
drawButtons(g);
}
public void drawButtons(Graphics g){
/**
* draws control buttons on right side of playing board
*/
g.setColor(Color.blue); //draws blue borders around buttons
g.drawRect(510,350,65,20);
g.drawRect(510,410,65,20);
g.drawRect(510,470,65,20);
g.setColor(Color.green); //fills button with green middle
g.fillRect(511,351,64,19);
g.fillRect(511,411,64,19);
g.fillRect(511,471,64,19);
g.setColor(Color.black); //draw text on buttons
g.drawString("Easy Start",515,365);
g.drawString("Solution",519,425);
g.drawString("Clear",526,485);
}
public void paintDominoes(Graphics g){
/**
* method contains all calls to paint each domino on board
*/
drawDomino66(g);
drawDomino64(g);
drawDomino35(g);
drawDomino56(g);
drawDomino20(g);
drawDominoZ3(g);
drawDominoDZ(g);
drawDomino10(g);
drawDominoZ4(g);
drawDomino55(g);
drawDomino45(g);
drawDomino44(g);
drawDomino43(g);
drawDomino63(g);
drawDomino33(g);
drawDomino62(g);
drawDomino52(g);
drawDomino14(g);
drawDomino24(g);
drawDomino32(g);
drawDomino22(g);
drawDomino50(g);
drawDomino61(g);
drawDomino15(g);
drawDomino11(g);
drawDominoZ6(g);
drawDomino21(g);
drawDomino13(g);
}
/////////////////////////////////////////////////////////////////////////////
// END OF DRAW FUNCTIONS FOR PLAYING BOARD
/////////////////////////////////////////////////////////////////////////////
public void initializeDominoes(){
/**
* method initializes each domino as a new Point()
*/
domino66=new Point(505,225);
domino64=new Point(505,225);
domino35=new Point(505,225);
domino56=new Point(505,225);
domino20=new Point(505,225);
dominoZ3=new Point(505,225);
dominoDZ=new Point(505,225);
domino10=new Point(505,225);
dominoZ4=new Point(505,225);
domino55=new Point(505,225);
domino45=new Point(505,225);
domino44=new Point(505,225);
domino43=new Point(505,225);
domino63=new Point(505,225);
domino33=new Point(505,225);
domino62=new Point(505,225);
domino52=new Point(505,225);
domino14=new Point(505,225);
domino24=new Point(505,225);
domino32=new Point(505,225);
domino50=new Point(505,225);
domino22=new Point(505,225);
domino61=new Point(505,225);
domino15=new Point(505,225);
domino11=new Point(505,225);
dominoZ6=new Point(505,225);
domino21=new Point(505,225);
domino13=new Point(505,225);
}
public void clearBoard(){
/**
* clears line scores and redraws all dominoes on stockpile
*/
initializeDominoes(); //call to redraw dominoes on stockpile
clearLineScores(); //call to reset all line scores
}
public void resetAttempt(){
/**
* reset boolean values relating to user attempts
*/
showAttemptedMessage=false;
removeAttemptedMessage=false;
}
public void getMousePoint(MouseEvent e){
/**
* called from mouse pressed and released methods
* - method contains all board area mappings
*/
getSelectedDomino(e); //call to read value of domino selected
/**
* all areas on board mapped out into selection areas
* processing for control of pieces to originate from nested if statements
*/
//510,350,x+65,y+20 - coordinates of "Easy Start" button
if((mouseX>510)&&(mouseX<575)&&(mouseY>350)&&(mouseY<370)){
clearBoard(); //call to reset board and scores
displayEasyStart(); //call to display 'Easy Start' option
showEasyStartText=true;
showSolutionText=false;
}
//510,410,x+65,y+20 - coordinates of "Solution" button
if((mouseX>510)&&(mouseX<575)&&(mouseY>410)&&(mouseY<430)){
showAttemptedMessage=false;
showSolutionText=true;
showEasyStartText=false;
checkAttempted(); //call to check if attempt has been made
}
//510,470,x+65,y+20 - coordinates of "Clear" button
if((mouseX>510)&&(mouseX<575)&&(mouseY>470)&&(mouseY<490)){
clearBoard(); //call to reset board and scores
showEasyStartText=false;
showSolutionText=false;
}
//491,501,x+109,y+39 - coordinates of 'let me try' button
if((mouseX>491)&&(mouseX<600)&&(mouseY>501)&&(mouseY<540)){
if(tryButtonEnabled==true){
clearBoard();
removeAttemptedMessage=true;
showSolutionText=false;
}
}
if((mouseX>614)&&(mouseX<616)&&(mouseY>4)&&(mouseY<6)){
clearBoard(); //microdot to allow programmer access to solution
try { //dot situated at top right corner of screen on red/yellow border
showSolution();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
//all board area mappings
//first horizontal row
if((mouseX>15)&&(mouseX<95)&&(mouseY>15)&&(mouseY<60)){
area01value_left=currentValue_left;
area01value_right=currentValue_right;
boardAreaValues_left[0]=area01value_left;
boardAreaValues_right[0]=area01value_right;
}else if((mouseX>110)&&(mouseX<190)&&(mouseY>15)&&(mouseY<60)){
area02value_left=currentValue_left;
area02value_right=currentValue_right;
boardAreaValues_left[1]=area02value_left;
boardAreaValues_right[1]=area02value_right;
}else if((mouseX>207)&&(mouseX<287)&&(mouseY>15)&&(mouseY<60)){
area03value_left=currentValue_left;
area03value_right=currentValue_right;
boardAreaValues_left[2]=area03value_left;
boardAreaValues_right[2]=area03value_right;
}else if((mouseX>303)&&(mouseX<383)&&(mouseY>15)&&(mouseY<60)){
area04value_left=currentValue_left;
area04value_right=currentValue_right;
boardAreaValues_left[3]=area04value_left;
boardAreaValues_right[3]=area04value_right;
//second horizontal row
}else if((mouseX>15)&&(mouseX<95)&&(mouseY>75)&&(mouseY<120)){
area05value_left=currentValue_left;
boardAreaValues_left[4]=area05value_left;
area05value_right=currentValue_right;
boardAreaValues_right[4]=area05value_right;
}else if((mouseX>110)&&(mouseX<190)&&(mouseY>75)&&(mouseY<120)){
area06value_left=currentValue_left;
boardAreaValues_left[5]=area06value_left;
area06value_right=currentValue_right;
boardAreaValues_right[5]=area06value_right;
}else if((mouseX>207)&&(mouseX<287)&&(mouseY>75)&&(mouseY<120)){
area07value_left=currentValue_left;
boardAreaValues_left[6]=area07value_left;
area07value_right=currentValue_right;
boardAreaValues_right[6]=area07value_right;
}else if((mouseX>303)&&(mouseX<383)&&(mouseY>75)&&(mouseY<120)){
area08value_left=currentValue_left;
boardAreaValues_left[7]=area08value_left;
area08value_right=currentValue_right;
boardAreaValues_right[7]=area08value_right;
//third horizontal row
}else if((mouseX>15)&&(mouseX<95)&&(mouseY>138)&&(mouseY<182)){
area09value_left=currentValue_left;
boardAreaValues_left[8]=area09value_left;
area09value_right=currentValue_right;
boardAreaValues_right[8]=area09value_right;
}else if((mouseX>110)&&(mouseX<190)&&(mouseY>138)&&(mouseY<182)){
area10value_left=currentValue_left;
boardAreaValues_left[9]=area10value_left;
area10value_right=currentValue_right;
boardAreaValues_right[9]=area10value_right;
}else if((mouseX>207)&&(mouseX<287)&&(mouseY>138)&&(mouseY<182)){
area11value_left=currentValue_left;
boardAreaValues_left[10]=area11value_left;
area11value_right=currentValue_right;
boardAreaValues_right[10]=area11value_right;
}else if((mouseX>303)&&(mouseX<383)&&(mouseY>138)&&(mouseY<182)){
area12value_left=currentValue_left;
boardAreaValues_left[11]=area12value_left;
area12value_right=currentValue_right;
boardAreaValues_right[11]=area12value_right;
//fourth horizontal row
}else if((mouseX>15)&&(mouseX<95)&&(mouseY>198)&&(mouseY<241)){
area13value_left=currentValue_left;
boardAreaValues_left[12]=area13value_left;
area13value_right=currentValue_right;
boardAreaValues_right[12]=area13value_right;
}else if((mouseX>303)&&(mouseX<383)&&(mouseY>198)&&(mouseY<241)){
area14value_left=currentValue_left;
boardAreaValues_left[13]=area14value_left;
area14value_right=currentValue_right;
boardAreaValues_right[13]=area14value_right;
//fifth horizontal row
}else if((mouseX>15)&&(mouseX<95)&&(mouseY>260)&&(mouseY<303)){
area15value_left=currentValue_left;
boardAreaValues_left[14]=area15value_left;
area15value_right=currentValue_right;
boardAreaValues_right[14]=area15value_right;
}else if((mouseX>303)&&(mouseX<383)&&(mouseY>260)&&(mouseY<303)){
area16value_left=currentValue_left;
boardAreaValues_left[15]=area16value_left;
area16value_right=currentValue_right;
boardAreaValues_right[15]=area16value_right;
//sixth horizontal row
}else if((mouseX>15)&&(mouseX<95)&&(mouseY>320)&&(mouseY<364)){
area17value_left=currentValue_left;
boardAreaValues_left[16]=area17value_left;
area17value_right=currentValue_right;
boardAreaValues_right[16]=area17value_right;
}else if((mouseX>110)&&(mouseX<190)&&(mouseY>320)&&(mouseY<364)){
area18value_left=currentValue_left;
boardAreaValues_left[17]=area18value_left;
area18value_right=currentValue_right;
boardAreaValues_right[17]=area18value_right;
}else if((mouseX>207)&&(mouseX<287)&&(mouseY>320)&&(mouseY<364)){
area19value_left=currentValue_left;
boardAreaValues_left[18]=area19value_left;
area19value_right=currentValue_right;
boardAreaValues_right[18]=area19value_right;
}else if((mouseX>303)&&(mouseX<383)&&(mouseY>320)&&(mouseY<364)){
area20value_left=currentValue_left;
boardAreaValues_left[19]=area20value_left;
area20value_right=currentValue_right;
boardAreaValues_right[19]=area20value_right;
//seventh horizontal row
}else if((mouseX>15)&&(mouseX<95)&&(mouseY>381)&&(mouseY<425)){
area21value_left=currentValue_left;
boardAreaValues_left[20]=area21value_left;
area21value_right=currentValue_right;
boardAreaValues_right[20]=area21value_right;
}else if((mouseX>110)&&(mouseX<190)&&(mouseY>381)&&(mouseY<425)){
area22value_left=currentValue_left;
boardAreaValues_left[21]=area22value_left;
area22value_right=currentValue_right;
boardAreaValues_right[21]=area22value_right;
}else if((mouseX>207)&&(mouseX<287)&&(mouseY>381)&&(mouseY<425)){
area23value_left=currentValue_left;
boardAreaValues_left[22]=area23value_left;
area23value_right=currentValue_right;
boardAreaValues_right[22]=area23value_right;
}else if((mouseX>303)&&(mouseX<383)&&(mouseY>381)&&(mouseY<425)){
area24value_left=currentValue_left;
boardAreaValues_left[23]=area24value_left;
area24value_right=currentValue_right;
boardAreaValues_right[23]=area24value_right;
//eighth horizontal row
}else if((mouseX>15)&&(mouseX<95)&&(mouseY>442)&&(mouseY<486)){
area25value_left=currentValue_left;
boardAreaValues_left[24]=area25value_left;
area25value_right=currentValue_right;
boardAreaValues_right[24]=area25value_right;
}else if((mouseX>110)&&(mouseX<190)&&(mouseY>442)&&(mouseY<486)){
area26value_left=currentValue_left;
boardAreaValues_left[25]=area26value_left;
area26value_right=currentValue_right;
boardAreaValues_right[25]=area26value_right;
}else if((mouseX>207)&&(mouseX<287)&&(mouseY>442)&&(mouseY<486)){
area27value_left=currentValue_left;
boardAreaValues_left[26]=area27value_left;
area27value_right=currentValue_right;
boardAreaValues_right[26]=area27value_right;
}else if((mouseX>303)&&(mouseX<383)&&(mouseY>442)&&(mouseY<486)){
area28value_left=currentValue_left;
boardAreaValues_left[27]=area28value_left;
area28value_right=currentValue_right;
boardAreaValues_right[27]=area28value_right;
}else{
}
}
public int setValue_left(int domValue_left) {
/**
* sets left side value of current domino selected
*/
currentValue_left=domValue_left;
return currentValue_left;
}
public int setValue_right(int domValue_right) {
/**
* sets right side value of current domino selected
*/
currentValue_right=domValue_right;
return currentValue_right;
}
public int getValue_left() {
/**
* method retrieves right side value of current domino selected
*/
currentValue_left=0;
if(select==100)domValue_left=0;
if(select==10)domValue_left=1;
if(select==20)domValue_left=2;
if(select==3)domValue_left=0;
if(select==4)domValue_left=0;
if(select==50)domValue_left=5;
if(select==6)domValue_left=0;
if(select==11)domValue_left=1;
if(select==21)domValue_left=2;
if(select==13)domValue_left=1;
if(select==14)domValue_left=1;
if(select==15)domValue_left=1;
if(select==61)domValue_left=6;
if(select==22)domValue_left=2;
if(select==32)domValue_left=3;
if(select==24)domValue_left=2;
if(select==52)domValue_left=5;
if(select==62)domValue_left=6;
if(select==33)domValue_left=3;
if(select==43)domValue_left=4;
if(select==35)domValue_left=3;
if(select==63)domValue_left=6;
if(select==44)domValue_left=4;
if(select==45)domValue_left=4;
if(select==64)domValue_left=6;
if(select==55)domValue_left=5;
if(select==56)domValue_left=5;
if(select==66)domValue_left=6;
setValue_left(domValue_left);
return domValue_left;
}
public int getValue_right() {
/**
* method retrieves right side value of current domino selected
*/
currentValue_right=0;
if(select==100)domValue_right=0;
if(select==10)domValue_right=0;
if(select==20)domValue_right=0;
if(select==3)domValue_right=3;
if(select==4)domValue_right=4;
if(select==50)domValue_right=0;
if(select==6)domValue_right=6;
if(select==11)domValue_right=1;
if(select==21)domValue_right=1;
if(select==13)domValue_right=3;
if(select==14)domValue_right=4;
if(select==15)domValue_right=5;
if(select==61)domValue_right=1;
if(select==22)domValue_right=2;
if(select==32)domValue_right=2;
if(select==24)domValue_right=4;
if(select==52)domValue_right=2;
if(select==62)domValue_right=2;
if(select==33)domValue_right=3;
if(select==43)domValue_right=3;
if(select==35)domValue_right=5;
if(select==63)domValue_right=3;
if(select==44)domValue_right=4;
if(select==45)domValue_right=5;
if(select==64)domValue_right=4;
if(select==55)domValue_right=5;
if(select==56)domValue_right=6;
if(select==66)domValue_right=6;
setValue_right(domValue_right);
return domValue_right;
}
public void getSelectedDomino(MouseEvent e){
/**
* method called when dominoes are selected
*/
if(mousePoint.x>domino66.x&&mousePoint.x<domino66.x+20&&
mousePoint.y>domino66.y&&mousePoint.y<domino66.y+20){
select=66;
completed=true;//completed message allowed when second last domino
//is taken from stockpile
}
if(mousePoint.x>domino64.x&&mousePoint.x<domino64.x+20&&
mousePoint.y>domino64.y&&mousePoint.y<domino64.y+20)select=64;
if(mousePoint.x>domino35.x&&mousePoint.x<domino35.x+80&&
mousePoint.y>domino35.y&&mousePoint.y<domino35.y+45)select=35;
if(mousePoint.x>domino56.x&&mousePoint.x<domino56.x+80&&
mousePoint.y>domino56.y&&mousePoint.y<domino56.y+45)select=56;
if(mousePoint.x>domino20.x&&mousePoint.x<domino20.x+80&&
mousePoint.y>domino20.y&&mousePoint.y<domino20.y+45)select=20;
if(mousePoint.x>dominoZ3.x&&mousePoint.x<dominoZ3.x+80&&
mousePoint.y>dominoZ3.y&&mousePoint.y<dominoZ3.y+45)select=3;
if(mousePoint.x>dominoDZ.x&&mousePoint.x<dominoDZ.x+80&&
mousePoint.y>dominoDZ.y&&mousePoint.y<dominoDZ.y+45)select=100;
if(mousePoint.x>domino10.x&&mousePoint.x<domino10.x+80&&
mousePoint.y>domino10.y&&mousePoint.y<domino10.y+45)select=10;
if(mousePoint.x>dominoZ4.x&&mousePoint.x<dominoZ4.x+80&&
mousePoint.y>dominoZ4.y&&mousePoint.y<dominoZ4.y+45)select=4;
if(mousePoint.x>domino55.x&&mousePoint.x<domino55.x+80&&
mousePoint.y>domino55.y&&mousePoint.y<domino55.y+45)select=55;
if(mousePoint.x>domino45.x&&mousePoint.x<domino45.x+80&&
mousePoint.y>domino45.y&&mousePoint.y<domino45.y+45)select=45;
if(mousePoint.x>domino44.x&&mousePoint.x<domino44.x+80&&
mousePoint.y>domino44.y&&mousePoint.y<domino44.y+45)select=44;
if(mousePoint.x>domino43.x&&mousePoint.x<domino43.x+80&&
mousePoint.y>domino43.y&&mousePoint.y<domino43.y+45)select=43;
if(mousePoint.x>domino63.x&&mousePoint.x<domino63.x+80&&
mousePoint.y>domino63.y&&mousePoint.y<domino63.y+45)select=63;
if(mousePoint.x>domino33.x&&mousePoint.x<domino33.x+80&&
mousePoint.y>domino33.y&&mousePoint.y<domino33.y+45)select=33;
if(mousePoint.x>domino62.x&&mousePoint.x<domino62.x+80&&
mousePoint.y>domino62.y&&mousePoint.y<domino62.y+45)select=62;
if(mousePoint.x>domino52.x&&mousePoint.x<domino52.x+80&&
mousePoint.y>domino52.y&&mousePoint.y<domino52.y+45)select=52;
if(mousePoint.x>domino14.x&&mousePoint.x<domino14.x+80&&
mousePoint.y>domino14.y&&mousePoint.y<domino14.y+45)select=14;
if(mousePoint.x>domino24.x&&mousePoint.x<domino24.x+80&&
mousePoint.y>domino24.y&&mousePoint.y<domino24.y+45)select=24;
if(mousePoint.x>domino32.x&&mousePoint.x<domino32.x+80&&
mousePoint.y>domino32.y&&mousePoint.y<domino32.y+45)select=32;
if(mousePoint.x>domino22.x&&mousePoint.x<domino22.x+80&&
mousePoint.y>domino22.y&&mousePoint.y<domino22.y+45)select=22;
if(mousePoint.x>domino50.x&&mousePoint.x<domino50.x+80&&
mousePoint.y>domino50.y&&mousePoint.y<domino50.y+45)select=50;
if(mousePoint.x>domino61.x&&mousePoint.x<domino61.x+80&&
mousePoint.y>domino61.y&&mousePoint.y<domino61.y+45)select=61;
if(mousePoint.x>domino15.x&&mousePoint.x<domino15.x+80&&
mousePoint.y>domino15.y&&mousePoint.y<domino15.y+45)select=15;
if(mousePoint.x>domino11.x&&mousePoint.x<domino11.x+80&&
mousePoint.y>domino11.y&&mousePoint.y<domino11.y+45)select=11;
if(mousePoint.x>dominoZ6.x&&mousePoint.x<dominoZ6.x+80&&
mousePoint.y>dominoZ6.y&&mousePoint.y<dominoZ6.y+45)select=6;
if(mousePoint.x>domino21.x&&mousePoint.x<domino21.x+80&&
mousePoint.y>domino21.y&&mousePoint.y<domino21.y+45)select=21;
if(mousePoint.x>domino13.x&&mousePoint.x<domino13.x+80&&
mousePoint.y>domino13.y&&mousePoint.y<domino13.y+45)select=13;
}
public void displayEasyStart(){
/**
* method fills 6 areas of board for puzzle 'easy start'
*/
assignArea_a4();
assignArea_a1();
assignArea_d1();
assignArea_d4();
assignArea_h1();
assignArea_h4();
}
public void showSolution() throws InterruptedException{
/**
* method fills all areas of board to reveal solution
*/
assignArea_a1();
assignArea_a2();
assignArea_a3();
assignArea_a4();
assignArea_b1();
assignArea_b2();
assignArea_b3();
assignArea_b4();
assignArea_c1();
assignArea_c2();
assignArea_c3();
assignArea_c4();
assignArea_d1();
assignArea_d4();
assignArea_e1();
assignArea_e4();
assignArea_f1();
assignArea_f2();
assignArea_f3();
assignArea_f4();
assignArea_g1();
assignArea_g2();
assignArea_g3();
assignArea_g4();
assignArea_h1();
assignArea_h2();
assignArea_h3();
assignArea_h4();
completed=false;
}
////////////////////////////////////////////////////////////////////////////////////
// methods below deal with all mouse events
///////////////////////////////////////////////////////////////////////////////////
public void mousePressed(MouseEvent e){
mouseX=e.getX(); // when mouse pressed retrieve
mouseY=e.getY(); // x&y co-ords for processing
mousePoint=e.getPoint();
getMousePoint(e);
getValues();
}
public void getValues(){
getValue_left();
getValue_right();
}
public void mouseDragged(MouseEvent e){
mousePoint=e.getPoint();
if(select==66)domino66=mousePoint;
if(select==64)domino64=mousePoint;
if(select==35)domino35=mousePoint;
if(select==56)domino56=mousePoint;
if(select==20)domino20=mousePoint;
if(select==3)dominoZ3=mousePoint;
if(select==100)dominoDZ=mousePoint;
if(select==10)domino10=mousePoint;
if(select==4)dominoZ4=mousePoint;
if(select==55)domino55=mousePoint;
if(select==45)domino45=mousePoint;
if(select==44)domino44=mousePoint;
if(select==43)domino43=mousePoint;
if(select==63)domino63=mousePoint;
if(select==33)domino33=mousePoint;
if(select==62)domino62=mousePoint;
if(select==52)domino52=mousePoint;
if(select==14)domino14=mousePoint;
if(select==24)domino24=mousePoint;
if(select==32)domino32=mousePoint;
if(select==50)domino50=mousePoint;
if(select==22)domino22=mousePoint;
if(select==61)domino61=mousePoint;
if(select==15)domino15=mousePoint;
if(select==11)domino11=mousePoint;
if(select==6)dominoZ6=mousePoint;
if(select==21)domino21=mousePoint;
if(select==13)domino13=mousePoint;
repaint();
}
public void mouseReleased(MouseEvent e){
mouseX=e.getX(); // when mouse pressed retrieve
mouseY=e.getY(); // x&y co-ords for processing
mousePoint=e.getPoint();
getMousePoint(e);
repaint();
select=0;
domValue_left=0;
currentValue_left=0;
domValue_right=0;
currentValue_right=0;
}
//mouse events added for interface
public void mouseEntered(MouseEvent e){}
public void mouseOver(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseMoved(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
/**
* methods below deal with completion of board for
* 'easy start' and 'solution' functions
*/
public void assignArea_a1(){ //first horizontal line solution
domino22.x=20;
domino22.y=20;
area01value_left=2;
area01value_right=2;
boardAreaValues_left[0]=area01value_left;
boardAreaValues_right[0]=area01value_right;
}
public void assignArea_a2(){
domino13.x=115;
domino13.y=20;
area02value_left=1;
area02value_right=3;
boardAreaValues_left[1]=area02value_left;
boardAreaValues_right[1]=area02value_right;
}
public void assignArea_a3(){
domino64.x=212;
domino64.y=20;
area03value_left=6;
area03value_right=4;
boardAreaValues_left[2]=area03value_left;
boardAreaValues_right[2]=area03value_right;
}
public void assignArea_a4(){
dominoZ3.x=308;
dominoZ3.y=20;
area04value_left=0;
area04value_right=3;
boardAreaValues_left[3]=area04value_left;
boardAreaValues_right[3]=area04value_right;
}
public void assignArea_b1(){ //second horizontal line solution
domino14.x=20;
domino14.y=80;
area05value_left=1;
area05value_right=4;
boardAreaValues_left[4]=area05value_left;
boardAreaValues_right[4]=area05value_right;
}
public void assignArea_b2(){
domino15.x=115;
domino15.y=80;
area06value_left=1;
area06value_right=5;
boardAreaValues_left[5]=area06value_left;
boardAreaValues_right[5]=area06value_right;
}
public void assignArea_b3(){
domino62.x=212;
domino62.y=80;
area07value_left=6;
area07value_right=2;
boardAreaValues_left[6]=area07value_left;
boardAreaValues_right[6]=area07value_right;
}
public void assignArea_b4(){
domino20.x=308;
domino20.y=80;
area08value_left=2;
area08value_right=0;
boardAreaValues_left[7]=area08value_left;
boardAreaValues_right[7]=area08value_right;
}
public void assignArea_c1(){ //third horizontal line solution
domino10.x=20;
domino10.y=142;
area09value_left=1;
area09value_right=0;
boardAreaValues_left[8]=area09value_left;
boardAreaValues_right[8]=area09value_right;
}
public void assignArea_c2(){
domino44.x=115;
domino44.y=142;
area10value_left=4;
area10value_right=4;
boardAreaValues_left[9]=area10value_left;
boardAreaValues_right[9]=area10value_right;
}
public void assignArea_c3(){
domino24.x=212;
domino24.y=142;
area11value_left=2;
area11value_right=4;
boardAreaValues_left[10]=area11value_left;
boardAreaValues_right[10]=area11value_right;
}
public void assignArea_c4(){
domino33.x=308;
domino33.y=142;
area12value_left=3;
area12value_right=3;
boardAreaValues_left[11]=area12value_left;
boardAreaValues_right[11]=area12value_right;
}
public void assignArea_d1(){ //fourth horizontal line solution
domino56.x=20;
domino56.y=203;
area13value_left=5;
area13value_right=6;
boardAreaValues_left[12]=area13value_left;
boardAreaValues_right[12]=area13value_right;
}
public void assignArea_d4(){
domino55.x=308;
domino55.y=203;
area14value_left=5;
area14value_right=5;
boardAreaValues_left[13]=area14value_left;
boardAreaValues_right[13]=area14value_right;
}
public void assignArea_e1(){ //fifth horizontal line solution
domino45.x=20;
domino45.y=265;
area15value_left=4;
area15value_right=5;
boardAreaValues_left[14]=area15value_left;
boardAreaValues_right[14]=area15value_right;
}
public void assignArea_e4(){
domino66.x=308;
domino66.y=265;
area16value_left=6;
area16value_right=6;
boardAreaValues_left[15]=area16value_left;
boardAreaValues_right[15]=area16value_right;
}
public void assignArea_f1(){ //sixth horizontal line solution
domino11.x=20;
domino11.y=325;
area17value_left=1;
area17value_right=1;
boardAreaValues_left[16]=area17value_left;
boardAreaValues_right[16]=area17value_right;
}
public void assignArea_f2(){
domino63.x=115;
domino63.y=325;
area18value_left=6;
area18value_right=3;
boardAreaValues_left[17]=area18value_left;
boardAreaValues_right[17]=area18value_right;
}
public void assignArea_f3(){
dominoZ6.x=212;
dominoZ6.y=325;
area19value_left=0;
area19value_right=6;
boardAreaValues_left[18]=area19value_left;
boardAreaValues_right[18]=area19value_right;
}
public void assignArea_f4(){
dominoZ4.x=308;
dominoZ4.y=325;
area20value_left=0;
area20value_right=4;
boardAreaValues_left[19]=area20value_left;
boardAreaValues_right[19]=area20value_right;
}
public void assignArea_g1(){ //seventh horizontal line solution
domino21.x=20;
domino21.y=386;
area21value_left=2;
area21value_right=1;
boardAreaValues_left[20]=area21value_left;
boardAreaValues_right[20]=area21value_right;
}
public void assignArea_g2(){
domino35.x=115;
domino35.y=386;
area22value_left=3;
area22value_right=5;
boardAreaValues_left[21]=area22value_left;
boardAreaValues_right[21]=area22value_right;
}
public void assignArea_g3(){
domino32.x=212;
domino32.y=386;
area23value_left=3;
area23value_right=2;
boardAreaValues_left[22]=area23value_left;
boardAreaValues_right[22]=area23value_right;
}
public void assignArea_g4(){
domino50.x=308;
domino50.y=386;
area24value_left=5;
area24value_right=0;
boardAreaValues_left[23]=area24value_left;
boardAreaValues_right[23]=area24value_right;
}
public void assignArea_h1(){ //eighth horizontal line solution
domino52.x=20;
domino52.y=447;
area25value_left=5;
area25value_right=2;
boardAreaValues_left[24]=area25value_left;
boardAreaValues_right[24]=area25value_right;
}
public void assignArea_h2(){
domino61.x=115;
domino61.y=447;
area26value_left=6;
area26value_right=1;
boardAreaValues_left[25]=area26value_left;
boardAreaValues_right[25]=area26value_right;
}
public void assignArea_h3(){
domino43.x=212;
domino43.y=447;
area27value_left=4;
area27value_right=3;
boardAreaValues_left[26]=area27value_left;
boardAreaValues_right[26]=area27value_right;
}
public void assignArea_h4(){
dominoDZ.x=308;
dominoDZ.y=447;
area28value_left=0;
area28value_right=0;
boardAreaValues_left[27]=area28value_left;