@@ -13,7 +13,8 @@ struct Pixel {
1313
1414contract EthPixelWar is Ownable {
1515 bool public immutable liteMode;
16- uint16 public immutable nbPixels;
16+ uint16 public immutable dimX;
17+ uint16 public immutable dimY;
1718 bool public pixelWarIsActive;
1819 mapping (uint16 => Pixel) public grid;
1920 mapping (address => uint256 ) public pendingWithdrawals;
@@ -22,15 +23,16 @@ contract EthPixelWar is Ownable {
2223 event ColorUpdated (uint16 pixelId , uint8 r , uint8 g , uint8 b );
2324 event PixelWarEnded ();
2425
25- constructor (uint16 _gridSize , bool _liteMode , address _initialOwner ) Ownable (_initialOwner) {
26- require (_gridSize > 0 && _gridSize <= 255 , "Grid size must be between 1 and 255 " );
27- nbPixels = _gridSize * _gridSize;
26+ constructor (uint16 _dimX , uint16 _dimY , bool _liteMode , address _initialOwner ) Ownable (_initialOwner) {
27+ require (_dimX > 0 && _dimX <= 255 && _dimY > 0 && _dimY <= 255 , "Grid dimensions must be between 1 and 255 " );
2828 liteMode = _liteMode;
29+ dimX = _dimX;
30+ dimY = _dimY;
2931 pixelWarIsActive = true ;
3032 }
3133
3234 modifier validPixelId (uint16 pixelId ) {
33- require (pixelId < nbPixels , "Invalid pixel id " );
35+ require (pixelId < dimX * dimY , "Invalid pixel id " );
3436 _;
3537 }
3638
@@ -84,7 +86,7 @@ contract EthPixelWar is Ownable {
8486 function endPixelWar () public onlyOwner onlyActivePixelWar {
8587 pixelWarIsActive = false ;
8688
87- for (uint16 pixelId = 0 ; pixelId < nbPixels ; pixelId++ ) {
89+ for (uint16 pixelId = 0 ; pixelId < dimX * dimY ; pixelId++ ) {
8890 Pixel storage pixel = grid[pixelId];
8991 if (pixel.owner != address (0 ) && pixel.highestBid > 0 ) {
9092 pendingWithdrawals[pixel.owner] += pixel.highestBid;
@@ -95,8 +97,8 @@ contract EthPixelWar is Ownable {
9597 }
9698
9799 function getGrid () public view returns (Pixel[] memory ) {
98- Pixel[] memory pixels = new Pixel [](nbPixels );
99- for (uint16 pixelId = 0 ; pixelId < nbPixels ; pixelId++ ) {
100+ Pixel[] memory pixels = new Pixel [](dimX * dimY );
101+ for (uint16 pixelId = 0 ; pixelId < dimX * dimY ; pixelId++ ) {
100102 pixels[pixelId] = grid[pixelId];
101103 }
102104 return pixels;
0 commit comments