Skip to content

Commit 608ece3

Browse files
authored
You_or_ME..py
1 parent 3cf83a0 commit 608ece3

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Diff for: PyGamesScripts/YOU_or_ME/youorme.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
#let's import the stuffs which will help in game
12
import numpy as np
23
import pygame
34
import sys
45
import math
56

7+
#now, let's initialize the colors of the game
68
BLUE=(0,255,255)
79
BLACK=(0,0,0)
810
RED=(255,0,0)
911
YELLOW=(255,255,0)
1012

1113
ROW_COUNT=6
1214
COLUMN_COUNT=7
13-
15+
#creating a board
1416
def create_board():
1517
board=np.zeros((ROW_COUNT,COLUMN_COUNT))
1618
return board
@@ -41,14 +43,14 @@ def winning_move(board,piece):
4143
if board[r][c]==piece and board[r+1][c]==piece and board[r+2][c] and board[r+3][c]==piece:
4244
return True
4345

44-
#CHECK POSITIVE SLOPE DIAGONALS
46+
#Checking Positive Slope DIAGONALS
4547
for c in range(COLUMN_COUNT-3):
4648
for r in range(ROW_COUNT-3):
4749
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:
4850
return True
4951

5052

51-
#CHECK NEGATIVE DIAGONALS
53+
#Checking Negative Slope DIAGONALS
5254
for c in range(COLUMN_COUNT-3):
5355
for r in range(3,ROW_COUNT):
5456
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):
6769

6870
elif board[r][c]==2:
6971
pygame.draw.circle(screen,YELLOW,(int(c*SQUARESIZE+SQUARESIZE/2),height-int(r*SQUARESIZE+SQUARESIZE/2)),RADIUS)
70-
72+
#updating the pygame
7173
pygame.display.update()
7274

7375

@@ -79,6 +81,7 @@ def draw_board(board):
7981
pygame.init()
8082
SQUARESIZE=100
8183

84+
#adjusting the width and height
8285
width=COLUMN_COUNT*SQUARESIZE
8386
height=(ROW_COUNT+1)*SQUARESIZE
8487

@@ -92,6 +95,7 @@ def draw_board(board):
9295

9396
myfont=pygame.font.SysFont("monosoace",75)
9497

98+
#let's create a loop, where the loop will exists until it is false
9599
while not game_over:
96100
for event in pygame.event.get():
97101
if event.type==pygame.QUIT:
@@ -124,7 +128,7 @@ def draw_board(board):
124128
label=myfont.render("Player 1 wins!!",1,RED)
125129
screen.blit(label,(40,10))
126130
game_over=True
127-
131+
#if-else ladder
128132

129133
else:
130134
posx=event.pos[0]
@@ -149,6 +153,6 @@ def draw_board(board):
149153

150154
turn+=1
151155
turn=turn%2
152-
156+
# when the loop is false, then return
153157
if game_over:
154158
pygame.time.wait(3000)

0 commit comments

Comments
 (0)