fields
This commit is contained in:
parent
b5fb630a3c
commit
d86c05fbe0
@ -133,6 +133,25 @@ def check_status(request):
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
def get_fields(request):
|
||||||
|
if request.method == 'OPTIONS':
|
||||||
|
return JsonResponse({})
|
||||||
|
data = json.loads(request.body.decode('utf-8'))
|
||||||
|
game_id = data['game_id']
|
||||||
|
token = data['token']
|
||||||
|
player = Player.objects.get(game_id=game_id, token=token)
|
||||||
|
my_field = list(player.field)
|
||||||
|
player2 = Player.objects.get(game_id=game_id, number=(1 - player.number))
|
||||||
|
another_field = list(player2.field.replace('o', ' '))
|
||||||
|
return JsonResponse({
|
||||||
|
'my_field': [my_field[x * 10: (x + 1) * 10] for x in range(0, 10)],
|
||||||
|
'opponent_field': [another_field[x * 10: (x + 1) * 10] for x in range(0, 10)],
|
||||||
|
'my_turn': player.game.turn == player.number,
|
||||||
|
'game_finished': 'o' not in player.field or 'o' not in player2.field
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def check_field_correct(request):
|
def check_field_correct(request):
|
||||||
if request.method == 'OPTIONS':
|
if request.method == 'OPTIONS':
|
||||||
|
@ -27,4 +27,5 @@ urlpatterns = [
|
|||||||
path('api/place_ships', views.place_ships),
|
path('api/place_ships', views.place_ships),
|
||||||
path('api/shoot', views.shoot),
|
path('api/shoot', views.shoot),
|
||||||
path('api/check_field_correct', views.check_field_correct),
|
path('api/check_field_correct', views.check_field_correct),
|
||||||
|
path('api/get_fields', views.get_fields)
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user