Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Professional Project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jananan.gugagayana
Professional Project
Commits
1ef01897
Commit
1ef01897
authored
Mar 29, 2020
by
nouman.ashraf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
157 additions
and
0 deletions
+157
-0
Stock Market Game.py
Stock Market Game.py
+157
-0
No files found.
Stock Market Game.py
0 → 100755
View file @
1ef01897
import
pygame
import
time
import
random
pygame
.
init
()
width
=
800
height
=
600
black
=
(
0
,
0
,
0
)
white
=
(
255
,
255
,
255
)
red
=
(
200
,
0
,
0
)
green
=
(
0
,
200
,
0
)
brightred
=
(
255
,
0
,
0
)
brightgreen
=
(
0
,
255
,
0
)
display
=
pygame
.
display
.
set_mode
((
width
,
height
))
pygame
.
display
.
set_caption
(
'Stock Market Game'
)
clock
=
pygame
.
time
.
Clock
()
def
money
(
credit
):
font
=
pygame
.
font
.
SysFont
(
None
,
25
)
text
=
font
.
render
(
"Money: "
+
str
(
credit
),
True
,
black
)
display
.
blit
(
text
.
(
0
,
0
))
def
items
():
items
=
[
"Computer"
,
"Apple_iphone"
,
"Comic book"
]
computer_price
=
10
Apple_iphone_price
=
100
comicbook_price
=
25
itemprices
=
[
computer_price
,
Apple_iphone_price
,
comicbook_price
]
def
text_objects
(
text
,
font
):
textSurface
=
font
.
render
(
text
,
True
,
black
)
return
textSurface
,
textSurface
.
get_rect
()
def
message_display
(
text
):
largeText
=
pygame
.
font
.
Font
(
'freesansbold.ttf'
,
60
)
TextSurf
,
TextRect
=
text_objects
(
text
,
largeText
)
TextRect
.
center
=
((
width
/
2
),(
height
/
2
))
display
.
blit
(
TextSurf
,
TextRect
)
pygame
.
display
.
update
()
main
()
def
button
(
m
,
x
,
y
,
w
,
h
,
nh
,
ih
,
action
=
None
):
mouse
=
pygame
.
mouse
.
get_pos
()
if
x
+
w
>
mouse
[
0
]
>
x
and
y
+
h
>
mouse
[
1
]
>
y
:
pygame
.
draw
.
rect
(
display
,
ih
,(
x
,
y
,
w
,
h
))
if
click
[
0
]
==
1
and
action
!=
None
:
action
()
else
:
pygame
.
draw
.
rect
(
display
,
nh
,(
x
,
y
,
w
,
h
))
text
=
pygame
.
font
.
Font
(
"freesansbold.ttf"
,
20
)
textSurf
,
textRect
=
text_objects
(
m
,
text
)
textRect
.
center
=
((
x
+
(
w
/
2
)),
(
y
+
(
h
/
2
)
)
display
.
blit
(
textSurf
,
textRect
)
def
endgame
():
pygame
.
quit
()
quit
()
def
gamestart
():
intro
=
True
while
intro
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
pygame
.
QUIT
:
pygame
.
quit
()
quit
()
display
.
fill
(
white
)
largeText
=
pygame
.
font
.
Font
(
'freesansbold.ttf'
,
60
)
TextSurf
,
TextRect
=
text_objects
(
"Stock Market Game"
,
largeText
)
TextRect
.
center
=
((
width
/
2
),(
height
/
2
))
display
.
blit
(
TextSurf
,
TextRect
)
button
(
"Start"
,
150
,
450
,
100
,
50
,
green
,
brightgreen
,
main
)
button
(
"Quit "
,
550
,
450
,
100
,
50
,
red
,
brightred
,
endgame
)
pygame
.
display
.
update
()
clock
.
tick
(
15
)
def
main
():
money
=
500
maingame
=
False
while
not
maingame
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
pygame
.
QUIT
:
pygame
.
quit
()
quit
()
pygame
.
display
.
update
()
gamestart
()
main
()
pygame
.
quit
()
quit
()
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