contract CommonGame is ICommonGame {
    address public gameAdmin;
    uint public blocks2Finish;
    uint internal totalV;
    uint internal sm_reserved;
    bool internal finishing;
    uint internal finishingBlock;
    bool internal autoCreation;
    bool internal autoCreationAfterOwn;
    bool internal transferInteractions;
    bool internal startMinPrizes;
    bool internal profitedGames;


    constructor(address _gameAdmin) public {
        assert(_gameAdmin != 0);
        
        gameAdmin = _gameAdmin;
        blocks2Finish = 50000;
        totalV = 1000;
        autoCreation = true;
        autoCreationAfterOwn = true;
        transferInteractions = false;
        startMinPrizes = false;
        profitedGames = false;
    }

    function getGameAdmin() public view returns (address) {
        return gameAdmin;
    }

    function gameFinished() public view returns(bool) {
        return gameFinishing() && gameFinishedBlock() < block.number;
    }

    // true if the game is finishing
    function gameFinishing() public view returns(bool) {
        return finishing;
    }

    // stops the game
    function stopGame() admin public {
        stopGameInternal(blocks2Finish);
    }

    function totalVariants() public view returns(uint) {
        return totalV;
    }

    function alterTotalVariants(uint _newVariants) admin public {
        totalV = _newVariants;
        emit TotalVariantsChanged(totalV);
    }

    function stopGameInternal(uint blocks2add) internal {
        require(!finishing);

        finishing = true;
        // about one month for finishing
        finishingBlock = block.number + blocks2add;
        emit GameStopInitiated(finishingBlock);
    }


    function gameFinishedBlock() public view returns(uint) {
        return finishingBlock;
    }

    function autoCreationAllowed() public view returns(bool) {
        return autoCreation;
    }

    function setAutoCreation(bool allowed) public admin {
        autoCreation = allowed;
        emit AutoCreationChanged(autoCreation);
    }

    function autoCreationAfterOwnAllowed() public view returns(bool) {
        return autoCreationAfterOwn;
    }

    function setAutoCreationAfterOwn(bool allowed) public admin {
        autoCreationAfterOwn = allowed;
        emit AutoCreationAfterOwnChanged(autoCreation);
    }


    function transferInteractionsAllowed() public view returns(bool) {
        return transferInteractions;
    }
    function setTransferInteractions(bool allowed) public admin {
        transferInteractions = allowed;
        emit TransferInteractionsChanged(transferInteractions);
    }

    function startOnlyMinPrizes() public view returns (bool) {
        return startMinPrizes;
    }

    function setStartOnlyMinPrizes(bool minPrizes) public admin {
        startMinPrizes = minPrizes;
        emit StartOnlyMinPrizesChanged(startMinPrizes);
    }

    function startProfitedGamesAllowed() public view returns (bool) {
        return profitedGames;
    }

    function setStartProfitedGamesAllowed(bool games) public admin {
        profitedGames = games;
        emit StartProfitedGamesAllowedChanged(profitedGames);
    }
}
function stopGame() admin public {
    stopGameInternal(blocks2Finish);
}

// stops the game