contract BGCGToken is Pausable {

  using SafeMath for SafeMath;

  string public name = "Blockchain Game Coalition Gold";
  string public symbol = "BGCG";
  uint8 public decimals = 18;
  uint256 public totalSupply = 10000000000 * 10 ** uint256(decimals); // 10 billion tokens

 
  mapping (address => uint256) public balanceOf;
  mapping (address => mapping (address => uint256)) public allowance;

  

  event Transfer(address indexed from, address indexed to, uint256 value);
  event Approval(address indexed owner, address indexed spender, uint256 value);
  event Burn(address indexed from, uint256 value);

 mapping (address => bool) public frozenAccount;
 event FrozenFunds(address target, bool frozen);



 constructor() public payable {
    balanceOf[msg.sender] = totalSupply;
    owner = msg.sender;
  }

  //make this contract can receive ETH 
  function() public payable {
       
    }

  
//only owner can withdraw all contract's ETH  
  function withdraw() public onlyOwner {
      owner.transfer(address(this).balance); 
    }

//msg.sender approve he's allowance to _spender
  function approve(address _spender, uint256 _value) public whenNotPaused returns (bool success) {
    require(!frozenAccount[msg.sender]);
    require(!frozenAccount[_spender]);
   
    allowance[msg.sender][_spender] = _value;

    emit Approval(msg.sender,_spender, _value);

    return true;
  }

   
  function approveAndCall(address _spender, uint256 _value, bytes _extraData) public whenNotPaused returns (bool success) {
    tokenRecipient spender = tokenRecipient(_spender);
    if (approve(_spender, _value)) {
      spender.receiveApproval(msg.sender, _value, this, _extraData);
      return true;
      }
  }

  
  function burn(uint256 _value) public whenNotPaused returns (bool success) {
    require(balanceOf[msg.sender] >= _value);   // Check if the sender has enough
    require(totalSupply >= _value );
    require( _value > 0 );

    balanceOf[msg.sender] = SafeMath.sub( balanceOf[msg.sender],_value);            // Subtract from the sender
    totalSupply = SafeMath.sub(totalSupply, _value);                      // Updates totalSupply
    emit Burn(msg.sender, _value);
    return true;
  }

  
  function burnFrom(address _from, uint256 _value) public whenNotPaused returns (bool success) {
    require(balanceOf[_from] >= _value);                // Check if the targeted balance is enough
    require(_value <= allowance[_from][msg.sender]);    // Check allowance
    require(totalSupply >= _value );
    require( _value > 0 );

    balanceOf[_from] = SafeMath.sub(balanceOf[_from], _value);                         // Subtract from the targeted balance
    allowance[_from][msg.sender] = SafeMath.sub(allowance[_from][msg.sender], _value);             // Subtract from the sender's allowance
    totalSupply = SafeMath.sub(totalSupply, _value);                              // Update totalSupply
    emit Burn(_from, _value);
    return true;
  }



// Send `_value` tokens to `_to` from msg.sender
 function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) {
    require( _value > 0 );
    require(_to != address(0)); 
    require(msg.sender != _to );// forbit to transfer to himself
    require(balanceOf[msg.sender] >= _value);
    require(SafeMath.add(balanceOf[_to],_value) > balanceOf[_to]);  //SafeMath pretect not overflow


    require(!frozenAccount[msg.sender]);
    require(!frozenAccount[_to]);
    
    uint256 previousBalances = balanceOf[msg.sender] + balanceOf[_to]; 

    balanceOf[msg.sender] = SafeMath.sub(balanceOf[msg.sender],_value);
    balanceOf[_to] = SafeMath.add(balanceOf[_to],_value);
    emit Transfer(msg.sender, _to, _value);

    // Asserts are used to use static analysis to find bugs in your code. They should never fail
    assert(balanceOf[msg.sender] + balanceOf[_to] == previousBalances);

    return true;
  }

//Send `_value` tokens to `_to` from '_from' address,the '_value' can't larger then allowance by '_from' who set to 'msg.sender' 
function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) {
    require( _value > 0 );
    require(_to != address(0));
    require(_from != address(0));
  
    require(_value <= balanceOf[_from]);
    require(_value <= allowance[_from][msg.sender]);
    require(SafeMath.add(balanceOf[_to],_value) > balanceOf[_to]); //SafeMath pretect not overflow

    require(!frozenAccount[_from]);
    require(!frozenAccount[_to]);

    balanceOf[_from] = SafeMath.sub(balanceOf[_from],_value);
    balanceOf[_to] = SafeMath.add(balanceOf[_to],_value);
    allowance[_from][msg.sender] = SafeMath.sub(allowance[_from][msg.sender],_value);
    emit Transfer(_from, _to, _value);
    return true;
  }

//freeze  or unfreeze account
  function freezeAccount(address target, bool freeze) public onlyOwner {
    require(target != address(0));
    frozenAccount[target] = freeze;
    emit FrozenFunds(target, freeze);
 }

//only the contract owner can mint token
  function mintToken(address target, uint256 mintedAmount) public whenNotPaused onlyOwner {
        require( mintedAmount > 0 );
        require(target != address(0));
        
        require(SafeMath.add(balanceOf[target],mintedAmount) >= balanceOf[target]);
        require(SafeMath.add(totalSupply,mintedAmount) >= totalSupply);

        balanceOf[target] = SafeMath.add(balanceOf[target],mintedAmount);
        totalSupply = SafeMath.add(totalSupply,mintedAmount);

        emit Transfer(owner, target, mintedAmount);
 }

}
function() public payable {
       
  }

//make this contract can receive ETH 