Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
Connect_4
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Anurag Kumar
Connect_4
Commits
bb7c00cd
Commit
bb7c00cd
authored
Mar 15, 2021
by
Anurag Kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload new file
parent
df3aafc2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
0 deletions
+82
-0
gui.py
gui.py
+82
-0
No files found.
gui.py
0 → 100644
View file @
bb7c00cd
import
pygame
# Color used
BLUE
=
(
0
,
0
,
255
)
WHITE
=
(
255
,
255
,
255
)
BLACK
=
(
0
,
0
,
0
)
RED
=
(
255
,
0
,
0
)
YELLOW
=
(
255
,
255
,
0
)
LIGHTWOOD
=
(
249
,
248
,
246
)
WOOD
=
(
202
,
164
,
114
)
DARKWOOD
=
(
184
,
134
,
69
)
BLOODRED
=
(
238
,
75
,
43
)
#Constants
SQUARESIZE
=
70
ROW
=
6
COLUMN
=
7
WIDTH
,
HEIGHT
=
COLUMN
*
SQUARESIZE
,
(
ROW
+
2
)
*
SQUARESIZE
FPS
=
60
class
Gui
:
def
__init__
(
self
,
WINDOW
):
self
.
WINDOW
=
WINDOW
# pygame.init()
def
draw_window
(
self
,
board
):
for
j
in
range
(
COLUMN
):
for
i
in
range
(
ROW
):
pygame
.
draw
.
rect
(
self
.
WINDOW
,
LIGHTWOOD
,
(
j
*
SQUARESIZE
,
(
i
+
2
)
*
SQUARESIZE
,
SQUARESIZE
,
SQUARESIZE
))
#Score board Row
pygame
.
draw
.
rect
(
self
.
WINDOW
,
WOOD
,
(
0
,
0
,
WIDTH
,
SQUARESIZE
))
#Horizontal line saparate Navigation row and score board row
pygame
.
draw
.
line
(
self
.
WINDOW
,
WHITE
,
(
0
,
SQUARESIZE
),
(
WIDTH
,
SQUARESIZE
),
width
=
1
)
# Horizontal line that spararate Score board row and Moving square row
pygame
.
draw
.
line
(
self
.
WINDOW
,
WHITE
,
(
0
,
2
*
SQUARESIZE
),
(
WIDTH
,
2
*
SQUARESIZE
),
width
=
1
)
# verticle line
for
i
in
range
(
COLUMN
):
pygame
.
draw
.
line
(
self
.
WINDOW
,
BLACK
,
(
SQUARESIZE
+
i
*
SQUARESIZE
,
2
*
SQUARESIZE
),
((
i
+
1
)
*
SQUARESIZE
,
COLUMN
*
SQUARESIZE
+
2
*
SQUARESIZE
),
width
=
3
)
# Horizontal Line
for
i
in
range
(
ROW
+
3
):
pygame
.
draw
.
line
(
self
.
WINDOW
,
BLACK
,
(
0
,
(
i
+
3
)
*
SQUARESIZE
),
(
WIDTH
,
(
i
+
3
)
*
SQUARESIZE
),
width
=
3
)
#Square filling when mouse clicked
for
j
in
range
(
COLUMN
):
for
i
in
range
(
ROW
):
if
(
board
[
i
][
j
]
==
1
):
pygame
.
draw
.
rect
(
self
.
WINDOW
,
BLUE
,
(
int
(
j
*
(
SQUARESIZE
)),
HEIGHT
-
int
((
i
+
1
)
*
SQUARESIZE
),
SQUARESIZE
-
1
,
SQUARESIZE
-
1
))
if
(
board
[
i
][
j
]
==
2
):
pygame
.
draw
.
rect
(
self
.
WINDOW
,
YELLOW
,
(
int
(
j
*
(
SQUARESIZE
)),
HEIGHT
-
int
((
i
+
1
)
*
(
SQUARESIZE
)),
SQUARESIZE
-
1
,
SQUARESIZE
-
1
))
pygame
.
display
.
update
()
def
show_score
(
self
,
SCORE_PLAYER1_X
,
SCORE_PLAYER1_Y
,
SCORE_PLAYER2_X
,
SCORE_PLAYER2_Y
,
player1_score
,
player2_score
,
player1_name
,
player2_name
):
font_player1
=
pygame
.
font
.
SysFont
(
"arial"
,
20
)
font_player2
=
pygame
.
font
.
SysFont
(
"arial"
,
20
)
score1
=
font_player1
.
render
(
" {} score: "
.
format
(
player1_name
)
+
str
(
player1_score
),
True
,
WHITE
)
self
.
WINDOW
.
blit
(
score1
,
(
SCORE_PLAYER1_X
,
SCORE_PLAYER1_Y
))
score2
=
font_player2
.
render
(
"{} score: "
.
format
(
player2_name
)
+
str
(
player2_score
),
True
,
WHITE
)
self
.
WINDOW
.
blit
(
score2
,
(
SCORE_PLAYER2_X
,
SCORE_PLAYER2_Y
))
pygame
.
display
.
update
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment