pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

epitaph64 private pastebin - collaborative debugging tool What's a private pastebin?


Posted by Epitaph64 on Wed 27 May 09:14
report abuse | download | new post

  1. private void generateLand()
  2.     {
  3.         for (int x = 0; x < 100; x++)
  4.         {
  5.             for (int y = 0; y < 100; y++)
  6.             {
  7.                 terrain[x][y] = 1;
  8.                 terrainDone[x][y] = false;
  9.             }
  10.         }
  11.         int amountOfSeeds = mt.nextInt(3)+1;
  12.         for (int i = 0; i < amountOfSeeds; i++)
  13.         {
  14.             int sX = mt.nextInt(50)+25;
  15.             int sY = mt.nextInt(50)+25;
  16.             int amount = mt.nextInt(50)+100;
  17.             growWater(sX, sY, amount);
  18.         }
  19.         for (int i = 0; i < 25; i++)
  20.         {
  21.             int LX = mt.nextInt(100);
  22.             int LY = mt.nextInt(100);
  23.             if (terrain[LX][LY] != 0)
  24.             {
  25.                 growLand(LX, LY, 5);
  26.             }
  27.         }
  28.         for (int x = 0; x < 100; x++)
  29.         {
  30.             for (int y = 0; y < 100; y++)
  31.             {
  32.                 if (terrain[x][y] < 0)
  33.                 {
  34.                     terrain[x][y] = 0;
  35.                 }
  36.             }
  37.         }
  38.         for (int i = 0; i < 4; i++)
  39.         {
  40.             for (int x = 0; x < 100; x++)
  41.             {
  42.                 for (int y = 0; y < 100; y++)
  43.                 {
  44.                     if (terrain[x][y] > 0)
  45.                     {
  46.                         int ticks = 0;
  47.                         if (x + 1 < 100)
  48.                         {
  49.                             if (terrain[x+1][y] == 0)
  50.                             {
  51.                                 ticks ++;
  52.                             }
  53.                         }
  54.                         if (y + 1 < 100)
  55.                         {
  56.                             if (terrain[x][y+1] == 0)
  57.                             {
  58.                                 ticks ++;
  59.                             }
  60.                         }
  61.                         if (x + 1 < 100 && y + 1 < 100)
  62.                         {
  63.                             if (terrain[x+1][y+1] == 0)
  64.                             {
  65.                                 ticks ++;
  66.                             }
  67.                         }
  68.                         if (x - 1 >= 0)
  69.                         {
  70.                             if (terrain[x-1][y] == 0)
  71.                             {
  72.                                 ticks ++;
  73.                             }
  74.                         }
  75.                         if (y - 1 >= 0)
  76.                         {
  77.                             if (terrain[x][y-1] == 0)
  78.                             {
  79.                                 ticks ++;
  80.                             }
  81.                         }
  82.                         if (x - 1 >= 0 && y - 1 >= 0)
  83.                         {
  84.                             if (terrain[x-1][y-1] == 0)
  85.                             {
  86.                                 ticks ++;
  87.                             }
  88.                         }
  89.                         if (x - 1 >= 0 && y + 1 < 100)
  90.                         {
  91.                             if (terrain[x-1][y+1] == 0)
  92.                             {
  93.                                 ticks ++;
  94.                             }
  95.                         }
  96.                         if (x + 1 < 100 && y - 1 >= 0)
  97.                         {
  98.                             if (terrain[x+1][y-1] == 0)
  99.                             {
  100.                                 ticks ++;
  101.                             }
  102.                         }
  103.                         if (ticks > 4)
  104.                         {
  105.                             terrain[x][y] = 0;
  106.                         }
  107.                     }
  108.                 }
  109.             }
  110.         }
  111.         for (int i = 0; i < 4; i++)
  112.         {
  113.             for (int x = 0; x < 100; x++)
  114.             {
  115.                 for (int y = 0; y < 100; y++)
  116.                 {
  117.                     if (terrain[x][y] == 0)
  118.                     {
  119.                         int ticks = 0;
  120.                         if (x + 1 < 100)
  121.                         {
  122.                             if (terrain[x+1][y] > 0)
  123.                             {
  124.                                 ticks ++;
  125.                             }
  126.                         }
  127.                         if (y + 1 < 100)
  128.                         {
  129.                             if (terrain[x][y+1] > 0)
  130.                             {
  131.                                 ticks ++;
  132.                             }
  133.                         }
  134.                         if (x + 1 < 100 && y + 1 < 100)
  135.                         {
  136.                             if (terrain[x+1][y+1] > 0)
  137.                             {
  138.                                 ticks ++;
  139.                             }
  140.                         }
  141.                         if (x - 1 >= 0)
  142.                         {
  143.                             if (terrain[x-1][y] > 0)
  144.                             {
  145.                                 ticks ++;
  146.                             }
  147.                         }
  148.                         if (y - 1 >= 0)
  149.                         {
  150.                             if (terrain[x][y-1] > 0)
  151.                             {
  152.                                 ticks ++;
  153.                             }
  154.                         }
  155.                         if (x - 1 >= 0 && y - 1 >= 0)
  156.                         {
  157.                             if (terrain[x-1][y-1] > 0)
  158.                             {
  159.                                 ticks ++;
  160.                             }
  161.                         }
  162.                         if (x - 1 >= 0 && y + 1 < 100)
  163.                         {
  164.                             if (terrain[x-1][y+1] > 0)
  165.                             {
  166.                                 ticks ++;
  167.                             }
  168.                         }
  169.                         if (x + 1 < 100 && y - 1 >= 0)
  170.                         {
  171.                             if (terrain[x+1][y-1] > 0)
  172.                             {
  173.                                 ticks ++;
  174.                             }
  175.                         }
  176.                         if (ticks > 4)
  177.                         {
  178.                             terrain[x][y] = 1;
  179.                         }
  180.                     }
  181.                 }
  182.             }
  183.         }
  184.     }
  185.  
  186.     private void growWater(int x, int y, int amount)
  187.     {
  188.         if (amount > 0 && terrain[x][y] == 1)
  189.         {
  190.             terrain[x][y] = 0;
  191.             boolean up = false;
  192.             boolean down = false;
  193.             boolean left = false;
  194.             boolean right = false;
  195.             if (y - 1 >= 0 && mt.nextInt(100) > 50)
  196.             {
  197.                 if (terrain[x][y-1] == 1)
  198.                 {
  199.                     up = true;
  200.                 }
  201.             }
  202.             if (x + 1 < 100 && mt.nextInt(100) > 50)
  203.             {
  204.                 if (terrain[x+1][y] == 1)
  205.                 {
  206.                     right = true;
  207.                 }
  208.             }
  209.             if (y + 1 < 100 && mt.nextInt(100) > 50)
  210.             {
  211.                 if (terrain[x][y+1] == 1)
  212.                 {
  213.                     down = true;
  214.                 }
  215.             }
  216.             if (x - 1 >= 0 && mt.nextInt(100) > 50)
  217.             {
  218.                 if (terrain[x-1][y] == 1)
  219.                 {
  220.                     left = true;
  221.                 }
  222.             }
  223.             int directionAmount = 0;
  224.             if (up) directionAmount ++;
  225.             if (right) directionAmount ++;
  226.             if (down) directionAmount ++;
  227.             if (left) directionAmount ++;
  228.             if (amount - directionAmount >= 0)
  229.             {
  230.                 if (up)
  231.                 {
  232.                     growWater(x, y-1, amount - 1);
  233.                 }
  234.                 if (right)
  235.                 {
  236.                     growWater(x+1, y, amount - 1);
  237.                 }
  238.                 if (down)
  239.                 {
  240.                     growWater(x, y+1, amount - 1);
  241.                 }
  242.                 if (left)
  243.                 {
  244.                     growWater(x-1, y, amount - 1);
  245.                 }
  246.             }
  247.         }
  248.     }
  249.    
  250.     private void growLand(int x, int y, int height)
  251.     {
  252.         if (terrain[x][y] != 0 && terrainDone[x][y] == false)
  253.         {
  254.             terrain[x][y] = height;
  255.             terrainDone[x][y] = true;
  256.  
  257.             if (mt.nextBoolean())
  258.             {
  259.                 if (y - 1 >= 0)
  260.                 {
  261.                     if (mt.nextBoolean())
  262.                     {
  263.                         growLand(x, y - 1, height + 1);
  264.                     }
  265.                     else
  266.                     {
  267.                         growLand(x, y - 1, height - 1);
  268.                     }
  269.                 }
  270.             }
  271.             if (mt.nextBoolean())
  272.             {
  273.                 if (x + 1 < 100)
  274.                 {
  275.                     if (mt.nextBoolean())
  276.                     {
  277.                         growLand(x + 1, y, height + 1);
  278.                     }
  279.                     else
  280.                     {
  281.                         growLand(x + 1, y, height - 1);
  282.                     }
  283.                 }
  284.             }
  285.             if (mt.nextBoolean())
  286.             {
  287.                 if (y + 1 < 100)
  288.                 {
  289.                     if (mt.nextBoolean())
  290.                     {
  291.                         growLand(x, y + 1, height + 1);
  292.                     }
  293.                     else
  294.                     {
  295.                         growLand(x, y + 1, height - 1);
  296.                     }
  297.                 }
  298.             }
  299.             if (mt.nextBoolean())
  300.             {
  301.                 if (x - 1 >= 0)
  302.                 {
  303.                     if (mt.nextBoolean())
  304.                     {
  305.                         growLand(x - 1, y, height + 1);
  306.                     }
  307.                     else
  308.                     {
  309.                         growLand(x - 1, y, height - 1);
  310.                     }
  311.                 }
  312.             }
  313.         }
  314.     }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post