Skip to content
Snippets Groups Projects
Commit b95055a5 authored by Roope Malinen's avatar Roope Malinen
Browse files

Lisätty sortteri pelaajan korteille

parent d95813f7
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ public class Ohituskortti extends Kortti implements Erikoiskortti {
}
public String toString() {
return "[" + this.vari + ", ]";
return "[" + this.vari + ", o]";
}
}
......@@ -11,6 +11,7 @@ import domain.kortit.Ohituskortti;
import domain.kortit.Peruskortti;
import domain.kortit.Suunnanvaihtokortti;
import domain.korttipakat.Nostopakka;
import domain.kortit.Erikoiskortti;
public abstract class Pelaaja {
......@@ -26,6 +27,51 @@ public abstract class Pelaaja {
this.kortit.add(k);
}
//Jrjest kortit vri ja numero/merkki jrjestykseen, 0-9-erikoiskortit
public void jarjestaKortit() {
ArrayList<Kortti> cardholder = new ArrayList<Kortti>();
ArrayList<Kortti> otherholder = new ArrayList<Kortti>();
Object placeholder = new Object();
String[] varivalikoima = {"punainen", "sininen", "keltainen", "vihre"};
for(int k = 0; k<4 ;k++) {
for(int i = 0; i<kortit.size(); i++) {
try {
if ((kortit.get(i).annaVari()).equals(varivalikoima[k])) {
otherholder.add(kortit.get(i));
}
}catch(NullPointerException e) {} //Jokerin null vriarvo...
}
for(int j = 0; j<10 ;j++) {
for(int x = 0; x<otherholder.size(); x++) {
placeholder = otherholder.get(x);
if(placeholder instanceof Peruskortti) {
if(((Peruskortti) placeholder).annaNumero()==j) {
cardholder.add(otherholder.get(x));
}
}
}
}
for(int x = 0; x<otherholder.size(); x++) {
if(otherholder.get(x) instanceof Erikoiskortti) {
cardholder.add(otherholder.get(x));
}
}
otherholder.clear();
}
for(int i = 0; i<kortit.size() ;i++) {
if(kortit.get(i) instanceof Jokerikortti) {
cardholder.add(kortit.get(i));
}
}
for(int i = 0; i<kortit.size() ;i++) {
if(kortit.get(i) instanceof Nosta4Jokerikortti) {
cardholder.add(kortit.get(i));
}
}
this.kortit = cardholder;
}
public void tulostaKortit() {
int i = 0;
for (Kortti k : this.kortit) {
......
......
......@@ -345,7 +345,6 @@ public class Peli {
}
}
if (pelaajallaSopivanVarinenKortti) {
System.out.println("Et voi kytt Nosta 4 -korttia, jos sinulla on sopivan vrinen kortti.");
return false;
}
this.annaPelaaja(seuraavaksiVuorossa).nostaNeljaKorttia(this.nostopakka);
......
......
......@@ -88,6 +88,7 @@ public class Tekstikayttoliittyma {
boolean korttiPelattu = false;
while (korttiPelattu == false) {
System.out.println("Sinulla on kdesssi kortit:");
pelaaja.jarjestaKortit();
pelaaja.tulostaKortit();
System.out.println("Kirjoita kortin numero pelataksesi kortin tai \"nosta\" nostaaksesi kortin.");
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment