Skip to content

Commit 96bfdc2

Browse files
committed
Added function for the pressing and releasing of each piece
1 parent 9c4de06 commit 96bfdc2

File tree

4 files changed

+242
-61
lines changed

4 files changed

+242
-61
lines changed

Board.py

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,30 @@
1-
21
from kivy.uix.screenmanager import Screen
3-
from kivy.config import Config
42
from kivy.core.window import Window
5-
from kivy.factory import Factory
6-
from kivy.uix.gridlayout import GridLayout
7-
from kivy.lang import Builder
8-
from kivy.uix.button import Button
93
from kivy.app import App
10-
from kivy.uix.gridlayout import GridLayout
11-
from kivy.uix.image import Image
12-
from kivy.uix.floatlayout import FloatLayout
13-
144

5+
from position_of_mouse import find_position
156

167
class board_setup(Screen):
17-
pass
188

9+
def on_mouse_pos(self, pos):
10+
#This function gets the position of the mouse, in chessboard labels
11+
position = find_position()
12+
print(position.chess_position(pos))
1913

20-
class window(App):
21-
def build(self):
22-
return board_setup()
2314

15+
def touched(self, id):
16+
print(id)
2417

25-
if __name__ == "__main__":
26-
width_of_board = 820
27-
height_of_board = 800
2818

29-
#Set the Hight and Width of the App
30-
Config.set('graphics', 'width', str(width_of_board))
31-
Config.set('graphics', 'height', str(height_of_board))
19+
def release(self):
20+
print("RRR")
3221

33-
#Make the App non-resizable
34-
Config.set('graphics', 'resizable', '0')
35-
Config.write()
3622

37-
#Make the top windows bar go away
38-
Window.borderless = True
3923

40-
#Runs the
41-
window().run()
24+
Window.bind(mouse_pos = on_mouse_pos)
25+
26+
27+
#Builds the App
28+
class window(App):
29+
def build(self):
30+
return board_setup()

main.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1-
from kivy.app import App
1+
from Board import window
2+
from kivy.config import Config
3+
from kivy.core.window import Window
24

5+
def setup():
6+
width_of_board = 820
7+
height_of_board = 800
38

9+
#Set the Hight and Width of the App
10+
Config.set('graphics', 'width', str(width_of_board))
11+
Config.set('graphics', 'height', str(height_of_board))
412

13+
#Make the App non-resizable
14+
Config.set('graphics', 'resizable', '0')
15+
Config.write()
516

17+
#Make the top windows bar go away
18+
Window.borderless = True
19+
20+
#Runs the
21+
window().run()
22+
23+
24+
if __name__ == "__main__":
25+
setup()
626

727
'''
828
TODO LIST
929
10-
1. FIGURE OUT CODE ARCHITECTURE (HARD)
11-
2. DISPLAY THE PIECES AND MAKE IT LOOK SEEMLESS (easy when code arch. is finished)
30+
31+
1232
2.5 CODE A DRAGGING SYSTEM AND A TOUCH-BASED SYSTEM
1333
2.75 MAKE THE DRAGGING SYSTEM HAVE THE PIECES MOVE A LAYER UP FROM THE BOARD
1434
3. CODE ALL OF THE MOVES FOR THE PIECES (HARD; MAKE CODE STILL NEAT)

position_of_mouse.py

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
'''
2+
This function's main goal is to translate the coordinates of the mouse into what position of the chessboard the mouse is in
3+
This was a repetative implementation, there might (most likely) another way to implement this that is more effecient both in the run time,
4+
and the time it took to code
5+
6+
IF YOU DON'T KNOW THE CHESS POSITIONS: http://www.chess-poster.com/english/learn_chess/notation/images/coordinates_2.gif
7+
'''
8+
9+
class find_position():
10+
def chess_position(self, pos):
11+
if pos[0] <= 102.5 and pos[1] <= 100:
12+
return "a1"
13+
elif pos[0] <= 205 and pos[1] <= 100:
14+
return "b1"
15+
elif pos[0] <= 307.5 and pos[1] <= 100:
16+
return "c1"
17+
elif pos[0] <= 410 and pos[1] <= 100:
18+
return "d1"
19+
elif pos[0] <= 512.5 and pos[1] <= 100:
20+
return "e1"
21+
elif pos[0] <= 615 and pos[1] <= 100:
22+
return "f1"
23+
elif pos[0] <= 717.5 and pos[1] <= 100:
24+
return "g1"
25+
elif pos[0] <= 820 and pos[1] <= 100:
26+
return "h1"
27+
elif pos[0] <= 102.5 and pos[1] <= 200:
28+
return("a2")
29+
elif pos[0] <= 205 and pos[1] <= 200:
30+
return("b2")
31+
elif pos[0] <= 307.5 and pos[1] <= 200:
32+
return("c2")
33+
elif pos[0] <= 410 and pos[1] <= 200:
34+
return("d2")
35+
elif pos[0] <= 512.5 and pos[1] <= 200:
36+
return("e2")
37+
elif pos[0] <= 615 and pos[1] <= 200:
38+
return("f2")
39+
elif pos[0] <= 717.5 and pos[1] <= 200:
40+
return("g2")
41+
elif pos[0] <= 820 and pos[1] <= 200:
42+
return("h2")
43+
elif pos[0] <= 102.5 and pos[1] <= 300:
44+
return("a3")
45+
elif pos[0] <= 205 and pos[1] <= 300:
46+
return("b3")
47+
elif pos[0] <= 307.5 and pos[1] <= 300:
48+
return("c3")
49+
elif pos[0] <= 410 and pos[1] <= 300:
50+
return("d3")
51+
elif pos[0] <= 512.5 and pos[1] <= 300:
52+
return("e3")
53+
elif pos[0] <= 615 and pos[1] <= 300:
54+
return("f3")
55+
elif pos[0] <= 717.5 and pos[1] <= 300:
56+
return("g3")
57+
elif pos[0] <= 820 and pos[1] <= 300:
58+
return("h3")
59+
elif pos[0] <= 102.5 and pos[1] <= 400:
60+
return("a4")
61+
elif pos[0] <= 205 and pos[1] <= 400:
62+
return("b4")
63+
elif pos[0] <= 307.5 and pos[1] <= 400:
64+
return("c4")
65+
elif pos[0] <= 410 and pos[1] <= 400:
66+
return("d4")
67+
elif pos[0] <= 512.5 and pos[1] <= 400:
68+
return("e4")
69+
elif pos[0] <= 615 and pos[1] <= 400:
70+
return("f4")
71+
elif pos[0] <= 717.5 and pos[1] <= 400:
72+
return("g4")
73+
elif pos[0] <= 820 and pos[1] <= 400:
74+
return("h4")
75+
elif pos[0] <= 102.5 and pos[1] <= 500:
76+
return("a5")
77+
elif pos[0] <= 205 and pos[1] <= 500:
78+
return("b5")
79+
elif pos[0] <= 307.5 and pos[1] <= 500:
80+
return("c5")
81+
elif pos[0] <= 410 and pos[1] <= 500:
82+
return("d5")
83+
elif pos[0] <= 512.5 and pos[1] <= 500:
84+
return("e5")
85+
elif pos[0] <= 615 and pos[1] <= 500:
86+
return("f5")
87+
elif pos[0] <= 717.5 and pos[1] <= 500:
88+
return("g5")
89+
elif pos[0] <= 820 and pos[1] <= 500:
90+
return("h5")
91+
elif pos[0] <= 102.5 and pos[1] <= 600:
92+
return("a6")
93+
elif pos[0] <= 205 and pos[1] <= 600:
94+
return("b6")
95+
elif pos[0] <= 307.5 and pos[1] <= 600:
96+
return("c6")
97+
elif pos[0] <= 410 and pos[1] <= 600:
98+
return("d6")
99+
elif pos[0] <= 512.5 and pos[1] <= 600:
100+
return("e6")
101+
elif pos[0] <= 615 and pos[1] <= 600:
102+
return("f6")
103+
elif pos[0] <= 717.5 and pos[1] <= 600:
104+
return("g6")
105+
elif pos[0] <= 820 and pos[1] <= 600:
106+
return("h6")
107+
elif pos[0] <= 102.5 and pos[1] <= 700:
108+
return("a7")
109+
elif pos[0] <= 205 and pos[1] <= 700:
110+
return("b7")
111+
elif pos[0] <= 307.5 and pos[1] <= 700:
112+
return("c7")
113+
elif pos[0] <= 410 and pos[1] <= 700:
114+
return("d7")
115+
elif pos[0] <= 512.5 and pos[1] <= 700:
116+
return("e7")
117+
elif pos[0] <= 615 and pos[1] <= 700:
118+
return("f7")
119+
elif pos[0] <= 717.5 and pos[1] <= 700:
120+
return("g7")
121+
elif pos[0] <= 820 and pos[1] <= 700:
122+
return("h7")
123+
elif pos[0] <= 102.5 and pos[1] <= 800:
124+
return("a8")
125+
elif pos[0] <= 205 and pos[1] <= 800:
126+
return("b8")
127+
elif pos[0] <= 307.5 and pos[1] <= 800:
128+
return("c8")
129+
elif pos[0] <= 410 and pos[1] <= 800:
130+
return("d8")
131+
elif pos[0] <= 512.5 and pos[1] <= 800:
132+
return("e8")
133+
elif pos[0] <= 615 and pos[1] <= 800:
134+
return("f8")
135+
elif pos[0] <= 717.5 and pos[1] <= 800:
136+
return("g8")
137+
elif pos[0] <= 820 and pos[1] <= 800:
138+
return("h8")

0 commit comments

Comments
 (0)