Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristhofer Travieso <cristhofert97@gmail.com>2013-08-26 00:11:19 (GMT)
committer Cristhofer Travieso <cristhofert97@gmail.com>2013-08-26 00:11:19 (GMT)
commit98834b9ab7999b5fb660e8e053c7049216aa83c4 (patch)
tree66d9d06cc884ab1749400b4880cfcc95517adf11
parentf41503959688561a855d37b32a1e9d5da18428a2 (diff)
Add button cards
Signed-off-by: Cristhofer Travieso <cristhofert97@gmail.com>
-rw-r--r--game.py180
1 files changed, 49 insertions, 131 deletions
diff --git a/game.py b/game.py
index c9908fb..ad733bf 100644
--- a/game.py
+++ b/game.py
@@ -27,6 +27,7 @@ HEIGHT = 700
OPPONENT_CARDS = [None, None, None]
MY_CARDS = [None, None, None]
+CARDS = []
class Eventbox(Gtk.EventBox):
def __init__(self):
@@ -36,151 +37,68 @@ class Eventbox(Gtk.EventBox):
self.modify_bg(Gtk.StateType.NORMAL, color)
self.add(Box())
- self.show()
+ self.show_all()
class Box(Gtk.VBox):
def __init__(self):
+ Gtk.VBox.__init__(self)
+
+ self.cards = []
self.opponent_box = Gtk.HBox()
self.add(self.opponent_box)
- self.my_box = Gtk.HBox()
- self.add(self.my_box)
self.play_box = Gtk.HBox()
self.add(self.play_box)
+ self.my_box = Gtk.HBox()
+ self.add(self.my_box)
self._deal()
- for image in MY_CARDS:
- b = Gtk.Button()
- i = Gtk.Image()
- i.set_from_file(image)
- b.add(i)
- b.connect('clicked', self._click)
- self.my_box.add(b)
-
- self.show_all()
-
- def _deal(self):
- OPPONENT_CARDS[0] = random.choice(os.getcwd() + '/cards')
- OPPONENT_CARDS[1] = random.choice(os.getcwd() + '/cards')
- OPPONENT_CARDS[2] = random.choice(os.getcwd() + '/cards')
-
- MY_CARDS[0] = random.choice(os.getcwd() + '/cards')
- MY_CARDS[1] = random.choice(os.getcwd() + '/cards')
- MY_CARDS[2] = random.choice(os.getcwd() + '/cards')
-
- def _click(self, widget):
- self.my_box.remove(widget)
- self.play_box.add(widget)
-
- image = random.choice(OPPONET_CARDS)
- btn = Gtk.Button()
- img = Gtk.Image()
- img.set_from_file(image)
- btn.add(img)
- btn.connect('clicked', self._click)
- self.paly_box.add(btn)
-
- del OPPONENT_CARDS[OPPONENT_CARDS.index(image)]
-
-class Fixed(Gtk.Fixed):
-
- def __init__(self):
- Gtk.Fixed.__init__(self)
-
- card_dir = '/home/cristhofer/prog/truco/icons/cards'
- #opponent cards
- opponent_card1 = Card()
- self.put(opponent_card1, WIDTH/2, 0)
- opponent_card2 = Card()
- self.put(opponent_card2, WIDTH/2, 10)
- opponent_card3 = Card()
- self.put(opponent_card3, WIDTH/2, 20)
-
- #my cards
- card1 = MyCard()
- card1.connect('clicked', self.play_card)
- self.put(card1, WIDTH/2, HEIGHT-10)
-
- card2 = MyCard()
- card2.connect('clicked', self.play_card)
- self.put(card2, WIDTH/2, HEIGHT-20)
-
- card3 = MyCard()
- card3.connect('clicked', self.play_card)
- self.put(card3, WIDTH/2, HEIGHT-30)
-
- #sample
- sample = Gtk.Image()
- self.put(sample, 10, 50)
-
- #deck
- deck = Gtk.Image()
- deck.set_from_file(card_dir + '/back.svg')
- self.put(deck, 0, 50)
-
- #button
- box = Gtk.VBox()
- self.put(box, WIDTH-100, HEIGHT-100)
-
- truco_box = Gtk.HBox()
- box.add(truco_box)
-
- truco_btn = Gtk.Button('Truco')
- truco_box.add(truco_btn)
-
- retruco_btn = Gtk.Button('Retruco')
- truco_box.add(retruco_btn)
-
- vale4_btn = Gtk.Button('Vale 4')
- truco_box.add(vale4_btn)
-
- other_box = Gtk.HBox()
- box.add(other_box)
-
- flor_btn = Gtk.Button('Flor')
- other_box.add(flor_btn)
-
- self.show_all()
-
- def deal(self):
- pass
-
- def play_card(self, widget):
- self.move(widget, WIDTH/2, HEIGHT/2+100)
-
- def back(self):
- fixed.move(self, self.x, self.y)
-
-class Card(Gtk.Button):
-
- def __init__(self):
- Gtk.Button.__init__(self)
-
- self.image = Gtk.Image()
- self.add(self.image)
+ #btn1
+ btn1 = Gtk.Button(self.cards[0])
+ btn1.connect('clicked', self._click)
+ self.my_box.add(btn1)
- self.x = 0#obtener posicion de la carta
- self.y = 0#obtener posicion de la carta
+ #btn2
+ btn2 = Gtk.Button(self.cards[1])
+ btn2.connect('clicked', self._click)
+ self.my_box.add(btn2)
- def back(self):
- fixed.move(self, self.x, self.y)
+ #btn3
+ btn3 = Gtk.Button(self.cards[2])
+ btn3.connect('clicked', self._click)
+ self.my_box.add(btn3)
-#def repartir():
- #repartir cartas
-
-
-class MyCard(Gtk.Button):
-
- def __init__(self):
- Gtk.Button.__init__(self)
-
- self.image = Gtk.Image()
- self.add(self.image)
+ def _deal(self):
- self.x = 0#obtener posicion de la carta
- self.y = 0#obtener posicion de la carta
+ num = 0
+ while num < 6:
+ self.cards.append( str(random.randint(0, 13))+ random.choice(['coarse', 'cup', 'gold', 'sword']) )
+ num += 1
+
+ '''OPPONENT_CARDS[0] = str(random.randint(0, 13))+ random.choice(['coarse',
+ 'cup', 'gold', 'sword'])
+ OPPONENT_CARDS[1] = str(random.randint(0, 13))+ random.choice(['coarse',
+ 'cup', 'gold', 'sword'])
+ OPPONENT_CARDS[2] = str(random.randint(0, 13))+ random.choice(['coarse',
+ 'cup', 'gold', 'sword'])
+
+ MY_CARDS[0] = str(random.randint(0, 13)) + random.choice(['coarse',
+ 'cup', 'gold', 'sword'])
+ MY_CARDS[2] = str(random.randint(0, 13)) + random.choice(['coarse',
+ 'cup', 'gold', 'sword'])
+ MY_CARDS[3] = str(random.randint(0, 13)) + random.choice(['coarse',
+ 'cup', 'gold', 'sword'])'''
+ def _click(self, widget):
+ self.my_box.remove(widget)
+ self.play_box.add(widget)
-#def repartir():
- #repartir cartas
+if __name__ == "__main__":
+ window = Gtk.Window()
+ window.connect('destroy', lambda w: Gtk.main_quit())
+ window.add(Eventbox())
+ window.maximize()
+ window.set_title('Truco')
+ window.show()
+ Gtk.main()