From d89b2a0c02bfbc0b999b84158c4e419b2980d944 Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Sun, 30 Jan 2022 22:35:24 +0100 Subject: [PATCH] Update check and test from StartStack --- src/main/java/solitaer/StartStack.java | 36 +++++++++------------- src/test/java/solitaer/StartStackTest.java | 5 +-- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/main/java/solitaer/StartStack.java b/src/main/java/solitaer/StartStack.java index 068b88f..0dd2f8f 100644 --- a/src/main/java/solitaer/StartStack.java +++ b/src/main/java/solitaer/StartStack.java @@ -3,11 +3,10 @@ package solitaer; import java.awt.Color; import java.awt.Graphics; - public class StartStack extends BaseStack { private static final long serialVersionUID = 1L; - + public StartStack(int _x, int _y) { super(true); super.setLocation(_x, _y); @@ -17,30 +16,27 @@ public class StartStack extends BaseStack { } public boolean cardCheck(Card _topStack, Card _playerCard) { - if(_topStack == null && _playerCard == null) { + if (_topStack == null && _playerCard == null) { return false; - } + } if (_topStack == null) { // Nur der König kann auf einen leeren Stapel gelegt werden return _playerCard.getNr() == 13; - }else { + } else if (!_topStack.isFaceUp()) { + return false; + } else { return (// Nummer nur aufsteigend - _topStack.getNr() == _playerCard.getNr() + 1) - && - // rot auf Schwarz - ( - ((_topStack.getSymbol() == Symbol.Herz || _topStack.getSymbol() == Symbol.Karo) - && (_playerCard.getSymbol() == Symbol.Pik || _playerCard.getSymbol() == Symbol.Kreuz)) - || + _topStack.getNr() == _playerCard.getNr() + 1) && + // rot auf Schwarz + (((_topStack.getSymbol() == Symbol.Herz || _topStack.getSymbol() == Symbol.Karo) + && (_playerCard.getSymbol() == Symbol.Pik || _playerCard.getSymbol() == Symbol.Kreuz)) || // schwarz auf rot - ((_topStack.getSymbol() == Symbol.Pik || _topStack.getSymbol() == Symbol.Kreuz) - && (_playerCard.getSymbol() == Symbol.Herz || _playerCard.getSymbol() == Symbol.Karo)) - ); + ((_topStack.getSymbol() == Symbol.Pik || _topStack.getSymbol() == Symbol.Kreuz) + && (_playerCard.getSymbol() == Symbol.Herz + || _playerCard.getSymbol() == Symbol.Karo))); } } - - @Override protected void paintComponent(Graphics g) { // TODO Auto-generated method stub @@ -48,12 +44,10 @@ public class StartStack extends BaseStack { if (stackIsEmpty()) { g.setColor(Color.gray); g.fillRect(0, 0, this.getWidth(), IMAGE_HIGHT); - + g.setColor(Color.black); - g.drawRect(0, 0, this.getWidth()-1, IMAGE_HIGHT-1); + g.drawRect(0, 0, this.getWidth() - 1, IMAGE_HIGHT - 1); } } - - } diff --git a/src/test/java/solitaer/StartStackTest.java b/src/test/java/solitaer/StartStackTest.java index e9515e8..d033e45 100644 --- a/src/test/java/solitaer/StartStackTest.java +++ b/src/test/java/solitaer/StartStackTest.java @@ -29,8 +29,9 @@ class StartStackTest { Arguments.of("5-Pik auf 6-Karo", new Card(6, Symbol.Karo, true), new Card(5, Symbol.Pik, true), true), Arguments.of("König-Karo auf Ass-Kreuz", new Card(1, Symbol.Kreuz, true), new Card(13, Symbol.Karo, true), false), Arguments.of("5-Karo auf 7-Kreuz", new Card(7, Symbol.Kreuz, true), new Card(5, Symbol.Karo, true), false), - Arguments.of("2-Herz auf Ass-Kreuz", new Card(2, Symbol.Herz, true), new Card(1, Symbol.Kreuz, true), true), - Arguments.of("null auf null", null, null, false) + Arguments.of("Ass-Herz auf 2-Kreuz", new Card(2, Symbol.Herz, true), new Card(1, Symbol.Kreuz, true), true), + Arguments.of("null auf null", null, null, false), + Arguments.of("Ass-Herz auf face-Down-2-Kreuz", new Card(2, Symbol.Herz, false), new Card(1, Symbol.Kreuz, true), false) ); }