Jogo Torre de Hanoi

0 respostas
L
import java.util.Scanner;


public class Tabuleiro {
	
	
	static int[][] tabuleiro = new int[3][3];
	static int[] score = new int[10];
	static String[] jogadores = new String[10];
	
	 static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args){
		
		
		menu();
	}
	
	public static boolean verificaJogada(int pecaAtual, int colunaAtual, int posicaoDestino, int colunaDestino){
		
		if(posicaoDestino == 2 ){
			
			return true;
		}else if(tabuleiro[pecaAtual][colunaAtual] > tabuleiro[posicaoDestino + 1][colunaDestino]){
			
			System.out.println("Movimento Invalido");
			
			return false;
		}else{
			
			return true;
		}
		
	}
	
	public static void exibeTabuleiro(){
		
		System.out.println(tabuleiro[0][0] + "\t" + tabuleiro[0][1] + "\t" + tabuleiro[0][2] + "\n" +
							tabuleiro[0][0] + "\t" + tabuleiro[0][1] + "\t" + tabuleiro[0][2] + "\n" +
							tabuleiro[0][0] + "\t" + tabuleiro[0][1] + "\t" + tabuleiro[0][2]);
	}
	
	public static void menu(){
		
		int op = 0;
		
		while(op != 2){
			
			System.out.println("Digite: \n 0 - Jogar \n 1 - Ver pontuação \n 2 - Sair");
			op = sc.nextInt();
			
			
			switch(op){
			
			case 0: iniciaJogo(); break;
			case 1: mostraScore();break;
			case 2: System.exit(0);

			}
				
		}
	}
	
	public static void iniciaJogo(){
		
		int pecaMov;
		int posDestino;
		int colunaAtual;
		int colunaDestino;
		
		tabuleiro[0][0] = 1;
		tabuleiro[1][0] = 2;
		tabuleiro[2][0] = 3;
		
		while(tabuleiro[2][0] != 1 && tabuleiro[2][1] != 2 && tabuleiro[2][2] != 3){
			
			
			System.out.println("Qual peça deseja mexer? (0, 1 ou 2?)");
			pecaMov = sc.nextInt();
			System.out.println("A peca está em qual coluna? (0, 1 ou 2?)");
			colunaAtual = sc.nextInt();
			System.out.println("Qual posiçao deseja colocar a peca? (0, 1 ou 2?))");
			posDestino = sc.nextInt();
			System.out.println("em qual coluna?? (0, 1 ou 2?)");
			colunaDestino = sc.nextInt();
			
			if(verificaJogada(pecaMov, colunaAtual, posDestino, colunaDestino)){
				
				tabuleiro[posDestino][colunaDestino] = tabuleiro[pecaMov][colunaAtual];
				tabuleiro[pecaMov][colunaAtual] = 0;
			}
			exibeTabuleiro();
		}
	}
	
	public static void mostraScore(){
		int auxScore;
		String auxJogador;
		
		for(int i = 0; i < score.length; i++){
			
			for(int j = i + 1; j < score.length; j++){
				
				if(score[i] < score[j]){
					
					auxScore = score[i];
					auxJogador = jogadores[i];
					
					score[i] = score[j];
					jogadores[i] = jogadores[j];
					
					score[j] = score[i];
					jogadores[j] = jogadores[i];
				}
			}
		}
	
	for(int i = 0; i < 10; i++){
		
		System.out.println(jogadores[i] + "\t" + score[i]);
	}
	}
	
	

}

E ae pessoal!
estou com um pequeno problema aqui...

quando eu rodo o jogo, as "peças" representadas por numeros, não mudam
alguem sabe o que pode estar acontecendo??

obrigado!!

abraços

Criado 28 de maio de 2012
Respostas 0
Participantes 1