Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
frandegrandis committed Jun 11, 2020
1 parent c20c520 commit cde36e1
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 24 deletions.
9 changes: 9 additions & 0 deletions repository/IngSoft2-Model/Acceleration.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ Acceleration class >> to: anUndefinedObject [
^self new
]

{ #category : #'as yet unclassified' }
Acceleration >> isIdenticalTo: anAcceleration [
^anAcceleration = self
]

{ #category : #'as yet unclassified' }
Acceleration >> target [
]

{ #category : #'as yet unclassified' }
Acceleration >> triggerEffectFor: aGame [
aGame moveActualPlayerForward: 1.
Expand Down
1 change: 1 addition & 0 deletions repository/IngSoft2-Model/Board.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ Board >> length [

{ #category : #playing }
Board >> triggerFor: aGame [
aGame forActualUpdateLastEffect: (fields at: (aGame actualPlayer position)+1).
(fields at: (aGame actualPlayer position)+1) triggerEffectFor: aGame.
]
5 changes: 5 additions & 0 deletions repository/IngSoft2-Model/Cancellation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Cancellation >> initializeWithTarget: aClass [
target := aClass
]

{ #category : #'as yet unclassified' }
Cancellation >> isIdenticalTo: aCard [
^(self = aCard) and: (aCard target = target)
]

{ #category : #'as yet unclassified' }
Cancellation >> triggerEffectFor: aGame [

Expand Down
6 changes: 3 additions & 3 deletions repository/IngSoft2-Model/Card.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ Card class >> playingAs: aCardPlayState [
initializeWithPlayState: aCardPlayState
]

{ #category : #comparing }
Card >> = aCard [
^aCard isMemberOf: self class.
{ #category : #'as yet unclassified' }
Card >> = aCard [
^ (aCard isMemberOf: self class)
]

{ #category : #'as yet unclassified' }
Expand Down
21 changes: 11 additions & 10 deletions repository/IngSoft2-Model/Game.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Class {
'scoreboard',
'board',
'deck',
'permanentCardDeck'
'thrownCards'
],
#category : #'IngSoft2-Model-Game'
}
Expand Down Expand Up @@ -41,7 +41,7 @@ Game class >> with: dice on: aBoard playedBy: players withLaps: laps shuffling:

{ #category : #'as yet unclassified' }
Game >> activatePermanentEffects [
permanentCardDeck do: [ :aCard | aCard triggerEffectFor: self ]
thrownCards do: [ :aCard | aCard triggerEffectFor: self ]
]

{ #category : #accessing }
Expand All @@ -51,7 +51,7 @@ Game >> actualPlayer [

{ #category : #'as yet unclassified' }
Game >> addPermanent: aCard [
permanentCardDeck add: aCard
thrownCards add: aCard
]

{ #category : #results }
Expand Down Expand Up @@ -102,7 +102,7 @@ Game >> initializeDice: aDice withBoard: aBoard andPlayers: players andLaps: amm
state := Started new.
laps := ammountLaps.
scoreboard := Scoreboard withRows: rows.
permanentCardDeck := OrderedCollection new.
thrownCards := OrderedCollection new.

]

Expand All @@ -113,7 +113,7 @@ Game >> laps [

{ #category : #'as yet unclassified' }
Game >> lastCard [
^permanentCardDeck last copy
^thrownCards last copy
]

{ #category : #accessing }
Expand Down Expand Up @@ -204,11 +204,12 @@ Game >> podiumOf: aScoreboardRaw [
]

{ #category : #'as yet unclassified' }
Game >> removePermanentCard: aClass [
| index |
index := permanentCardDeck indexOf: aClass.
index > 0
ifTrue: [ permanentCardDeck removeAt: index ]
Game >> removePermanentCard: aCard [
| aColl |
aColl := thrownCards select: [ :card | (card isIdenticalTo: aCard) ].
aColl isEmpty ifFalse: [aColl removeFirst].
thrownCards :=(thrownCards select: [ :card | (card isIdenticalTo: aCard) not]) addAll: aColl.

]

{ #category : #playing }
Expand Down
1 change: 0 additions & 1 deletion repository/IngSoft2-Model/Player.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ Player >> layCard: aCardType for: aGame [
index := hand indexOf: aCardType.
index > 0
ifFalse: [ InvalidAction signal: 'Player does not have this type of card' ].

aCardType useEffectFor: aGame.
self getCardAt: index
]
Expand Down
10 changes: 10 additions & 0 deletions repository/IngSoft2-Model/Speed.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ Speed >> initializeWithTarget: aString [
target := aString
]

{ #category : #'as yet unclassified' }
Speed >> isIdenticalTo: aSpeed [
^ (aSpeed = self) and:( aSpeed target= target)
]

{ #category : #'as yet unclassified' }
Speed >> target [
^ target
]

{ #category : #'as yet unclassified' }
Speed >> triggerEffectFor: aGame [
((aGame player: target )= (aGame actualPlayer)) ifTrue: [ aGame moveActualPlayerForward: 1 ]
Expand Down
122 changes: 112 additions & 10 deletions repository/IngSoft2-Tests/GameTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Class {
'aNoEffect',
'aWormhole',
'anAtomicBomb',
'aSpeedUp'
'aSpeedUp',
'anAcceleration'
],
#category : #'IngSoft2-Tests-Game-Tests'
}
Expand Down Expand Up @@ -59,7 +60,8 @@ GameTest >> setUp [
aNoEffect := NoEffect new.
aWormhole := Wormhole new.
anAtomicBomb := AtomicBomb new.
aSpeedUp := SpeedUp new
aSpeedUp := SpeedUp new.
anAcceleration := Acceleration new.
]

{ #category : #tests }
Expand All @@ -74,9 +76,9 @@ GameTest >> testActivateCancellationOfNonPlayedCard [
(CardDeck
with:
{Cancellation new.
Acceleration new}
anAcceleration}
of: #(1 2)).
aGame player: 'Manu' playCard: (Cancellation to: Acceleration new).
aGame player: 'Manu' playCard: (Cancellation to: anAcceleration).
self assert: (self cardsOf: 'Fran' in: aGame) equals: 2.
self assert: (self cardsOf: 'Manu' in: aGame) equals: 1.
self assert: (self positionOf: 'Fran' in: aGame) equals: 0.
Expand Down Expand Up @@ -504,10 +506,10 @@ GameTest >> testTriggerCancellationEffect [
(CardDeck
with:
{Cancellation new.
Acceleration new}
anAcceleration}
of: #(1 2)).
aGame player: 'Fran' playCard: Acceleration new.
aGame player: 'Manu' playCard: (Cancellation to: Acceleration new).
aGame player: 'Fran' playCard: anAcceleration.
aGame player: 'Manu' playCard: (Cancellation to: anAcceleration).
self assert: (self cardsOf: 'Fran' in: aGame) equals: 1.
self assert: (self cardsOf: 'Manu' in: aGame) equals: 1.
self assert: (self positionOf: 'Fran' in: aGame) equals: 0.
Expand All @@ -516,6 +518,61 @@ GameTest >> testTriggerCancellationEffect [
self assert: (self positionOf: 'Manu' in: aGame) equals: 0
]

{ #category : #tests }
GameTest >> testTriggerCancellationEffectToAnSpecificSpeed [
| aGame |
aGame := Game
with: (Die of: 6 rolling: #(4))
on: self noEffectBoardOf12
playedBy: players
withLaps: 1
shuffling:
(CardDeck
with:
{Cancellation new.
Speed new}
of: #(1 2)).
aGame player: 'Fran' playCard: (Speed to: 'Fran').
self assert: (self cardsOf: 'Fran' in: aGame) equals: 1.
self assert: (self cardsOf: 'Manu' in: aGame) equals: 2.
self assert: (self positionOf: 'Fran' in: aGame) equals: 0.
aGame playTurn.
aGame player: 'Manu' playCard: (Speed to: 'Manu').
aGame player: 'Fran' playCard:( Cancellation to:(Speed to: 'Manu')).
self assert: (self positionOf: 'Fran' in: aGame) equals: 5.
self assert: (self positionOf: 'Manu' in: aGame) equals: 0.
aGame playTurn.
self assert: (self positionOf: 'Manu' in: aGame) equals: 4.
]

{ #category : #tests }
GameTest >> testTriggerCancellationEffectToAnSpecificSpeedButManuHavingTwoOfThem [
| aGame |
aGame := Game
with: (Die of: 6 rolling: #(4))
on: self noEffectBoardOf12
playedBy: players
withLaps: 1
shuffling:
(CardDeck
with:
{Speed new.
Cancellation new}
of: #(2 1 1 1)).
aGame player: 'Fran' playCard: (Speed to: 'Fran').
self assert: (self cardsOf: 'Fran' in: aGame) equals: 1.
self assert: (self cardsOf: 'Manu' in: aGame) equals: 2.
self assert: (self positionOf: 'Fran' in: aGame) equals: 0.
aGame playTurn.
aGame player: 'Manu' playCard: (Speed to: 'Manu').
aGame player: 'Manu' playCard: (Speed to: 'Manu').
aGame player: 'Fran' playCard: (Cancellation to: (Speed to: 'Manu')).
self assert: (self positionOf: 'Fran' in: aGame) equals: 5.
self assert: (self positionOf: 'Manu' in: aGame) equals: 0.
aGame playTurn.
self assert: (self positionOf: 'Manu' in: aGame) equals: 5
]

{ #category : #tests }
GameTest >> testTriggerOverloadEffect [
| aGame |
Expand Down Expand Up @@ -543,9 +600,9 @@ GameTest >> testTriggerRedoAcceleration [
on: self noEffectBoardOf12
playedBy: players
withLaps: 1
shuffling: (CardDeck with: {Acceleration new. Redo new} of: #(1 2)).
shuffling: (CardDeck with: {anAcceleration. Redo new} of: #(1 2)).
self assert: (self cardsOf: 'Fran' in: aGame) equals: 2.
aGame player: 'Fran' playCard: Acceleration new.
aGame player: 'Fran' playCard: anAcceleration.
aGame player: 'Fran' playCard: Redo new.
self assert: (self cardsOf: 'Fran' in: aGame) equals: 0.
self assert: (self positionOf: 'Fran' in: aGame) equals: 0.
Expand All @@ -554,6 +611,29 @@ GameTest >> testTriggerRedoAcceleration [
self assert: (self positionOf: 'Manu' in: aGame) equals: 0.
]

{ #category : #tests }
GameTest >> testTriggerRedoCancellation [
| aGame |
aGame := Game
with: (Die of: 6 rolling: #(4))
on: self noEffectBoardOf12
playedBy: players
withLaps: 1
shuffling: (CardDeck with: {anAcceleration. Speed new. Redo new. Cancellation new.} of: #(1 2 3 4)).
self assert: (self cardsOf: 'Fran' in: aGame) equals: 2.
aGame player: 'Fran' playCard: (Speed to: 'Fran').
aGame player: 'Fran' playCard: (anAcceleration).
aGame player: 'Manu' playCard: (Cancellation to: Speed new).
aGame player: 'Manu' playCard: (Redo to: Acceleration new).
self assert: (self cardsOf: 'Fran' in: aGame) equals: 0.
self assert: (self cardsOf: 'Manu' in: aGame) equals: 0.
self assert: (self positionOf: 'Fran' in: aGame) equals: 0.
aGame playTurn.
self assert: (self positionOf: 'Fran' in: aGame) equals: 4.
self assert: (self positionOf: 'Manu' in: aGame) equals: 0.

]

{ #category : #tests }
GameTest >> testTriggerRedoSpeed [
| aGame |
Expand All @@ -562,7 +642,7 @@ GameTest >> testTriggerRedoSpeed [
on: self noEffectBoardOf12
playedBy: players
withLaps: 1
shuffling: (CardDeck with: {Speed new. Redo new} of: #(1 2)).
shuffling: (CardDeck with: {Cancellation new. Speed new. Redo new} of: #(2 2 1 3)).
self assert: (self cardsOf: 'Fran' in: aGame) equals: 2.
aGame player: 'Fran' playCard: (Speed to: 'Fran').
aGame player: 'Manu' playCard: (Redo to: 'Manu').
Expand All @@ -576,6 +656,28 @@ GameTest >> testTriggerRedoSpeed [
self assert: (self positionOf: 'Manu' in: aGame) equals: 5.
]

{ #category : #tests }
GameTest >> testTriggerRepeat [
| aGame |
aGame := Game
with: (Die of: 6 rolling: #(4))
on: self noEffectBoardOf12
playedBy: players
withLaps: 1
shuffling: (CardDeck with: {Acceleration new}).
self assert: (self cardsOf: 'Fran' in: aGame) equals: 2.
aGame player: 'Fran' playCard: Acceleration new.
self assert: (self cardsOf: 'Fran' in: aGame) equals: 1.
self assert: (self positionOf: 'Fran' in: aGame) equals: 0.
aGame playTurn.
self assert: (self positionOf: 'Fran' in: aGame) equals: 5.
self assert: (self positionOf: 'Manu' in: aGame) equals: 0.
aGame player: 'Manu' playCard: Acceleration new.
aGame playTurn.
self assert: (self positionOf: 'Fran' in: aGame) equals: 5.
self assert: (self positionOf: 'Manu' in: aGame) equals: 6
]

{ #category : #tests }
GameTest >> testTriggerSpeedEffect [
| aGame |
Expand Down

0 comments on commit cde36e1

Please sign in to comment.