Oct-30-2020, 03:49 PM
(This post was last modified: Oct-30-2020, 08:38 PM by snippsat.
Edit Reason: Added code tag
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
from kivy.uix.layout import Layout from kivy.uix.image import Image from kivy.uix.behaviors import ButtonBehavior from random import shuffle from kivy.app import App from kivy.uix.gridlayout import GridLayout import time class Board(GridLayout): def __init__( self ): GridLayout.__init__( self ) backCard1 = r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\backCard.png" card1 = r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Harden.jpg" card2 = r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Harden.jpg" card3 = r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Giannis.jpg" card4 = r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Giannis.jpg" card5 = r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Iverson.jpg" card6 = r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Iverson.jpg" card7 = r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Jordan.jpg" card8 = r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Jordan.jpg" card9 = r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Kobe.jpg" card10 = r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Kobe.jpg" card11 = r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\LebronJames1.jpg" card12 = r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\LebronJames1.jpg" card13 = r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\shaq.jpg" card14 = r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\shaq.jpg" card15 = r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\StephCurry.png" card16 = r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\StephCurry.png" cardList = [] cardList.append(card1) cardList.append(card2) cardList.append(card3) cardList.append(card4) cardList.append(card5) cardList.append(card6) cardList.append(card7) cardList.append(card8) cardList.append(card9) cardList.append(card10) cardList.append(card11) cardList.append(card12) cardList.append(card13) cardList.append(card14) cardList.append(card15) cardList.append(card16) shuffle(cardList) # creating a Board self .listBoard = [] for i in range ( 8 ): # number of rows self .listLine = [] # making array listline for j in range ( 2 ): # number of cols cell = Image_Button( self , i, j, backCard1, cardList[ 0 ], False ) # putting button cardList.remove(cardList[ 0 ]) cell.x = i * 200 cell.y = j * 200 self .add_widget(cell) # adding to the app window self .listLine.append(cell) # adding to listline self .listBoard.append( self .listLine) # adding to listboard redButton = Compare_Button(r "C:\Users\benya\OneDrive\שולחן העבודה\Cards\\Button.png" ) redButton.y = 400 redButton.x = 400 self .add_widget(redButton) self .count = 0 self .firstAdd = "a" self .secondAdd = "b" def flipOver( self ): time.sleep( 2 ) for i in self .listBoard: for j in i: if j.flip: j.source = j.back j.flip = False def deleteCards( self ): time.sleep( 2 ) for i in self .listBoard: for j in i: if j.flip: self .remove_widget(j) j.flip = False class Compare_Button(ButtonBehavior, Image): def __init__( self , frontSource): ButtonBehavior.__init__( self ) Image.__init__( self ) self .source = frontSource self .front = str (frontSource) def on_press( self ): print ( "big small" ) if str ( self .board.SecondAdd) ! = str ( self .board.firstAdd): print ( "small small" ) self .board.flipOver() else : print ( "small big" ) self .board.deleteCards() class Image_Button(ButtonBehavior, Image): ''' num - the number on the card mycolor - the color of the card myBord - link to the class board mySource - string the path to the picture belong- "player" or "kupa" or "open card" ''' def __init__( self , i, j, myBoard, backSource, frontSource, flip): ButtonBehavior.__init__( self ) Image.__init__( self ) self .source = backSource self .i = i self .j = j self .board = myBoard self .flip = flip self .front = str (frontSource) self .back = str (backSource) def on_press( self ): if not self .flip: self .source = self .front self .flip = True if self .board.count % 3 = = 1 : self .board.SecondAdd = str ( self .source) self .board.count + = 1 if self .board.count % 3 = = 0 : self .board.firstAdd = str ( self .source) print ( self .board.lastAdd) self .board.count + = 1 class TestApp(App): def build( self ): self .title = 'game' return Board() TestApp().run() |
Error:File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
File "C:/Users/benya/NewZikaronGame.py", line 128, in on_press
if self.board.count % 3 == 1:
AttributeError: 'int' object has no attribute 'count'
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
Please help me figure out what the problem is