Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
SadTomCat committed Jul 10, 2021
2 parents 68d5034 + af2cc9e commit 28772ee
Show file tree
Hide file tree
Showing 219 changed files with 12,018 additions and 1,883 deletions.
31 changes: 12 additions & 19 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,27 @@ APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_URL=
APP_IMAGES_DIRECTORY=./public/images

DEFAULT_ADMIN_EMAIL='[email protected]'
DEFAULT_ADMIN_PASSWORD='min8Charters'

LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
BROADCAST_DRIVER=pusher
CACHE_DRIVER=none
QUEUE_CONNECTION=database
SESSION_DRIVER=file
SESSION_LIFETIME=120

MEMCACHED_HOST=127.0.0.1

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
SESSION_LIFETIME=3600

MAIL_MAILER=smtp
MAIL_HOST=mailhog
Expand All @@ -35,15 +33,10 @@ MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
PUSHER_APP_CLUSTER=

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"vue"
],
"rules": {
"no-underscore-dangle": "off",
"no-trailing-spaces": "off",
"consistent-return": 1,
"no-useless-return": 0,
Expand Down
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
## About Chess
# About project

This is web chess. Project was created for learn how to use websocket and up my programming skills.
This is web chess. Project was created for learn how to use websocket, vue 3, laravel, and up my programming skills.

I used laravel, vue, axios, laravel breeze and sass. As static code analysis i used eslint.
![Снимок экрана от 2021-07-10 20-21-32](https://user-images.githubusercontent.com/47294127/125165508-7272dc80-e1c1-11eb-82f5-52921afbb3cc.png)

## Installation

First you need to set up the env file. Register an account in pusher https://pusher.com, before setting. An administrator user is created in the seeder, you can set his parameters in the env file.

Next enter the following commands.

`npm install`

`npm run production`

`composer install`

`php artisan migrate`

`php artisan db:seed`

`php artisan key:generate`

`php artisan serve`

`php artisan queue:listen`
2 changes: 1 addition & 1 deletion app/Events/GameNewMessageEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public function broadcastOn()
*/
public function broadcastWith(): array
{
return ['message' => $this->message];
return ['message' => $this->message, 'id' => $this->user->id];
}
}
59 changes: 59 additions & 0 deletions app/Exceptions/ChessRuleException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use JetBrains\PhpStorm\Pure;
use Throwable;

class ChessRuleException extends Exception
{
/**
* This fields can override default fields in render method
* $default = [
* status => false,
* message => $this->message
* ]
*
* @var array
*/
protected array $additionalResponseFields = [];

/**
* ChessRuleException constructor.
*
* @param string $message
* @param int $code
* @param Throwable|null $previous
* @param array $additionalResponseFields
*/
#[Pure] public function __construct(
string $message = "",
int $code = 0,
Throwable $previous = null,
array $additionalResponseFields = []
)
{
parent::__construct($message, $code, $previous);

$this->additionalResponseFields = $additionalResponseFields;
}

/**
* Render the exception into an HTTP response.
*
* @param Request $request
* @return JsonResponse
*/
public function render(Request $request): JsonResponse
{
$defaultResponse = [
'status' => false,
'message' => $this->message,
];

return response()->json(array_merge($defaultResponse, $this->additionalResponseFields));
}
}
8 changes: 8 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Pusher\PusherException;
use Throwable;

class Handler extends ExceptionHandler
Expand Down Expand Up @@ -37,5 +38,12 @@ public function register()
$this->reportable(function (Throwable $e) {
//
});

$this->renderable(function (PusherException $e) {
return response()->json([
'status' => false,
'message' => 'Something went wrong',
], 500);
});
}
}
22 changes: 22 additions & 0 deletions app/Exceptions/TablePaginationValidationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Http\JsonResponse;

class TablePaginationValidationException extends Exception
{
/**
* @return JsonResponse
*/
public function render(): JsonResponse
{
$status = $this->code >= 400 && $this->code <= 500 ? $this->code : 422;

return response()->json([
'status' => false,
'message' => $this->message,
], $status);
}
}
35 changes: 17 additions & 18 deletions app/Game/Chessmen/AbstractChessman.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Game\GameBoard;
use App\Game\MoveInfo;
use Exception;

abstract class AbstractChessman
{
Expand Down Expand Up @@ -38,7 +39,6 @@ abstract public function canMoveSomewhere(): bool;
*
* @param $to
* @return MoveInfo
* @throws \Exception
*/
public function moveValidation($to): MoveInfo
{
Expand Down Expand Up @@ -153,7 +153,7 @@ public function safetyMoveOnVertical(array $kingPos): bool
/**
* @param array $kingPos
* @return bool
* @throws \Exception
* @throws Exception
*/
public function safetyMoveOnMainDiagonal(array $kingPos): bool
{
Expand Down Expand Up @@ -223,7 +223,7 @@ public function safetyMoveOnMainDiagonal(array $kingPos): bool
/**
* @param array $kingPos
* @return bool
* @throws \Exception
* @throws Exception
*/
public function safetyMoveOnAntiDiagonal(array $kingPos): bool
{
Expand Down Expand Up @@ -292,21 +292,20 @@ public function safetyMoveOnAntiDiagonal(array $kingPos): bool
/**
* @param array $to
* @return bool
* @throws \Exception
*/
public function willKingSafeAfterMove(array $to): bool
{
$kingPos = $this->board->getKing($this->color)->getPosition();
try {
$kingPos = $this->board->getKing($this->color)->getPosition();

if ($kingPos['x'] === $this->pos['x'] && $this->pos['x'] !== $to['x']) {
return $this->safetyMoveOnHorizontal($kingPos);
}
if ($kingPos['x'] === $this->pos['x'] && $this->pos['x'] !== $to['x']) {
return $this->safetyMoveOnHorizontal($kingPos);
}

if ($kingPos['y'] === $this->pos['y'] && $this->pos['y'] !== $to['y']) {
return $this->safetyMoveOnVertical($kingPos);
}
if ($kingPos['y'] === $this->pos['y'] && $this->pos['y'] !== $to['y']) {
return $this->safetyMoveOnVertical($kingPos);
}

try {
$ownDiagonal = $this->board->getMainDiagonal($this->pos);

if ($this->board->getMainDiagonal($kingPos) === $ownDiagonal
Expand All @@ -321,7 +320,7 @@ public function willKingSafeAfterMove(array $to): bool
return $this->safetyMoveOnAntiDiagonal($kingPos);
}

} catch (\Exception $e) {
} catch (Exception $e) {
return false;
}

Expand Down Expand Up @@ -502,7 +501,7 @@ protected function createMoveInfo(array $to, $status = true, string $message = '
/**
* @param $moves
* @return bool
* @throws \Exception
* @throws Exception
*/
protected function canAnyByMoves($moves): bool
{
Expand All @@ -521,7 +520,7 @@ protected function canAnyByMoves($moves): bool

/**
* @return bool
* @throws \Exception
* @throws Exception
*/
protected function anyOnHorizontal(): bool
{
Expand All @@ -538,7 +537,7 @@ protected function anyOnHorizontal(): bool

/**
* @return bool
* @throws \Exception
* @throws Exception
*/
protected function anyOnVertical(): bool
{
Expand All @@ -555,7 +554,7 @@ protected function anyOnVertical(): bool

/**
* @return bool
* @throws \Exception
* @throws Exception
*/
protected function anyOnMainDiagonal(): bool
{
Expand All @@ -575,7 +574,7 @@ protected function anyOnMainDiagonal(): bool

/**
* @return bool
* @throws \Exception
* @throws Exception
*/
protected function anyOnAntiDiagonal(): bool
{
Expand Down
Loading

0 comments on commit 28772ee

Please sign in to comment.