Skip to content

Commit

Permalink
Merge pull request #12 from deanblackborough/main
Browse files Browse the repository at this point in the history
Initial playable release
  • Loading branch information
deanblackborough authored Jul 19, 2022
2 parents dfd6377 + 344ff61 commit 9ad46e2
Show file tree
Hide file tree
Showing 9 changed files with 419 additions and 99 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

The complete changelog for the Costs to Expect REST API, our changelog follows the format defined at https://keepachangelog.com/en/1.0.0/

## [0.3.0] - Initial playable release

Initial release of the Yahtzee game scorer which is powered by the Costs to Expect API. If you have an
account on the Costs to Expect API, you can set your players and track your games.

Many features are planned, this is very much a work in progress, but it is usable.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Score sheet](/resources/art/score-sheet.png)

# Yahtzee Game Scoring

## Overview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use App\Actions\Action;
use App\Api\Service;

class ScoreUpper extends Action
class Score extends Action
{
public function __invoke(
Service $api,
Expand Down
50 changes: 48 additions & 2 deletions app/Http/Controllers/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use App\Actions\Game\AddPlayersToGame;
use App\Actions\Game\Create;
use App\Actions\Game\ScoreUpper;
use App\Actions\Game\Score;
use Illuminate\Http\Request;

class Game extends Controller
Expand Down Expand Up @@ -218,7 +218,53 @@ public function scoreUpper(Request $request)
$score_sheet['score']['bonus'] = $score_bonus;
$score_sheet['score']['total'] = $score_sheet['score']['lower'] + $score_upper + $score_bonus;

$action = new ScoreUpper();
$action = new Score();
$result = $action(
$this->api,
$this->resource_type_id,
$this->resource_id,
$request->input('game_id'),
$request->input('player_id'),
$score_sheet
);

if ($result === 204) {
return response()->json([
'message' => 'Score updated',
'score' => $score_sheet['score']
]);
}

return response()->json(['message' => 'Failed to update your score sheet'], $result);
}

public function scoreLower(Request $request)
{
$this->boostrap($request);

$score_sheet = $this->api->getPlayerScoreSheet(
$this->resource_type_id,
$this->resource_id,
$request->input('game_id'),
$request->input('player_id')
);

if ($score_sheet['status'] !== 200) {
return response()->json(['message' => 'Unable to fetch your score sheet'], $score_sheet['status']);
}

$score_sheet = $score_sheet['content']['value'];

$score_sheet['lower-section'][$request->input('combo')] = $request->input('score');
$score_lower = 0;
foreach ($score_sheet['lower-section'] as $value) {
$score_lower += $value;
}

$score_sheet['score']['lower'] = $score_lower;
$score_sheet['score']['total'] = $score_sheet['score']['upper'] + $score_sheet['score']['bonus'] + $score_lower;

$action = new Score();
$result = $action(
$this->api,
$this->resource_type_id,
Expand Down
6 changes: 3 additions & 3 deletions config/app/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
'item_subtype_id' => env('ITEM_SUBTYPE_ID'),
'cookie_user' => env('SESSION_NAME_USER'),
'cookie_bearer' => env('SESSION_NAME_BEARER'),
'version' => '0.2.0',
'release_date' => '18th July 2022'
];
'version' => '0.3.0',
'release_date' => '19th July 2022'
];
Loading

0 comments on commit 9ad46e2

Please sign in to comment.