1
+ import pygame
2
+ import time
3
+ from threading import *
4
+ import SortingAlgorithm
5
+
6
+ class Clock (Thread ):
7
+ def __init__ (self ,screen ,CordinateX ,CordinateY ,font ,* args ):
8
+ Thread .__init__ (self )
9
+ self .screen = screen
10
+ self .CordinateX = CordinateX
11
+ self .CordinateY = CordinateY
12
+ self .ClockComplete = False
13
+ self .font = font
14
+ self .running = True
15
+ self .Clock = [0 ,0 ]
16
+ self .printTime = "00:00"
17
+
18
+ def run (self ):
19
+ try :
20
+ while (SortingAlgorithm .RunClock ):
21
+
22
+ pygame .font .init ()
23
+
24
+ myfont = pygame .font .SysFont ('Comic Sans MS' , self .font )
25
+ self .textsurface = myfont .render (self .printTime , False , (255 , 255 , 255 ))
26
+ self .screen .blit (self .textsurface , (self .CordinateX - 50 , self .CordinateY ))
27
+
28
+ myfont = pygame .font .SysFont ('Comic Sans MS' , self .font )
29
+ self .textsurface = myfont .render (" Time Escaped:" , False , (255 , 255 , 255 ))
30
+ self .screen .blit (self .textsurface , (self .CordinateX - 120 , self .CordinateY - 30 ))
31
+
32
+
33
+ time .sleep (1 )
34
+ if not SortingAlgorithm .RunClock :
35
+ break
36
+ textsurface = myfont .render (self .printTime , False , (0 , 0 , 0 ))
37
+ self .screen .blit (textsurface , (self .CordinateX - 50 , self .CordinateY ))
38
+
39
+
40
+ if not self .ClockComplete :
41
+
42
+ if self .Clock [1 ]== 59 :
43
+
44
+ self .Clock [0 ]+= 1
45
+ self .Clock [1 ]= 0
46
+ if len (str (self .Clock [0 ])) == 1 :
47
+ self .printTime = '0' + str (self .Clock [0 ])
48
+ else :
49
+ self .printTime = str (self .Clock [0 ])
50
+ self .printTime = str (self .Clock [0 ])+ ':' + '0' + str (self .Clock [1 ])
51
+
52
+ else :
53
+
54
+ self .Clock [1 ]+= 1
55
+ if len (str (self .Clock [0 ])) == 1 and len (str (self .Clock [1 ]))== 1 :
56
+ self .printTime = '0' + str (self .Clock [0 ])+ ':' + '0' + str (self .Clock [1 ])
57
+ elif len (str (self .Clock [1 ]))== 1 :
58
+ self .printTime = str (self .Clock [0 ])+ ':' + '0' + str (self .Clock [1 ])
59
+ elif len (str (self .Clock [0 ])) == 1 :
60
+ self .printTime = '0' + str (self .Clock [0 ]) + ':' + str (self .Clock [1 ])
61
+ else :
62
+ self .printTime = str (self .Clock [0 ])+ ':' + str (self .Clock [1 ])
63
+
64
+ myfont = pygame .font .SysFont ('Comic Sans MS' , self .font )
65
+ textsurface = myfont .render (self .printTime , False , (255 , 255 , 255 ))
66
+ self .screen .blit (textsurface , (self .CordinateX - 50 , self .CordinateY ))
67
+ except :
68
+ pass
69
+
70
+
71
+
72
+ class MainMenuButton (Thread ):
73
+ def __init__ (self ,screen ,CordinateX ,CordinateY ,* args ):
74
+ Thread .__init__ (self )
75
+ self .X = CordinateX
76
+ self .Y = CordinateY
77
+ self .screen = screen
78
+ self .CordinateX = CordinateX
79
+ self .CordinateY = CordinateY
80
+ self .ClockComplete = False
81
+
82
+ def run (self ):
83
+ try :
84
+ while (True ):
85
+ self .pos = pygame .mouse .get_pos ()
86
+
87
+ self .OnMainMenuButton = False
88
+ if self .pos [0 ] > self .X and self .pos [0 ] < self .X + 240 and self .pos [1 ] > self .Y and self .pos [1 ] < self .Y + 35 :
89
+ self .OnMainMenuButton = True
90
+
91
+ pygame .font .init ()
92
+
93
+ if self .OnMainMenuButton == False :
94
+ pygame .draw .rect (self .screen ,(255 ,255 ,255 ),(self .X ,self .Y ,240 ,35 ))
95
+ myfont = pygame .font .SysFont ('Comic Sans MS' , 20 )
96
+ textsurface = myfont .render ("Go Back to Main Menu" , False , (0 , 0 , 0 ))
97
+ self .screen .blit (textsurface , (self .X + 17 , self .Y ))
98
+ else :
99
+ pygame .draw .rect (self .screen ,(0 ,0 ,0 ),(self .X ,self .Y ,240 ,35 ))
100
+ pygame .draw .rect (self .screen ,(255 ,255 ,255 ),(self .X ,self .Y ,240 ,35 ),3 )
101
+ myfont = pygame .font .SysFont ('Comic Sans MS' , 20 )
102
+ textsurface = myfont .render ("Go Back to Main Menu" , False , (255 , 255 , 255 ))
103
+ self .screen .blit (textsurface , (self .X + 17 , self .Y ))
104
+
105
+ pygame .display .update ()
106
+ except :
107
+ pass
108
+
109
+
110
+
111
+ class OperationsDone :
112
+ def __init__ (self ,NoOfOperations ,screen ,X ,Y ):
113
+ try :
114
+ self .NoOfOperations = NoOfOperations
115
+ self .screen = screen
116
+ self .X = X
117
+ self .Y = Y
118
+ pygame .font .init ()
119
+
120
+ myfont = pygame .font .SysFont ('Comic Sans MS' , 20 )
121
+ textsurface = myfont .render ("Sorting Completed." , False , (255 , 255 , 255 ))
122
+ self .screen .blit (textsurface , (self .X , self .Y ))
123
+ myfont = pygame .font .SysFont ('Comic Sans MS' , 20 )
124
+ textsurface = myfont .render ("Operations Performed: " + str (self .NoOfOperations ), False , (255 , 255 , 255 ))
125
+ self .screen .blit (textsurface , (self .X , self .Y + 40 ))
126
+ except :
127
+ pass
128
+
129
+
130
+
131
+ class ExitText (Thread ):
132
+ def __init__ (self ,screen ,CordinateX ,CordinateY ,* args ):
133
+ Thread .__init__ (self )
134
+ self .X = CordinateX
135
+ self .Y = CordinateY
136
+ self .screen = screen
137
+ self .CordinateX = CordinateX
138
+ self .CordinateY = CordinateY
139
+ self .ClockComplete = False
140
+
141
+ def run (self ):
142
+ try :
143
+ while (True ):
144
+ pygame .font .init ()
145
+ myfont = pygame .font .SysFont ('Comic Sans MS' , 20 )
146
+ textsurface = myfont .render ("Press Esc to Exit." , False , (255 , 255 , 255 ))
147
+ self .screen .blit (textsurface , (self .X + 17 , self .Y ))
148
+ except :
149
+ pass
0 commit comments