//Write your own contracts here. Currently compiles using solc v0.4.15+commit.bbb8e64f. pragma solidity ^0.4.16; //Erc20 contract User { /*modifier enoughmoney { require(balanceOf[msg.sender>=1]); _; }*/ address public PlayerA; address public PlayerB; function DefineUserA() public { PlayerA = msg.sender; } function DefineUserB() public { PlayerB = msg.sender; } //needs a lock, so functions can't be called while game is still going on } contract Fields { User user = User(0x0); //How can I find out the address of the "User contract? enum fieldValue { noValue, aValue, bValue } fieldValue Value; fieldValue constant defaultValue= fieldValue.noValue; //Field on a 3x3 Plan, value describes which player has chosen this field fieldValue [3][3] public fields; //I'm not sure if this is the way you use enums //together with twodimensional arrays modifier occupation(uint i, uint k) { // fields is already public require(fields[i][k] == fieldValue.noValue); _; } //if someone wants to choose a field, we need to make sure that it isn't occupied yet // i describes the row, k the column // function names should follow camelCase https://en.wikipedia.org/wiki/Camel_case function fieldChange (uint i, uint k, fieldValue Value){ //not sure if I used enum correctly here fields[i][k] = Value; } //this function is called when sb. wants to choose a field function PlayA(uint i, uint k) public occupation(i, k) { require(msg.sender == user.PlayerA()); Value = fieldValue.aValue; fieldChange (i, k, Value); } //function which is called by PlayerA to choose field i,k function PlayB(uint i, uint k) public occupation(i, k) { require(msg.sender == user.PlayerB()); Value = fieldValue.bValue; fieldChange (i, k, Value); } //function which is called by PlayerA to choose field i,k } /* k=1 k=2 k=3 ___________ Plan i=1 |___|___|___| i=2 |___|___|___| i=3 |___|___|___| */ contract Winner is Fields{ uint count = 0; function wonGame (fieldValue Value) public returns (bool) { //columns for (uint i=0; i<=2; i++) { for (uint k=0; k<=2; k++) { if (fields[i][k] == Value) { count++; } } } if (count == 3) { return true; } else { count = 0; } //rows for (k=0; k<=2; k++) { for (i=0; i<=2; i++) { if (fields[i][k] == Value) { count++; } } } if (count == 3) { return true; } else {count = 0; } //bottom left to top right i = 3; for (k=0; k<=2; k++) { i = i - 1; if (fields[i][k] == Value) { count++; } } if (count == 3) { return true; } else {count = 0; } //top left to bottom right i = 0; for ( k=0; k<=2; k++) { if (fields[i][k] == Value) { count++; } i++; } if (count == 3) { return true; } else {count = 0; } } }
0.4.24