Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Didattica > Corsi N - Z > Programmazione > Problema con programma. AIUTO!
  Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
richard.greco
.novellino.

User info:
Registered: Oct 2014
Posts: 2 (0.00 al dì)
Location:
Corso: Informatica per la comunicazione digitale
Anno: 1
Time Online: 0:26:17 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
Problema con programma. AIUTO!

Buongiorno a tutti. Io ho un problema con un programma scritto da me. Sto creando un programma in java per giocare a solitario ed ho creato le classi Carta, Mazzo e Tavolo. Il mio problema arriva quando cerco di spostare le carte del tavolo da un "mazzetto" all'altro. Nell'immagine potete vedere che se sposto una carta alla volta funziona tutto, mentre se ne sposto più di una mi sposta solo quelle in posizione dispari!!!

Vi metto ora in allegato i codici di programma attinenti alla parte in questione

//estratto classe Carta//
protected int numero, seme;
protected boolean bol = false;

public Carta(int i, int j){
if(i>0 && i<14)
numero = i;
else
System.out.println("ERRORE: Il numero della carta deve essere compreso tra 1 e 13");

if(j>0 && j<5)
seme = j;
else
System.out.println("ERRORE: Il numero del seme deve essere compreso tra 1 e 4 (Cuori, Quadri, Fiori, Picche)");
}

public void setBol(boolean b){
bol = b;
}

public boolean getBol(){
return bol;
}
//

//estratto classe Mazzo//
public Mazzo(){
for(int i=1; i<14; i++)
mazzo.add(new Carta(i,1));
for(int i=1; i<14; i++)
mazzo.add(new Carta(i,2));
for(int i=1; i<14; i++)
mazzo.add(new Carta(i,3));
for(int i=1; i<14; i++)
mazzo.add(new Carta(i,4));
}


public Carta getCarta(int i){
return mazzo.get(i);
}

public int size(){
int k=0;
for(Carta c: mazzo)
k++;
return k;
}

public Carta estraiCarta(int i){
if(mazzo.size()==0){
System.out.println("ERRORE: inserire un numero tra 1 e mazzo.size()");
return new Carta(-1,-1);
} else {
Carta c = mazzo.get(i);
mazzo.remove(i);
return c;
}
}

public void insCartaDown(Carta c){
boolean bol = true;
for(Carta q: mazzo)
if(c.equals(q))
bol = false;
if(bol)
mazzo.add(c);
else
System.out.println("Carta gia' presente nel mazzo");
}
////

//estratto classe Tavolo//
public void sposta(int i, int j){
ArrayList<Carta> c = new ArrayList<Carta>();
for(int k=0; k<tav.get(i-1).size(); k++){
if(tav.get(i-1).getCarta(k).getBol()){
c.add(tav.get(i-1).estraiCarta(k));
}
}
for(int k=0; k<c.size(); k++){
tav.get(j-1).insCartaDown(c.get(k));
}
for(int k=0; k<7; k++)
if(tav.get(k).size()!=0)
tav.get(k).getCarta(tav.get(k).size()-1).setBol(true);
}

public void verita(){
for(int k=0; k<tav.size(); k++){
for(int h=0; h<tav.get(k).size(); h++){
System.out.print(tav.get(k).getCarta(h).getBol()+" ");
}
System.out.print(tav.get(k).size());
System.out.println();
}
}
////

i metodi che eseguo nella schermata sono i metodi "verita" e i metodi "sposta". Vorrei capire perché mi prende solo le carte "TRUE" in posizione dispari.
Grazie mille!!!

Attachment: schermata da 2014-12-29 14:04:18.png
This has been downloaded 10 time(s).

29-12-2014 13:09
Click Here to See the Profile for richard.greco Click here to Send richard.greco a Private Message Find more posts by richard.greco Add richard.greco to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 17:43.    Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 1.695 seconds (8.49% PHP - 91.51% MySQL) con 26 query.