GeminiAi commited on
Commit
c5181a6
·
verified ·
1 Parent(s): b0fb74a

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +113 -0
main.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # importing stuff
2
+
3
+ from Scripts.Variables import *
4
+ from Scripts.Engine import *
5
+ import pygame
6
+
7
+ # initializing the variables to get assigned later in the initialize method
8
+ display = 0
9
+ board = 0
10
+
11
+
12
+
13
+ class Main:
14
+ @staticmethod
15
+ def onEveryFrame():
16
+
17
+ x, y = pygame.mouse.get_pos()
18
+
19
+ Board.draw_board(display)
20
+ Board.draw_pieces(board, display)
21
+ Board.draw_hovered_piece(display, hover_piece, x, y)
22
+ pygame.display.update()
23
+
24
+ @staticmethod
25
+ def onRightClickDown(x, y):
26
+
27
+ global hover_piece, took_from, avails
28
+
29
+ row, column = helper.fromAxis(x, y)
30
+
31
+ # assigning the available moves for the held piece
32
+ avails = []
33
+ if board[column][row] in chance :
34
+ if board[column][row] == 1:
35
+ avails = (Available.check_down(board, row, column, u))
36
+ elif board[column][row] == 2:
37
+ avails = (Available.check_up(board, row, column, d))
38
+ elif board[column][row] == 3:
39
+ avails = Available.check_king(board, row, column, u)
40
+ elif board[column][row] == 4:
41
+ avails = Available.check_king(board, row, column, d)
42
+
43
+
44
+
45
+ hover_piece = board[column][row]
46
+ took_from = [column, row]
47
+ board[column][row] = 0
48
+
49
+ @staticmethod
50
+ def onRightClickUp(x, y):
51
+
52
+ global hover_piece, avails, next, chance
53
+
54
+ row, column = helper.fromAxis(x, y)
55
+ if hover_piece != 0:
56
+
57
+ if helper.fromIndex(column, row) in avails:
58
+ board[column][row] = hover_piece
59
+ res = helper.sub_list([column,row],[took_from[0],took_from[1]])
60
+ if res[0] in [2,-2]:
61
+ to = helper.dev_list_by2(res)
62
+ board[took_from[0] + to[0]][took_from[1] + to [1]] = 0
63
+ chance , next = next , chance
64
+ else:
65
+ board[took_from[0]][took_from[1]] = hover_piece
66
+ hover_piece = 0
67
+ avails = 0
68
+
69
+ Board.check_promotion(board)
70
+
71
+
72
+ @staticmethod
73
+ def main():
74
+ global board
75
+
76
+ Main.initialize()
77
+
78
+ while True:
79
+ for event in pygame.event.get():
80
+
81
+ if event.type == pygame.QUIT:
82
+ Main.onQuit()
83
+
84
+ if event.type == pygame.MOUSEBUTTONDOWN:
85
+ if event.button == 1:
86
+ Main.onRightClickDown(event.pos[0], event.pos[1])
87
+
88
+ if event.type == pygame.MOUSEBUTTONUP:
89
+ if event.button == 1:
90
+ Main.onRightClickUp(event.pos[0], event.pos[1])
91
+
92
+ if event.type == pygame.KEYDOWN:
93
+ if event.key == pygame.K_r:
94
+ board = Board.newBoard()
95
+
96
+
97
+ Main.onEveryFrame()
98
+
99
+ @staticmethod
100
+ def initialize():
101
+ global display, board
102
+ pygame.init()
103
+ display = pygame.display.set_mode((dimension, dimension))
104
+ pygame.display.set_caption("Checkers")
105
+ board = Board.newBoard()
106
+
107
+ @staticmethod
108
+ def onQuit():
109
+ quit()
110
+
111
+
112
+
113
+ Main.main()