Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.io.File;
- public class Proj1401{
- public static ArrayList<Life> list = new ArrayList<Life>();
- public static void main(String[] args) throws Exception{
- File file = new File("Proj1.dat");
- Scanner scan = new Scanner(file);
- String cord = "";
- for(int i = 0; scan.hasNext(); i++){
- list.add(new Life(scan.nextInt(),scan.nextInt()));
- Scanner scan2 = new Scanner(cord);
- }
- for(int i = 0; i<list.size(); i++){
- System.out.println(list.get(i));
- }
- }
- public static Life up(Life temp){
- return new Life(temp.xcord,temp.ycord+1);
- }
- public static Life down(Life temp){
- return new Life(temp.xcord,temp.ycord-1);
- }
- public static Life left(Life temp){
- return new Life(temp.xcord-1,temp.ycord);
- }
- public static Life right(Life temp){
- return new Life(temp.xcord+1,temp.ycord);
- }
- public static Life upRight(Life temp){
- return new Life(temp.xcord+1,temp.ycord+1);
- }
- public static Life upLeft(Life temp){
- return new Life(temp.xcord-1,temp.ycord+1);
- }
- public static Life downLeft(Life temp){
- return new Life(temp.xcord-1,temp.ycord-1);
- }
- public static Life downRight(Life temp){
- return new Life(temp.xcord+1,temp.ycord-1);
- }
- public static boolean cellAlive(Life temp) {
- boolean flag = false;
- for(int i= 0; i<list.size(); i++){
- if(temp.xcord == (list.get(i)).xcord && temp.ycord == (list.get(i)).ycord)
- flag = true;
- }
- return flag;
- }
- public static int numOfCellsAlive(Life temp){
- int counter = 0;
- if(cellAlive(up(temp)))
- counter++;
- if(cellAlive(down(temp)))
- counter++;
- if(cellAlive(right(temp)))
- counter++;
- if(cellAlive(left(temp)))
- counter++;
- if(cellAlive(upRight(temp)))
- counter++;
- if(cellAlive(upLeft(temp)))
- counter++;
- if(cellAlive(downRight(temp)))
- counter++;
- if(cellAlive(downLeft(temp)))
- counter++;
- return counter;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement