# Class represents a location in the minefield

class Mine:
    ## A mine can be planted
    ## Flagging asserts that there is a mine; this may
    ##   be incorrect
    ## Revealing asserts that there is no mine. 
    def __init__(self):
        self.cleared = False
        self.planted = False
        self.flagged = False
        self.count = 0

    ##  Plant a mine - no condition
    def plant(self):
        self.planted = True

    ##  Toggle the flag, provided not cleared
    def flag(self):
        if self.cleared : return False
        self.flagged = not self.flagged
        return True
        
    ##  Clear the mine, provided not flagged or cleared
    def clear(self):
        if self.flagged or self.cleared:
            return False
        self.cleared = True
        return True

    ##  Set the neighbour count - no condition
    def setCount(self, num):
        self.count = num

    ##  Get the clear status
    def getClear(self):
        return self.cleared

    ##  Get the planted (i.e. mined) status 
    def getPlant(self):
        return self.planted

    ##  Get the flagged status 
    def getFlag(self):
        return self.flagged

## This function shows a mine at the end of the game.
## The mines are displayed as follows:
##   - cleared, no mine                     .
##   - cleared, mine (BOOM)                 B
##   - uncleared, no mine                   *
##   - flagged, mine(correctly detected)    m
##   - unflagged, mine (undetected)         M
##   - flagged, no mine(incorrect)          x
    def revealState(self):
        if self.cleared:
            if self.planted:
                return 'B'
            else:
                return '.'
        else:
            if self.planted and self.flagged:
                return 'm'
            elif self.planted and not self.flagged:
                return 'M'
            elif not self.planted and self.flagged:
                return 'x'
            else:
                return '*'
            
## This function shows the state of a mine during the game.
## The mines are displayed as follows:
##   - revealed, no mine                     count
##   - unrevealed                            *
##   - flagged                               m
    def showState(self):
        if self.cleared:
            return str(self.count)
        elif self.flagged:
            return 'm'
        else:
            return '*'


                
