Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3. import java.io.File;
  4.  
  5. public class Proj1401{
  6. public static ArrayList<Life> list = new ArrayList<Life>();
  7. public static void main(String[] args) throws Exception{
  8. File file = new File("Proj1.dat");
  9. Scanner scan = new Scanner(file);
  10.  
  11. String cord = "";
  12. for(int i = 0; scan.hasNext(); i++){
  13. list.add(new Life(scan.nextInt(),scan.nextInt()));
  14. Scanner scan2 = new Scanner(cord);
  15. }
  16.  
  17.  
  18. for(int i = 0; i<list.size(); i++){
  19. System.out.println(list.get(i));
  20. }
  21. }
  22.  
  23. public static Life up(Life temp){
  24. return new Life(temp.xcord,temp.ycord+1);
  25. }
  26.  
  27. public static Life down(Life temp){
  28. return new Life(temp.xcord,temp.ycord-1);
  29. }
  30.  
  31. public static Life left(Life temp){
  32. return new Life(temp.xcord-1,temp.ycord);
  33. }
  34. public static Life right(Life temp){
  35. return new Life(temp.xcord+1,temp.ycord);
  36. }
  37.  
  38. public static Life upRight(Life temp){
  39. return new Life(temp.xcord+1,temp.ycord+1);
  40. }
  41.  
  42. public static Life upLeft(Life temp){
  43. return new Life(temp.xcord-1,temp.ycord+1);
  44. }
  45.  
  46. public static Life downLeft(Life temp){
  47. return new Life(temp.xcord-1,temp.ycord-1);
  48. }
  49.  
  50. public static Life downRight(Life temp){
  51. return new Life(temp.xcord+1,temp.ycord-1);
  52. }
  53. public static boolean cellAlive(Life temp) {
  54. boolean flag = false;
  55. for(int i= 0; i<list.size(); i++){
  56. if(temp.xcord == (list.get(i)).xcord && temp.ycord == (list.get(i)).ycord)
  57. flag = true;
  58. }
  59. return flag;
  60. }
  61. public static int numOfCellsAlive(Life temp){
  62. int counter = 0;
  63. if(cellAlive(up(temp)))
  64. counter++;
  65. if(cellAlive(down(temp)))
  66. counter++;
  67. if(cellAlive(right(temp)))
  68. counter++;
  69. if(cellAlive(left(temp)))
  70. counter++;
  71. if(cellAlive(upRight(temp)))
  72. counter++;
  73. if(cellAlive(upLeft(temp)))
  74. counter++;
  75. if(cellAlive(downRight(temp)))
  76. counter++;
  77. if(cellAlive(downLeft(temp)))
  78. counter++;
  79. return counter;
  80. }
  81.  
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement