Informatik10/maedn/Field.py

69 lines
1.6 KiB
Python

import Board
class Field():
""" Class of single field on game board
:version: 0.1
:author: Martin Putzlocher
"""
def __init__(self, board:Board.Board=None, number:int=0, color:str="black", house:bool=False):
""" Constructor
"""
if board is None:
raise Exception("No Board Exception")
self.board = board
self._n = number
self._c = color
self._h = house
self._id = ""
self.set_id(color, number, house)
self.occupied = False
def get_id(self):
""" Get ID of field instance
"""
return self._id
def set_id(self, color:str, number:int, house:bool):
""" Set ID of field instance
:param color:str:
:param number:int:
:param house:bool:
"""
if house:
assert 0 <= number <= 3
self._id = "H" + color[:3] + str(number)
else:
assert 0 <= number <= 10
self._id = "S" + color[:3] + str(number)
return self._id
def get_number(self):
""" Get the number 0...9 of the field
"""
return self._n
def get_color(self):
""" Get the color of the field
"""
return self._c
def get_next_field(self, color_of_stone="black"):
""" Give back next field on board, dependent on the color of a stone on the current
field.
:param color_of_stone: Default value = "black")
:returns: Field :
@author : Martin Putzlocher
"""
return self.board.get_next_field_by_color(self, color_of_stone)