Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Moleri <pmoleri@PABLOMOLERI-PC.(none)>2009-09-21 02:13:24 (GMT)
committer Pablo Moleri <pmoleri@PABLOMOLERI-PC.(none)>2009-09-21 02:13:24 (GMT)
commit62d25ba69184219577df2757c778940cbb81e665 (patch)
tree9efba7998269b9b4d9b57c64e55b58bf45523130
parent57419bb9cd31978a455dd9c5abf4842dc2c101dc (diff)
Release v2. sugar cursor added, sound added, number now blink when someone scores.
-rw-r--r--Quinteti.activity/MANIFEST90
-rw-r--r--Quinteti.activity/NEWS8
-rw-r--r--Quinteti.activity/activity/activity.info4
-rw-r--r--Quinteti.activity/gui/board.py74
-rw-r--r--Quinteti.activity/gui/button.py6
-rw-r--r--Quinteti.activity/gui/cell.py32
-rw-r--r--Quinteti.activity/gui/instructions.pngbin132322 -> 130342 bytes
-rw-r--r--Quinteti.activity/gui/instructions.svg34
-rw-r--r--Quinteti.activity/gui/jupeee.oggbin0 -> 11708 bytes
-rw-r--r--Quinteti.activity/logic/game.py25
-rw-r--r--Quinteti.activity/main.py25
11 files changed, 168 insertions, 130 deletions
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("<N>", str(number))
+ path = os.path.join(file_dir, image_number.replace("<N>", 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("<N>", str(number))
+ path = os.path.join(file_dir, image_disabled_number.replace("<N>", 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">
<defs
@@ -157,11 +157,11 @@
sodipodi:role="line"
x="556.71631"
y="51.842243"
- id="tspan5059">Quin-te-ti 0.1 fue desarrollada</tspan><tspan
+ id="tspan5059">QuinTeTi v2 fue desarrollado</tspan><tspan
sodipodi:role="line"
x="556.71631"
y="71.842239"
- id="tspan6422">en Ceibal JAM</tspan><tspan
+ id="tspan6422">en ceibalJAM</tspan><tspan
sodipodi:role="line"
x="556.71631"
y="91.842239"
@@ -185,58 +185,54 @@
sodipodi:role="line"
x="556.71631"
y="191.84224"
- id="tspan5041">Desarrollo:</tspan><tspan
+ id="tspan5041">Autor:</tspan><tspan
sodipodi:role="line"
x="556.71631"
y="211.84224"
- id="tspan5033"> Pablo Moleri</tspan><tspan
+ id="tspan6412"> Pablo Moleri</tspan><tspan
sodipodi:role="line"
x="556.71631"
y="231.84224"
- id="tspan5035"> Juan Manuel Picerno</tspan><tspan
+ id="tspan5055" /><tspan
sodipodi:role="line"
x="556.71631"
y="251.84224"
- id="tspan5053"> Leonardo Val</tspan><tspan
+ id="tspan5121">Diseño gráfico:</tspan><tspan
sodipodi:role="line"
x="556.71631"
y="271.84225"
- id="tspan6412"> Pablo Garin</tspan><tspan
+ id="tspan5071"> Magdalena Sayagués</tspan><tspan
sodipodi:role="line"
x="556.71631"
y="291.84225"
- id="tspan5055" /><tspan
+ id="tspan5047" /><tspan
sodipodi:role="line"
x="556.71631"
y="311.84225"
- id="tspan5121">Diseño gráfico:</tspan><tspan
+ id="tspan2446">Colaboración:</tspan><tspan
sodipodi:role="line"
x="556.71631"
y="331.84225"
- id="tspan5123"> Magdalena Sayagués</tspan><tspan
+ id="tspan2448"> Juan Manuel Picerno</tspan><tspan
sodipodi:role="line"
x="556.71631"
y="351.84225"
- id="tspan5125" /><tspan
+ id="tspan2450"> Leonardo Val</tspan><tspan
sodipodi:role="line"
x="556.71631"
y="371.84225"
- id="tspan5069">Colaboración:</tspan><tspan
+ id="tspan2452"> Pablo Garin</tspan><tspan
sodipodi:role="line"
x="556.71631"
y="391.84225"
- id="tspan5071"> Silvio Sisto</tspan><tspan
+ id="tspan2454" /><tspan
sodipodi:role="line"
x="556.71631"
y="411.84225"
- id="tspan5047" /><tspan
- sodipodi:role="line"
- x="556.71631"
- y="431.84225"
id="tspan5049">Consultas y sugerencias:</tspan><tspan
sodipodi:role="line"
x="556.71631"
- y="451.84225"
+ y="431.84225"
id="tspan5051"> pmoleri@gmail.com</tspan></text>
<text
xml:space="preserve"
diff --git a/Quinteti.activity/gui/jupeee.ogg b/Quinteti.activity/gui/jupeee.ogg
new file mode 100644
index 0000000..f89adbe
--- /dev/null
+++ b/Quinteti.activity/gui/jupeee.ogg
Binary files differ
diff --git a/Quinteti.activity/logic/game.py b/Quinteti.activity/logic/game.py
index 07df8ad..247de6c 100644
--- a/Quinteti.activity/logic/game.py
+++ b/Quinteti.activity/logic/game.py
@@ -81,7 +81,10 @@ class GameState:
return self.numbers
def make_move(self, row1, col1, number, player):
- """Makes a move with the given number in the given cell. Returns a boolean if the move is valid."""
+ """Makes a move with the given number in the given cell.
+
+ Returns a boolean if the move is valid and the score difference.
+ """
row, col = (row1-1, col1-1)
if (self.state[row][col] == None):
@@ -93,11 +96,19 @@ class GameState:
# shadow copy of the given row
row_list = self.matrix[row][:]
+ hits = [] # collection of posistions that made points
+
# Test the move
- score = 0
- score += self._check_action(col_list, row, number)
- score += self._check_action(row_list, col, number)
-
+ col_score = self._check_action(col_list, row, number)
+ row_score = self._check_action(row_list, col, number)
+ score = col_score + row_score
+
+ if col_score:
+ hits.extend(col_list)
+
+ if row_score:
+ hits.extend(row_list)
+
self.state[row][col] = self.turn
self.matrix[row][col] = number
self.numbers.remove(number)
@@ -108,8 +119,8 @@ class GameState:
else:
self.player_2_score += score
self.turn = 1
- return True
- return False
+ return True, hits
+ return False, None
def _check_action(self, list, pos, number):
"""Tests if a move in a row (or column) scores."""
diff --git a/Quinteti.activity/main.py b/Quinteti.activity/main.py
index 7d8c717..dde1bd5 100644
--- a/Quinteti.activity/main.py
+++ b/Quinteti.activity/main.py
@@ -41,7 +41,7 @@ import os
log = logging.getLogger('quinteti')
log.setLevel(logging.DEBUG)
-MAX_FPS = 25 # Max frames per second
+MAX_FPS = 20 # Max frames per second
SLEEP_TIMEOUT = 30 # Seconds until the PauseScreen if no events show up
def main():
@@ -79,12 +79,12 @@ def main():
else:
# Running on regular PC, the screen its scaled to te target_size
internal_screen = pygame.Surface(internal_size)
- scale = (internal_size[0] / float(target_size[0]), internal_size[1] / float(target_size[1]) )
+ scale = (internal_size[0] / float(target_size[0]), internal_size[1] / float(target_size[1]) )
# Creates a new logic game, player names aren't used without mesh
game = GameState("Jugador1", "Jugador2")
board = Board(internal_screen, game)
- board.paintBoardElements()
+ board.paint_board_elements()
pygame.display.update()
@@ -114,25 +114,30 @@ def main():
y = event.pos[1] * scale[1] # to get the internal coordinates
else:
(x, y) = event.pos
-
+
update = board.processXY(x, y)
if event.type == pygame.USEREVENT:
if event.code == olpcgames.FILE_READ_REQUEST:
- game = read_file(event.filename)
+ game = _read_file(event.filename)
log.debug("Loaded:" + game.serialization())
board = Board(internal_screen, game)
update = True
- if event.code == olpcgames.FILE_WRITE_REQUEST:
- save_file(event.filename, game)
-
+ elif event.code == olpcgames.FILE_WRITE_REQUEST:
+ _save_file(event.filename, game)
+
+ if event.type > 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()