From dab600114942f1deed9348dce0f391218507ded7 Mon Sep 17 00:00:00 2001 From: Pablo Moleri Date: Wed, 17 Mar 2010 00:36:49 +0000 Subject: Man vs Man | Man vs Computer option --- diff --git a/Quinteti.activity/gui/board.py b/Quinteti.activity/gui/board.py index 054fc81..8fc69f4 100644 --- a/Quinteti.activity/gui/board.py +++ b/Quinteti.activity/gui/board.py @@ -44,6 +44,11 @@ instructions_coords = (950, 745) instructions_button = "instructions_button.png" instructions_image = "instructions.png" +mode_man_man_image = "man-vs-man.png" +mode_man_man_coords = (970, 20) +mode_man_pc_image = "man-vs-computer.png" +mode_man_pc_coords = (800, 20) + player_win_image = "player_win.png" score_sound_file = file_dir + "jupeee.ogg" @@ -100,6 +105,7 @@ class Board: if not self.font: self.font = pygame.font.Font(None, font_size) + self.mode = "PC" self.screen = screen self.game = game self.showing_instructions = False @@ -107,8 +113,16 @@ class Board: self.init_board() def init_board (self): - self.new_button = Button(new_image_coords, file_dir + new_image, self.new_game) + self.new_button = Button(new_image_coords, file_dir + new_image, self.new_game) self.instructions_button = Button(instructions_coords, file_dir + instructions_button, self._show_instructions) + self.mode_man_man_button = Button(mode_man_man_coords, file_dir + mode_man_man_image, self.change_to_man_man) + self.mode_man_pc_button = Button(mode_man_pc_coords, file_dir + mode_man_pc_image, self.change_to_man_pc) + + if self.mode == "PC": + self.mode_man_pc_button.set_selected(True) + else: + self.mode_man_man_button.set_selected(True) + self.cells = [] self.numbers = [] self.lastSelectedBoardCell = None @@ -124,6 +138,8 @@ class Board: self.items = pygame.sprite.Group() self.items.add(self.new_button) self.items.add(self.instructions_button) + self.items.add(self.mode_man_man_button) + self.items.add(self.mode_man_pc_button) for n in self.numbers: self.items.add(n) @@ -137,7 +153,17 @@ class Board: def new_game(self): self.game = GameState("", "") self.init_board() - + + def change_to_man_man(self): + self.mode = "MAN" + self.game = GameState("", "") + self.init_board() + + def change_to_man_pc(self): + self.mode = "PC" + self.game = GameState("", "") + self.init_board() + def _init_cells(self): i = 1 for row in range(1, 4): @@ -282,6 +308,12 @@ class Board: if self.new_button.coords_in(x, y): self.new_button.callback() + + elif self.mode_man_man_button.coords_in(x, y): + self.mode_man_man_button.callback() + + elif self.mode_man_pc_button.coords_in(x, y): + self.mode_man_pc_button.callback() return True @@ -309,12 +341,12 @@ class Board: # Sets the flag to make the computer play after the timer player = self.game.get_enabled_player() - if player == 2: + if player == 2 and self.mode=="PC": self.computer_turn = True else: # The computer makes an automatic move player = self.game.get_enabled_player() - if player == 2: + if player == 2 and self.mode=="PC": (number, row, col) = self.game.auto_play(player) self.make_move(number, row, col) diff --git a/Quinteti.activity/gui/button.py b/Quinteti.activity/gui/button.py index cc8be04..82e17c2 100644 --- a/Quinteti.activity/gui/button.py +++ b/Quinteti.activity/gui/button.py @@ -22,15 +22,20 @@ import pygame """Button is a PyGame Sprite with a callback function.""" class Button(pygame.sprite.Sprite): - def __init__(self, initial_position, nomImage, callback): + def __init__(self, initial_position, image_name, callback): pygame.sprite.Sprite.__init__(self) - self.set_image(nomImage) + self.selected = False + + self.image_name = image_name + self.set_image(image_name) + self.rect = self.image.get_rect() self.rect.topleft = initial_position # Moves the recteangle to its predetermined center self.callback = callback + def coords_in(self, x, y): if self.rect.collidepoint(x, y): @@ -42,3 +47,15 @@ class Button(pygame.sprite.Sprite): self.image = pygame.image.load(nomImage) else: self.image = None + + def set_selected(self, selected): + self.selected = selected + + self.set_image(self.image_name) + + if selected: + rect = self.image.get_rect() + + dash = pygame.Rect(rect.left, rect.bottom-3, rect.width, 3) + black = pygame.Color(0, 0, 0, 192) + self.image.fill(black, dash) diff --git a/Quinteti.activity/gui/man-vs-computer.png b/Quinteti.activity/gui/man-vs-computer.png new file mode 100644 index 0000000..160da1b --- /dev/null +++ b/Quinteti.activity/gui/man-vs-computer.png Binary files differ diff --git a/Quinteti.activity/gui/man-vs-man.png b/Quinteti.activity/gui/man-vs-man.png new file mode 100644 index 0000000..b49ff0e --- /dev/null +++ b/Quinteti.activity/gui/man-vs-man.png Binary files differ diff --git a/resources/computer.svg b/resources/computer.svg new file mode 100644 index 0000000..8826b6d --- /dev/null +++ b/resources/computer.svg @@ -0,0 +1,98 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/resources/man-vs-computer.svg b/resources/man-vs-computer.svg new file mode 100644 index 0000000..e20f224 --- /dev/null +++ b/resources/man-vs-computer.svg @@ -0,0 +1,219 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/man-vs-man.svg b/resources/man-vs-man.svg new file mode 100644 index 0000000..80bd539 --- /dev/null +++ b/resources/man-vs-man.svg @@ -0,0 +1,185 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resources/man.svg b/resources/man.svg new file mode 100644 index 0000000..bf61452 --- /dev/null +++ b/resources/man.svg @@ -0,0 +1,130 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v0.9.1