-
-
Save altuntasfatih/a733d17e5a72743f5523801e8078da5c to your computer and use it in GitHub Desktop.
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.19+commit.c4cbbb05.js&optimize=false&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.0; | |
| contract Blackjack { | |
| event test_value(string name); | |
| event joinedPlayer( | |
| address playerAdd, | |
| uint bet, | |
| address ownAdd | |
| ); | |
| address owner; | |
| function Blackjack() public { // Add this constructor | |
| owner = msg.sender; | |
| } | |
| modifier onlyOwner { | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| mapping (address => Game) public Games; | |
| uint public gameCount; | |
| struct Player{ | |
| string name; | |
| uint bet; | |
| uint score; | |
| } | |
| struct Game { | |
| uint minBet; | |
| uint totalBet; | |
| address own; | |
| mapping (address => Player) players; | |
| address[] participants; | |
| uint countPlayers; | |
| } | |
| function createGame(uint _startBet, uint _countPlayers,string name) public payable{ | |
| if (msg.value != _startBet* 10**18 ){ | |
| revert(); | |
| } | |
| var game = Games[msg.sender]; | |
| game.minBet=_startBet; | |
| game.countPlayers=_countPlayers-1; | |
| game.own=msg.sender; | |
| game.totalBet+=msg.value/ (10**18) ; | |
| game.players[msg.sender]=Player(name,_startBet,0); | |
| game.participants.push(msg.sender); | |
| //msg.value/ (10**18) ; | |
| gameCount+=1; | |
| } | |
| function joinGame(address play,string name) payable { | |
| var game=Games[play]; | |
| if ( game.countPlayers==0 || msg.value != game.minBet* 10**18){//game is full | |
| revert(); | |
| } | |
| game.players[msg.sender]=Player(name,msg.value/ (10**18) ,0); | |
| //game.players[msg.sender]=msg.value/ (10**18) ; | |
| game.countPlayers-=1; | |
| game.totalBet+=msg.value/ (10**18) ; | |
| joinedPlayer(msg.sender,msg.value,play); | |
| } | |
| function updateState(address play,uint score) public { | |
| var game=Games[play]; | |
| if (game.minBet == 0 || game.players[msg.sender].bet==0){ | |
| revert();//player is not found | |
| } | |
| game.players[msg.sender].score=score; | |
| bool finish=true; | |
| for(uint i=0;i<game.participants.length;i++) | |
| { | |
| var ply=game.players[game.participants[i]]; | |
| test_value(ply.name); | |
| if (ply.score==0){ | |
| finish=false; | |
| break; | |
| } | |
| } | |
| if (finish==true){ | |
| //send ether to winner | |
| test_value("kazandi biri"); | |
| } | |
| joinedPlayer(msg.sender,msg.value,play); | |
| } | |
| function getBalance() view public returns (uint) { | |
| return address(this).balance ; | |
| } | |
| function getBet(address play) view public returns (uint) { | |
| var game=Games[play]; | |
| return game.minBet; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.0; | |
| contract EtherTransferTo { | |
| function () public payable { | |
| } | |
| function getBalance() public returns (uint) { | |
| return address(this).balance; | |
| } | |
| } | |
| contract EtherTransferFrom { | |
| EtherTransferTo private _instance; | |
| function EtherTransferFrom() public { | |
| // _instance = EtherTransferTo(address(this)); | |
| _instance = new EtherTransferTo(); | |
| } | |
| function getBalance() public returns (uint) { | |
| return address(this).balance; | |
| } | |
| function getBalanceOfInstance() public returns (uint) { | |
| //return address(_instance).balance; | |
| return _instance.getBalance(); | |
| } | |
| function () public payable { | |
| //msg.sender.send(msg.value); | |
| address(_instance).send(msg.value); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.0; | |
| contract FuncConcert { | |
| address owner; | |
| uint public tickets; | |
| uint public constant price =1 ether; | |
| //diffrent modifier represent value | |
| // | |
| mapping (address => uint) public purchasers; | |
| function FuncConcert(){ | |
| owner = msg.sender; | |
| tickets =5; | |
| } | |
| function () payable{//fallback function | |
| buyTickets(1); | |
| } | |
| function buyTickets(uint amount) payable { | |
| //msg.value how much ether send this function | |
| if (msg.value != (amount*price) || amount > tickets){ | |
| throw; | |
| } | |
| purchasers[msg.sender] += amount; | |
| tickets -= amount; | |
| if (tickets==0){ | |
| selfdestruct(owner); | |
| } | |
| } | |
| /* | |
| function Balance() public returns(uint){ | |
| return this.balance(); | |
| } | |
| */ | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment