Ir para conteúdo
Fórum Script Brasil
  • 0

Problema em movimentar


Reaper

Pergunta

Pessoal tenho que fazer o seguinte trabalho:

Uma das categorias de jogos mais populares é a de Estratégia. Nessa categoria, dois ou mais jogadores criam exércitos com soldados, tanques e outras unidades, afim de destruir o exército inimigo. Esses jogos incentivavam o crescimento da maturidade no processo de tomada de decisão e nas percepções do mundo ao seu redor.

O seu objetivo será desenvolver um algoritmo que simule o funcionamento de um programa especializado em jogos de estratégia: o UniFORCE.

O jogo consiste em um tabuleiro com 20 (vinte) posições de largura e 20 posições de altura, formando um tabuleiro de 20x20.

Nesse tabuleiro, dois exércitos se gladiarão pelo domínio do território, cada um com cinco soldados. Cada soldado possui cinco atributos: ataque, defesa, inteligência, resistência e velocidade. Esses atributos são do tipo inteiro, e a soma de seus valores sempre é 12 (doze). Exemplo:

Soldado A

Ataque: 4

Defesa: 2

Inteligência: 1

Resistência: 3

Velocidade: 2

Soldado B

Ataque: 2

Defesa: 5

Inteligência: 3

Resistência: 1

Velocidade: 1

Soldado C

Ataque: 3

Defesa: 3

Inteligência: 3

Resistência: 0

Velocidade: 3

Soldado D

Ataque: 1

Defesa: 4

Inteligência: 3

Resistência: 2

Velocidade: 2

Soldado E

Ataque: 4

Defesa: 0

Inteligência: 0

Resistência: 3

Velocidade: 5

Quando o jogo é iniciado, o programa solicita o nome dos dois jogadores. Em seguida, o jogo solicita ao primeiro jogador definir o valor dos atributos de cada um de seus cinco soldados (lembrando que o total de pontos de todos os atributos deve ser igual a 12). É possível que o jogador informe o valor 0 (zero) para um atributo, caso deseje. Quando o primeiro player termina de configurar os seus jogadores, o programa exibe a lista dos cinco soldados, e pergunta se o player deseja alterar os valores de um de seus soldados ou confirmar a criação do seu exército. Caso queira alterar os valores de um de seus soldados, ele informa o número do soldado e todos os atributos são solicitados novamente para aquele soldado. Caso esteja tudo OK, o jogador confirma a criação do seu exército.

O segundo jogador, em seguida, realiza o mesmo procedimento do primeiro jogador, definindo o seu exército.

Uma vez os dois exércitos criados, eles são então posicionados aleatoriamente no tabuleiro, de tal forma que um soldado não pode ocupar um espaço já alocado por outro soldado.

Depois de posicionados, a cada rodada do jogo, cada soldado movimenta-se aleatoriamente para uma das quatro direções: cima, baixo, esquerda e direita. A quantidade de passos do soldado é igual ao valor da velocidade deste. O soldado não pode sair do tabuleiro, de tal forma que se ele chegar em uma das bordas, ele deve continuar o movimento na direção oposta.

Se em um ciclo dois soldados de exércitos inimigos se encontram, ocorre uma LUTA!

Na luta, os valores de cada atributo dos soldados são comparados. A cada comparação, um soldado ganha se o valor de seu atributo é maior que o do inimigo. Ao final da comparação dos cinco atributos, morre aquele que perder em mais atributos. Observe o exemplo:

Soldado Time Vermelho

Ataque: 4

Defesa: 2

Inteligência: 1

Resistência: 3

Velocidade: 2

Soldado Time Azul

Ataque: 2

Defesa: 5

Inteligência: 3

Resistência: 1

Velocidade: 1

Neste exemplo, o soldado do time azul morre, e o do time vermelho permanece no tabuleiro.

O final da partida ocorre quando todos os soldados de um exército são eliminados. Após a execução de uma partida, o programa deve perguntar se ele deseja continuar jogando ou não. Caso o jogador selecione a opção negativa, o programa é então encerrado. Caso contrário, ele inicia o jogo da parte onde os jogadores definem seus nomes.

Já fiz isso:

import java.util.Random;
import java.util.Scanner;

class soldado{
        int ataque, defesa, inteligencia, resistencia, velocidade;
        
        Random random = new Random();
        
        soldado(int a, int b, int c, int d, int e){
            ataque = a;
            defesa = b;
            inteligencia = c;
            resistencia = d;
            velocidade = e;
        }
        
        void RetornaAtributos(int i){
                System.out.println("---------------");
            System.out.println("  Soldado "+i);
                System.out.println("---------------");
                System.out.println("Ataque: " + ataque);
                System.out.println("Defesa: " + defesa);
                System.out.println("Inteligencia: " + inteligencia);
                System.out.println("Resistencia: " + resistencia);
                System.out.println("Velocidade: " + velocidade);
        }
        
        void TrocaAtributos(int a, int b, int c, int d, int e ){
                ataque = a;
            defesa = b;
            inteligencia = c;
            resistencia = d;
            velocidade = e;
        }
        
        void Posicao(char matriz[][], String matriz1[][], int a, int b, char simbolo, String c){
                if(matriz[a][b] == '*'){
                       matriz[a][b] = simbolo;
                       matriz1[a][b] = c;
                }
                else{
                   a = random.nextInt(20);
                   b = random.nextInt(20);
                   matriz[a][b] = simbolo;
                   matriz1[a][b] = c;
            }
        }
        
        void Mover(char matriz[][], String matriz1[][], int a, int B){
                int numero = random.nextInt(4);
                char aux;
                String aux1;
                
                switch(numero){
                      case 0:
                                 a = a - velocidade;
                             if (a<0){
                                    a = 0;
                             }
                             if(matriz[a][b] == 'X' || matriz[a][b] == 'O'){
                                      a = a - velocidade - 1;
                             }
                             aux = matriz[a][b];
                             matriz[a+velocidade][b] = matriz[a][b];
                             matriz[a][b] = aux;
                             aux1 = matriz1[a][b];
                             matriz1[a+velocidade][b] = matriz1[a][b];
                             matriz1[a][b] = aux1;
                             break;
                      case 1:
                            b = b - velocidade;
                            if (b<0){
                                    b = 0;
                            }
                            if(matriz[a][b] == 'X' || matriz[a][b] == 'O'){
                                    b = b - velocidade - 1;
                            }
                            aux = matriz[a][b];
                            matriz[a][b+velocidade] = matriz[a][b];
                            matriz[a][b] = aux;
                            aux1 = matriz1[a][b];
                            matriz1[a][b+velocidade] = matriz1[a][b];
                            matriz1[a][b] = aux1;
                            break;
                      case 2:
                            a = a + velocidade;
                            if (a>20){
                                    a = 20;
                            }
                            if(matriz[a][b] == 'X' || matriz[a][b] == 'O'){
                                    a = a + velocidade - 1;
                            }
                            aux = matriz[a][b];
                            matriz[a-velocidade][b] = matriz[a][b];
                            matriz[a][b] = aux;
                            aux1 = matriz1[a][b];
                            matriz1[a-velocidade][b] = matriz1[a][b];
                            matriz1[a][b] = aux1;
                            break;
                      case 3:
                            b = b + velocidade;
                            if (b>20){
                                    b = 20;
                            }
                            if(matriz[a][b] == 'X' || matriz[a][b] == 'O'){
                                    b = b + velocidade - 1;
                            }
                            aux = matriz[a][b];
                            matriz[a][b-velocidade] = matriz[a][b];
                            matriz[a][b] = aux;
                            aux1 = matriz1[a][b];
                            matriz1[a][b-velocidade] = matriz1[a][b];
                            matriz1[a][b] = aux1;
                            break;
                }
                
        }
}

public class Jogo {
        public static Scanner entrada = new Scanner(System.in);
        
        public static Random random = new Random();

        public static int a, b, c, d, e;
        public static int opcao;
        public static int opcao1;
        public static char matriz[][] = new char [20][20];
        public static String matriz1[][] = new String [20][20];
        
        public static void imprimir(){
                for(int i = 0; i<20; i++){
                        System.out.print("\n");
                        for(int j = 0; j<20; j++){
                                System.out.print(matriz[i][j]);
                        }
                }
        }

        public static void preencher(int i){
           a = 0;
           b = 0; 
           c = 0; 
           d = 0; 
           e = 0;
                
           System.out.println("---------------");
           System.out.println("  Soldado "+i);
           System.out.println("---------------");
           System.out.println("Digite o ataque do soldado");
           a = entrada.nextInt();
           while(a<0 || a>12 || (a+b+c+d+e)>12){
                   System.out.println("Numero invalido. Digite novamente");
                   a = entrada.nextInt();
           }
           System.out.println("Digite a defesa do soldado");
           b = entrada.nextInt();
           while(b<0 || b>12 || (a+b+c+d+e)>12){
                   System.out.println("Numero invalido. Digite novamente");
                   b = entrada.nextInt();
           }
           System.out.println("Digite a inteligencia do soldado");
           c = entrada.nextInt();
           while(c<0 || c>12 || (a+b+c+d+e)>12){
                   System.out.println("Numero invalido. Digite novamente");
                   c = entrada.nextInt();
           }
           System.out.println("Digite a resistencia do soldado");
           d = entrada.nextInt();
           while(d<0 || d>12 || (a+b+c+d+e)>12){
                   System.out.println("Numero invalido. Digite novamente");
                   d = entrada.nextInt();
           }
           System.out.println("Digite a velocidade do soldado");
           e = entrada.nextInt();
           while(e<0 || e>12 || (a+b+c+d+e)>12){
                   System.out.println("Numero invalido. Digite novamente");
                   e = entrada.nextInt();
           }
        }
        
        public static void Briga(String matriz1[][], soldado s1, soldado s2, soldado s3, soldado s4, soldado s5, soldado s6, soldado s7, soldado s8, soldado s9, soldado s10, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10){
                int c1 = 0, c2 = 0;
                
                for(int i = 0; i<20; i++){
                  for(int j =0; j<20; j++){
                        if(matriz1[i][j]=="s1" && matriz1[i-1][j]=="s6"){
                                System.out.println("Briga entre s1 e s6");
                                if(s1.ataque>s6.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s6.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s6.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s6.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s6.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a6 = 0;
                                        matriz1[i-1][j] = " ";
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s6 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a6 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i-1][j] = " ";
                                        matriz[i-1][j] = '*';
                                        matriz[i][j] = '*';
                                }
                        }
                        if(matriz1[i][j]=="s1" && matriz1[i+1][j]=="s6"){
                                System.out.println("Briga entre s1 e s6");
                                if(s1.ataque>s6.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s6.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s6.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s6.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s6.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a6 = 0;
                                        matriz1[i+1][j] = " ";
                                        matriz[i+1][j] = '*';
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s6 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a6 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i+1][j] = " ";
                                        matriz[i][j] = '*';
                                        matriz[i+1][j] = '*';
                                }
                        }
                        if(matriz1[i][j]=="s1" && matriz1[i][j-1]=="s6"){
                                System.out.println("Briga entre s1 e s6");
                                if(s1.ataque>s6.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s6.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s6.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s6.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s6.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a6 = 0;
                                        matriz1[i][j-1] = " "; 
                                        matriz[i][j-1] = '*';
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s6 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a6 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i][j-1] = " ";
                                        matriz[i][j-1] = '*';
                                        matriz[i][j] = '*';
                                }
                        }
                        if(matriz1[i][j]=="s1" && matriz1[i][j+1]=="s6"){
                                System.out.println("Briga entre s1 e s6");
                                if(s1.ataque>s6.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s6.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s6.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s6.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s6.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a6 = 0;
                                        matriz1[i][j+1] = " "; 
                                        matriz[i][j+1] = '*';
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s6 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a6 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i][j+1] = " ";
                                        matriz[i][j+1] = '*';
                                        matriz[i][j] = '*';
                                }
                        }
                        if(matriz1[i][j]=="s1" && matriz1[i-1][j]=="s7"){
                                System.out.println("Briga entre s1 e s7");
                                if(s1.ataque>s7.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s7.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s7.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s7.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s7.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a7 = 0;
                                        matriz1[i-1][j] = " ";
                                        matriz[i-1][j] = '*';
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s7 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a7 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i-1][j] = " ";
                                        matriz[i][j] = '*';
                                        matriz[i-1][j] = '*';
                                }
                        }
                        if(matriz1[i][j]=="s1" && matriz1[i+1][j]=="s7"){
                                System.out.println("Briga entre s1 e s7");
                                if(s1.ataque>s7.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s7.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s7.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s7.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s7.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a7 = 0;
                                        matriz1[i+1][j] = " ";
                                        matriz[i+1][j] = '*';
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s7 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a7 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i+1][j] = " ";
                                        matriz[i][j] = '*';
                                        matriz[i+1][j] = '*';
                                }
                        }
                        if(matriz1[i][j]=="s1" && matriz1[i][j+1]=="s7"){
                                System.out.println("Briga entre s1 e s7");
                                if(s1.ataque>s7.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s7.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s7.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s7.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s7.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a7 = 0;
                                        matriz1[i][j+1] = " ";
                                        matriz[i][j+1] = '*';
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s7 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a7 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i][j+1] = " ";
                                        matriz[i][j] = '*';
                                        matriz[i][j+1] = '*';
                                }
                        }
                        if(matriz1[i][j]=="s1" && matriz1[i][j-1]=="s7"){
                                System.out.println("Briga entre s1 e s7");
                                if(s1.ataque>s7.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s7.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s7.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s7.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s7.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a7 = 0;
                                        matriz1[i][j-1] = " ";
                                        matriz[i][j-1] = '*';
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s7 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a7 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i][j-1] = " ";
                                        matriz[i][j] = '*';
                                        matriz[i][j-1] = '*';
                                }
                        }
                        if(matriz1[i][j]=="s1" && matriz1[i-1][j]=="s8"){
                                System.out.println("Briga entre s1 e s8");
                                if(s1.ataque>s8.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s8.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s8.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s8.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s8.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a8 = 0;
                                        matriz1[i-1][j] = " ";
                                        matriz[i-1][j] = '*';
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s8 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a8 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i-1][j] = " ";
                                        matriz[i][j] = '*';
                                        matriz[i-1][j] = '*';
                                }
                        }
                        if(matriz1[i][j]=="s1" && matriz1[i+1][j]=="s8"){
                                System.out.println("Briga entre s1 e s8");
                                if(s1.ataque>s8.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s8.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s8.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s8.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s8.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a8 = 0;
                                        matriz1[i+1][j] = " ";
                                        matriz[i+1][j] = '*';
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s8 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a8 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i+1][j] = " ";
                                        matriz[i][j] = '*';
                                        matriz[i+1][j] = '*';
                                }
                        }
                        if(matriz1[i][j]=="s1" && matriz1[i][j-1]=="s8"){
                                System.out.println("Briga entre s1 e s8");
                                if(s1.ataque>s8.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s8.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s8.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s8.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s8.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a8 = 0;
                                        matriz1[i][j-1] = " ";
                                        matriz[i][j-1] = '*';
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s8 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a8 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i][j-1] = " ";
                                        matriz[i][j] = '*';
                                        matriz[i][j-1] = '*';
                                }
                        }
                        if(matriz1[i][j]=="s1" && matriz1[i][j+1]=="s8"){
                                System.out.println("Briga entre s1 e s8");
                                if(s1.ataque>s8.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s8.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s8.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s8.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s8.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a8 = 0;
                                        matriz1[i][j+1] = " ";
                                        matriz[i][j+1] = '*';
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s8 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a8 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i][j+1] = " ";
                                        matriz[i][j] = '*';
                                        matriz[i][j+1] = '*';
                                }
                        }
                        if(matriz1[i][j]=="s1" && matriz1[i][j-1]=="s8"){
                                System.out.println("Briga entre s1 e s8");
                                if(s1.ataque>s8.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s8.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s8.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s8.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s8.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a8 = 0;
                                        matriz1[i][j-1] = " ";
                                        matriz[i][j-1] = '*';
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s8 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a8 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i][j-1] = " ";
                                        matriz[i][j] = '*';
                                        matriz[i][j-1] = '*';
                                }
                        }
                        if(matriz1[i][j]=="s1" && matriz1[i-1][j]=="s9"){
                                System.out.println("Briga entre s1 e s9");
                                if(s1.ataque>s9.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s9.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s9.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s9.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s9.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a9 = 0;
                                        matriz1[i-1][j] = " ";
                                        matriz[i-1][j] = '*';
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s9 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a9 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i-1][j] = " ";
                                        matriz[i][j] = '*';
                                        matriz[i-1][j] = '*';
                                }
                        }
                        if(matriz1[i][j]=="s1" && matriz1[i+1][j]=="s9"){
                                System.out.println("Briga entre s1 e s9");
                                if(s1.ataque>s9.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s9.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s9.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s9.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s9.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a9 = 0;
                                        matriz1[i+1][j] = " ";
                                        matriz[i+1][j] = '*';
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s9 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a9 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i+1][j] = " ";
                                        matriz[i][j] = '*';
                                        matriz[i+1][j] = '*';
                                }
                        }
                        if(matriz1[i][j]=="s1" && matriz1[i][j-1]=="s9"){
                                System.out.println("Briga entre s1 e s9");
                                if(s1.ataque>s9.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s9.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s9.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s9.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s9.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a9 = 0;
                                        matriz1[i][j-1] = " ";
                                        matriz[i][j-1] = '*';
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s9 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a9 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i][j-1] = " ";
                                        matriz[i][j] = '*';
                                        matriz[i][j-1] = '*';
                                }
                        }
                        if(matriz1[i][j]=="s1" && matriz1[i][j+1]=="s9"){
                                System.out.println("Briga entre s1 e s9");
                                if(s1.ataque>s9.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s9.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s9.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s9.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s9.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a9 = 0;
                                        matriz1[i][j+1] = " ";
                                        matriz[i][j+1] = '*';
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s9 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a9 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i][j+1] = " ";
                                        matriz[i][j] = '*';
                                        matriz[i][j+1] = '*';
                                }
                        }
                        if(matriz1[i][j]=="s1" && matriz1[i-1][j]=="s10"){
                                System.out.println("Briga entre s1 e s10");
                                if(s1.ataque>s10.ataque){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.defesa>s10.defesa){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.inteligencia>s10.inteligencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.resistencia>s10.resistencia){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(s1.velocidade>s10.velocidade){
                                        c1++;
                                }
                                else{
                                        c2++;
                                }
                                if(c1>c2){
                                        System.out.println("O soldado s1 ganhou");
                                        a10 = 0;
                                        matriz1[i-1][j] = " ";
                                        matriz[i-1][j] = '*';
                                }
                                else if(c1<c2){
                                        System.out.println("O soldado s10 ganhou");
                                        a1 = 0;
                                        matriz1[i][j] = " ";
                                        matriz[i][j] = '*';
                                }
                                else{
                                        System.out.println("Deu empate");
                                        a1 = 0;
                                        a10 = 0;
                                        matriz1[i][j] = " ";
                                        matriz1[i-1][j] = " ";
                                        matriz[i][j] = '*';
                                        matriz[i-1][j] = '*';
                                }
                        }
                  }
                  }
        }
        
      public static void main(String[] args){
          for(int i = 0; i<20; i++){
                        for(int j = 0; j<20;  j++){
                                matriz[i][j]= '*';
                        }
                        }
                
        Scanner entrada = new Scanner(System.in);
                System.out.println("************************************************");
                System.out.println("-----------Bem-vindo ao Jogo UniFORCE-----------");
                System.out.println("************************************************");
                System.out.println("Digite o nome do primeiro jogador");
                String nome1 = entrada.nextLine();
                System.out.println("Digite o nome do segundo jogador");
                String nome2 = entrada.nextLine();
                System.out.println("************************************************");
                System.out.println(nome1 + " digite os atributos do seus personagens");
                System.out.println("************************************************");
                preencher(1);
                soldado s1 = new soldado(a,b,c,d,e);
                preencher(2);
                soldado s2 = new soldado(a,b,c,d,e);
                preencher(3);
                soldado s3 = new soldado(a,b,c,d,e);
                preencher(4);
                soldado s4 = new soldado(a,b,c,d,e);
                preencher(5);
                soldado s5 = new soldado(a,b,c,d,e);
                
                System.out.println("************************************************");
                System.out.println(nome2 + " digite os atributos do seus personagens");
                System.out.println("************************************************");
                preencher(6);
                soldado s6 = new soldado(a,b,c,d,e);
                preencher(7);
                soldado s7 = new soldado(a,b,c,d,e);
                preencher(8);
                soldado s8 = new soldado(a,b,c,d,e);
                preencher(9);
                soldado s9 = new soldado(a,b,c,d,e);
                preencher(10);
                soldado s10 = new soldado(a,b,c,d,e);
                
                System.out.println("************************************************");
                System.out.println("Os atributos dos personagens do "+nome1+" são:");
                System.out.println("************************************************");
                s1.RetornaAtributos(1);
                s2.RetornaAtributos(2);
                s3.RetornaAtributos(3);
                s4.RetornaAtributos(4);
                s5.RetornaAtributos(5);
                System.out.println("Voce deseja trocar os atributos de algum soldado?");
                System.out.println("0- sim");
                System.out.println("1- não");
                opcao = entrada.nextInt();
                while(opcao == 0){
                        System.out.println("Digite o numero do soldado que deseja alterar (1-5) 0-para sair");
                        int valor = entrada.nextInt();
                        switch(valor){
                           case 0:
                                   opcao = 1;
                                   System.out.println(opcao);
                                   break;
                           case 1:
                                   preencher(1);
                                   s1.TrocaAtributos(a,b,c,d,e);
                                   System.out.println("Os novos atributos são: ");
                                   s1.RetornaAtributos(1);
                                   break;
                           case 2:
                                   preencher(2);
                                   s2.TrocaAtributos(a,b,c,d,e);
                                   System.out.println("Os novos atributos são: ");
                                   s2.RetornaAtributos(2);
                                   break;
                           case 3:
                                   preencher(3);
                                   s3.TrocaAtributos(a,b,c,d,e);
                                   System.out.println("Os novos atributos são: ");
                                   s3.RetornaAtributos(3);
                                   break;
                           case 4:
                                   preencher(4);
                                   s4.TrocaAtributos(a,b,c,d,e);
                                   System.out.println("Os novos atributos são: ");
                                   s4.RetornaAtributos(4);
                                   break;
                           case 5:
                                   preencher(5);
                                   s5.TrocaAtributos(a,b,c,d,e);
                                   System.out.println("Os novos atributos são: ");
                                   s5.RetornaAtributos(5);
                                   break;
                           default: 
                                   System.out.println("Numero invalido. Digite novamente");
                                   valor = entrada.nextInt();
                                   break;
                        }
                }
        
                System.out.println("Os atributos dos personagens do "+nome2+" são:");
                s6.RetornaAtributos(6);
                s7.RetornaAtributos(7);
                s8.RetornaAtributos(8);
                s9.RetornaAtributos(9);
                s10.RetornaAtributos(10);
                System.out.println("Voce deseja trocar os atributos de algum soldado?");
                System.out.println("0- sim");
                System.out.println("1- não");
                opcao = entrada.nextInt();
                while(opcao == 0){
                        System.out.println("Digite o numero do soldado que deseja alterar (6-10) 0-para sair");
                        int valor = entrada.nextInt();
                        switch(valor){
                           case 0:
                                opcao = 1;
                                break;
                           case 6:
                                   preencher(6);
                                   s6.TrocaAtributos(a,b,c,d,e);
                                   System.out.println("Os novos atributos são: ");
                                   s6.RetornaAtributos(6);
                                   break;
                           case 7:
                                   preencher(7);
                                   s7.TrocaAtributos(a,b,c,d,e);
                                   System.out.println("Os novos atributos são: ");
                                   s7.RetornaAtributos(7);
                                   break;
                           case 8:
                                   preencher(8);
                                   s8.TrocaAtributos(a,b,c,d,e);
                                   System.out.println("Os novos atributos são: ");
                                   s8.RetornaAtributos(8);
                                   break;
                           case 9:
                                   preencher(9);
                                   s9.TrocaAtributos(a,b,c,d,e);
                                   System.out.println("Os novos atributos são: ");
                                   s9.RetornaAtributos(9);
                                   break;
                           case 10:
                                   preencher(10);
                                   s10.TrocaAtributos(a,b,c,d,e);
                                   System.out.println("Os novos atributos são: ");
                                   s10.RetornaAtributos(10);
                                   break;
                           default: 
                                   System.out.println("Numero invalido. Digite novamente");
                                   valor = entrada.nextInt();
                                   break;
                        }
                }
                int v1 = random.nextInt(20);
                int v2 = random.nextInt(20);
                s1.Posicao(matriz, matriz1, v1, v2, 'X', "s1");
                int v3 = random.nextInt(20);
                int v4 = random.nextInt(20);
                s2.Posicao(matriz, matriz1, v3, v4, 'X', "s2");
                int v5 = random.nextInt(20);
                int v6 = random.nextInt(20);
                s3.Posicao(matriz, matriz1, v5, v6, 'X', "s3");
                int v7 = random.nextInt(20);
                int v8 = random.nextInt(20);
                s4.Posicao(matriz, matriz1, v7, v8, 'X', "s4");
                int v9 = random.nextInt(20);
                int v10 = random.nextInt(20);
                s5.Posicao(matriz, matriz1, v9, v10, 'X', "s5");
                int v11 = random.nextInt(20);
                int v12 = random.nextInt(20);
                s6.Posicao(matriz, matriz1, v11, v12, 'O', "s6");
                int v13 = random.nextInt(20);
                int v14 = random.nextInt(20);
                s7.Posicao(matriz, matriz1, v13, v14, 'O', "s7");
                int v15 = random.nextInt(20);
                int v16 = random.nextInt(20);
                s8.Posicao(matriz, matriz1, v15, v16, 'O', "s8");
                int v17 = random.nextInt(20);
                int v18 = random.nextInt(20);
                s9.Posicao(matriz, matriz1, v17, v18, 'O', "s9");
                int v19 = random.nextInt(20);
                int v20 = random.nextInt(20);
                s10.Posicao(matriz, matriz1, v19, v20, 'O', "s10");
                imprimir();
                System.out.println(" ");
                s1.Mover(matriz, matriz1, v1, v2);
                s2.Mover(matriz, matriz1, v3, v4);
                s3.Mover(matriz, matriz1, v5, v6);
                s4.Mover(matriz, matriz1, v7, v8);
                s5.Mover(matriz, matriz1, v9, v10);
                s6.Mover(matriz, matriz1, v11, v12);
                s7.Mover(matriz, matriz1, v13, v14);
                s8.Mover(matriz, matriz1, v15, v16);
                s9.Mover(matriz, matriz1, v17, v18);
                s10.Mover(matriz, matriz1, v19, v20);
                imprimir();
         }
}

Porém estou com problemas no método Mover. Os personagens não se movem. Será que alguém pode me ajudar. Agradeço desde já.

Editado por Reaper
Link para o comentário
Compartilhar em outros sites

0 respostass a esta questão

Posts Recomendados

Até agora não há respostas para essa pergunta

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,3k
    • Posts
      652,3k
×
×
  • Criar Novo...