1
+ #let's import the stuffs which will help in game
1
2
import numpy as np
2
3
import pygame
3
4
import sys
4
5
import math
5
6
7
+ #now, let's initialize the colors of the game
6
8
BLUE = (0 ,255 ,255 )
7
9
BLACK = (0 ,0 ,0 )
8
10
RED = (255 ,0 ,0 )
9
11
YELLOW = (255 ,255 ,0 )
10
12
11
13
ROW_COUNT = 6
12
14
COLUMN_COUNT = 7
13
-
15
+ #creating a board
14
16
def create_board ():
15
17
board = np .zeros ((ROW_COUNT ,COLUMN_COUNT ))
16
18
return board
@@ -41,14 +43,14 @@ def winning_move(board,piece):
41
43
if board [r ][c ]== piece and board [r + 1 ][c ]== piece and board [r + 2 ][c ] and board [r + 3 ][c ]== piece :
42
44
return True
43
45
44
- #CHECK POSITIVE SLOPE DIAGONALS
46
+ #Checking Positive Slope DIAGONALS
45
47
for c in range (COLUMN_COUNT - 3 ):
46
48
for r in range (ROW_COUNT - 3 ):
47
49
if board [r ][c ]== piece and board [r + 1 ][c + 1 ]== piece and board [r + 2 ][c + 2 ] and board [r + 3 ][c + 3 ]== piece :
48
50
return True
49
51
50
52
51
- #CHECK NEGATIVE DIAGONALS
53
+ #Checking Negative Slope DIAGONALS
52
54
for c in range (COLUMN_COUNT - 3 ):
53
55
for r in range (3 ,ROW_COUNT ):
54
56
if board [r ][c ]== piece and board [r - 1 ][c + 1 ]== piece and board [r - 2 ][c + 2 ] and board [r - 3 ][c + 3 ]== piece :
@@ -67,7 +69,7 @@ def draw_board(board):
67
69
68
70
elif board [r ][c ]== 2 :
69
71
pygame .draw .circle (screen ,YELLOW ,(int (c * SQUARESIZE + SQUARESIZE / 2 ),height - int (r * SQUARESIZE + SQUARESIZE / 2 )),RADIUS )
70
-
72
+ #updating the pygame
71
73
pygame .display .update ()
72
74
73
75
@@ -79,6 +81,7 @@ def draw_board(board):
79
81
pygame .init ()
80
82
SQUARESIZE = 100
81
83
84
+ #adjusting the width and height
82
85
width = COLUMN_COUNT * SQUARESIZE
83
86
height = (ROW_COUNT + 1 )* SQUARESIZE
84
87
@@ -92,6 +95,7 @@ def draw_board(board):
92
95
93
96
myfont = pygame .font .SysFont ("monosoace" ,75 )
94
97
98
+ #let's create a loop, where the loop will exists until it is false
95
99
while not game_over :
96
100
for event in pygame .event .get ():
97
101
if event .type == pygame .QUIT :
@@ -124,7 +128,7 @@ def draw_board(board):
124
128
label = myfont .render ("Player 1 wins!!" ,1 ,RED )
125
129
screen .blit (label ,(40 ,10 ))
126
130
game_over = True
127
-
131
+ #if-else ladder
128
132
129
133
else :
130
134
posx = event .pos [0 ]
@@ -149,6 +153,6 @@ def draw_board(board):
149
153
150
154
turn += 1
151
155
turn = turn % 2
152
-
156
+ # when the loop is false, then return
153
157
if game_over :
154
158
pygame .time .wait (3000 )
0 commit comments