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
|
#!/usr/bin/env python
# Copyright (C) 2013 Cristhofer Travieso <cristhofert97@gmail.com>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject
import os
import random
WIDTH = 1200
HEIGHT = 700
class Eventbox(Gtk.EventBox):
def __init__(self):
Gtk.EventBox.__init__(self)
#773525
parse, color = Gdk.Color.parse('#773525')
self.modify_bg(Gtk.StateType.NORMAL, color)
self.add(Box())
self.show_all()
class Box(Gtk.VBox):
def __init__(self):
Gtk.VBox.__init__(self)
self.cards = []
#opponent box
self.opponent_box = Gtk.HBox()
self.pack_start(self.opponent_box, True, True, 0)
#play box
self.play_box = Gtk.HBox()
self.pack_start(self.play_box, True, True, 0)
#my box
self.my_box = Gtk.HBox()
self.pack_start(self.my_box, True, True, 0)
self._deal()
def _deal(self):
num = 0
while num < 7:
l = [1, 2, 3, 4, 5, 6, 7, 10, 11, 12]
self.cards.append( str(random.choice(l))+ random.choice(['coarse', 'cup', 'gold', 'sword']) )
num += 1
#card1
btn1 = Gtk.Button()
img1 = Gtk.Image()
img1.set_from_file('icons/cards/' + self.cards[0] + '.svg')
btn1.add(img1)
btn1.connect('clicked', self._click)
self.my_box.pack_start(btn1, True, False, 0)
#card2
btn2 = Gtk.Button()
img2 = Gtk.Image()
img2.set_from_file('icons/cards/' + self.cards[1] + '.svg')
btn2.add(img2)
btn2.connect('clicked', self._click)
self.my_box.pack_start(btn2, True, False, 0)
#card3
btn3 = Gtk.Button()
img3 = Gtk.Image()
img3.set_from_file('icons/cards/' + self.cards[2] + '.svg')
btn3.add(img3)
btn3.connect('clicked', self._click)
self.my_box.pack_start(btn3, True, False, 0)
#deck
deck = Gtk.Image()
deck.set_from_file('icons/cards/back.svg')
self.play_box.pack_start(deck, False, False, 0)
#sample
sample = Gtk.Image()
sample.set_from_file('icons/cards/' + self.cards[6] + '.svg')
self.play_box.pack_start(sample, False, False, 0)
#card_opponent 1
card1 = Gtk.Image()
card1.set_from_file('icons/cards/back.svg')
self.opponent_box.pack_start(card1, True, True, 0)
#card_opponent 2
card2 = Gtk.Image()
card2.set_from_file('icons/cards/back.svg')
self.opponent_box.pack_start(card2, True, True, 0)
#card_opponent 3
card3 = Gtk.Image()
card3.set_from_file('icons/cards/back.svg')
self.opponent_box.pack_start(card3, True, True, 0)
def _click(self, widget):
children = self.play_box.get_children()
if len(children) > 2:
self.play_box.remove(children[-1])
self.play_box.remove(children[-2])
self.my_box.remove(widget)
self.play_box.pack_start(widget, True, False, 0)
self.opponent_box.remove(random.choice(self.opponent_box.get_children()))
img = Gtk.Image()
c = random.choice(self.cards[3: 5])
img.set_from_file('icons/cards/' + c + '.svg')
self.play_box.pack_start(img, True, False, 0)
img.show()
|