• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nika3007 / SE_Memory / 19620831742

24 Nov 2025 01:39AM UTC coverage: 71.304% (-11.7%) from 82.979%
19620831742

push

github

nazzaaar
Specs angepasst für 100% coverage

22 of 41 new or added lines in 4 files covered. (53.66%)

1 existing line in 1 file now uncovered.

82 of 115 relevant lines covered (71.3%)

0.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.29
/src/main/scala/controller/Controller.scala
1
package controller
2

3
import model.MemoryGame
4
import model.Board
5
import util.Observable
6
import scala.util.Try
7

8
class Controller(rows: Int, cols: Int) extends Observable:
9

10
  var game: MemoryGame = MemoryGame(rows, cols)
11
  var gameStatus: GameStatus = GameStatus.Idle // aktueller spielstatus
12

13
  def board: Board = game.board
1✔
14

15
  def processInput(input: String): Boolean =
1✔
16
    // Spiel beenden, wenn Abbruchbedingung
17
    if input == null || input.trim.isEmpty then
1✔
18
      //gameStatus = GameStatus.Idle
19
      //notifyObservers()
20
      //println("Spiel beendet durch Eingabeabbruch. Bye👋")
21
      return false
1✔
22

23
    // Zahl prüfen
24
    val inputOpt = Try(input.toInt).toOption
1✔
25

26
    inputOpt match
27
      case Some(i) if i >= 0 && i < board.cards.size =>
1✔
28
        handleCardSelection(i)
1✔
29
        true
30

31
      case _ =>
32
        //println(s"❗ Ungültige Eingabe. Bitte Zahl zwischen 0 und ${board.cards.size - 1}.")
33
        gameStatus = GameStatus.InvalidSelection(-1)
1✔
34
        notifyObservers
1✔
35
        true
36

37

38

39
  // Spiellogik:
40

41
  private def handleCardSelection(i: Int): Unit =
1✔
42
    val oldBoard = board
1✔
43
    val (nextBoard, result) = board.choose(i)
1✔
44

45
    // Ungültige, wenn schon matched / faceUp / gleiche Karte ---
UNCOV
46
    val invalid = (nextBoard eq oldBoard) && result.isEmpty
×
47

48
    if invalid then
49
      //println(s"❗ Karte $i kann nicht gewählt werden (bereits offen oder matched).\n")
NEW
50
      gameStatus = GameStatus.InvalidSelection(i)
×
NEW
51
      notifyObservers
×
52
      return
1✔
53

54
    // Gültige Karte:
55
    game.board = nextBoard
56

57

58
    result match
59
      //erste Karte:
60
      case None =>
61
        gameStatus = GameStatus.SecondCard
1✔
62
        // Erst Board anzeigen
63
        notifyObservers
1✔
64

65
        // Dann Meldung unter Board
66
        //println()
67
        //println("zweite Karte wählen...")
68
        //notifyObservers()
69

70
      // Match:
71
      case Some(true) =>
72
        gameStatus = GameStatus.Match
1✔
73
        notifyObservers
1✔
74
        //println("✅ Treffer!\n")
75

76
      // Kein Match:
77
      case Some(false) =>
78
        gameStatus = GameStatus.NoMatch
1✔
79
        notifyObservers
1✔
80
        //println("❌ Kein Treffer.\n")
81

82
        Thread.sleep(1500)
1✔
83
        //println()
84
        //println("nächste Runde...\n")
85

86
        // Karten zurückdrehen
87
        val resetBoard = board.copy(
1✔
88
          cards = board.cards.map {
1✔
89
            case c if c.isFaceUp && !c.isMatched => c.flip
1✔
90
            case c => c
1✔
91
          }
92
        )
93

94
        game.board = resetBoard
95
        gameStatus = GameStatus.NextRound
96
        notifyObservers
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc