Module tablero
[hide private]
[frames] | no frames]

Source Code for Module tablero

 1  #!/usr/bin/env python 
 2  # -*- coding: utf-8 -*- 
 3  # 
 4  #    tablero.py 
 5  #        
 6  #    Copyright 2010 Victor Ramirez <virako.9@gmail.com> 
 7  #        
 8  #    This program is free software: you can redistribute it and/or modify 
 9  #    it under the terms of the GNU General Public License as published by 
10  #    the Free Software Foundation, either version 3 of the License, or 
11  #    (at your option) any later version. 
12  # 
13  #    This program is distributed in the hope that it will be useful, 
14  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
15  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
16  #    GNU General Public License for more details. 
17  # 
18  #    You should have received a copy of the GNU General Public License 
19  #    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
20   
21   
22   
23  from cte import SIZE, SPACE 
24   
25 -class Tablero:
26 """Clase que nos crea una matriz tablero para poder guardar todos los datos 27 de las intersecciones y las piedras puestas""" 28
29 - def __init__(self, size = SIZE): # size es el tamaño del tablero, 19 por defecto
30 self.size = size 31 # Esto nos crea una matriz de escalar 4-tuplas, las cuales usaremos para (x pos imagen, y pos imagen, ocupado, num_jugada) 32 self.matriz = [[[0,0,{0:SPACE}] for x in range(size)] for y in range(size)] 33 self.square = [0,0]
34
35 - def get_x_y(self):
36 """Funcion que nos devuelve en que coordenadas se encuentra la 37 intersección del tablero 1-1, y la 19-19""" 38 x1 = self.matriz[0][0][0] - self.square[0] 39 y1 = self.matriz[0][1][1] - self.square[1] 40 x2 = self.matriz[self.size-1][self.size-1][0] + self.square[0] 41 y2 = self.matriz[self.size-1][self.size-1][1] + self.square[1] 42 return x1, x2, y1, y2
43 44
45 - def get_square(self):
46 """Función que cambia el valor de la variable self.square, la cual 47 contiene la información del tamaño de un cuadrado del tablero""" 48 self.square[0] = self.matriz[1][0][0] - self.matriz[0][0][0] 49 self.square[1] = self.matriz[0][1][1] - self.matriz[0][0][1]
50
51 - def __str__(self):
52 cadena = "" 53 for x in range(self.size): 54 for y in range(self.size): 55 cadena += str(self.matriz[x][y][2].items()[-1]) + " " 56 if y == 18: 57 cadena += "\n" 58 return cadena
59