/
hangman.c
1015 lines (934 loc) · 38 KB
/
hangman.c
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
//*****************************************************************************
//
// David Rosales
// EID: dar542
// Lab Project 4
//
// The classic Hangman game with two game modes
//
//*****************************************************************************
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/pwm.h"
#include "driverlib/sysctl.h"
#include "drivers/rit128x96x4.h"
#include "inc/lm3s8962.h"
#include "inc/hw_gpio.h"
#include "utils/ustdlib.h"
#include "utils/ustdlib.c"
#include "inc/hw_ints.h"
#include "inc/hw_nvic.h"
#include "driverlib/interrupt.h"
#include "driverlib/systick.h"
//*****************************************************************************
//
// Initialize functions
//
//*****************************************************************************
extern void drawUnderscore(int x, int y);
extern void drawPointer(int y);
//*****************************************************************************
//
// Initialize global variables.
//
//*****************************************************************************
char *alpha[26] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
char *selected[26] = {"!","!","!","!","!","!","!","!","!","!","!","!","!","!","!","!","!","!","!","!","!","!","!","!","!","!"};
char *words[] = {"BOBCAT", "IRONMAN", "FOOTBALL", "CATFISH", "STOMACH", "TEXAS", "LONGHORNS", "CHRISTMAS", "SEAHORSE", "PEANUT"};
int wotd = -1;
int wordLen = 0;
volatile int position = 0;
volatile int position2 = 0;
volatile int score = 0;
volatile long x = 0;
volatile int state = 0;
volatile int try = 0;
volatile int pointer = 0;
volatile int pointer2 = 0;
volatile int correct = 0;
volatile int tick = 0;
volatile int done = 0;
volatile int classic = 0;
volatile int continuous = 0;
volatile int lose = 0;
static const unsigned char g_pucLogo1[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
static const unsigned char g_pucLogo2[] = {0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F};
static const unsigned char g_pucLogo3[] = {0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F};
static const unsigned char g_pucLogo4[] = {0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F};
static const unsigned char g_pucLogo5[] = {0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F};
static const unsigned char g_pucLogo6[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
static const unsigned char g_pucLogo7[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo8[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo9[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo10[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo11[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo12[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo13[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo14[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo15[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo16[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo17[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo18[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo19[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo20[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo21[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo22[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo23[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo24[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo25[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo26[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo27[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo28[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo29[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo30[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo31[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo32[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo33[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo34[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo35[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo36[] = {0x00, 0x00, 0xF0, 0x0F};
static const unsigned char g_pucLogo37[] = {0x00, 0x00, 0xF0, 0x0F, 0xF0};
static const unsigned char g_pucLogo38[] = {0x00, 0x00, 0xF0, 0x0F, 0x0F};
static const unsigned char g_pucLogo39[] = {0x00, 0x00, 0xF0, 0x0F, 0x00, 0xF0};
static const unsigned char g_pucLogo40[] = {0x00, 0x00, 0xF0, 0x0F, 0xF0, 0x0F};
static const unsigned char g_pucLogo41[] = {0x00, 0x00, 0xF0, 0x0F, 0x0F, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00};
static const unsigned char g_pucLogo42[] = {0x00, 0x00, 0xF0, 0x0F, 0x00, 0xF0, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00};
static const unsigned char g_pucLogo43[] = {0x00, 0x00, 0xF0, 0x0F, 0x00, 0x0F, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00};
static const unsigned char g_pucLogo44[] = {0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00};
static const unsigned char g_pucLogo45[] = {0x00, 0x00, 0xF0, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
static const unsigned char g_pucLogo46[] = {0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F};
static const unsigned char g_pucLogo47[] = {0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F};
static const unsigned char g_pucLogo48[] = {0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
static const unsigned char g_pucHangman1[] = {0xFF, 0xF0, 0x0F, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char g_pucHangman2[] = {0xF0, 0xF0, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char g_pucHangman3[] = {0xF0, 0xF0, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char g_pucHangman4[] = {0xF0, 0xF0, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char g_pucHangman5[] = {0xF0, 0xFF, 0xFF, 0x0F, 0x00, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, 0xF0, 0x00, 0x00, 0xFF, 0xF0, 0xFF, 0xF0, 0xFF, 0xF0, 0xFF, 0x00, 0x0F, 0xF0, 0x00, 0x00, 0xFF, 0xF0, 0xFF, 0xF0, 0xFF, 0xF0, 0xFF, 0x00, 0x00};
static const unsigned char g_pucHangman6[] = {0xF0, 0x00, 0x00, 0x0F, 0x00, 0xF0, 0x00, 0xFF, 0x0F, 0x0F, 0x0F, 0xF0, 0x0F, 0x00, 0x0F, 0x00, 0x0F, 0xF0, 0xF0, 0xF0, 0xFF, 0x00, 0xFF, 0xF0, 0x0F, 0x00, 0x0F, 0x00, 0x0F, 0xF0, 0xF0, 0xF0, 0xFF, 0x00, 0xF0, 0x00};
static const unsigned char g_pucHangman7[] = {0xF0, 0xFF, 0xFF, 0x0F, 0x0F, 0x00, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0xF0, 0xF0, 0x0F, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x0F, 0x00, 0x00, 0xF0, 0xF0, 0x0F, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0x0F, 0x00};
static const unsigned char g_pucHangman8[] = {0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x00, 0x0F, 0x0F, 0x00, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x00, 0xF0, 0xF0, 0x00, 0xFF, 0x0F, 0x00};
static const unsigned char g_pucHangman9[] = {0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x00, 0xF0, 0x0F, 0x0F, 0x0F, 0x00, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x00, 0x00, 0xF0, 0xF0, 0x0F, 0xF0, 0x00, 0xFF, 0x00, 0xF0, 0xF0, 0x0F, 0x00, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x0F, 0x00};
static const unsigned char g_pucHangman10[] ={0xF0, 0xF0, 0x0F, 0x0F, 0x00, 0xF0, 0x00, 0xFF, 0x0F, 0x0F, 0x0F, 0x00, 0xF0, 0xF0, 0x0F, 0x00, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x00, 0xF0, 0xF0, 0x0F, 0x00, 0x0F, 0xF0, 0xF0, 0xF0, 0xF0, 0x0F, 0x0F, 0x00};
static const unsigned char g_pucHangman11[] ={0xFF, 0xF0, 0x0F, 0xFF, 0x00, 0x0F, 0xFF, 0x0F, 0xFF, 0x0F, 0xFF, 0x00, 0xFF, 0xF0, 0x00, 0xFF, 0xF0, 0xF0, 0xF0, 0xFF, 0xF0, 0x0F, 0xFF, 0x00, 0xFF, 0xF0, 0x00, 0xFF, 0xF0, 0xFF, 0xF0, 0xFF, 0xF0, 0x0F, 0xFF, 0x00};
static const unsigned char g_pucHangman12[] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char g_pucHangman13[] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xF0, 0x00, 0xF0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char g_pucHangman14[] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x0F, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char g_pucHangman15[] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0xF0, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char g_pucHangman16[] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char g_pucHangman17[] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char g_pucHangman18[] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char g_pucHead1[] = {0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00};
static const unsigned char g_pucHead2[] = {0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00};
static const unsigned char g_pucHead3[] = {0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00};
static const unsigned char g_pucHead4[] = {0x00, 0xF0, 0x00, 0xFF, 0xFF, 0xF0, 0x00, 0xF0, 0x00};
static const unsigned char g_pucHead5[] = {0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00};
static const unsigned char g_pucHead6[] = {0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00};
static const unsigned char g_pucHead7[] = {0x0F, 0x00, 0xF0, 0xF0, 0x00, 0xF0, 0xF0, 0x0F, 0x00};
static const unsigned char g_pucHead8[] = {0x0F, 0x00, 0x0F, 0x00, 0x00, 0x0F, 0x00, 0x0F, 0x00};
static const unsigned char g_pucHead9[] = {0x0F, 0x00, 0xF0, 0xF0, 0x00, 0xF0, 0xF0, 0x0F, 0x00};
static const unsigned char g_pucHead10[] = {0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00};
static const unsigned char g_pucHead11[] = {0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00};
static const unsigned char g_pucHead12[] = {0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00};
static const unsigned char g_pucHead13[] = {0x00, 0x00, 0x0F, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00};
static const unsigned char g_pucUnderscoreClear[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const unsigned char g_pucPointer1[] = {0xF0, 0x00};
static const unsigned char g_pucPointer2[] = {0xFF, 0x00};
static const unsigned char g_pucPointer3[] = {0xFF, 0xF0};
static const unsigned char g_pucPointer4[] = {0xFF, 0xFF};
static const unsigned char g_pucPointer5[] = {0xFF, 0xF0};
static const unsigned char g_pucPointer6[] = {0xFF, 0x00};
static const unsigned char g_pucPointer7[] = {0xF0, 0x00};
static const unsigned char g_clearPointer[] = {0x00, 0x00};
static const unsigned char g_pucLeftArm[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xF0};
static const unsigned char g_pucRightArm[] = {0xFF, 0xFF, 0xFF, 0xFF};
static const unsigned char g_pucUnderscore[] = {0xFF, 0xFF, 0xF0};
static const unsigned char g_pucBody[] = {0xF0};
static const unsigned char g_pucLeg1[] = {0xF0};
static const unsigned char g_pucLeg2[] = {0x0F};
//*****************************************************************************
//
// Helper Functions
//
//*****************************************************************************
static void drawLogo(void){
// Method for displaying the Hangman logo
int x0 = (128-72)/2;
RIT128x96x4ImageDraw(g_pucHangman1, x0, 20, 72, 1);
RIT128x96x4ImageDraw(g_pucHangman2, x0, 21, 72, 1);
RIT128x96x4ImageDraw(g_pucHangman3, x0, 22, 72, 1);
RIT128x96x4ImageDraw(g_pucHangman4, x0, 23, 72, 1);
RIT128x96x4ImageDraw(g_pucHangman5, x0, 24, 72, 1);
RIT128x96x4ImageDraw(g_pucHangman6, x0, 25, 72, 1);
RIT128x96x4ImageDraw(g_pucHangman7, x0, 26, 72, 1);
RIT128x96x4ImageDraw(g_pucHangman8, x0, 27, 72, 1);
RIT128x96x4ImageDraw(g_pucHangman9, x0, 28, 72, 1);
RIT128x96x4ImageDraw(g_pucHangman10, x0, 29, 72, 1);
RIT128x96x4ImageDraw(g_pucHangman11, x0, 30, 72, 1);
RIT128x96x4ImageDraw(g_pucHangman12, x0, 31, 72, 1);
RIT128x96x4ImageDraw(g_pucHangman13, x0, 32, 72, 1);
RIT128x96x4ImageDraw(g_pucHangman14, x0, 33, 72, 1);
RIT128x96x4ImageDraw(g_pucHangman15, x0, 34, 72, 1);
RIT128x96x4ImageDraw(g_pucHangman16, x0, 35, 72, 1);
RIT128x96x4ImageDraw(g_pucHangman17, x0, 36, 72, 1);
RIT128x96x4ImageDraw(g_pucHangman18, x0, 37, 72, 1);
}
static void displayAlphabet(void){
// Method for displaying the alphabet on the bottom of the OLED
RIT128x96x4StringDraw("A", 0, 75, 15);
RIT128x96x4StringDraw("B", 10, 75, 15);
RIT128x96x4StringDraw("C", 20, 75, 15);
RIT128x96x4StringDraw("D", 30, 75, 15);
RIT128x96x4StringDraw("E", 40, 75, 15);
RIT128x96x4StringDraw("F", 50, 75, 15);
RIT128x96x4StringDraw("G", 60, 75, 15);
RIT128x96x4StringDraw("H", 70, 75, 15);
RIT128x96x4StringDraw("I", 80, 75, 15);
RIT128x96x4StringDraw("J", 90, 75, 15);
RIT128x96x4StringDraw("K", 100, 75, 15);
RIT128x96x4StringDraw("L", 110, 75, 15);
RIT128x96x4StringDraw("M", 120, 75, 15);
RIT128x96x4StringDraw("N", 0, 87, 15);
RIT128x96x4StringDraw("O", 10, 87, 15);
RIT128x96x4StringDraw("P", 20, 87, 15);
RIT128x96x4StringDraw("Q", 30, 87, 15);
RIT128x96x4StringDraw("R", 40, 87, 15);
RIT128x96x4StringDraw("S", 50, 87, 15);
RIT128x96x4StringDraw("T", 60, 87, 15);
RIT128x96x4StringDraw("U", 70, 87, 15);
RIT128x96x4StringDraw("V", 80, 87, 15);
RIT128x96x4StringDraw("W", 90, 87, 15);
RIT128x96x4StringDraw("X", 100, 87, 15);
RIT128x96x4StringDraw("Y", 110, 87, 15);
RIT128x96x4StringDraw("Z", 120, 87, 15);
}
static void drawGallow(void){
// method for displaying the gallow
RIT128x96x4ImageDraw(g_pucLogo1, 10, 50, 32, 1);
RIT128x96x4ImageDraw(g_pucLogo2, 10, 49, 32, 1);
RIT128x96x4ImageDraw(g_pucLogo3, 10, 48, 32, 1);
RIT128x96x4ImageDraw(g_pucLogo4, 10, 47, 32, 1);
RIT128x96x4ImageDraw(g_pucLogo5, 10, 46, 32, 1);
RIT128x96x4ImageDraw(g_pucLogo6, 10, 45, 32, 1);
RIT128x96x4ImageDraw(g_pucLogo7, 10, 44, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo8, 10, 43, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo9, 10, 42, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo10, 10, 41, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo11, 10, 40, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo12, 10, 39, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo13, 10, 38, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo14, 10, 37, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo15, 10, 36, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo16, 10, 35, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo17, 10, 34, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo18, 10, 33, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo19, 10, 32, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo20, 10, 31, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo21, 10, 30, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo22, 10, 29, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo23, 10, 28, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo24, 10, 27, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo25, 10, 26, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo26, 10, 25, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo27, 10, 24, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo28, 10, 23, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo29, 10, 22, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo30, 10, 21, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo31, 10, 20, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo32, 10, 19, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo33, 10, 18, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo34, 10, 17, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo35, 10, 16, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo36, 10, 15, 8, 1);
RIT128x96x4ImageDraw(g_pucLogo37, 10, 14, 10, 1);
RIT128x96x4ImageDraw(g_pucLogo38, 10, 13, 10, 1);
RIT128x96x4ImageDraw(g_pucLogo39, 10, 12, 12, 1);
RIT128x96x4ImageDraw(g_pucLogo40, 10, 11, 12, 1);
RIT128x96x4ImageDraw(g_pucLogo41, 10, 10, 28, 1);
RIT128x96x4ImageDraw(g_pucLogo42, 10, 9, 28, 1);
RIT128x96x4ImageDraw(g_pucLogo43, 10, 8, 28, 1);
RIT128x96x4ImageDraw(g_pucLogo44, 10, 7, 28, 1);
RIT128x96x4ImageDraw(g_pucLogo45, 10, 6, 32, 1);
RIT128x96x4ImageDraw(g_pucLogo46, 10, 5, 32, 1);
RIT128x96x4ImageDraw(g_pucLogo47, 10, 4, 32, 1);
RIT128x96x4ImageDraw(g_pucLogo48, 10, 3, 32, 1);
}
static void drawHead(void){
// Method for displaying the head of the hangman
RIT128x96x4ImageDraw(g_pucHead13, 28, 11, 18, 1);
RIT128x96x4ImageDraw(g_pucHead12, 28, 12, 18, 1);
RIT128x96x4ImageDraw(g_pucHead11, 28, 13, 18, 1);
RIT128x96x4ImageDraw(g_pucHead10, 28, 14, 18, 1);
RIT128x96x4ImageDraw(g_pucHead9, 28, 15, 18, 1);
RIT128x96x4ImageDraw(g_pucHead8, 28, 16, 18, 1);
RIT128x96x4ImageDraw(g_pucHead7, 28, 17, 18, 1);
RIT128x96x4ImageDraw(g_pucHead6, 28, 18, 18, 1);
RIT128x96x4ImageDraw(g_pucHead5, 28, 19, 18, 1);
RIT128x96x4ImageDraw(g_pucHead4, 28, 20, 18, 1);
RIT128x96x4ImageDraw(g_pucHead3, 28, 21, 18, 1);
RIT128x96x4ImageDraw(g_pucHead2, 28, 22, 18, 1);
RIT128x96x4ImageDraw(g_pucHead1, 28, 23, 18, 1);
}
static void drawBody(void){
// Method for displaying the body of the hangman
RIT128x96x4ImageDraw(g_pucBody, 36, 24, 2, 1);
RIT128x96x4ImageDraw(g_pucBody, 36, 25, 2, 1);
RIT128x96x4ImageDraw(g_pucBody, 36, 26, 2, 1);
RIT128x96x4ImageDraw(g_pucBody, 36, 27, 2, 1);
RIT128x96x4ImageDraw(g_pucBody, 36, 28, 2, 1);
RIT128x96x4ImageDraw(g_pucBody, 36, 29, 2, 1);
RIT128x96x4ImageDraw(g_pucBody, 36, 30, 2, 1);
RIT128x96x4ImageDraw(g_pucBody, 36, 31, 2, 1);
RIT128x96x4ImageDraw(g_pucBody, 36, 32, 2, 1);
}
static void drawLeftLeg(void){
// Method for displaying the left leg of the hangman
RIT128x96x4ImageDraw(g_pucLeg2, 36, 33, 2, 1);
RIT128x96x4ImageDraw(g_pucLeg1, 38, 34, 2, 1);
RIT128x96x4ImageDraw(g_pucLeg2, 38, 35, 2, 1);
RIT128x96x4ImageDraw(g_pucLeg1, 40, 36, 2, 1);
RIT128x96x4ImageDraw(g_pucLeg2, 40, 37, 2, 1);
RIT128x96x4ImageDraw(g_pucLeg1, 42, 38, 2, 1);
RIT128x96x4ImageDraw(g_pucLeg2, 42, 39, 2, 1);
RIT128x96x4ImageDraw(g_pucLeg1, 44, 40, 2, 1);
}
static void drawRightLeg(void){
// Method for displaying the right leg of the hangman
RIT128x96x4ImageDraw(g_pucLeg2, 34, 33, 2, 1);
RIT128x96x4ImageDraw(g_pucLeg1, 34, 34, 2, 1);
RIT128x96x4ImageDraw(g_pucLeg2, 32, 35, 2, 1);
RIT128x96x4ImageDraw(g_pucLeg1, 32, 36, 2, 1);
RIT128x96x4ImageDraw(g_pucLeg2, 30, 37, 2, 1);
RIT128x96x4ImageDraw(g_pucLeg1, 30, 38, 2, 1);
RIT128x96x4ImageDraw(g_pucLeg2, 28, 39, 2, 1);
RIT128x96x4ImageDraw(g_pucLeg1, 28, 40, 2, 1);
}
static void drawLeftArm(void){
// Method for displaying the left arm of the hangman
RIT128x96x4ImageDraw(g_pucLeftArm, 36, 27, 10, 1);
}
static void drawRightArm(void){
// Method for displaying the right arm of the handman
RIT128x96x4ImageDraw(g_pucRightArm, 28, 27, 8, 1);
}
static void drawUnderscore(int x, int y){
// Method for displaying an underline
RIT128x96x4ImageDraw(g_pucUnderscore, x, y, 6, 1);
}
static void removeUnderscore(int x, int y){
// Method for removing an underscore from the display
RIT128x96x4ImageDraw(g_pucUnderscoreClear, x, y, 128, 1);
}
static void moveCursor(void){
// Method for moving the cursor in the alphabet section.
// Cursor go on line 83 or 95
int a = position * 10;
int b = 83;
if (a>120){
int a2 = position2 * 10;
int b2 = 95;
removeUnderscore(0, 83);
removeUnderscore(0, 95);
drawUnderscore(a2, b2);
}
else {
removeUnderscore(0, 83);
removeUnderscore(0, 95);
drawUnderscore(a, b);
}
x = 0;
}
static void drawHiddenWord(void){
// Method for displaying underscores for each letter in the word
int num = abs(urand() % 10);
char *word = words[num];
int x = 10;
int y = 60;
int len = strlen(word);
int i;
for (i=0; i<len; i++){
drawUnderscore(x,y);
x += 10;
}
wotd = num;
wordLen = len;
}
static void initMain(void){
// Method for displaying the screen for the main menu
drawLogo();
RIT128x96x4StringDraw("Classic", 10, 50, 15);
RIT128x96x4StringDraw("Continuous", 10, 60, 15);
RIT128x96x4StringDraw("Instructions", 10, 70, 15);
RIT128x96x4StringDraw("High Scores", 10, 80, 15);
drawPointer(50);
}
static void drawPointer(int y){
// Method for drawing a pointer
RIT128x96x4ImageDraw(g_pucPointer1, 0, y, 4, 1);
RIT128x96x4ImageDraw(g_pucPointer2, 0, y+1, 4, 1);
RIT128x96x4ImageDraw(g_pucPointer3, 0, y+2, 4, 1);
RIT128x96x4ImageDraw(g_pucPointer4, 0, y+3, 4, 1);
RIT128x96x4ImageDraw(g_pucPointer5, 0, y+4, 4, 1);
RIT128x96x4ImageDraw(g_pucPointer6, 0, y+5, 4, 1);
RIT128x96x4ImageDraw(g_pucPointer7, 0, y+6, 4, 1);
}
static void clearPointer(int y){
// Method for clearing a pointer
int i;
for (i=0; i<50; i++){
RIT128x96x4ImageDraw(g_clearPointer, 0, y+i, 4, 15);
}
}
static void resetClassic(void){
// Method for resetting all the variables for the game
int i;
for (i=0; i<26; i++){
selected[i] = "!";
}
try = 0;
wotd = -1;
correct = 0;
position = 0;
position2 = 0;
RIT128x96x4Clear();
}
static void resetContinuous(void){
// Method for resetting all the variables for the game
int i;
for (i=0; i<26; i++){
selected[i] = "!";
}
wotd = -1;
correct = 0;
position = 0;
position2 = 0;
RIT128x96x4Clear();
}
static void startContinuous(void){
// Method for continuing the Continuous mode
resetContinuous();
drawGallow();
int i;
for (i=0; i<try; i++){
if (i==0){
drawHead();
}
else if (i==1){
drawBody();
}
else if (i==2){
drawRightArm();
}
else if (i==3){
drawLeftArm();
}
else if (i==4){
drawRightLeg();
}
}
static char puc_score[10];
usprintf(puc_score, "Score: %d", score);
RIT128x96x4StringDraw(puc_score, 69, 0, 15);
displayAlphabet();
drawUnderscore(0, 83);
drawHiddenWord();
}
static void startClassic(void){
// Method for starting the Classic mode
resetClassic();
drawGallow();
static char puc_score[10];
usprintf(puc_score, "Score: %d", score);
RIT128x96x4StringDraw(puc_score, 69, 0, 15);
displayAlphabet();
drawUnderscore(0, 83);
drawHiddenWord();
}
static void displayInstructions(void){
// Method for displaying instructions to the user
RIT128x96x4StringDraw("Uncover all the", 0, 0, 15);
RIT128x96x4StringDraw("hidden characters to!", 0, 10, 15);
RIT128x96x4StringDraw("complete each level!", 0, 20, 15);
RIT128x96x4StringDraw("To move the cursor,", 0, 40, 15);
RIT128x96x4StringDraw("press left or right.", 0, 50, 15);
RIT128x96x4StringDraw("To select a letter,", 0, 70, 15);
RIT128x96x4StringDraw("press select", 0, 80, 15);
}
static void displayScores(void){
// Method for displaying high scores
RIT128x96x4StringDraw("High Scores", 40, 0, 15);
static char s1[24];
usprintf(s1, "Classic Mode: %d", classic);
RIT128x96x4StringDraw(s1, 0, 40, 15);
static char s2[24];
usprintf(s2, "Continuous Mode: %d", continuous);
RIT128x96x4StringDraw(s2, 0, 60, 15);
}
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif
//*****************************************************************************
//
// Interrupt handlers
//
//*****************************************************************************
void
SysTickIntHandler(void){
// Handle state changes
if (done){
tick++;
if (tick>1){
if (lose){
// Turn off the noise
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, false);
PWMGenDisable(PWM0_BASE, PWM_GEN_0);
unsigned long ulPeriod = SysCtlClockGet() / 220;
// Set the PWM period to 220 (A) Hz.
PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod);
// Make some noise again
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
}
}
if (tick>2){
if (lose){
// Turn off the noise
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, false);
PWMGenDisable(PWM0_BASE, PWM_GEN_0);
unsigned long ulPeriod = SysCtlClockGet() / 440;
// Set the PWM period to 440 (A) Hz. again
PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod);
lose = 0;
}
if (state==1){
startClassic();
tick = 0;
done = 0;
}
else if(state==2){
if(tick>4){
RIT128x96x4Clear();
initMain();
state = 0;
pointer = 0;
tick = 0;
done = 0;
}
}
else if (state==3){
startContinuous();
tick = 0;
done = 0;
}
}
}
}
void
GPIOEIntHandler(void)
{
// Method for handling directional pad interrupts. The left and right
// buttons allow the user to move the alphabet cursor left and right. This
// behavior is handled here.
// Clear the GPIO interrupt
GPIOPinIntClear(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
// Disable Interrupts
GPIOPinIntDisable(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
if (state==0){
while(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_0)==0 ||
GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1)==0){
// Increment the counter
x++;
if (x>19999){
if (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_0)==0){
if (pointer!=0){
clearPointer(50+(pointer*10));
pointer--;
drawPointer(50+(pointer*10));
}
x = 0;
break;
}
if (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1)==0){
if (pointer!=3){
clearPointer(50+(pointer*10));
pointer++;
drawPointer(50+(pointer*10));
}
x = 0;
break;
}
}
}
x = 0;
}
else if (state==1 || state==3){
// Count to 15000 so that we don't move the cursor too fast
while(GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2)==0 ||
GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3)==0){
// Increment the counter
x++;
if (x>14999){
// Check to see which button was pressed
if (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2)==0){
// Check if the cursor is not in the original position on the
// top row. If it is, we do nothing
if (position>0){
// Check if the cursor is not in the original position on
// the bottom row
if (position2>0){
// Move the cursor one spot to the left
position2--;
}
else {
// Move the cursor one spot to the left
position--;
}
}
}
else if (GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3)==0){
// Check if the cursor is at the last possible position on the
// bottom row. If it is, we do nothing
if (position2<12){
// Check if the cursor is at the last spot on the top row
if (position<13){
// Move the cursor one spot to the right
position++;
}
else {
// Move the cursor one spot to the right
position2++;
}
}
}
// Update the position of the cursor
moveCursor();
break;
}
}
x = 0;
}
// Enable Interrupts
GPIOPinIntEnable(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
}
void
GPIOFIntHandler(void){
// Method for handling multiple functions for a select button press
// Clear the GPIO interrupt
GPIOPinIntClear(GPIO_PORTF_BASE, GPIO_PIN_1);
// Disable Interrupts
GPIOPinIntDisable(GPIO_PORTF_BASE, GPIO_PIN_1);
GPIOPinIntDisable(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
// Check which state we are in
if (state==0){
// This state handles the main menu
if (pointer==0){
// Begin Classic Mode
state = 1;
startClassic();
}
else if (pointer==1){
// Begin Continuous Mode
state = 3;
startClassic();
}
else if (pointer==2){
// Show the instructions
state = 2;
RIT128x96x4Clear();
displayInstructions();
done = 1;
}
else if (pointer==3){
// Show the high scores
state = 2;
RIT128x96x4Clear();
displayScores();
done = 1;
}
else if (pointer==4){
state = 0;
initMain();
}
}
else if (state==1){
// This state handles classic mode
// Black out the letter that was selected
int idx = position + position2;
int pos = 0;
char *puc_letter = alpha[idx];
if (idx>12){
pos = position2 * 10;
RIT128x96x4StringDraw(puc_letter, pos, 87, 2);
}
else {
pos = position * 10;
RIT128x96x4StringDraw(puc_letter, pos, 75, 2);
}
// Add the letter to the list of selected letters
int i;
int wrong = 1;
int used = 0;
// Loop through the list until we find an empty spot to place the letter
for (i=0; i<26; i++){
if (strcmp(selected[i],"!")==0){
selected[i] = puc_letter;
break;
}
if (strcmp(selected[i],puc_letter)==0){
wrong = 0;
used = 1;
break;
}
}
// Check to see if the letter was already used
if (!used){
// Check the word to see if a letter matches the one selected. If it
// does, we need to display the letters instead of an underscore
for (i=0; i<strlen(words[wotd]); i++){
char w_let = words[wotd][i];
static char g[3];
usprintf(g, "%d", w_let);
char p_let = *puc_letter;
if (w_let==p_let){
wrong = 0;
// Display the letter selected
RIT128x96x4StringDraw(puc_letter, 10+i*10, 53, 15);
correct++;
}
}
}
// Check to see if it was a wrong selection
if (wrong==1){
// Increment the number of wrong attempts
try++;
// If the selection was wrong, we need to draw a piece of the hangman
if (try==1){
drawHead();
}
else if (try==2){
drawBody();
}
else if (try==3){
drawRightArm();
}
else if (try==4){
drawLeftArm();
}
else if (try==5){
drawRightLeg();
}
else if (try==6){
drawLeftLeg();
RIT128x96x4StringDraw(" ", 0, 53, 15);
RIT128x96x4StringDraw(words[wotd], 20, 53, 2);
RIT128x96x4StringDraw("!!!!GAME OVER!!!", 23, 30, 15);
if (score > classic){
classic = score;
}
score = 0;
state = 2;
done = 1;
lose = 1;
// Make some noise
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
}
}
else if (correct==wordLen){
correct = 0;
RIT128x96x4StringDraw("!!!!YOU WON!!!!", 26, 30, 15);
score++;
done = 1;
}
}
else if (state==3){
// This state handles Continuous mode
// Black out the letter that was selected
int idx = position + position2;
int pos = 0;
char *puc_letter = alpha[idx];
if (idx>12){
pos = position2 * 10;
RIT128x96x4StringDraw(puc_letter, pos, 87, 2);
}
else {
pos = position * 10;
RIT128x96x4StringDraw(puc_letter, pos, 75, 2);
}
// Add the letter to the list of selected letters
int i;
int wrong = 1;
int used = 0;
// Loop through the list until we find an empty spot to place the letter
for (i=0; i<26; i++){
if (strcmp(selected[i],"!")==0){
selected[i] = puc_letter;
break;
}
if (strcmp(selected[i],puc_letter)==0){
wrong = 0;
used = 1;
break;
}
}
// Check to see if the letter was already used
if (!used){
// Check the word to see if a letter matches the one selected. If it
// does, we need to display the letters instead of an underscore
for (i=0; i<strlen(words[wotd]); i++){
char w_let = words[wotd][i];
static char g[3];
usprintf(g, "%d", w_let);
char p_let = *puc_letter;
if (w_let==p_let){
wrong = 0;
// Display the letter selected
RIT128x96x4StringDraw(puc_letter, 10+i*10, 53, 15);
correct++;
}
}
}
// Check to see if it was a wrong selection
if (wrong==1){
// Increment the number of wrong attempts
try++;
// If the selection was wrong, we need to draw a piece of the hangman
if (try==1){
drawHead();
}
else if (try==2){
drawBody();
}
else if (try==3){
drawRightArm();
}
else if (try==4){
drawLeftArm();
}
else if (try==5){
drawRightLeg();
}
else if (try==6){
drawLeftLeg();
RIT128x96x4StringDraw(" ", 0, 53, 15);
RIT128x96x4StringDraw(words[wotd], 20, 53, 2);
RIT128x96x4StringDraw("!!!!GAME OVER!!!", 23, 30, 15);
if (score > continuous){
continuous = score;
}
score = 0;
state = 2;
done = 1;
lose = 1;
// Make some noise
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
}
}
else if (correct==wordLen){
correct = 0;
RIT128x96x4StringDraw("!!!!YOU WON!!!!", 26, 30, 15);
score++;
done = 1;
}
}
// Enable Interrupts
GPIOPinIntEnable(GPIO_PORTF_BASE, GPIO_PIN_1);
GPIOPinIntEnable(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
}
//*****************************************************************************
//
// Main
//
//*****************************************************************************
int
main(void)
{
unsigned long ulPeriod;
// Set the clocking to run directly from the crystal.
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_8MHZ);
// Initialize the OLED display.
RIT128x96x4Init(1000000);
// Enable the peripherals used by this application
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
// Set GPIO F0 and G1 as PWM pins. They are used to output the PWM0 and
// PWM1 signals.
GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_1);
// Compute the PWM period based on the system clock.
ulPeriod = SysCtlClockGet() / 440;
// Set the PWM period to 440 (A) Hz.
PWMGenConfigure(PWM0_BASE, PWM_GEN_0,
PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod);
// Set PWM0 to a duty cycle of 25% and PWM1 to a duty cycle of 75%.
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, ulPeriod / 4);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, ulPeriod * 3 / 4);
// Enable the PWM0 and PWM1 output signals.
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true);
// Configure the 'up' button as input and enable the pin to interrupt on
// the falling edge (i.e. when the push button is pressed).
GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_0);
GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA,
GPIO_PIN_TYPE_STD_WPU);
// Configure the 'down' button as input and enable the pin to interrupt on
// the falling edge (i.e. when the push button is pressed).
GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_1);
GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA,
GPIO_PIN_TYPE_STD_WPU);
// Configure the 'left' button as input and enable the pin to interrupt on
// the falling edge (i.e. when the push button is pressed).
GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_2);
GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA,
GPIO_PIN_TYPE_STD_WPU);
// Configure the 'right' button as input and enable the pin to interrupt on
// the falling edge (i.e. when the push button is pressed).
GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_3);
GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA,
GPIO_PIN_TYPE_STD_WPU);
GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3,
GPIO_FALLING_EDGE);
GPIOPortIntRegister(GPIO_PORTE_BASE, GPIOEIntHandler);
GPIOPinIntEnable(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
IntEnable(INT_GPIOE);
// Configure the select buttons as input and enable the pin to interrupt on
// the falling edge (i.e. when the push button is pressed).
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1);
GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA,
GPIO_PIN_TYPE_STD_WPU);
GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_FALLING_EDGE);
GPIOPortIntRegister(GPIO_PORTF_BASE, GPIOFIntHandler);