Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //***********************************************
- // Nathan Schnitzer
- // 3/1/17
- //********************************
- import java.util.Arrays;
- import java.util.Scanner;
- public class LightsOut {
- public static void main(String[] args) {
- int rowAmount;
- int strNumbers = 0;
- String indicateTile;
- Scanner scan = new Scanner(System.in);
- boolean[] power = new boolean[64];
- String[] position = new String[64];
- String[] desc = new String[64];
- //Set all desc values to "none"
- for (int a = 0; a < 64; a++)
- {
- desc[a] = "none";
- }
- System.out.println("Enter the amount of rows");
- rowAmount = scan.nextInt();
- String[] locations = new String[rowAmount];
- for (int w = 0; w < rowAmount; w++)
- {
- System.out.println("Enter a string:");
- locations[w] = scan.next();
- strNumbers = w;
- }
- //Prompt for the tile indication string
- System.out.println("Enter the location of the pressed tile");
- indicateTile = scan.next();
- System.out.println(Character.toString(locations[0].charAt(0)));
- //set all power[] values to false
- for (int k = 0; k < 64; k++)
- {
- power[k] = false;
- }
- //set all value[] values to its position
- // i is the row & m is the column (0,0) is top right
- for (int i = 0; i < 8; i++)
- {
- for (int m = 0; m < 8; m++)
- {
- //Array its on
- int n = (i*8) + m;
- position[n] = "" + i + m;
- }
- }
- int length;
- String[] columns = new String[rowAmount];
- String[] rows = new String[rowAmount];
- String row;
- String loc = "";
- for (int r = 0; r <= strNumbers; r++)
- {
- columns[r] = Character.toString(locations[r].charAt(0));
- length = locations[r].length();
- row = Character.toString(locations[r].charAt(0));
- boolean match = false;
- for (int o = 1; o < length -1; o++)
- {
- columns[o] = Character.toString(locations[r].charAt(o));
- loc = row.concat(columns[o]);
- for (int c = 0; c < 64; c++)
- {
- power[Integer.valueOf(loc)] = true;
- desc[Integer.valueOf(loc)] = "on";
- }
- }
- }
- int tracker = 0;
- while(tracker < 64)
- {
- boolean tenDown = false, tenUp = false, oneDown = false, oneUp = false;
- //Set the pressed tiles values
- power[Integer.valueOf(indicateTile)] = true;
- desc[Integer.valueOf(indicateTile)] = "pressed";
- //Set all tiles values adjacent to pressed tile
- if (Integer.valueOf(indicateTile) > 10)
- {
- desc[(Integer.valueOf(indicateTile))-10] = "adjacent a";
- tenDown = true;
- }
- if (!(Integer.valueOf(indicateTile) >= 70))
- {
- desc[(Integer.valueOf(indicateTile))+10] = "adjacent a";
- tenUp = true;
- }
- if ((Integer.valueOf(indicateTile))/10 != (int)Integer.valueOf(indicateTile))
- {
- desc[(Integer.valueOf(indicateTile)) -1] = "adjacent a";
- oneDown = true;
- }
- if (((Integer.valueOf(indicateTile))-7)/10 != (int)Integer.valueOf(indicateTile))
- {
- desc[(Integer.valueOf(indicateTile)) + 1] = "adjacent a";
- oneUp = true;
- }
- if (oneUp == true)
- {
- if (Integer.valueOf(indicateTile) > 20)
- {
- desc[(Integer.valueOf(indicateTile))-20] = "adjacent b";
- }
- if (!(Integer.valueOf(indicateTile) >= 60))
- {
- desc[(Integer.valueOf(indicateTile))+20] = "adjacent b";
- }
- if ((Integer.valueOf(indicateTile))/10 != (int)Integer.valueOf(indicateTile))
- {
- desc[(Integer.valueOf(indicateTile)) -2] = "adjacent b";
- }
- if (((Integer.valueOf(indicateTile))-7)/10 != (int)Integer.valueOf(indicateTile))
- {
- desc[(Integer.valueOf(indicateTile)) + 2] = "adjacent b";
- }
- }
- if (oneDown == true)
- {
- if (Integer.valueOf(indicateTile) > 20)
- {
- desc[(Integer.valueOf(indicateTile))-20] = "adjacent b";
- }
- if (!(Integer.valueOf(indicateTile) >= 60))
- {
- desc[(Integer.valueOf(indicateTile))+20] = "adjacent b";
- }
- if ((Integer.valueOf(indicateTile))/10 != (int)Integer.valueOf(indicateTile))
- {
- desc[(Integer.valueOf(indicateTile)) -2] = "adjacent b";
- }
- if (((Integer.valueOf(indicateTile))-7)/10 != (int)Integer.valueOf(indicateTile))
- {
- desc[(Integer.valueOf(indicateTile)) + 2] = "adjacent b";
- }
- }
- if (tenUp == true)
- {
- if (Integer.valueOf(indicateTile) > 20)
- {
- desc[(Integer.valueOf(indicateTile))-20] = "adjacent b";
- }
- if (!(Integer.valueOf(indicateTile) >= 60))
- {
- desc[(Integer.valueOf(indicateTile))+20] = "adjacent b";
- }
- if ((Integer.valueOf(indicateTile))/10 != (int)Integer.valueOf(indicateTile))
- {
- desc[(Integer.valueOf(indicateTile)) -2] = "adjacent b";
- }
- if (((Integer.valueOf(indicateTile))-7)/10 != (int)Integer.valueOf(indicateTile))
- {
- desc[(Integer.valueOf(indicateTile)) + 2] = "adjacent b";
- }
- }
- if (tenDown == true)
- {
- if (Integer.valueOf(indicateTile) > 20)
- {
- desc[(Integer.valueOf(indicateTile))-20] = "adjacent b";
- }
- if (!(Integer.valueOf(indicateTile) >= 60))
- {
- desc[(Integer.valueOf(indicateTile))+20] = "adjacent b";
- }
- if ((Integer.valueOf(indicateTile))/10 != (int)Integer.valueOf(indicateTile))
- {
- desc[(Integer.valueOf(indicateTile)) -2] = "adjacent b";
- }
- if (((Integer.valueOf(indicateTile))-7)/10 != (int)Integer.valueOf(indicateTile))
- {
- desc[(Integer.valueOf(indicateTile)) + 2] = "adjacent b";
- }
- }
- int count = 0;
- for (int x = 0; x < 64; x++)
- {
- if ((desc[x].equals("adjacent a") || desc[x].equals("adjacent b")) && power[x] == false)
- count++;
- }
- System.out.println(Integer.valueOf(loc));
- System.out.println(loc);
- System.out.println(Character.toString(locations[0].charAt(0)));
- System.out.println(Arrays.toString(power));
- System.out.println(Arrays.toString(position));
- System.out.println(Arrays.toString(desc));
- System.out.println(count);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment