From 62d25ba69184219577df2757c778940cbb81e665 Mon Sep 17 00:00:00 2001 From: Pablo Moleri Date: Mon, 21 Sep 2009 02:13:24 +0000 Subject: Release v2. sugar cursor added, sound added, number now blink when someone scores. --- diff --git a/Quinteti.activity/MANIFEST b/Quinteti.activity/MANIFEST index 0e4067e..d2bee1a 100644 --- a/Quinteti.activity/MANIFEST +++ b/Quinteti.activity/MANIFEST @@ -1,67 +1,63 @@ -MANIFEST -MANIFEST.in -NEWS +main.py TODO -activity.py -create_maifest.sh -run.py setup.py -setup_python.py -activity/activity-quin-te-ti.svg -activity/activity.info +activity.py +NEWS +logic/__init__.py +logic/mesh.py +logic/game.py +gui/2selected.png gui/1.png gui/1selected.png -gui/2.png -gui/2selected.png -gui/3.png -gui/3selected.png -gui/4.png +gui/board.py +gui/instructions.svg gui/4selected.png gui/5.png -gui/5selected.png -gui/6.png -gui/6_bak.png -gui/6selected.png -gui/7.png -gui/7selected.png -gui/8.png -gui/8selected.png +gui/instructions.png gui/9.png -gui/9selected.png -gui/BoardUI.py -gui/Button.py -gui/Cell.py -gui/GameMain.py -gui/Player.py +gui/jupeee.mp3 +gui/button.py +gui/player_win.png +gui/standardcursor_mask.xbm +gui/instructions_button.png +gui/7selected.png +gui/cell.py +gui/standardcursor.xbm +gui/2.png gui/__init__.py +gui/9selected.png +gui/5selected.png +gui/4.png gui/background.png -gui/instructions.png -gui/instructions.svg -gui/instructions_button.png -gui/player_win.png +gui/8.png +gui/3selected.png gui/quinteti-new.png -gui/tablero.png -logic/GameState.py -logic/Mesh.py -logic/__init__.py +gui/3.png +gui/8selected.png +gui/6selected.png +gui/6.png +gui/jupeee.ogg +gui/7.png +activity/activity-quin-te-ti.svg +activity/activity.info olpcgames/COPYING -olpcgames/__init__.py olpcgames/_cairoimage.py olpcgames/_gtkmain.py -olpcgames/_version.py -olpcgames/activity.py -olpcgames/buildmanifest.py olpcgames/camera.py -olpcgames/canvas.py olpcgames/dbusproxy.py -olpcgames/eventwrap.py -olpcgames/gtkEvent.py -olpcgames/mesh.py -olpcgames/pangofont.py -olpcgames/pausescreen.py olpcgames/svgsprite.py +olpcgames/_version.py +olpcgames/__init__.py +olpcgames/pausescreen.py olpcgames/textsprite.py +olpcgames/pangofont.py +olpcgames/eventwrap.py +olpcgames/activity.py +olpcgames/buildmanifest.py +olpcgames/mesh.py +olpcgames/gtkEvent.py olpcgames/util.py olpcgames/video.py -olpcgames/data/__init__.py +olpcgames/canvas.py olpcgames/data/sleeping_svg.py +olpcgames/data/__init__.py diff --git a/Quinteti.activity/NEWS b/Quinteti.activity/NEWS index 38f3f99..1985d92 100644 --- a/Quinteti.activity/NEWS +++ b/Quinteti.activity/NEWS @@ -1,3 +1,9 @@ -Esta es la versión 0.1 de Quinteti. +Version 2: +- Se agrega el cursor estándar de Sugar. +- Al hacer puntos agrega un sonido. +- Al hacer puntos muestra las fichas que hicieron puntos. +- Se mejora el código para respetar los estándares PEP8. +Versión 1: - Es una versión totalmente funcional, pero todavía hay muchas cosas que se pueden hacer para mejorarlo, las mismas están enumeradas en el archivo TODO. + diff --git a/Quinteti.activity/activity/activity.info b/Quinteti.activity/activity/activity.info index 156ec9d..fb0e304 100644 --- a/Quinteti.activity/activity/activity.info +++ b/Quinteti.activity/activity/activity.info @@ -1,7 +1,7 @@ [Activity] name = Quinteti -service_name = uy.ceibaljam.Quinteti +service_name = org.ceibaljam.Quinteti class = activity.Quinteti icon = activity-quin-te-ti -activity_version = 1 +activity_version = 2 show_launcher = yes diff --git a/Quinteti.activity/gui/board.py b/Quinteti.activity/gui/board.py index 6cb67ab..ebbb338 100644 --- a/Quinteti.activity/gui/board.py +++ b/Quinteti.activity/gui/board.py @@ -21,6 +21,8 @@ import pygame +import os + from logic.game import GameState from button import Button @@ -44,6 +46,8 @@ instructions_image = "instructions.png" player_win_image = "player_win.png" +score_sound_file = file_dir + "jupeee.ogg" + font_name = "DejaVu Serif" #"DejaVuLGCSerif.ttf" # None to load pygame default font font_size = 24 user_font_color = (255, 255, 255) @@ -99,6 +103,7 @@ class Board: self.screen = screen self.game = game self.showing_instructions = False + self.score_sound = pygame.mixer.Sound(score_sound_file) self.init_board() def init_board (self): @@ -119,13 +124,9 @@ class Board: self.items = pygame.sprite.Group() self.items.add(self.new_button) self.items.add(self.instructions_button) - for c in self.cells: - if c.image: - self.items.add( c ) - + for n in self.numbers: - if n.image: - self.items.add( n ) + self.items.add(n) def new_game(self): self.game = GameState("", "") @@ -133,21 +134,23 @@ class Board: def _init_cells(self): i = 1 - for row in range(1,4): - for col in range(1,4): + for row in range(1, 4): + for col in range(1, 4): if self.game: number = self.game.get_cell(row, col)[0] else: number = None location = self.locations[i-1] - self.cells.append( Cell(location, self._get_number_name(number), i, image_size) ) + self.cells.append( Cell(location, None, None, i, image_size) ) i += 1 def _init_numbers(self): k = 0 for location in self.number_locations: k += 1 - self.numbers.append(Cell(location, self._get_number_name(k), k, image_size)) + normal_image = self._get_number(k) + selected_image = self._get_disabled_number(k) + self.numbers.append( Cell(location, normal_image, selected_image, k, image_size) ) def set_players(self, name_player1, name_player2): self.game = GameState(name_player1, name_player2) @@ -193,7 +196,7 @@ class Board: score_rect.center = self.players_score_center_location[i-1] self.screen.blit(score_surface, score_rect) - def paintBoardElements(self): + def paint_board_elements(self): # Using an sprite group all the items are painted: #self.items.clear(self.screen, self.backgroundImage) # If only sprites are cleared, players scores remain @@ -216,52 +219,69 @@ class Board: self.showing_instructions = False return else: - if self.instructions_button.coordsIn(x, y): + if self.instructions_button.coords_in(x, y): self.instructions_button.callback() # Checks if the selected coordinate is a board cell isCell = False for c in self.cells: - if c.coordsIn(x, y): + if c.coords_in(x, y): isCell = True self.lastSelectedBoardCell = c if self.lastSelectedNumberCell != None: row, col = c.get_pos() player = self.game.get_enabled_player() - ok = self.game.make_move(row, col, self.lastSelectedNumberCell.idxCell, player) - if ok: - self.lastSelectedBoardCell.setImage( self._get_number_name(self.lastSelectedNumberCell.idxCell) ) - self.items.add(self.lastSelectedBoardCell) - self.items.remove(self.lastSelectedNumberCell) - self.lastSelectedNumberCell.setImage(None) + ok, hits = self.game.make_move(row, col, self.lastSelectedNumberCell.id_cell, player) + if ok: + self.lastSelectedNumberCell.rect = self.lastSelectedBoardCell.rect # Moves the number to the board + self.lastSelectedNumberCell.set_selected(False) self.lastSelectedNumberCell = None + + if hits: + self.score_sound.play() + # Sets a timer to update blinked cells in one second + pygame.time.set_timer(pygame.USEREVENT + 1, 1500) + for number in self.numbers: + if number.id_cell in hits: + number.set_selected(True) + + break # Checks if the selected coordinate is a number if isCell == False: for n in self.numbers: - if n.coordsIn(x,y): + if n.coords_in(x,y): if self.lastSelectedNumberCell: - self.lastSelectedNumberCell.setImage( self._get_number_name(self.lastSelectedNumberCell.idxCell) ) + self.lastSelectedNumberCell.set_selected(False) self.lastSelectedNumberCell = n - n.setImage( self._get_disabled_number_name(n.idxCell) ) + n.set_selected(True) - if self.new_button.coordsIn(x, y): + if self.new_button.coords_in(x, y): self.new_button.callback() return True + def user_event(self, event): + pygame.time.set_timer(pygame.USEREVENT + 1, 0) + if event.type == pygame.USEREVENT + 1: + # Deselect all numbers + for number in self.numbers: + number.set_selected(False) + def _show_instructions(self): self.showing_instructions = True - def _get_number_name(self, number): + def _get_number(self, number): if (number == None) or (number == 0): return None else: - return file_dir + image_number.replace("", str(number)) + path = os.path.join(file_dir, image_number.replace("", str(number))) + return pygame.image.load(path) - def _get_disabled_number_name(self, number): + def _get_disabled_number(self, number): if (number == None) or (number == 0): return None else: - return file_dir + image_disabled_number.replace("", str(number)) + path = os.path.join(file_dir, image_disabled_number.replace("", str(number))) + return pygame.image.load(path) diff --git a/Quinteti.activity/gui/button.py b/Quinteti.activity/gui/button.py index d2efbc2..cc8be04 100644 --- a/Quinteti.activity/gui/button.py +++ b/Quinteti.activity/gui/button.py @@ -26,18 +26,18 @@ class Button(pygame.sprite.Sprite): pygame.sprite.Sprite.__init__(self) - self.setImage(nomImage) + self.set_image(nomImage) self.rect = self.image.get_rect() self.rect.topleft = initial_position # Moves the recteangle to its predetermined center self.callback = callback - def coordsIn(self, x, y): + def coords_in(self, x, y): if self.rect.collidepoint(x, y): return True return False - def setImage(self, nomImage): + def set_image(self, nomImage): if nomImage: self.image = pygame.image.load(nomImage) else: diff --git a/Quinteti.activity/gui/cell.py b/Quinteti.activity/gui/cell.py index 40a4578..83930aa 100644 --- a/Quinteti.activity/gui/cell.py +++ b/Quinteti.activity/gui/cell.py @@ -22,34 +22,38 @@ import pygame """Cell is a PyGame Sprite, capable of loading an image and retain a cell identifier.""" class Cell(pygame.sprite.Sprite): - def __init__(self, initial_position, nomImage, idxCell, size_rect): + + def __init__(self, initial_position, image, selected_image, id_cell, size_rect): pygame.sprite.Sprite.__init__(self) - self.idxCell = idxCell + self.id_cell = id_cell + + self.rect = size_rect.move(0, 0) # Attempting to move creates a copy + self.rect.center = initial_position # Moves the recteangle to its predetermined center - self.rect = size_rect.move(0, 0) # Attempting to move creates a copy - self.rect.center = initial_position # Moves the recteangle to its predetermined center + self.normal_image = image + self.selected_image = selected_image - self.setImage(nomImage) + if image: + self.set_selected(False) - def coordsIn(self, x, y): + def coords_in(self, x, y): #print "Test x: %s < %s < %s Test y: %s < %s < %s" % (self.rect.left, x, self.rect.right, self.rect.top, y, self.rect.bottom) if ( self.rect.collidepoint(x, y) ): return True return False - def setImage(self, nomImage): - if nomImage: - self.image = pygame.image.load(nomImage) - self.nameImage = nomImage + def set_selected(self, selected): + self.selected = selected + if self.selected: + self.image = self.selected_image else: - self.image = None - self.nameImage = None + self.image = self.normal_image def get_pos(self): - row = (self.idxCell - 1) / 3 + 1 - col = (self.idxCell - 1) % 3 + 1 + row = (self.id_cell - 1) / 3 + 1 + col = (self.id_cell - 1) % 3 + 1 return row, col if __name__ == "__main__": diff --git a/Quinteti.activity/gui/instructions.png b/Quinteti.activity/gui/instructions.png index 946b9da..5c55db4 100644 --- a/Quinteti.activity/gui/instructions.png +++ b/Quinteti.activity/gui/instructions.png Binary files differ diff --git a/Quinteti.activity/gui/instructions.svg b/Quinteti.activity/gui/instructions.svg index 5cd917a..b56222a 100644 --- a/Quinteti.activity/gui/instructions.svg +++ b/Quinteti.activity/gui/instructions.svg @@ -16,7 +16,7 @@ version="1.0" sodipodi:docname="instructions.svg" inkscape:output_extension="org.inkscape.output.svg.inkscape" - inkscape:export-filename="/home/pmoleri/quin-te-ti.activity/src/gui/instructions.png" + inkscape:export-filename="/home/pmoleri/quinteti/Quinteti.activity/gui/instructions.png" inkscape:export-xdpi="90" inkscape:export-ydpi="90"> Quin-te-ti 0.1 fue desarrolladaQuinTeTi v2 fue desarrolladoen Ceibal JAMen ceibalJAMDesarrollo:Autor: Pablo Moleri Pablo Moleri Juan Manuel Picerno Leonardo ValDiseño gráfico: Pablo Garin Magdalena SayaguésDiseño gráfico:Colaboración: Magdalena Sayagués Juan Manuel Picerno Leonardo ValColaboración: Pablo Garin Silvio SistoConsultas y sugerencias: pmoleri@gmail.com pygame.USEREVENT and event.type <= pygame.USEREVENT + 10: + log.debug("New user event") + board.user_event(event) + update = True + if update == True: - board.paintBoardElements() + board.paint_board_elements() if scale: pygame.transform.scale(internal_screen, target_size, real_screen) update = False - pygame.display.flip() + pygame.display.flip() # Una vez que sale del loop manda la senal de quit para que cierre la ventana pygame.quit() -- cgit v0.9.1