Skip to content

Commit

Permalink
Fixed sort bug, and fixing the test that didnt pass
Browse files Browse the repository at this point in the history
  • Loading branch information
frandegrandis committed May 7, 2020
1 parent 033a9dc commit e51aee5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion repository/IngSoft2-Model/CircularIterator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ CircularIterator >> reset [

{ #category : #accessing }
CircularIterator >> sort [
options := options sort
options := options sort: [ :a :b | a>=b ]
]
27 changes: 10 additions & 17 deletions repository/IngSoft2-Model/Game.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Game class >> with: aDice andPlayers: players [
^self with: aDice andFields: 12 andPlayers: players
]

{ #category : #'as yet unclassified' }
{ #category : #instanceCreation }
Game class >> with: aDie andPlayers: aCollection ofLaps: anInteger [
^self with: aDie andFields: 16 andPlayers: aCollection andLaps: anInteger
]
Expand All @@ -45,7 +45,7 @@ Game class >> withPlayers: players [
^self with: Die d6 andFields: 12 andPlayers: players
]

{ #category : #'as yet unclassified' }
{ #category : #playing }
Game >> addLapTo: aPlayer [
aPlayer position >= length ifTrue: [ aPlayer addLap:(aPlayer position%length)].
^aPlayer laps
Expand All @@ -59,17 +59,17 @@ Game >> att: aPosition [
^playerSequence att: aPosition
]

{ #category : #accessing }
Game >> dice [
^dice
]

{ #category : #StateChanging }
Game >> finishAnStartedGame [
state := Finished new.
playerSequence sort
]

{ #category : #accessing }
Game >> getDice [
^dice
]

{ #category : #initialization }
Game >> initializeDice: aDice withFields: aNumber andPlayers: players andLaps: ammountLaps [
dice := aDice.
Expand All @@ -79,17 +79,12 @@ Game >> initializeDice: aDice withFields: aNumber andPlayers: players andLaps: a
laps := ammountLaps.
]

{ #category : #'as yet unclassified' }
{ #category : #results }
Game >> isFinished [
^state isFinished.
]

{ #category : #checking }
Game >> isPlayedBy: aPlayer [
^ playerSequence includes: aPlayer.
]

{ #category : #'as yet unclassified' }
{ #category : #accessing }
Game >> laps [
^ laps
]
Expand Down Expand Up @@ -119,9 +114,7 @@ Game >> playNext [
Game >> playUntilFinished [
"playNext pero juega hasta que termine el juego, no sólo la próxima jugada"

| position |
position := self play.
state finishAndContinue: self at: position
[self isFinished] whileFalse: [ self playNext ]
]

{ #category : #playing }
Expand Down
4 changes: 2 additions & 2 deletions repository/IngSoft2-Model/Player.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Player class >> named: aNameSurname [
]

{ #category : #comparing }
Player >> <= aPlayer [
^position >= (aPlayer position)
Player >> >= aPlayer [
^laps >= (aPlayer laps)
]

{ #category : #'as yet unclassified' }
Expand Down
8 changes: 3 additions & 5 deletions repository/IngSoft2-Model/Started.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ Started >> finish: aGame at: aPosition [
ifFalse: [ aGame finishAnStartedGame ]
]

{ #category : #StateChanging }
Started >> finishAndContinue: aGame at: aPosition [
(self isFinished: aGame at: aPosition)
ifFalse: [ aGame finishAnStartedGame ]
ifTrue: [ aGame playUntilFinished ]
{ #category : #'as yet unclassified' }
Started >> isFinished [
^false
]

{ #category : #StateChanging }
Expand Down
4 changes: 2 additions & 2 deletions repository/IngSoft2-Tests/GameTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ self assert: (aGame isFinished).
GameTest >> test06PlayAGameAndFranWins [

| aGame aPlayer otherPlayer |
aPlayer := Player named: 'Fran'.
otherPlayer := Player named: 'Manu'.
aPlayer := self anotherPlayer.
otherPlayer := self newPlayer .
aGame := Game with: (Die of: 6 rolling: #(4 1)) andPlayers: { aPlayer. otherPlayer} .
aGame playUntilFinished.
self assert: (aGame winner name) equals: 'Fran'.
Expand Down

0 comments on commit e51aee5

Please sign in to comment.