Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package shell;
- import java.util.ArrayList;
- import java.util.List;
- import shell.Shell;
- import shell.Command;
- public class myShell extends Shell{
- char[][] matrix = new char[10][10];
- int aknak_szama;
- int zaszlok_szama;
- int vege = 0; //0-nem ert veget; 1-gyozelem; 2-vereseg
- Boolean ini = false;
- List<Result> mezo = new ArrayList<>();
- public void matrix_mezok(){
- for (int i = 0; i < 10; i++){
- for (int j = 0; j < 10; j++){
- matrix[i][j] = 'H'; //felderitetlen mezo
- }
- }
- }
- public void kiir(){
- format("Aktualis allapot:\n");
- format(" A B C D E F G H I J\n");
- for (int i = 0; i < 10; i++){
- if (i != 9)
- format(" %d", i+1);
- else
- format("%d", i+1);
- for (int j = 0; j < 10; j++){
- format(" %c", matrix[i][j]);
- }
- format("\n");
- }
- format("\nAknak szama: %d\n", aknak_szama);
- format("Zaszlok szama: %d\n", zaszlok_szama);
- format("Jatek statusza: ");
- if (vege == 0)
- format("Nem ert meg veget\n");
- if (vege == 1)
- format("Gyozelem\n");
- if (vege == 2)
- format("Vereseg\n");
- }
- @Override
- protected void init(){
- vege = 0;
- ini = true;
- aknak_szama = 10;
- zaszlok_szama = 10;
- matrix_mezok();
- }
- public myShell(){
- addCommand(new Command("new") {
- @Override
- public boolean execute(String... args) {
- if (args.length > 1)
- return false;
- if (args.length == 0){
- init();
- } else {
- char[] betu = args[0].toCharArray();
- for (int i = 0; i < args[0].length(); i++)
- if (!Character.isDigit(betu[i]))
- return false;
- if (Integer.parseInt(args[0]) < 1 ||
- Integer.parseInt(args[0]) > 99)
- return false;
- init();
- aknak_szama = Integer.parseInt(args[0]);
- }
- kiir();
- return true;
- }
- });
- addCommand(new Command("print") {
- @Override
- public boolean execute(String... args) {
- if (args.length > 0)
- return false;
- if (ini == false)
- return false;
- kiir();
- return true;
- }
- });
- addCommand(new Command("flag") {
- @Override
- public boolean execute(String... args) {
- if (args.length != 2)
- return false;
- if (ini == false)
- return false;
- if (zaszlok_szama == 0)
- return false;
- if (vege != 0)
- return false;
- if (args[0].length()!=1)
- return false;
- int oszlopindex;
- if (args[0].equals("A"))
- oszlopindex = 0;
- else if (args[0].equals("B"))
- oszlopindex = 1;
- else if (args[0].equals("C"))
- oszlopindex = 2;
- else if (args[0].equals("D"))
- oszlopindex = 3;
- else if (args[0].equals("E"))
- oszlopindex = 4;
- else if (args[0].equals("F"))
- oszlopindex = 5;
- else if (args[0].equals("G"))
- oszlopindex = 6;
- else if (args[0].equals("H"))
- oszlopindex = 7;
- else if (args[0].equals("I"))
- oszlopindex = 8;
- else if (args[0].equals("J"))
- oszlopindex = 9;
- else
- return false;
- char[] sor = args[1].toCharArray();
- for (int i = 0; i < args[1].length(); i++){
- if (!Character.isDigit(sor[i]))
- return false;
- }
- int sorindex = Integer.parseInt(args[1]);
- if (sorindex < 1 || sorindex > 10)
- return false;
- if (matrix[sorindex-1][oszlopindex] == 'F')
- return false;
- matrix[sorindex-1][oszlopindex] = 'F'; //zaszloval megjelolt mezo
- zaszlok_szama--;
- return true;
- }
- });
- addCommand(new Command("unflag") {
- @Override
- public boolean execute(String... args) {
- if (args.length != 2)
- return false;
- if (ini == false)
- return false;
- if (zaszlok_szama == aknak_szama)
- return false;
- int oszlopindex;
- if (args[0].equals("A"))
- oszlopindex = 0;
- else if (args[0].equals("B"))
- oszlopindex = 1;
- else if (args[0].equals("C"))
- oszlopindex = 2;
- else if (args[0].equals("D"))
- oszlopindex = 3;
- else if (args[0].equals("E"))
- oszlopindex = 4;
- else if (args[0].equals("F"))
- oszlopindex = 5;
- else if (args[0].equals("G"))
- oszlopindex = 6;
- else if (args[0].equals("H"))
- oszlopindex = 7;
- else if (args[0].equals("I"))
- oszlopindex = 8;
- else if (args[0].equals("J"))
- oszlopindex = 9;
- else
- return false;
- char[] sor = args[1].toCharArray();
- for (int i = 0; i < args[1].length(); i++){
- if (!Character.isDigit(sor[i]))
- return false;
- }
- int sorindex = Integer.parseInt(args[1]);
- if (sorindex < 1 || sorindex > 10)
- return false;
- if (matrix[sorindex-1][oszlopindex] != 'F')
- return false;
- matrix[sorindex-1][oszlopindex] = 'H';
- zaszlok_szama++;
- return true;
- }
- });
- addCommand(new Command("fire") {
- @Override
- public boolean execute(String... args) {
- if (args.length != 2)
- return false;
- if (ini == false)
- return false;
- if (vege != 0)
- return false;
- int oszlopindex;
- if (args[0].equals("A"))
- oszlopindex = 0;
- else if (args[0].equals("B"))
- oszlopindex = 1;
- else if (args[0].equals("C"))
- oszlopindex = 2;
- else if (args[0].equals("D"))
- oszlopindex = 3;
- else if (args[0].equals("E"))
- oszlopindex = 4;
- else if (args[0].equals("F"))
- oszlopindex = 5;
- else if (args[0].equals("G"))
- oszlopindex = 6;
- else if (args[0].equals("H"))
- oszlopindex = 7;
- else if (args[0].equals("I"))
- oszlopindex = 8;
- else if (args[0].equals("J"))
- oszlopindex = 9;
- else
- return false;
- char[] sor = args[1].toCharArray();
- for (int i = 0; i < args[1].length(); i++){
- if (!Character.isDigit(sor[i]))
- return false;
- }
- int sorindex = Integer.parseInt(args[1]);
- if (sorindex < 1 || sorindex > 10)
- return false;
- if (matrix[sorindex-1][oszlopindex] == 'F' || matrix[sorindex-1][oszlopindex] != 'H')
- return false;
- mezo = resultOfShot(sorindex-1, oszlopindex);
- if (mezo.size() == 1){
- matrix[sorindex-1][oszlopindex] = 'X';
- vege = 2;
- return true;
- }
- for (int i = 0; i < mezo.size(); i++){
- matrix[mezo.get(i).getRow()][mezo.get(i).getColumn()] = Integer.toString(mezo.get(i).getValue()).charAt(0);
- }
- kiir();
- return true;
- }
- });
- addCommand(new Command("solution") {
- @Override
- public boolean execute(String... args) {
- if (args.length > 0)
- return false;
- if (ini == false)
- return false;
- if (vege == 0)
- return false;
- if (vege == 1 || vege == 2){
- String game_board = solution();
- System.out.println(game_board);
- return true;
- }
- else return true;
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement