Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementacion de laps #3

Merged
merged 8 commits into from
May 9, 2020
Merged
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
```smalltalk
Metacello new
baseline: 'IngSoft2';
githubUser: 'uca-is2' project: 'los-discipulos-de-roger' commitish: 'master' path: 'repository';
githubUser: 'uca-is2' project: 'los-discipulos-de-roger' commitish: 'ImplementacionDeLaps' path: 'repository';
load: 'development'.
```
29 changes: 29 additions & 0 deletions repository/IngSoft2-Model/BoardGenerator.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Class {
#name : #BoardGenerator,
#superclass : #Object,
#instVars : [
'fields'
],
#category : #'IngSoft2-Model-BoardGenerator'
}

{ #category : #initialization }
BoardGenerator class >> createWithFields: aNumberofFields [
^self withFields: aNumberofFields.
]

{ #category : #'class initialization' }
BoardGenerator class >> withFields: aNumberOfFields [
^self new
withFields: aNumberOfFields.
]

{ #category : #'as yet unclassified' }
BoardGenerator >> fields [
^ fields
]

{ #category : #initialization }
BoardGenerator >> withFields: aNumberOfFields [
fields := aNumberOfFields.
]
15 changes: 0 additions & 15 deletions repository/IngSoft2-Model/CircularIterator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,12 @@ CircularIterator class >> cyclingOver: aSequentiableCollection [
^ self new initializeCyclingOver: aSequentiableCollection asArray
]

{ #category : #accessing }
CircularIterator >> att: aPosition [
^options at: aPosition
]

{ #category : #accessing }
CircularIterator >> current [

^options at: currentIndex + 1
]

{ #category : #accessing }
CircularIterator >> first [
^options first
]

{ #category : #testing }
CircularIterator >> includes: anObject [

Expand All @@ -65,8 +55,3 @@ CircularIterator >> reset [

currentIndex := 0
]

{ #category : #accessing }
CircularIterator >> sort [
options := options sort
]
4 changes: 2 additions & 2 deletions repository/IngSoft2-Model/Finished.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Class {
#category : #'IngSoft2-Model-Game'
}

{ #category : #'as yet unclassified' }
Finished >> isFinished [
{ #category : #evaluation }
Finished >> hasFinished [
^true.
]

Expand Down
87 changes: 53 additions & 34 deletions repository/IngSoft2-Model/Game.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,90 @@ Class {
'dice',
'state',
'playerSequence',
'length'
'length',
'laps',
'scoreboard'
],
#category : #'IngSoft2-Model-Game'
}

{ #category : #instanceCreation }
Game class >> with: dice andFields: aNumber andPlayers: players [
Game class >> with: dice andFields: aNumber andPlayers: players andLaps: laps [
^ self new
initializeDice: dice
withFields: aNumber
andPlayers: players.
andPlayers: players
andLaps: laps.
]

{ #category : #instanceCreation }
Game class >> with: aDice andPlayers: players [
^self with: aDice andFields: 12 andPlayers: players
^self with: aDice andFields: 12 andPlayers: players andLaps: 1
]

{ #category : #instanceCreation }
Game class >> withFields: aNumber andPlayers: players [
^self with: Die d4 andFields: aNumber andPlayers: players
Game class >> with: aDie andPlayers: aCollection ofLaps: anInteger [
^self with: aDie andFields: 16 andPlayers: aCollection andLaps: anInteger
]

{ #category : #instanceCreation }
Game class >> withPlayers: players [
^self with: Die d6 andFields: 12 andPlayers: players
^self with: Die d6 andFields: 12 andPlayers: players andLaps: 1
]

{ #category : #accessing }
Game >> actualPlayer [
^playerSequence current
]

{ #category : #playing }
Game >> addLapTo: aPlayer [
aPlayer position >= length ifTrue: [ aPlayer addLapAndMove:(aPlayer position%length)].
]

{ #category : #results }
Game >> att: aPosition [

"This could be used to get when is a players turn or to get the positions at the end of the game"

^playerSequence att: aPosition
^scoreboard at: aPosition
]

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

{ #category : #playing }
Game >> finishATurn [
state finish: self.
playerSequence next.
self updateScoreboard
]

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

{ #category : #accessing }
Game >> getDice [
^dice
{ #category : #results }
Game >> hasFinished [
^state hasFinished.
]

{ #category : #initialization }
Game >> initializeDice: aDice withFields: aNumber andPlayers: players [
Game >> initializeDice: aDice withFields: aNumber andPlayers: players andLaps: ammountLaps [
dice := aDice.
playerSequence := CircularIterator cyclingOver: players.
length := aNumber.
state := Started new.
"tablePosition := players."
laps := ammountLaps.
scoreboard := Scoreboard withRows: players
]

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

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

{ #category : #accessing }
Expand All @@ -77,28 +97,27 @@ Game >> length [
]

{ #category : #playing }
Game >> playNext [
| position |
position := playerSequence next move: self roll.
state finish:self at: position.
Game >> playATurn [
self actualPlayer updateAPlayerPosition: self roll.
self addLapTo: self actualPlayer.
self finishATurn.
]

{ #category : #playing }
Game >> playUntilFinished [
"playNext pero juega hasta que termine el juego, no sólo la próxima jugada"
| position |
position := playerSequence next move: self roll.
state finishAndContinue:self at: position.
"playNext pero juega hasta que termine el juego, no sólo la próxima jugada"

[self hasFinished] whileFalse: [ self playATurn ]
]

{ #category : #playing }
Game >> roll [
^dice roll.
]

{ #category : #accessing }
Game >> state [
^state
{ #category : #results }
Game >> updateScoreboard [
scoreboard sort: [ :a :b | a>=b ]
]

{ #category : #accessing }
Expand All @@ -108,5 +127,5 @@ Game >> winner [

{ #category : #results }
Game >> winnerWhenFinished [
^playerSequence first.
^scoreboard first.
]
45 changes: 0 additions & 45 deletions repository/IngSoft2-Model/Player.class.st

This file was deleted.

34 changes: 34 additions & 0 deletions repository/IngSoft2-Model/Scoreboard.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Class {
#name : #Scoreboard,
#superclass : #Object,
#instVars : [
'rowList'
],
#category : #'IngSoft2-Model-Scoreboard'
}

{ #category : #instanceCreation }
Scoreboard class >> withRows: rows [
^self new
initializeWithRows: rows
]

{ #category : #accesing }
Scoreboard >> at: anIndex [
^rowList at: anIndex
]

{ #category : #accesing }
Scoreboard >> first [
^rowList first
]

{ #category : #initialization }
Scoreboard >> initializeWithRows: rows [
rowList := rows
]

{ #category : #accesing }
Scoreboard >> sort: aSortProtocol [
rowList sort: aSortProtocol.
]
64 changes: 64 additions & 0 deletions repository/IngSoft2-Model/ScoreboardRaw.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Class {
#name : #ScoreboardRaw,
#superclass : #Object,
#instVars : [
'playerName',
'position',
'laps'
],
#category : #'IngSoft2-Model-Scoreboard'
}

{ #category : #instanceCreation }
ScoreboardRaw class >> ofPlayerNamed: aNameSurname [
aNameSurname isEmpty
ifTrue: [ InstanceCreationFailed
signal: 'The player name cannot be blank' ].

^self new
initializeWithName: aNameSurname
]

{ #category : #comparing }
ScoreboardRaw >> >= aPlayer [
^laps >= (aPlayer laps)
]

{ #category : #playing }
ScoreboardRaw >> addLapAndMove: aMovement [
laps := laps + 1.
self resetPosition.
self updateAPlayerPosition: aMovement
]

{ #category : #initialization }
ScoreboardRaw >> initializeWithName: aName [
playerName := aName.
position := 0.
laps := 0.
]

{ #category : #accessing }
ScoreboardRaw >> laps [
^ laps
]

{ #category : #accessing }
ScoreboardRaw >> name [
^playerName
]

{ #category : #accessing }
ScoreboardRaw >> position [
^position
]

{ #category : #playing }
ScoreboardRaw >> resetPosition [
position := 0
]

{ #category : #playing }
ScoreboardRaw >> updateAPlayerPosition: aMovement [
position := position + aMovement.
]
Loading