Skip to content

Add files via upload #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Games/python-rolling-dice-master/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Python Rolling Dice Simulation
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
48 changes: 48 additions & 0 deletions Games/python-rolling-dice-master/buttons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from graphics import *


class Button:
"""activated() and deactivated() and clicked(p) is a method that returns if the user pressed within the required area"""

def __init__(self, win, center, width, height, label):
"""Create rectangular button e.g qb=Button(myWin,centerPoint,width,height,'Quit')"""
w, h = width / 2.0, height / 2.0
x, y = center.getX(), center.getY()

self.xmax, self.xmin = x + w, x - w
self.ymax, self.ymin = y + h, y - h

p1 = Point(self.xmin, self.ymin)
p2 = Point(self.xmax, self.ymax)

self.rect = Rectangle(p1, p2)
self.rect.setFill("lightgrey")
self.rect.draw(win)
self.label = Text(center, label)
self.label.draw(win)
self.deactivate()

def clicked(self, p):
"""return true if active and inside p"""
return (
self.active
and self.xmin <= p.getX() <= self.xmax
and self.ymin <= p.getY() <= self.ymax
) # use return when you change an already set variable/variables

def getLabel(self):
"""label of the string"""
return self.label.getText() # here as well

def activate(self):
"""sets button to active"""
self.label.setFill("black")
self.rect.setWidth(2)
self.active = True

def deactivate(self):
"""sets button to unactive"""
self.label.setFill("darkgray")
self.rect.setWidth(1)
self.active = False

80 changes: 80 additions & 0 deletions Games/python-rolling-dice-master/die.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from graphics import *


class DieView:
# shows graphical representation of a 6 sided dice
def __init__(self, win, center, size):
# create a view of the die e.g. d1=DieView(myWin,Point(40,50),20) its centered at 40,50 and length of 20
self.win = win
self.background = "white" # color of face
self.foreground = "black" # Thats for the pips
self.psize = 0.1 * size # radius of each pip
hsize = size / 2.0 # size of die
offset = 0.6 * hsize # distance from center to other pips
cx, cy = center.getX(), center.getY()
p1 = Point(cx - hsize, cy - hsize)
p2 = Point(cx + hsize, cy + hsize)
rect = Rectangle(p1, p2)
rect.draw(win)
rect.setFill(self.background)

# create 7 circles
self.pip1 = self.__makePip(cx - offset, cy - offset)
self.pip2 = self.__makePip(cx - offset, cy)
self.pip3 = self.__makePip(cx - offset, cy + offset)
self.pip4 = self.__makePip(cx, cy)
self.pip5 = self.__makePip(cx + offset, cy - offset)
self.pip6 = self.__makePip(cx + offset, cy)
self.pip7 = self.__makePip(cx + offset, cy + offset)

# draw an initial value
self.setValue(1)

def __makePip(self, x, y):
# Internal helper method to draw a pip at (x,y)
pip = Circle(Point(x, y), self.psize)
pip.setFill(self.background)
pip.setOutline(self.background)
pip.draw(self.win)
return pip

def setValue(self, value):
# set this to display value
# turn all pips off
self.pip1.setFill(self.background)
self.pip2.setFill(self.background)
self.pip3.setFill(self.background)
self.pip4.setFill(self.background)
self.pip5.setFill(self.background)
self.pip6.setFill(self.background)
self.pip7.setFill(self.background)

# turn correct pips on
if value == 1:
self.pip4.setFill(self.foreground)
elif value == 2:
self.pip1.setFill(self.foreground)
self.pip7.setFill(self.foreground)
elif value == 3:
self.pip1.setFill(self.foreground)
self.pip7.setFill(self.foreground)
self.pip4.setFill(self.foreground)
elif value == 4:
self.pip1.setFill(self.foreground)
self.pip3.setFill(self.foreground)
self.pip5.setFill(self.foreground)
self.pip7.setFill(self.foreground)
elif value == 5:
self.pip1.setFill(self.foreground)
self.pip3.setFill(self.foreground)
self.pip4.setFill(self.foreground)
self.pip5.setFill(self.foreground)
self.pip7.setFill(self.foreground)
else:
self.pip1.setFill(self.foreground)
self.pip2.setFill(self.foreground)
self.pip3.setFill(self.foreground)
self.pip4.setFill(self.foreground)
self.pip5.setFill(self.foreground)
self.pip7.setFill(self.foreground)

Loading