Advertisement
marwanpro

processing 421 v2

Oct 8th, 2015
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.81 KB | None | 0 0
  1. int Dice1;
  2. int Dice2;
  3. int Dice3;
  4. IntList DiceList;
  5. int DiceSize = 160; // Valeur de la taille des dés (Max: 200)
  6. int PointSize = 20; // Valeur de la taille des points
  7. int ScoreJ1 = 0;
  8. int ScoreJ2 = 0;
  9. boolean SelectorD1 = true;
  10. boolean SelectorD2 = true;
  11. boolean SelectorD3 = true;
  12. boolean PlayAgain = true;
  13.  
  14. //String NameJ1 = "";
  15. //String NameJ2 = "";
  16.  
  17. void setup() {
  18.   size(800, 400);
  19.   surface.setTitle("Jeu du 421 - Grimaud Industry");
  20.   background(0, 153, 0);
  21.   //noLoop();
  22.   DiceList = new IntList();
  23. }
  24.  
  25. void draw() {
  26.   //InputPlayer();
  27.   if (PlayAgain == true){
  28.     DisplayDice();
  29.     Randomizer();
  30.     DisplayNumber();
  31.   }
  32.   DispStopButton();
  33.   ButtonDetector();
  34.   DiagnosticVoid();
  35. }
  36.  
  37. void DiagnosticVoid() {
  38.   println(DiceList); // Valeur des dés Sorted
  39.   //println(NameJ1);
  40.   String LenghtStr = "Relancer"; // Longueur en pixel d'un String
  41.   println(textWidth(LenghtStr));
  42. }
  43.  
  44. /*void InputPlayer() {
  45.   String TJ1 = input("Entrer le nombre du joueur 1:");
  46.   String TJ2 = input("Entrer le nombre du joueur 1:");
  47.   int RandomStartOrder = int(random(0,1));
  48.   if (RandomStartOrder == 0) {
  49.     NameJ1 = TJ1;
  50.     NameJ2 = TJ2;
  51.   }
  52.   else {
  53.     NameJ1 = TJ2;
  54.     NameJ2 = TJ1;
  55.   }
  56. }*/
  57.  
  58. void DisplayDice() {
  59.   generateDice(200, 200, DiceSize);
  60.   generateDice(400, 200, DiceSize);
  61.   generateDice(600, 200, DiceSize);
  62. }
  63.  
  64. void generateDice(int XLocation, int YLocation, int SquareSize) {
  65.   rectMode(CENTER);
  66.   fill(255);
  67.   rect(XLocation, YLocation, SquareSize, SquareSize, 7);
  68. }
  69.  
  70. void Randomizer() {
  71.   if (SelectorD1 == true) {
  72.     Dice1 = int(random(1, 6));
  73.     SelectorD1 = false;
  74.   }
  75.   if (SelectorD2 == true) {
  76.     Dice2 = int(random(1, 6));
  77.     SelectorD2 = false;
  78.   }
  79.   if (SelectorD3 == true) {
  80.     Dice3 = int(random(1, 6));
  81.     SelectorD3 = false;
  82.   }
  83.   DiceList.clear();
  84.   DiceList.append(Dice1);
  85.   DiceList.append(Dice2);
  86.   DiceList.append(Dice3);
  87.   DiceList.sort();
  88.   PlayAgain = false;
  89. }
  90.  
  91. void DisplayNumber() {
  92.   dispFace(200, 200, DiceSize, Dice1);
  93.   dispFace(400, 200, DiceSize, Dice2);
  94.   dispFace(600, 200, DiceSize, Dice3);
  95. }
  96.  
  97. void dispFace(int XLocation, int YLocation, int DiceSize, int DiceValue) {
  98.   switch(DiceValue) {
  99.     case 1:
  100.       Disp1(XLocation, YLocation);
  101.       break;
  102.     case 2:
  103.       Disp2(XLocation, YLocation);
  104.       break;
  105.     case 3:
  106.       Disp1(XLocation, YLocation);
  107.       Disp2(XLocation, YLocation);
  108.       break;
  109.     case 4:
  110.       Disp2(XLocation, YLocation);
  111.       Disp4(XLocation, YLocation);
  112.       break;
  113.     case 5:
  114.       Disp1(XLocation, YLocation);
  115.       Disp2(XLocation, YLocation);
  116.       Disp4(XLocation, YLocation);
  117.       break;
  118.     case 6:
  119.       Disp2(XLocation, YLocation);
  120.       Disp4(XLocation, YLocation);
  121.       Disp6(XLocation, YLocation);
  122.       break;
  123.   }
  124. }
  125.  
  126. void Disp1(int XLocation, int YLocation) {
  127.   fill(0);
  128.   ellipse(XLocation, YLocation, PointSize, PointSize);
  129. }
  130.  
  131. void Disp2(int XLocation, int YLocation) {
  132.   fill(0);
  133.   ellipse(XLocation+int(0.25*DiceSize), YLocation-int(0.25*DiceSize),PointSize, PointSize);
  134.   fill(0);
  135.   ellipse(XLocation-int(0.25*DiceSize), YLocation+int(0.25*DiceSize), PointSize, PointSize);
  136. }
  137.  
  138. void Disp4(int XLocation, int YLocation) {
  139.   fill(0);
  140.   ellipse(XLocation+int(0.25*DiceSize), YLocation+int(0.25*DiceSize), PointSize, PointSize);
  141.   fill(0);
  142.   ellipse(XLocation-int(0.25*DiceSize), YLocation-int(0.25*DiceSize), PointSize, PointSize);
  143. }
  144.  
  145. void Disp6(int XLocation, int YLocation) {
  146.   fill(0);
  147.   ellipse(XLocation+int(0.25*DiceSize), YLocation, PointSize, PointSize);
  148.   fill(0);
  149.   ellipse(XLocation-int(0.25*DiceSize), YLocation, PointSize, PointSize);
  150. }
  151.  
  152. void DispStopButton() {
  153.   if (SelectorD1 == false) {
  154.     StopButtonDrawer(200, int(200+(DiceSize/2)+25), DiceSize, 20, 64);
  155.   }
  156.   else {
  157.     StopButtonDrawer(200, int(200+(DiceSize/2)+25), DiceSize, 20, 255);
  158.   }
  159.   if (SelectorD2 == false) {
  160.     StopButtonDrawer(400, int(200+(DiceSize/2)+25), DiceSize, 20, 64);
  161.   }
  162.   else {
  163.     StopButtonDrawer(400, int(200+(DiceSize/2)+25), DiceSize, 20, 255);
  164.   }
  165.   if (SelectorD3 == false) {
  166.     StopButtonDrawer(600, int(200+(DiceSize/2)+25), DiceSize, 20, 64);
  167.   }
  168.   else {
  169.     StopButtonDrawer(600, int(200+(DiceSize/2)+25), DiceSize, 20, 255);
  170.   }
  171.   rectMode(CENTER);
  172.   fill(255);
  173.   rect(400, int((200+(DiceSize/2)+25)+35), int(400+(DiceSize)), 20, 3);
  174. }
  175.  
  176. void StopButtonDrawer(int XLocation, int YLocation, int SquareSize, int HighSize, int DiceSelected) {
  177.   rectMode(CENTER);
  178.   fill(DiceSelected,0,0);
  179.   rect(XLocation, YLocation, SquareSize, HighSize, 1);
  180. }
  181.  
  182. void ButtonDetector() {
  183.   if (mousePressed) {
  184.     if (int(200-int(DiceSize/2)) < mouseX && mouseX < int(200+int(DiceSize/2)) && int(200+(DiceSize/2)+15) < mouseY && mouseY < int(200+(DiceSize/2)+35)) {
  185.       delay(125);
  186.       if (SelectorD1 == false) {
  187.         SelectorD1 = true;
  188.       }
  189.       else {
  190.         SelectorD1 = false;
  191.       }
  192.     }
  193.     if (int(400-int(DiceSize/2)) < mouseX && mouseX < int(400+int(DiceSize/2)) && int(200+(DiceSize/2)+15) < mouseY && mouseY < int(200+(DiceSize/2)+35)) {
  194.       delay(125);
  195.       if (SelectorD2 == false) {
  196.         SelectorD2 = true;
  197.       }
  198.       else {
  199.         SelectorD2 = false;
  200.       }
  201.     }
  202.     if (int(600-int(DiceSize/2)) < mouseX && mouseX < int(600+int(DiceSize/2)) && int(200+(DiceSize/2)+15) < mouseY && mouseY < int(200+(DiceSize/2)+35)) {
  203.       delay(125);
  204.       if (SelectorD3 == false) {
  205.         SelectorD3 = true;
  206.       }
  207.       else {
  208.         SelectorD3 = false;
  209.       }
  210.     }
  211.     if ((400-int((400+(DiceSize))/2)) < mouseX && mouseX < (400+int((400+(DiceSize))/2)) && int((200+(DiceSize/2)+25)+25) < mouseY && mouseY < int((200+(DiceSize/2)+25)+45)) {
  212.       delay(125);
  213.       if (PlayAgain == false) {
  214.         PlayAgain = true;
  215.       }
  216.       else {
  217.         PlayAgain = false;
  218.       }
  219.     }
  220.   }
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement