Apr-01-2021, 06:51 PM
Thought I would try my luck at doing a simple yahtzee in wxpython. Just wanted to share what I have gotten done so far. It is not complete. Only have the scorecard at the moment. Might give someone else a start if they would also like to try.
#! /usr/bin/env python3 import wx class Card: def __init__(self): self.section = { 'ones': None, 'twos': None, 'threes': None, 'fours': None, 'fives': None, 'sixes': None, 'upper score': None, 'bonus': None, 'upper total': None, '3 of a kind': None, '4 of a kind': None, 'sm. straight': None, 'lg. straight': None, 'fullhouse': None, 'yahtzee': None, 'chance': None, 'lower score': None, 'upper score': None, 'grand total': None } class MyPanel(wx.Panel): def __init__(self, parent, id): wx.Panel.__init__(self, parent, id) self.Bind(wx.EVT_PAINT, self.OnPaint) def OnPaint(self, event): self.SetBackgroundColour('white') self.SetForegroundColour(wx.Colour(10, 10, 10)) font = wx.Font(25, wx.ROMAN, wx.ITALIC, wx.BOLD) header = wx.PaintDC(self) header.SetFont(font) header.DrawText('wxPython Yahtzee', 251, 6) self.SetForegroundColour('tomato') header = wx.PaintDC(self) font = wx.Font(25, wx.ROMAN, wx.ITALIC, wx.BOLD) header.SetFont(font) header.DrawText('wxPython Yahtzee', 250, 5) self.SetBackgroundColour('white') self.SetForegroundColour('black') labels = Card() colored_rows = ['upper score', 'bonus', 'upper total', 'lower score'] i = 75 j = 78 for label, score in labels.section.items(): if score == None: score = '' dc = wx.PaintDC(self) dc.SetPen(wx.Pen('gray')) if label in colored_rows: dc.SetBrush(wx.Brush('light yellow')) elif label == 'grand total': dc.SetBrush(wx.Brush('light blue')) else: dc.SetBrush(wx.Brush('gray', wx.TRANSPARENT)) dc.DrawRectangle(10, i, 250, 25) dc.DrawRectangle(260, i, 50, 25) dc.DrawText(label.upper(), 15, j) dc.DrawText(score, 275, j) i += 26 j += 26 class MyApp(wx.App): def OnInit(self): frame = wx.Frame(None, -1, 'Yahtzee', size=(800, 600)) MyPanel(frame, -1) frame.Show() return True app = MyApp() app.MainLoop()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts