Skip to content

Commit

Permalink
Merge pull request #110 from Part-Time-Team/dev
Browse files Browse the repository at this point in the history
Final release
  • Loading branch information
lucagiorgettismp committed Sep 15, 2020
2 parents 11edb05 + 22c3ff8 commit 1af5f6b
Show file tree
Hide file tree
Showing 135 changed files with 2,175 additions and 1,172 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,24 @@ jobs:
- git config --local user.email "daniele.tentoni.1996@gmail.com"
- export TRAVIS_TAG=${TRAVIS_TAG:-$(date +'%Y%m%d%H%M%S')-$(git log --format=%h -1)}
- git tag $TRAVIS_TAG
before_deploy:
- sbt clean packArchive
deploy:
provider: releases
skip_cleanup: true
token: $GH_TOKEN
file_glob: true
file:
- target/client-*.tar.gz
- target/client-*.zip
- target/server-*.tar.gz
- target/server-*.zip
on:
branch: master
tags: true

stages:
- name: Run sbt with OpenJdk11
if: type IN (pull_request, push) && !(branch = master)
if: type IN (pull_request, push)
- name: Generate coverage and scaladoc
if: type = push && branch IN (master, dev)
- name: Deploy to Github Releases
Expand Down
55 changes: 32 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
# Scalavelli project

### Build status
| Branch | Status |
| --- | --- |
| Master | [![Build Status](https://travis-ci.com/Part-Time-Team/scalavelli.svg?branch=master)](https://travis-ci.com/Part-Time-Team/scalavelli) |
| Dev | [![Build Status](https://travis-ci.com/Part-Time-Team/scalavelli.svg?branch=dev)](https://travis-ci.com/Part-Time-Team/scalavelli) |

### Coverage status
| Branch | Status |
| --- | --- |
| Master | [![codecov](https://codecov.io/gh/Part-Time-Team/scalavelli/branch/master/graph/badge.svg)](https://codecov.io/gh/Part-Time-Team/scalavelli) |
| Dev | [![codecov](https://codecov.io/gh/Part-Time-Team/scalavelli/branch/dev/graph/badge.svg)](https://codecov.io/gh/Part-Time-Team/scalavelli) |
# Scalavelli project

Project for PPS.

Use openjdk11 and scala 2.12.8.

### How to execute
### Build status
| Branch | Build | Coverage |
| --- | --- | --- |
| Master | [![Build Status](https://travis-ci.com/Part-Time-Team/scalavelli.svg?branch=master)](https://travis-ci.com/Part-Time-Team/scalavelli) | [![codecov](https://codecov.io/gh/Part-Time-Team/scalavelli/branch/master/graph/badge.svg)](https://codecov.io/gh/Part-Time-Team/scalavelli) |
| Dev | [![Build Status](https://travis-ci.com/Part-Time-Team/scalavelli.svg?branch=dev)](https://travis-ci.com/Part-Time-Team/scalavelli) | [![codecov](https://codecov.io/gh/Part-Time-Team/scalavelli/branch/dev/graph/badge.svg)](https://codecov.io/gh/Part-Time-Team/scalavelli) |

### How to compile
Move to main dir of project and execute following commands to compile executable packages

```shell script
sbt pack
sbt clean pack
```

This command produce executable scripts in client and server directories. You can execute them with those commands:
You can also modify configuration files to execute the server on a different machine. You have to change the Constant as:

| Project | Command |
| --- | --- |
| Server | `./server/target/pack/bin/scalavelli-server` |
| Client | `./client/target/pack/bin/applauncher` |
```scala
// Run on a LAN machine.
final val SERVER_ADDRESS = "192.168.43.21"
final val SERVER_PORT = 8081
```

```scala
// Run on the local machine.
final val SERVER_ADDRESS = "localhost"
final val SERVER_PORT = 5150
```

Look to our travis.yml file for packaging scripts.

### How to execute

This command produces executable scripts in client and server directories. You can execute them with those commands:

| Project | Linux | Windows |
| --- | --- | --- |
| Server | `./server/target/pack/bin/scalavelli-server` | `.\server\target\pack\bin\scalavelli-server` |
| Client | `./client/target/pack/bin/applauncher` | `.\client\target\pack\bin\applauncher` |

Be aware to execute first the server and after that how many clients you want.
You can also modify configuration files to execute server on a different machine.
We don't provide guide to deploy on remote machine or containers.

We don't provide the guide to deploy on a remote machine or containers.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "scalavelli"

version in ThisBuild := "0.1.2"
version in ThisBuild := "0.1.3"

scalaVersion in ThisBuild := "2.12.8"
organization in ThisBuild := "it.parttimeteam"
Expand Down Expand Up @@ -132,4 +132,4 @@ lazy val client = Project(

/*
* END PROJECT DEFINITIONS.
*/
*/
2 changes: 1 addition & 1 deletion client/src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
akka {

loglevel = "DEBUG"
loglevel = "INFO"

actor {
provider = remote
Expand Down
Binary file modified client/src/main/resources/images/game_title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package it.parttimeteam.controller

import it.parttimeteam.controller.game.{GameController, GameControllerImpl}
import it.parttimeteam.controller.startup.{StartUpController, StartUpControllerImpl}
import it.parttimeteam.controller.startup.{StartupController, StartupControllerImpl}
import it.parttimeteam.model.startup.GameMatchInformations
import it.parttimeteam.view.{View, ViewImpl}
import scalafx.application.JFXApp

class MainControllerImpl(app: JFXApp) extends MainController {

val view: View = new ViewImpl(app)
val startUpController: StartUpController = new StartUpControllerImpl
val startUpController: StartupController = new StartupControllerImpl
val gameController: GameController = new GameControllerImpl(() => playAgain())

override def start(): Unit = {
startUpController.start(app, startGame)
}

def startGame(gameInfo: GameMatchInformations): Unit = {
private def startGame(gameInfo: GameMatchInformations): Unit = {
startUpController.end()
gameController.start(app, gameInfo)
}

def playAgain(): Unit = {
private def playAgain(): Unit = {
startUpController.start(app, startGame)
gameController.end()
}
Expand Down
11 changes: 11 additions & 0 deletions client/src/main/scala/it/parttimeteam/controller/ViewMessage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package it.parttimeteam.controller

sealed class ViewMessage

object ViewMessage {

case class ActualPlayerTurn(playerUsername: String) extends ViewMessage

case object YourTurn extends ViewMessage

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,101 +3,42 @@ package it.parttimeteam.controller.game
import java.util.concurrent.TimeUnit

import it.parttimeteam.Constants
import it.parttimeteam.controller.ViewMessage
import it.parttimeteam.controller.game.TurnTimer.TurnTimerImpl
import it.parttimeteam.core.{GameError, GameInterfaceImpl}
import it.parttimeteam.core.GameInterfaceImpl
import it.parttimeteam.core.cards.Card
import it.parttimeteam.core.collections.{Board, CardCombination, Hand}
import it.parttimeteam.gamestate.{Opponent, PlayerGameState}
import it.parttimeteam.model.ErrorEvent
import it.parttimeteam.model.game._
import it.parttimeteam.model.startup.GameMatchInformations
import it.parttimeteam.view.game._
import scalafx.application.{JFXApp, Platform}

class GameControllerImpl(playAgain: () => Unit) extends GameController {

private var gameStage: MachiavelliGameStage = _
private var gameStage: GameStage = _
private var gameService: GameService = _
private var currentState: ClientGameState = _

private val turnTimer: TurnTimer = new TurnTimerImpl(Constants.Client.TURN_TIMER_DURATION, new TurnTimerListener {

override def onStart(): Unit = {
val time = millisToMinutesAndSeconds(Constants.Client.TURN_TIMER_DURATION * 1000)
println(s"TIMER -> Timer started: ${time._1}:${time._2}")
gameStage.showTimer(time._1, time._2)
}

override def onEnd(): Unit = {
println(s"TIMER -> Timer ended")
gameStage.notifyTimerEnded()
gameService.endTurnDrawingACard()
}

override def onTick(millis: Long): Unit = {
val time = millisToMinutesAndSeconds(millis)

println(s"TIMER -> Timer tick: ${time._1}:${time._2}")

gameStage.updateTimer(time._1, time._2)
}
})

override def start(app: JFXApp, gameInfo: GameMatchInformations): Unit = {
Platform.runLater({
gameStage = MachiavelliGameStage(this)
gameStage.initMatch()
app.stage = gameStage
})

this.gameService = new GameServiceImpl(gameInfo, notifyEvent, new GameInterfaceImpl())
this.gameService.playerReady()
}

def notifyEvent(serverGameEvent: GameEvent): Unit = serverGameEvent match {

case StateUpdatedEvent(state: ClientGameState) => {
currentState = state
Platform.runLater({
gameStage.matchReady()
gameStage.updateState(state)
})
}

case OpponentInTurnEvent(actualPlayerName) => {
gameStage.setMessage(s"It's $actualPlayerName turn")
}

case InTurnEvent => {
gameStage.setInTurn()
}

case InfoEvent(message: String) => {
gameStage.notifyInfo(message)
}

case GameErrorEvent(reason: GameError) => {
gameStage.notifyError(reason)
}

case GameWonEvent => {
gameStage.notifyGameEnd(GameWon)
}

case GameLostEvent(winnerName: String) => {
gameStage.notifyGameEnd(GameLost(winnerName))
}

case GameEndedWithErrorEvent(reason: String) => {
gameStage.notifyGameEnd(GameEndWithError(reason))
}

case TurnEndedEvent => {
gameStage.setTurnEnded()
}

case _ =>
}

override def onViewEvent(viewEvent: ViewGameEvent): Unit = viewEvent match {
case LeaveGameEvent => gameService.leaveGame()

Expand Down Expand Up @@ -133,6 +74,50 @@ class GameControllerImpl(playAgain: () => Unit) extends GameController {
case TurnStartedEvent => turnTimer.start()
}

override def start(app: JFXApp, gameInfo: GameMatchInformations): Unit = {
Platform.runLater({
gameStage = GameStage(this)
gameStage.initMatch()
app.stage = gameStage
})

this.gameService = new GameServiceImpl(gameInfo, notifyEvent, new GameInterfaceImpl())
this.gameService.playerReady()
}

override def end(): Unit = {

}

private def notifyEvent(serverGameEvent: GameEvent): Unit = serverGameEvent match {

case StateUpdatedEvent(state: ClientGameState) => {
currentState = state
Platform.runLater({
gameStage.matchReady()
gameStage.updateState(state)
})
}

case OpponentInTurnEvent(actualPlayerName) => gameStage.setMessage(ViewMessage.ActualPlayerTurn(actualPlayerName))

case InTurnEvent => gameStage.setInTurn()

case InfoEvent(message: String) => gameStage.notifyInfo(message)

case GameErrorEvent(error: ErrorEvent) => gameStage.notifyError(error)

case GameWonEvent => gameStage.notifyGameEnd(GameWon)

case GameLostEvent(winnerName: String) => gameStage.notifyGameEnd(GameLost(winnerName))

case GameEndedBecausePlayerLeft => gameStage.notifyGameEnd(GameEndPlayerLeft)

case TurnEndedEvent => gameStage.setTurnEnded()

case _ =>
}

private def millisToMinutesAndSeconds(millis: Long): (Long, Long) = {
val minutes: Long = TimeUnit.MILLISECONDS.toMinutes(millis)
val seconds: Long = TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(minutes)
Expand Down Expand Up @@ -172,9 +157,4 @@ class GameControllerImpl(playAgain: () => Unit) extends GameController {

ClientGameState(PlayerGameState(board, hand, players), true, true, true, true)
}


override def end(): Unit = {

}
}

This file was deleted.

Loading

0 comments on commit 1af5f6b

Please sign in to comment.