本文整理汇总了Python中sprites.Sprites类的典型用法代码示例。如果您正苦于以下问题:Python Sprites类的具体用法?Python Sprites怎么用?Python Sprites使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sprites类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, canvas, parent=None, colors=['#A0FFA0', '#FF8080']):
self._activity = parent
self._colors = [colors[0]]
self._colors.append(colors[1])
self._colors.append('#D0D0D0')
self._colors.append('#000000')
self._canvas = canvas
if parent is not None:
parent.show_all()
self._parent = parent
self._canvas.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self._canvas.connect("draw", self.__draw_cb)
self._canvas.connect("button-press-event", self._button_press_cb)
self._width = Gdk.Screen.width()
self._height = Gdk.Screen.height() - (GRID_CELL_SIZE * 1.5)
self._scale = self._width / (10 * DOT_SIZE * 1.2)
self._dot_size = int(DOT_SIZE * self._scale)
self._space = int(self._dot_size / 5.)
self.we_are_sharing = False
self._edge = 4
self._move_list = []
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
self._dots = []
self._generate_grid()
示例2: _setup_workspace
def _setup_workspace(self):
''' Add the bones. '''
self._width = Gdk.Screen.width()
self._height = int(Gdk.Screen.height() - (GRID_CELL_SIZE * 2))
self._scale = self._height * 1.0 / BONE_HEIGHT
self._bone_width = int(BONE_WIDTH * self._scale)
self._bone_height = int(BONE_HEIGHT * self._scale)
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
self._bone_index = Sprite(self._sprites, 0, 0, _load_svg_from_file(
os.path.join(self._bone_path, 'bones-index.svg'),
self._bone_width, self._bone_height))
self._max_bones = int(self._width / self._bone_width) - 1
self._blank_image = _load_svg_from_file(
os.path.join(self._bone_path, 'blank-bone.svg'),
self._bone_width, self._bone_height)
for bones in range(self._max_bones):
self._bones.append(Sprite(self._sprites, bones * self._bone_width,
0, self._blank_image))
circle_image = _load_svg_from_file(
os.path.join(self._bone_path, 'circle.svg'), int(self._scale * 45),
int(self._scale * 45))
self._circles[0] = Sprite(self._sprites, 0, -100, circle_image)
self._circles[1] = Sprite(self._sprites, 0, -100, circle_image)
oval_image = _load_svg_from_file(
os.path.join(self._bone_path, 'oval.svg'), int(self._scale * 129),
int(self._scale * 92))
for bones in range(self._max_bones - 1):
self._ovals.append(Sprite(self._sprites, 0, -100, oval_image))
示例3: __init__
def __init__(self, canvas, parent=None, path=None,
colors=['#A0FFA0', '#FF8080']):
self._canvas = canvas
self._parent = parent
self._parent.show_all()
self._path = path
self.level = 1
self._colors = ['#FFFFFF']
self._colors.append(colors[0])
self._colors.append(colors[1])
self._colors.append(colors[0])
self._colors.append('#FF0000')
self._canvas.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self._canvas.connect("draw", self.__draw_cb)
self._canvas.connect("button-press-event", self._button_press_cb)
self._width = Gdk.Screen.width()
self._height = Gdk.Screen.height() - GRID_CELL_SIZE
if self._width < self._height:
self.portrait = True
self.grid_height = TEN
self.grid.width = SEVEN
else:
self.portrait = False
self.grid_height = SEVEN
self.grid_width = TEN
self._scale = min(self._width / (self.grid_width * DOT_SIZE * 1.2),
self._height / (self.grid_height * DOT_SIZE * 1.2))
self._dot_size = int(DOT_SIZE * self._scale)
self._space = int(self._dot_size / 5.)
self.we_are_sharing = False
# '-1' Workaround for showing 'second 0'
self._game_time_seconds = -1
self._game_time = "00:00"
self._timeout_id = None
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
self._dots = []
for y in range(self.grid_height):
for x in range(self.grid_width):
xoffset = int((self._width - self.grid_width * self._dot_size -
(self.grid_width - 1) * self._space) / 2.)
self._dots.append(
Sprite(self._sprites,
xoffset + x * (self._dot_size + self._space),
y * (self._dot_size + self._space),
self._new_dot(self._colors[0])))
self._dots[-1].type = 0 # not set
self._dots[-1].set_label_attributes(40)
self._all_clear()
Gdk.Screen.get_default().connect('size-changed', self._configure_cb)
示例4: __init__
def __init__(self, canvas, parent=None, colors=['#A0FFA0', '#FF8080']):
self._activity = parent
self._colors = colors
self._canvas = canvas
parent.show_all()
self._canvas.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self._canvas.connect("draw", self.__draw_cb)
self._canvas.connect("button-press-event", self._button_press_cb)
self._width = Gdk.Screen.width()
self._height = Gdk.Screen.height() - (GRID_CELL_SIZE * 1.5)
self._scale = self._height / (14.0 * DOT_SIZE * 1.2)
self._dot_size = int(DOT_SIZE * self._scale)
self._turtle_offset = 0
self._space = int(self._dot_size / 5.)
self._orientation = 0
self.level = 0
self.custom_strategy = None
self.strategies = [BEGINNER_STRATEGY, INTERMEDIATE_STRATEGY,
EXPERT_STRATEGY, self.custom_strategy]
self.strategy = self.strategies[self.level]
self._timeout_id = None
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
self._dots = []
for y in range(THIRTEEN):
for x in range(THIRTEEN):
xoffset = int((self._width - THIRTEEN * (self._dot_size + \
self._space) - self._space) / 2.)
if y % 2 == 1:
xoffset += int((self._dot_size + self._space) / 2.)
if x == 0 or y == 0 or x == THIRTEEN - 1 or y == THIRTEEN - 1:
self._dots.append(
Sprite(self._sprites,
xoffset + x * (self._dot_size + self._space),
y * (self._dot_size + self._space),
self._new_dot('#B0B0B0')))
else:
self._dots.append(
Sprite(self._sprites,
xoffset + x * (self._dot_size + self._space),
y * (self._dot_size + self._space),
self._new_dot(self._colors[FILL])))
self._dots[-1].type = False # not set
# Put a turtle at the center of the screen...
self._turtle_images = []
self._rotate_turtle(self._new_turtle())
self._turtle = Sprite(self._sprites, 0, 0,
self._turtle_images[0])
self._move_turtle(self._dots[int(THIRTEEN * THIRTEEN / 2)].get_xy())
# ...and initialize.
self._all_clear()
示例5: __init__
def __init__(self, canvas, parent=None, colors=['#A0FFA0', '#FF8080']):
self._activity = parent
self.colors = colors
# Starting from command line
if parent is None:
self._running_sugar = False
self._canvas = canvas
else:
self._running_sugar = True
self._canvas = canvas
parent.show_all()
self._canvas.set_flags(gtk.CAN_FOCUS)
self._canvas.add_events(gtk.gdk.BUTTON_PRESS_MASK)
self._canvas.add_events(gtk.gdk.BUTTON_RELEASE_MASK)
self._canvas.add_events(gtk.gdk.POINTER_MOTION_MASK)
self._canvas.connect("expose-event", self._expose_cb)
self._canvas.connect("button-press-event", self._button_press_cb)
self._canvas.connect("button-release-event", self._button_release_cb)
self._canvas.connect("motion-notify-event", self._mouse_move_cb)
self._canvas.connect("key_press_event", self._keypress_cb)
self._width = gtk.gdk.screen_width()
self._height = gtk.gdk.screen_height() - (GRID_CELL_SIZE * 1.5)
self._scale = self._height / (8.0 * TILE_HEIGHT)
self.tile_width = TILE_WIDTH * self._scale
self.tile_height = TILE_HEIGHT * self._scale
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
self.grid = Grid(self._sprites, self._width, self._height,
self.tile_width, self.tile_height, self._scale,
colors[0])
self.deck = Deck(self._sprites, self._scale, colors[1])
self.deck.board.move((self.grid.left, self.grid.top))
self.hands = []
self.hands.append(Hand(self.tile_width, self.tile_height))
self._errormsg = []
for i in range(4):
self._errormsg.append(error_graphic(self._sprites))
self._highlight = highlight_graphic(self._sprites, self._scale)
self._score_card = blank_tile(self._sprites, scale=self._scale * 2,
color=colors[1])
self._score_card.set_label_attributes(64)
self._score_card.move(((int(self._width / 2) - self.tile_width),
int(self._height / 2) - self.tile_height))
# and initialize a few variables we'll need.
self.buddies = []
self._my_hand = MY_HAND
self.playing_with_robot = False
self._all_clear()
示例6: __init__
def __init__(self, canvas, parent=None, mycolors=['#A0FFA0', '#FF8080']):
self._activity = parent
self.colors = [mycolors[0]]
self.colors.append(mycolors[1])
self._canvas = canvas
if parent is not None:
parent.show_all()
self._parent = parent
self._canvas.connect("draw", self.__draw_cb)
self._canvas.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self._canvas.connect("button-press-event", self._button_press_cb)
self._canvas.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK)
self._canvas.connect('button-release-event', self._button_release_cb)
self._canvas.add_events(Gdk.EventMask.POINTER_MOTION_MASK)
self._canvas.connect("motion-notify-event", self._mouse_move_cb)
self._width = Gdk.Screen.width()
self._height = Gdk.Screen.height() - GRID_CELL_SIZE
self._scale = self._width / 1200.
self.press = None
self.dragpos = [0, 0]
self.startpos = [0, 0]
self._dot_cache = {}
self._xo_cache = {}
self._radius = 22.5
self._stroke_width = 9.5
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
self._sprites.set_delay(True)
self._dots = []
self._xo_man = None
self._generate_bg('#FFF')
# First dot, starting angle
self._cxy = [self._width / 2, self._height / 2]
self._xy = [self._width / 2 + 120 * self._scale,
self._height / 2 - self._radius * self._scale]
self._angle = 0
self._dot_size_plus = self._radius * 3 * self._scale
self._min = -self._dot_size_plus / 3
self._max = self._height - (self._dot_size_plus / 2.2)
self._zones = []
self._calc_zones()
self._generate_spiral()
self._sprites.draw_all()
示例7: __init__
def __init__(self, canvas, path, parent=None):
""" Initialize the playing surface """
self.path = path
self.activity = parent
# starting from command line
# we have to do all the work that was done in CardSortActivity.py
if parent is None:
self.sugar = False
self.canvas = canvas
# starting from Sugar
else:
self.sugar = True
self.canvas = canvas
parent.show_all()
self.canvas.set_flags(gtk.CAN_FOCUS)
self.canvas.add_events(gtk.gdk.BUTTON_PRESS_MASK)
self.canvas.add_events(gtk.gdk.BUTTON_RELEASE_MASK)
self.canvas.connect("expose-event", self._expose_cb)
self.canvas.connect("button-press-event", self._button_press_cb)
self.canvas.connect("button-release-event", self._button_release_cb)
self.canvas.connect("key_press_event", self._keypress_cb)
self.width = gtk.gdk.screen_width()
self.height = gtk.gdk.screen_height() - GRID_CELL_SIZE
self.card_dim = CARD_DIM
self.scale = 0.6 * self.height / (self.card_dim * 3)
# Initialize the sprite repository
self.sprites = Sprites(self.canvas)
# Initialize the grid
self.mode = 'rectangle'
self.grid = Grid(self, self.mode)
self.bounds = LEVEL_BOUNDS[0]
self.level = 0
# Start solving the puzzle
self.press = None
self.release = None
self.start_drag = [0, 0]
示例8: __init__
def __init__(self, canvas, parent=None, colors=['#A0FFA0', '#FF8080']):
self._activity = parent
self._colors = [colors[0]]
self._colors.append(colors[1])
self._canvas = canvas
if parent is not None:
parent.show_all()
self._parent = parent
self._canvas.connect("draw", self.__draw_cb)
self._width = Gdk.Screen.width()
self._height = Gdk.Screen.height() - (GRID_CELL_SIZE * 1.5)
self._scale = self._width / (10 * DOT_SIZE * 1.2)
self._dot_size = int(DOT_SIZE * self._scale)
self._space = int(self._dot_size / 5.)
self.max_levels = len(LEVELS_TRUE)
self.this_pattern = False
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
self._dots = []
self._generate_grid()
示例9: __init__
def __init__(self, canvas, parent=None, path=None):
self._canvas = canvas
self._parent = parent
self._parent.show_all()
self._path = path
self._canvas.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self._canvas.connect("draw", self.__draw_cb)
self._canvas.connect("button-press-event", self._button_press_cb)
self._width = Gdk.Screen.width()
self._height = Gdk.Screen.height()
self._scale = self._width / 1200.
self._target = 0
self._tries = 0
self.level = 0
self._picture_cards = []
self._small_picture_cards = []
self.food_cards = []
self._group_cards = []
self._quantity_cards = []
self._balance_cards = []
self._last_twenty = []
self._background = None
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
self._background = Sprite(
self._sprites, 0, 0, GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images','background.png'),
self._width, self._height))
self._background.set_layer(0)
self._background.type = None
self._background.hide()
self.pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images', 'word-box.png'),
int(350 * self._scale), int(100 * self._scale))
for i in range(len(FOOD_DATA) / 4):
FOOD.append([FOOD_DATA[i * 4 + NAME], FOOD_DATA[i * 4 + CALS],
FOOD_DATA[i * 4 + GROUP], FOOD_DATA[i * 4 + IMAGE]])
self.food_cards.append(None)
self._picture_cards.append(None)
for j in range(6):
self._small_picture_cards.append(None)
self.allocate_food(0)
x = 10
dx, dy = self.food_cards[0].get_dimensions()
y = 10
for i in range(len(MYPLATE)):
self.word_card_append(self._group_cards, self.pixbuf)
self._group_cards[-1].type = i
self._group_cards[-1].set_label(MYPLATE[i][0])
self._group_cards[-1].move((x, y))
y += int(dy * 1.25)
y = 10
for i in range(len(QUANTITIES)):
self.word_card_append(self._quantity_cards, self.pixbuf)
self._quantity_cards[-1].type = i
self._quantity_cards[-1].set_label(QUANTITIES[i])
self._quantity_cards[-1].move((x, y))
y += int(dy * 1.25)
y = 10
for i in range(len(BALANCE)):
self.word_card_append(self._balance_cards, self.pixbuf)
self._balance_cards[-1].type = i
self._balance_cards[-1].set_label(BALANCE[i])
self._balance_cards[-1].move((x, y))
y += int(dy * 1.25)
self._smile = Sprite(self._sprites,
int(self._width / 4),
int(self._height / 4),
GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images', 'correct.png'),
int(self._width / 2),
int(self._height / 2)))
self._smile.set_label_attributes(36)
self._smile.set_margins(10, 0, 10, 0)
self._frown = Sprite(self._sprites,
int(self._width / 4),
int(self._height / 4),
GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images', 'wrong.png'),
int(self._width / 2),
int(self._height / 2)))
self._frown.set_label_attributes(36)
self._frown.set_margins(10, 0, 10, 0)
self.build_food_groups()
self._all_clear()
示例10: Game
class Game():
def __init__(self, canvas, parent=None, path=None):
self._canvas = canvas
self._parent = parent
self._parent.show_all()
self._path = path
self._canvas.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self._canvas.connect("draw", self.__draw_cb)
self._canvas.connect("button-press-event", self._button_press_cb)
self._width = Gdk.Screen.width()
self._height = Gdk.Screen.height()
self._scale = self._width / 1200.
self._target = 0
self._tries = 0
self.level = 0
self._picture_cards = []
self._small_picture_cards = []
self.food_cards = []
self._group_cards = []
self._quantity_cards = []
self._balance_cards = []
self._last_twenty = []
self._background = None
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
self._background = Sprite(
self._sprites, 0, 0, GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images','background.png'),
self._width, self._height))
self._background.set_layer(0)
self._background.type = None
self._background.hide()
self.pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images', 'word-box.png'),
int(350 * self._scale), int(100 * self._scale))
for i in range(len(FOOD_DATA) / 4):
FOOD.append([FOOD_DATA[i * 4 + NAME], FOOD_DATA[i * 4 + CALS],
FOOD_DATA[i * 4 + GROUP], FOOD_DATA[i * 4 + IMAGE]])
self.food_cards.append(None)
self._picture_cards.append(None)
for j in range(6):
self._small_picture_cards.append(None)
self.allocate_food(0)
x = 10
dx, dy = self.food_cards[0].get_dimensions()
y = 10
for i in range(len(MYPLATE)):
self.word_card_append(self._group_cards, self.pixbuf)
self._group_cards[-1].type = i
self._group_cards[-1].set_label(MYPLATE[i][0])
self._group_cards[-1].move((x, y))
y += int(dy * 1.25)
y = 10
for i in range(len(QUANTITIES)):
self.word_card_append(self._quantity_cards, self.pixbuf)
self._quantity_cards[-1].type = i
self._quantity_cards[-1].set_label(QUANTITIES[i])
self._quantity_cards[-1].move((x, y))
y += int(dy * 1.25)
y = 10
for i in range(len(BALANCE)):
self.word_card_append(self._balance_cards, self.pixbuf)
self._balance_cards[-1].type = i
self._balance_cards[-1].set_label(BALANCE[i])
self._balance_cards[-1].move((x, y))
y += int(dy * 1.25)
self._smile = Sprite(self._sprites,
int(self._width / 4),
int(self._height / 4),
GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images', 'correct.png'),
int(self._width / 2),
int(self._height / 2)))
self._smile.set_label_attributes(36)
self._smile.set_margins(10, 0, 10, 0)
self._frown = Sprite(self._sprites,
int(self._width / 4),
int(self._height / 4),
GdkPixbuf.Pixbuf.new_from_file_at_size(
os.path.join(self._path, 'images', 'wrong.png'),
int(self._width / 2),
int(self._height / 2)))
self._frown.set_label_attributes(36)
self._frown.set_margins(10, 0, 10, 0)
self.build_food_groups()
#.........这里部分代码省略.........
示例11: BBoardActivity
class BBoardActivity(activity.Activity):
''' Make a slideshow from starred Journal entries. '''
def __init__(self, handle):
''' Initialize the toolbars and the work surface '''
super(BBoardActivity, self).__init__(handle)
self.datapath = get_path(activity, 'instance')
self._hw = get_hardware()
self._playback_buttons = {}
self._audio_recordings = {}
self.colors = profile.get_color().to_string().split(',')
self._setup_toolbars()
self._setup_canvas()
self.slides = []
self._setup_workspace()
self._buddies = [profile.get_nick_name()]
self._setup_presence_service()
self._thumbs = []
self._thumbnail_mode = False
self._recording = False
self._grecord = None
self._alert = None
self._dirty = False
def _setup_canvas(self):
''' Create a canvas '''
self._canvas = gtk.DrawingArea()
self._canvas.set_size_request(int(gtk.gdk.screen_width()),
int(gtk.gdk.screen_height()))
self._canvas.show()
self.set_canvas(self._canvas)
self.show_all()
self._canvas.set_flags(gtk.CAN_FOCUS)
self._canvas.add_events(gtk.gdk.BUTTON_PRESS_MASK)
self._canvas.add_events(gtk.gdk.POINTER_MOTION_MASK)
self._canvas.add_events(gtk.gdk.BUTTON_RELEASE_MASK)
self._canvas.add_events(gtk.gdk.KEY_PRESS_MASK)
self._canvas.connect("expose-event", self._expose_cb)
self._canvas.connect("button-press-event", self._button_press_cb)
self._canvas.connect("button-release-event", self._button_release_cb)
self._canvas.connect("motion-notify-event", self._mouse_move_cb)
def _setup_workspace(self):
''' Prepare to render the datastore entries. '''
# Use the lighter color for the text background
if lighter_color(self.colors) == 0:
tmp = self.colors[0]
self.colors[0] = self.colors[1]
self.colors[1] = tmp
self._width = gtk.gdk.screen_width()
self._height = gtk.gdk.screen_height()
self._scale = gtk.gdk.screen_height() / 900.
if not HAVE_TOOLBOX and self._hw[0:2] == 'xo':
titlef = 18
descriptionf = 12
else:
titlef = 36
descriptionf = 24
self._find_starred()
for ds in self.dsobjects:
if 'title' in ds.metadata:
title = ds.metadata['title']
else:
title = None
pixbuf = None
media_object = False
mimetype = None
if 'mime_type' in ds.metadata:
mimetype = ds.metadata['mime_type']
if mimetype[0:5] == 'image':
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(
ds.file_path, MAXX, MAXY)
# ds.file_path, 300, 225)
media_object = True
else:
pixbuf = get_pixbuf_from_journal(ds, MAXX, MAXY) # 300, 225)
if 'description' in ds.metadata:
desc = ds.metadata['description']
else:
desc = None
self.slides.append(Slide(True, ds.object_id, self.colors,
title, pixbuf, desc))
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
#.........这里部分代码省略.........
示例12: Yupana
class Yupana():
def __init__(self, canvas, parent=None, colors=['#A0FFA0', '#FF8080']):
self._activity = parent
self._colors = ['#FFFFFF']
self._colors.append(colors[0])
self._colors.append(colors[1])
self._colors.append('#000000')
self._canvas = canvas
if parent is not None:
parent.show_all()
self._parent = parent
self._canvas.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self._canvas.connect("draw", self.__draw_cb)
self._canvas.connect("button-press-event", self._button_press_cb)
self._width = Gdk.Screen.width()
self._height = Gdk.Screen.height() - (GRID_CELL_SIZE * 1.5)
self._scale = self._width / (20 * DOT_SIZE * 1.1)
self._dot_size = int(DOT_SIZE * self._scale)
self._space = int(self._dot_size / 5.)
self.we_are_sharing = False
self._sum = 0
self._mode = 'ten'
self.custom = [1, 1, 1, 1, 10]
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
Sprite(self._sprites, 0, 0, self._box(self._width, self._height,
color=colors[1]))
self._number_box = Sprite(self._sprites, 0, 0, self._box(
self._width, 2 * self._dot_size, color=colors[1]))
self._number_box.set_label_attributes(48)
self._dots = []
for p in range(SIX):
y = self._height - self._space
Sprite(self._sprites, 0, y, self._line(vertical=False))
x = int(p * self._width / 6) + self._space
y -= self._dot_size
for d in range(3): # bottom of fives row
self._dots.append(
Sprite(self._sprites, x, y,
self._new_dot(self._colors[0])))
self._dots[-1].type = 0 # not set
# self._dots[-1].set_label_color('white')
x += self._dot_size + self._space
x = int((p * self._width / 6.) + self._dot_size / 2.) + self._space
y -= self._dot_size + self._space
for d in range(2): # top of fives row
self._dots.append(
Sprite(self._sprites, x, y,
self._new_dot(self._colors[0])))
self._dots[-1].type = 0 # not set
# self._dots[-1].set_label_color('white')
x += self._dot_size + self._space
y -= self._dot_size
Sprite(self._sprites, 0, y, self._line(vertical=False))
x = int((p * self._width / 6.) + self._dot_size / 2.) + self._space
y -= self._dot_size
for d in range(2): # bottom of threes row
self._dots.append(
Sprite(self._sprites, x, y,
self._new_dot(self._colors[0])))
self._dots[-1].type = 0 # not set
# self._dots[-1].set_label_color('white')
x += self._dot_size + self._space
x = int((p * self._width / 6.) + self._dot_size) + self._space
y -= self._dot_size + self._space
for d in range(1): # top of threes row
self._dots.append(
Sprite(self._sprites, x, y,
self._new_dot(self._colors[0])))
self._dots[-1].type = 0 # not set
# self._dots[-1].set_label_color('white')
x += self._dot_size + self._space
y -= self._dot_size
Sprite(self._sprites, 0, y, self._line(vertical=False))
x = int((p * self._width / 6.) + self._dot_size / 2.) + self._space
y -= self._dot_size
for d in range(2): # twos row
self._dots.append(
Sprite(self._sprites, x, y,
self._new_dot(self._colors[0])))
self._dots[-1].type = 0 # not set
# self._dots[-1].set_label_color('white')
x += self._dot_size + self._space
y -= self._dot_size
Sprite(self._sprites, 0, y, self._line(vertical=False))
x = int((p * self._width / 6.) + self._dot_size) + self._space
#.........这里部分代码省略.........
示例13: Game
class Game():
def __init__(self, canvas, parent=None, colors=['#A0FFA0', '#FF8080']):
self._activity = parent
self.colors = colors
# Starting from command line
if parent is None:
self._running_sugar = False
self._canvas = canvas
else:
self._running_sugar = True
self._canvas = canvas
parent.show_all()
self._canvas.set_flags(gtk.CAN_FOCUS)
self._canvas.add_events(gtk.gdk.BUTTON_PRESS_MASK)
self._canvas.add_events(gtk.gdk.BUTTON_RELEASE_MASK)
self._canvas.add_events(gtk.gdk.POINTER_MOTION_MASK)
self._canvas.connect("expose-event", self._expose_cb)
self._canvas.connect("button-press-event", self._button_press_cb)
self._canvas.connect("button-release-event", self._button_release_cb)
self._canvas.connect("motion-notify-event", self._mouse_move_cb)
self._canvas.connect("key_press_event", self._keypress_cb)
self._width = gtk.gdk.screen_width()
self._height = gtk.gdk.screen_height() - (GRID_CELL_SIZE * 1.5)
self._scale = self._height / (8.0 * TILE_HEIGHT)
self.tile_width = TILE_WIDTH * self._scale
self.tile_height = TILE_HEIGHT * self._scale
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
self.grid = Grid(self._sprites, self._width, self._height,
self.tile_width, self.tile_height, self._scale,
colors[0])
self.deck = Deck(self._sprites, self._scale, colors[1])
self.deck.board.move((self.grid.left, self.grid.top))
self.hands = []
self.hands.append(Hand(self.tile_width, self.tile_height))
self._errormsg = []
for i in range(4):
self._errormsg.append(error_graphic(self._sprites))
self._highlight = highlight_graphic(self._sprites, self._scale)
self._score_card = blank_tile(self._sprites, scale=self._scale * 2,
color=colors[1])
self._score_card.set_label_attributes(64)
self._score_card.move(((int(self._width / 2) - self.tile_width),
int(self._height / 2) - self.tile_height))
# and initialize a few variables we'll need.
self.buddies = []
self._my_hand = MY_HAND
self.playing_with_robot = False
self._all_clear()
def _all_clear(self):
''' Things to reinitialize when starting up a new game. '''
self._hide_highlight()
self._hide_errormsgs()
self.deck.hide()
self.deck.clear()
self.grid.clear()
for hand in self.hands:
hand.clear()
self.show_connected_tiles()
self._press = None
self._release = None
self._dragpos = [0, 0]
self._total_drag = [0, 0]
self.last_spr_moved = None
self._last_tile_played = None
self._last_tile_orientation = 0
self._last_grid_played = None
self.whos_turn = MY_HAND
self._waiting_for_my_turn = False
self._waiting_for_robot = False
self.placed_a_tile = False
self._there_are_errors = False
self.score = 0
self._score_card.set_layer(HIDE)
self._score_card.move(((int(self._width / 2) - self.tile_width),
int(self._height / 2) - self.tile_height))
self.saw_game_over = False
def _initiating(self):
if not self._running_sugar:
return True
return self._activity.initiating
def new_game(self, saved_state=None, deck_index=0):
''' Start a new game. '''
self._all_clear()
# If we are not sharing or we are the sharer...
if not self.we_are_sharing() or self._initiating():
# Let joiners know we are starting a new game...
#.........这里部分代码省略.........
示例14: Game
class Game():
def __init__(self, canvas, parent=None, colors=['#A0FFA0', '#FF8080']):
self._activity = parent
self._colors = [colors[0]]
self._colors.append(colors[1])
self._colors.append('#FFFFFF')
self._colors.append('#000000')
self._colors.append('#FF0000')
self._colors.append('#FF8000')
self._colors.append('#FFFF00')
self._colors.append('#00FF00')
self._colors.append('#00FFFF')
self._colors.append('#0000FF')
self._colors.append('#FF00FF')
self._canvas = canvas
if parent is not None:
parent.show_all()
self._parent = parent
self._canvas.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self._canvas.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK)
self._canvas.add_events(Gdk.EventMask.POINTER_MOTION_MASK)
self._canvas.connect("draw", self.__draw_cb)
self._canvas.connect("button-press-event", self._button_press_cb)
self._canvas.connect("button-release-event", self._button_release_cb)
self._canvas.connect("motion-notify-event", self._mouse_move_cb)
self._width = Gdk.Screen.width()
self._height = Gdk.Screen.height() - GRID_CELL_SIZE
scale = [self._width / (10 * DOT_SIZE * 1.2),
self._height / (6 * DOT_SIZE * 1.2)]
self._scale = min(scale)
self._dot_size = int(DOT_SIZE * self._scale)
self._space = int(self._dot_size / 5.)
self._orientation = 'horizontal'
self.we_are_sharing = False
self.playing_with_robot = False
self._press = False
self.last_spr = None
self._timer = None
self.roygbiv = False
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
self._dots = []
for y in range(SIX):
for x in range(TEN):
xoffset = int((self._width - TEN * self._dot_size - \
(TEN - 1) * self._space) / 2.)
self._dots.append(
Sprite(self._sprites,
xoffset + x * (self._dot_size + self._space),
y * (self._dot_size + self._space),
self._new_dot(self._colors[2])))
self._dots[-1].type = 2 # not set
self._dots[-1].set_label_attributes(40)
self.vline = Sprite(self._sprites,
int(self._width / 2.) - 1,
0, self._line(vertical=True))
n = SIX / 2.
self.hline = Sprite(
self._sprites, 0,
int(self._dot_size * n + self._space * (n - 0.5)) - 1,
self._line(vertical=False))
self.hline.hide()
# and initialize a few variables we'll need.
self._all_clear()
def _all_clear(self):
''' Things to reinitialize when starting up a new game. '''
for dot in self._dots:
dot.type = 2
dot.set_shape(self._new_dot(self._colors[2]))
dot.set_label('')
self._set_orientation()
def _set_orientation(self):
''' Set bar and message for current orientation '''
if self._orientation == 'horizontal':
self.hline.hide()
self.vline.set_layer(1000)
elif self._orientation == 'vertical':
self.hline.set_layer(1000)
self.vline.hide()
else:
self.hline.set_layer(1000)
self.vline.set_layer(1000)
'''
if self._orientation == 'horizontal':
self._set_label(
_('Click on the dots to make a horizontal reflection.'))
elif self._orientation == 'vertical':
self._set_label(
#.........这里部分代码省略.........
示例15: Game
class Game():
''' OLPC XO man color changer designed in memory of Nat Jacobson '''
def __init__(self, canvas, parent=None, mycolors=['#A0FFA0', '#FF8080']):
self._activity = parent
self.colors = [mycolors[0]]
self.colors.append(mycolors[1])
self._canvas = canvas
if parent is not None:
parent.show_all()
self._parent = parent
self._canvas.connect("draw", self.__draw_cb)
self._canvas.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
self._canvas.connect("button-press-event", self._button_press_cb)
self._canvas.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK)
self._canvas.connect('button-release-event', self._button_release_cb)
self._canvas.add_events(Gdk.EventMask.POINTER_MOTION_MASK)
self._canvas.connect("motion-notify-event", self._mouse_move_cb)
self._width = Gdk.Screen.width()
self._height = Gdk.Screen.height() - GRID_CELL_SIZE
self._scale = self._width / 1200.
self.press = None
self.dragpos = [0, 0]
self.startpos = [0, 0]
self._dot_cache = {}
self._xo_cache = {}
self._radius = 22.5
self._stroke_width = 9.5
# Generate the sprites we'll need...
self._sprites = Sprites(self._canvas)
self._sprites.set_delay(True)
self._dots = []
self._xo_man = None
self._generate_bg('#FFF')
# First dot, starting angle
self._cxy = [self._width / 2, self._height / 2]
self._xy = [self._width / 2 + 120 * self._scale,
self._height / 2 - self._radius * self._scale]
self._angle = 0
self._dot_size_plus = self._radius * 3 * self._scale
self._min = -self._dot_size_plus / 3
self._max = self._height - (self._dot_size_plus / 2.2)
self._zones = []
self._calc_zones()
self._generate_spiral()
self._sprites.draw_all()
def _calc_zones(self):
for color in colors:
rgb1 = _from_hex(color[0])
rgb2 = _from_hex(color[1])
dv = _contrast(rgb1, rgb2)
dh = _delta_hue(rgb1, rgb2)
self._zones.append(_zone(dv, dh))
def _calc_next_dot_position(self):
''' calculate spiral coordinates '''
dx = self._xy[0] - self._cxy[0]
dy = self._xy[1] - self._cxy[1]
r = sqrt(dx * dx + dy * dy)
c = 2 * r * pi
a = atan2(dy, dx)
da = (self._dot_size_plus / c) * 2 * pi
a += da
r += self._dot_size_plus / (c / self._dot_size_plus)
self._xy[0] = r * cos(a) + self._cxy[0]
self._xy[1] = r * sin(a) + self._cxy[1]
if self._xy[1] < self._min or self._xy[1] > self._max:
self._calc_next_dot_position()
def _generate_spiral(self):
''' Make a new set of dots for a sprial '''
for z in range(4):
for i in range(len(colors)):
if self._zones[i] == z:
self._dots.append(
Sprite(self._sprites, self._xy[0], self._xy[1],
self._new_dot(colors[i])))
self._dots[-1].type = i
self._calc_next_dot_position()
if self._xo_man is None:
x = 510 * self._scale
y = 280 * self._scale
self._xo_man = Sprite(self._sprites, x, y,
self._new_xo_man(self.colors))
self._xo_man.type = None
def move_dot(self, i, x, y):
self._dots[i].move((x, y))
def get_dot_xy(self, i):
#.........这里部分代码省略.........