Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ija.ija2016.homework2.model.cards;
- public interface Card {
- //nested class Card.Color- Výčtový typ reprezentující barvu karty.
- enum Color {
- CLUBS,
- DIAMONDS,
- HEARTS,
- SPADES;
- @Override
- public String toString() {
- switch (this) {
- case CLUBS:
- return "C";
- case DIAMONDS:
- return "D";
- case HEARTS:
- return "H";
- case SPADES:
- return "S";
- default:
- throw new IllegalArgumentException();
- }
- }
- }
- Color color();
- int compareValue(Card c);
- boolean isTurnedFaceUp();
- boolean similarColorTo(Card c);
- boolean turnFaceUp();
- int value();
- }
- class CardClass implements Card{
- private int value;
- private boolean face;
- private Color color;
- public Color color(){
- return this.color;
- }
- public int value(){
- return this.value;
- }
- public boolean similarColorTo(Card c){
- if ((this.color == Color.HEARTS || this.color == Color.DIAMONDS) && (c.color == Color.HEARTS || c.color == Color.DIAMONDS)) {
- return true;
- }
- if ( (this.color == Color.CLUBS || this.color == Color.SPADES) && (c.color == Color.CLUBS || c.color == Color.SPADES) ){
- return true;
- }
- return false;
- }
- public boolean isTurnedFaceUp(){
- return this.face;
- }
- public boolean turnFaceUp(){
- if (this.face == false){
- this.face = true;
- return true;
- }
- return false;
- }
- public int compareValue(Card c){
- return this.value - c.value;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement