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 Sun 31 May 02:33
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] = 0;
  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 < mt.nextInt(50)+10; 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, mt.nextInt(500)+100);
  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.                 else
  37.                 {
  38.                     if (terrain[x][y] < 5)
  39.                     {
  40.                         terrain[x][y] += mt.nextInt(5);
  41.                     }
  42.                     else
  43.                     {
  44.                         terrain[x][y] /= 5;
  45.                     }
  46.                 }
  47.             }
  48.         }
  49.         for (int i = 0; i < 3; i++)
  50.         {
  51.             for (int x = 0; x < 100; x++)
  52.             {
  53.                 for (int y = 0; y < 100; y++)
  54.                 {
  55.                     if (terrain[x][y] > 0)
  56.                     {
  57.                         int ticks = 0;
  58.                         float amount = 0;
  59.                         if (x + 1 < 100)
  60.                         {
  61.                             ticks ++;
  62.                             amount += terrain[x+1][y];
  63.                         }
  64.                         if (y + 1 < 100)
  65.                         {
  66.                             ticks ++;
  67.                             amount += terrain[x][y+1];
  68.                         }
  69.                         if (x + 1 < 100 && y + 1 < 100)
  70.                         {
  71.                             ticks ++;
  72.                             amount += terrain[x+1][y+1];
  73.                         }
  74.                         if (x - 1 >= 0)
  75.                         {
  76.                             ticks ++;
  77.                             amount += terrain[x-1][y];
  78.                         }
  79.                         if (y - 1 >= 0)
  80.                         {
  81.                             ticks ++;
  82.                             amount += terrain[x][y-1];
  83.                         }
  84.                         if (x - 1 >= 0 && y - 1 >= 0)
  85.                         {
  86.                             ticks ++;
  87.                             amount += terrain[x-1][y-1];
  88.                         }
  89.                         if (x - 1 >= 0 && y + 1 < 100)
  90.                         {
  91.                             ticks ++;
  92.                             amount += terrain[x-1][y+1];
  93.                         }
  94.                         if (x + 1 < 100 && y - 1 >= 0)
  95.                         {
  96.                             ticks ++;
  97.                             amount += terrain[x+1][y-1];
  98.                         }
  99.                         terrain[x][y] = Math.round(amount / ticks);
  100.                     }
  101.                 }
  102.             }
  103.         }
  104.         for (int i = 0; i < 4; i++)
  105.         {
  106.             for (int x = 0; x < 100; x++)
  107.             {
  108.                 for (int y = 0; y < 100; y++)
  109.                 {
  110.                     if (terrain[x][y] > 0)
  111.                     {
  112.                         int ticks = 0;
  113.                         if (x + 1 < 100)
  114.                         {
  115.                             if (terrain[x+1][y] == 0)
  116.                             {
  117.                                 ticks ++;
  118.                             }
  119.                         }
  120.                         if (y + 1 < 100)
  121.                         {
  122.                             if (terrain[x][y+1] == 0)
  123.                             {
  124.                                 ticks ++;
  125.                             }
  126.                         }
  127.                         if (x + 1 < 100 && y + 1 < 100)
  128.                         {
  129.                             if (terrain[x+1][y+1] == 0)
  130.                             {
  131.                                 ticks ++;
  132.                             }
  133.                         }
  134.                         if (x - 1 >= 0)
  135.                         {
  136.                             if (terrain[x-1][y] == 0)
  137.                             {
  138.                                 ticks ++;
  139.                             }
  140.                         }
  141.                         if (y - 1 >= 0)
  142.                         {
  143.                             if (terrain[x][y-1] == 0)
  144.                             {
  145.                                 ticks ++;
  146.                             }
  147.                         }
  148.                         if (x - 1 >= 0 && y - 1 >= 0)
  149.                         {
  150.                             if (terrain[x-1][y-1] == 0)
  151.                             {
  152.                                 ticks ++;
  153.                             }
  154.                         }
  155.                         if (x - 1 >= 0 && y + 1 < 100)
  156.                         {
  157.                             if (terrain[x-1][y+1] == 0)
  158.                             {
  159.                                 ticks ++;
  160.                             }
  161.                         }
  162.                         if (x + 1 < 100 && y - 1 >= 0)
  163.                         {
  164.                             if (terrain[x+1][y-1] == 0)
  165.                             {
  166.                                 ticks ++;
  167.                             }
  168.                         }
  169.                         if (ticks > 4)
  170.                         {
  171.                             terrain[x][y] = 0;
  172.                         }
  173.                     }
  174.                 }
  175.             }
  176.         }
  177.         for (int i = 0; i < 4; i++)
  178.         {
  179.             for (int x = 0; x < 100; x++)
  180.             {
  181.                 for (int y = 0; y < 100; y++)
  182.                 {
  183.                     if (terrain[x][y] == 0)
  184.                     {
  185.                         int ticks = 0;
  186.                         if (x + 1 < 100)
  187.                         {
  188.                             if (terrain[x+1][y] > 0)
  189.                             {
  190.                                 ticks ++;
  191.                             }
  192.                         }
  193.                         if (y + 1 < 100)
  194.                         {
  195.                             if (terrain[x][y+1] > 0)
  196.                             {
  197.                                 ticks ++;
  198.                             }
  199.                         }
  200.                         if (x + 1 < 100 && y + 1 < 100)
  201.                         {
  202.                             if (terrain[x+1][y+1] > 0)
  203.                             {
  204.                                 ticks ++;
  205.                             }
  206.                         }
  207.                         if (x - 1 >= 0)
  208.                         {
  209.                             if (terrain[x-1][y] > 0)
  210.                             {
  211.                                 ticks ++;
  212.                             }
  213.                         }
  214.                         if (y - 1 >= 0)
  215.                         {
  216.                             if (terrain[x][y-1] > 0)
  217.                             {
  218.                                 ticks ++;
  219.                             }
  220.                         }
  221.                         if (x - 1 >= 0 && y - 1 >= 0)
  222.                         {
  223.                             if (terrain[x-1][y-1] > 0)
  224.                             {
  225.                                 ticks ++;
  226.                             }
  227.                         }
  228.                         if (x - 1 >= 0 && y + 1 < 100)
  229.                         {
  230.                             if (terrain[x-1][y+1] > 0)
  231.                             {
  232.                                 ticks ++;
  233.                             }
  234.                         }
  235.                         if (x + 1 < 100 && y - 1 >= 0)
  236.                         {
  237.                             if (terrain[x+1][y-1] > 0)
  238.                             {
  239.                                 ticks ++;
  240.                             }
  241.                         }
  242.                         if (ticks > 4)
  243.                         {
  244.                             terrain[x][y] = 1;
  245.                         }
  246.                     }
  247.                 }
  248.             }
  249.         }
  250.         for (int x = 0; x < 100; x++)
  251.         {
  252.             for (int y = 0; y < 100; y++)
  253.             {
  254.                 if (terrain[x][y] > 0)
  255.                 {
  256.                     terrain[x][y] += mt.nextInt(10);
  257.                 }
  258.             }
  259.         }
  260.     }
  261.  
  262.     private void growWater(int x, int y, int amount)
  263.     {
  264.         if (amount > 0 && terrain[x][y] == 1)
  265.         {
  266.             terrain[x][y] = 0;
  267.             boolean up = false;
  268.             boolean down = false;
  269.             boolean left = false;
  270.             boolean right = false;
  271.             if (y - 1 >= 0 && mt.nextInt(100) > 50)
  272.             {
  273.                 if (terrain[x][y-1] == 1)
  274.                 {
  275.                     up = true;
  276.                 }
  277.             }
  278.             if (x + 1 < 100 && mt.nextInt(100) > 50)
  279.             {
  280.                 if (terrain[x+1][y] == 1)
  281.                 {
  282.                     right = true;
  283.                 }
  284.             }
  285.             if (y + 1 < 100 && mt.nextInt(100) > 50)
  286.             {
  287.                 if (terrain[x][y+1] == 1)
  288.                 {
  289.                     down = true;
  290.                 }
  291.             }
  292.             if (x - 1 >= 0 && mt.nextInt(100) > 50)
  293.             {
  294.                 if (terrain[x-1][y] == 1)
  295.                 {
  296.                     left = true;
  297.                 }
  298.             }
  299.             int directionAmount = 0;
  300.             if (up) directionAmount ++;
  301.             if (right) directionAmount ++;
  302.             if (down) directionAmount ++;
  303.             if (left) directionAmount ++;
  304.             if (amount - directionAmount >= 0)
  305.             {
  306.                 if (up)
  307.                 {
  308.                     growWater(x, y-1, amount - 1);
  309.                 }
  310.                 if (right)
  311.                 {
  312.                     growWater(x+1, y, amount - 1);
  313.                 }
  314.                 if (down)
  315.                 {
  316.                     growWater(x, y+1, amount - 1);
  317.                 }
  318.                 if (left)
  319.                 {
  320.                     growWater(x-1, y, amount - 1);
  321.                 }
  322.             }
  323.         }
  324.     }
  325.    
  326.     private void growLand(int x, int y, int height)
  327.     {
  328.         if (terrainDone[x][y] < 1)
  329.         {
  330.             terrain[x][y] = height;
  331.             terrainDone[x][y] ++;
  332.             if (mt.nextBoolean())
  333.             {
  334.                 if (y - 1 >= 0 && height - 1 > 0)
  335.                 {
  336.                     if (terrain[x][y-1] > 0)
  337.                     {
  338.                         growLand(x, y - 1, height - 1);
  339.                     }
  340.                 }
  341.             }
  342.             else
  343.             {
  344.                 if (y + 1 < 100 && height - 1 > 0)
  345.                 {
  346.                     if (terrain[x][y+1] > 0)
  347.                     {
  348.                         growLand(x, y + 1, height - 1);
  349.                     }
  350.                 }
  351.             }
  352.             if (mt.nextBoolean())
  353.             {
  354.                 if (x + 1 < 100 && height - 1 > 0)
  355.                 {
  356.                     if (terrain[x+1][y] > 0)
  357.                     {
  358.                         growLand(x + 1, y, height - 1);
  359.                     }
  360.                 }
  361.             }
  362.             else
  363.             {
  364.                 if (x - 1 >= 0 && height - 1 > 0)
  365.                 {
  366.                     if (terrain[x-1][y] > 0)
  367.                     {
  368.                         growLand(x - 1, y, height - 1);
  369.                     }
  370.                 }
  371.             }
  372.         }
  373.     }

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