11from kivy .app import App
22from kivy .uix .screenmanager import Screen
3-
3+ from Data_Conversion . position_of_pieces import teams_turn
44from Data_Conversion .position_of_mouse import find_position
55from Data_Conversion .position_of_pieces import position_dic
66from Data_Conversion .chess_coords_to_real_coords import convert_coordinates
7-
7+ from kivy .uix .popup import Popup
8+ from kivy .uix .floatlayout import FloatLayout
9+ from kivy .uix .button import Button
810from valid_move import is_valid_move
11+ from Data_Conversion .difference_for_letter import promotion_piece
912
1013class Scatter_Text_widget (Screen ):
1114
@@ -45,36 +48,36 @@ def on_touch_up(self, touch):
4548
4649 #Gets the position of the mouse, and translates it into a chess corrd
4750 pos_chess = self .position .chess_position (touch .pos )
48-
51+ self . pos_chess = pos_chess
4952 #opens the text file, to get the previous data
5053 with open ('Data_Conversion\saved_input.txt' , 'r' ) as f :
5154 list_of_previous_data = f .read ()
5255 f .close ()
5356
5457 #OLD DATA; for the chess corrdinate
5558 chess_position_numerical = str (str (list_of_previous_data [2 ]) + str (list_of_previous_data [3 ]))
56-
59+ self . chess_position_numerical = chess_position_numerical
5760 #This is the piece that was moved, taken from the text file
58- piece_that_moved = ""
61+ self . piece_that_moved = ""
5962 index = 8
6063 while index != len (list_of_previous_data ) - 2 :
61- piece_that_moved += str (list_of_previous_data [index ])
64+ self . piece_that_moved += str (list_of_previous_data [index ])
6265 index += 1
6366
6467 '''
6568 Checks with another python file to see if the move was valid or not, against all rules of Chess
6669 '''
6770 st = is_valid_move ()
68- valid_or_not = st .main (chess_position_numerical , self .position_piece , pos_chess , piece_that_moved )
71+ valid_or_not = st .main (chess_position_numerical , self .position_piece , pos_chess , self . piece_that_moved )
6972
7073 #IF THE MOVE WAS VALID
7174 if valid_or_not == "True" :
7275 #Move the piece to the location
73- self .ids [piece_that_moved ].pos = (conversion .to_number ()[pos_chess ][0 ], conversion .to_number ()[pos_chess ][1 ])
76+ self .ids [self . piece_that_moved ].pos = (conversion .to_number ()[pos_chess ][0 ], conversion .to_number ()[pos_chess ][1 ])
7477
7578 #Updates the Dictionary of all the piece locations
7679 position_dic [str (chess_position_numerical )] = 'None'
77- position_dic [str (pos_chess )] = str (piece_that_moved )
80+ position_dic [str (pos_chess )] = str (self . piece_that_moved )
7881
7982 elif valid_or_not == "True, Captured" :
8083 #If the move was valid, and a capture occured
@@ -83,15 +86,15 @@ def on_touch_up(self, touch):
8386 #Deletes the piece that was captured
8487 self .ids [piece_occupied ].pos = (1000 ,1000 )
8588 #Moves the piece in play
86- self .ids [piece_that_moved ].pos = (conversion .to_number ()[pos_chess ][0 ], conversion .to_number ()[pos_chess ][1 ])
89+ self .ids [self . piece_that_moved ].pos = (conversion .to_number ()[pos_chess ][0 ], conversion .to_number ()[pos_chess ][1 ])
8790
8891 #Updates Dictionary
8992 position_dic [str (chess_position_numerical )] = 'None'
90- position_dic [str (pos_chess )] = str (piece_that_moved )
93+ position_dic [str (pos_chess )] = str (self . piece_that_moved )
9194
9295 elif valid_or_not == "Castle" :
9396 #Move the piece to the location
94- self .ids [piece_that_moved ].pos = (conversion .to_number ()[pos_chess ][0 ], conversion .to_number ()[pos_chess ][1 ])
97+ self .ids [self . piece_that_moved ].pos = (conversion .to_number ()[pos_chess ][0 ], conversion .to_number ()[pos_chess ][1 ])
9598 if str (pos_chess ) == 'g1' :
9699 self .ids ['Right White Rook' ].pos = (conversion .to_number ()['f1' ][0 ], conversion .to_number ()['f1' ][1 ])
97100 position_dic ['h1' ] = 'None'
@@ -110,16 +113,74 @@ def on_touch_up(self, touch):
110113 position_dic ['d8' ] = 'Left Black Rook'
111114 #Updates the Dictionary of all the piece locations
112115 position_dic [str (chess_position_numerical )] = 'None'
113- position_dic [str (pos_chess )] = str (piece_that_moved )
116+ position_dic [str (pos_chess )] = str (self . piece_that_moved )
114117
115118 elif valid_or_not == "New_Piece" :
116- pass
119+ content = Button (id = 'Queen Promotion' , background_normal = 'Pictures\White_Queen.png' , size = (60 ,60 ), pos = (410 ,300 ))
120+ content1 = Button (id = 'Rook Promotion' , background_normal = 'Pictures\white_rook.png' , size = (60 ,60 ), pos = (307.5 ,400 ))
121+ content2 = Button (id = 'Bishop Promotion' , background_normal = 'Pictures\white_Bishop.png' , size = (60 ,60 ), pos = (307.5 ,300 ))
122+ content3 = Button (id = 'Knight Promotion' , background_normal = 'Pictures\white_horse.png' , size = (60 ,60 ), pos = (410 ,400 ))
123+ float = FloatLayout ()
124+ float .add_widget (content )
125+ float .add_widget (content1 )
126+ float .add_widget (content2 )
127+ float .add_widget (content3 )
128+ damn = []
129+ popup = Popup (content = float , size_hint = (None , None ), size = (120 , 160 ), auto_dismiss = False , pos_hint = {'x' : 10.0 ,
130+ 'y' :10.0 })
131+ sc = Scatter_Text_widget ()
132+ content .bind (on_press = self .yup , on_release = popup .dismiss )
133+ content1 .bind (on_press = self .yup ,on_release = popup .dismiss )
134+ content2 .bind (on_press = self .yup ,on_release = popup .dismiss )
135+ content3 .bind (on_press = self .yup ,on_release = popup .dismiss )
136+ popup .open ()
137+
138+ del promotion_piece [:]
139+
117140 else :
118141 #If the move was not valid
119142
120143 #Places the piece in the beggining location
121- self .ids [piece_that_moved ].pos = (conversion .to_number ()[chess_position_numerical ][0 ], conversion .to_number ()[chess_position_numerical ][1 ])
122-
144+ self .ids [self .piece_that_moved ].pos = (conversion .to_number ()[chess_position_numerical ][0 ], conversion .to_number ()[chess_position_numerical ][1 ])
145+
146+
147+
148+
149+ def yup (self , obj ):
150+ global teams_turn
151+ conversion = convert_coordinates
152+
153+
154+ promotion_piece .append (obj .pos [0 ])
155+ promotion_piece .append (obj .pos [1 ])
156+
157+ self .ids [self .piece_that_moved ].pos = (10000 ,1000 )
158+ #If the move was valid, and a capture occured
159+ piece_occupied = str (self .position_piece [self .pos_chess ])
160+ print (promotion_piece )
161+ if piece_occupied != "None" :
162+ self .ids [piece_occupied ].pos = (1000 ,1000 )
163+ if promotion_piece == [410 ,300 ]:
164+ self .ids ['Whire Queen' ].pos = (conversion .to_number ()[self .pos_chess ][0 ], conversion .to_number ()[self .pos_chess ][1 ])
165+ position_dic [str (self .chess_position_numerical )] = 'None'
166+ position_dic [str (self .pos_chess )] = 'Whire Queen'
167+ elif promotion_piece == [307.5 , 400 ]:
168+ self .ids ['Ledt White Rook' ].pos = (conversion .to_number ()[self .pos_chess ][0 ], conversion .to_number ()[self .pos_chess ][1 ])
169+ position_dic [str (self .chess_position_numerical )] = 'None'
170+ position_dic [str (self .pos_chess )] = 'Ledt White Rook'
171+ elif promotion_piece == [307.5 , 300 ]:
172+ self .ids ['Ledt White Bishop' ].pos = (conversion .to_number ()[self .pos_chess ][0 ], conversion .to_number ()[self .pos_chess ][1 ])
173+ position_dic [str (self .chess_position_numerical )] = 'None'
174+ position_dic [str (self .pos_chess )] = 'Ledt White Bishop'
175+ elif promotion_piece == [410 , 400 ]:
176+ self .ids ['Ledt White Knight' ].pos = (conversion .to_number ()[self .pos_chess ][0 ], conversion .to_number ()[self .pos_chess ][1 ])
177+ position_dic [str (self .chess_position_numerical )] = 'None'
178+ position_dic [str (self .pos_chess )] = 'Ledt White Knight'
179+
180+ if teams_turn == "W" :
181+ teams_turn = "B"
182+ else :
183+ teams_turn = "W"
123184#Builds the App
124185class window (App ):
125186 def build (self ):
0 commit comments