Bugs correction

This commit is contained in:
Léo 2020-04-26 11:32:30 +02:00
parent 3b8e28b4f3
commit 350283959f
15 changed files with 58 additions and 29 deletions

2
.gitignore vendored
View File

@ -27,6 +27,8 @@ venv.bak/
# Secret configuration # Secret configuration
settings.cfg settings.cfg
settings.py
*.sqlite
# Personal conf # Personal conf
static/jquery.js static/jquery.js

11
app.py Normal file
View File

@ -0,0 +1,11 @@
import os
import sys
here = os.path.dirname(os.path.abspath(__file__))
os.chdir(here)
sys.path.insert(0,here+'/venv/lib/python{}.{}/site-packages'.format(sys.version_info.major, sys.version_info.minor))
sys.path.insert(0,here)
import settings
from belote import app, socketio
socketio.run(app, debug=False, host=settings.PUBLIC_URL, port=8080)

View File

@ -8,6 +8,7 @@ import datetime
from db import db, User, Game, Player, levels_users from db import db, User, Game, Player, levels_users
from belote_jeu import N_TURN, N_PLAYERS from belote_jeu import N_TURN, N_PLAYERS
import belote_ws import belote_ws
import settings
login_manager = fll.LoginManager() login_manager = fll.LoginManager()
@ -19,7 +20,7 @@ app.config.from_pyfile('settings.cfg')
####################################################################### #######################################################################
# SocketIO # SocketIO
socketio = SocketIO(app) socketio = SocketIO(app, cors_allowed_origins=settings.PUBLIC_URL)
login_manager.init_app(app) login_manager.init_app(app)
# Database management # Database management
@ -362,5 +363,5 @@ def delete_game(user=None, game=None):
if __name__ == '__main__': if __name__ == '__main__':
socketio.run(app, debug=True, host='127.0.0.1') socketio.run(app, debug=True, host='127.0.0.1', port=8080 )

View File

@ -20,7 +20,7 @@ class CustomNamespacePlay(fio.Namespace):
if len(self.users)==1: if len(self.users)==1:
fio.emit('text', {'text': '{} est là !'.format(self.users[0]), 'username':None, 'name':NAME_BONJOUR}) fio.emit('text', {'text': '{} est là !'.format(self.users[0]), 'username':None, 'name':NAME_BONJOUR})
elif len(self.users)>1: elif len(self.users)>1:
fio.emit('text', {'text': '{} est là !'.format(', '.join(self.users)), 'username':None, 'name':NAME_BONJOUR}) fio.emit('text', {'text': '{} sont là !'.format(', '.join(self.users)), 'username':None, 'name':NAME_BONJOUR})
self.users.append(current_user.name) self.users.append(current_user.name)
fio.emit('text', {'text': '{} vient d\'arriver !'.format(current_user.name), 'username':None, 'name':NAME_BONJOUR}, broadcast=True) fio.emit('text', {'text': '{} vient d\'arriver !'.format(current_user.name), 'username':None, 'name':NAME_BONJOUR}, broadcast=True)
pass pass
@ -28,7 +28,7 @@ class CustomNamespacePlay(fio.Namespace):
def on_disconnect(self): def on_disconnect(self):
if current_user.name in self.users: if current_user.name in self.users:
self.users.remove(current_user.name) self.users.remove(current_user.name)
fio.emit('text', {'text': '{} est parti.'.format(current_user.name), 'username':None, 'name':NAME_BONJOUR}, broadcast=True) fio.emit('text', {'text': '{} est parti.e.'.format(current_user.name), 'username':None, 'name':NAME_BONJOUR}, broadcast=True)
pass pass
def on_join(self, data): def on_join(self, data):
@ -69,7 +69,7 @@ class CustomNamespacePlay(fio.Namespace):
card = data['card'] card = data['card']
game = self.game() game = self.game()
if game.turn<0: if game.turn<0 or game.atout is None or game.atout =='':
fio.emit('text', {'text': "Jeu pas encore disponible. Il faut choisir l'atout !", 'username':None, 'name':NAME_ARBITRE}) fio.emit('text', {'text': "Jeu pas encore disponible. Il faut choisir l'atout !", 'username':None, 'name':NAME_ARBITRE})
return return
# C'est mon tour ? # C'est mon tour ?
@ -99,7 +99,7 @@ class CustomNamespacePlay(fio.Namespace):
def on_restart(self, data): def on_restart(self, data):
game = self.game() game = self.game()
if game.isadmin(current_user): if game.isadmin(current_user):
if game.turn==N_TURN*N_PLAYERS: if game.turn==N_TURN*N_PLAYERS or (game.turn==0 and (game.atout is None or game.atout == '')):
game.restart_jeu() game.restart_jeu()
fio.emit('restart', game.serialize_state_anonymous(), broadcast=True) fio.emit('restart', game.serialize_state_anonymous(), broadcast=True)
else: else:

7
db.py
View File

@ -53,11 +53,11 @@ class Game(db.Model):
id = db.Column(db.Integer, id = db.Column(db.Integer,
primary_key=True) primary_key=True)
name = db.Column(db.String(100)) name = db.Column(db.String(200))
players = relationship("Player") players = relationship("Player")
turn = db.Column(db.Integer, default=-8) turn = db.Column(db.Integer, default=-8)
atout = db.Column(db.String(1)) atout = db.Column(db.String(1))
preneur = db.Column(db.Integer) preneur = db.Column(db.String(100))
admin = db.Column(db.String(100), db.ForeignKey('users.login')) admin = db.Column(db.String(100), db.ForeignKey('users.login'))
cards_to_distribute = db.Column(db.String(200)) cards_to_distribute = db.Column(db.String(200))
first_player = db.Column(db.Integer) first_player = db.Column(db.Integer)
@ -305,7 +305,7 @@ class Game(db.Model):
return False, -1 return False, -1
def restart_jeu(self): def restart_jeu(self):
if self.turn==N_TURN*N_PLAYERS: if (self.turn==0 and (self.atout=='' or self.atout is None)) or self.turn==N_TURN*N_PLAYERS:
self.turn = -8 self.turn = -8
self.atout = None self.atout = None
self.preneur = None self.preneur = None
@ -315,6 +315,7 @@ class Game(db.Model):
self.cumul_1 += self.points_1 self.cumul_1 += self.points_1
self.points_0 = 0 self.points_0 = 0
self.points_1 = 0 self.points_1 = 0
if self.turn>0:
self.partie +=1 self.partie +=1
self.first_player = 0 self.first_player = 0
self.distribute() self.distribute()

3
settings.example.py Normal file
View File

@ -0,0 +1,3 @@
# The public url for preventing
# Cross_origin bugs
PUBLIC_URL='127.0.0.1'

View File

@ -270,11 +270,13 @@ position: absolute;
#a-vous { #a-vous {
float: left; float: left;
width: 90px; width: 90px;
height: 79px; height: 59px;
padding-top: 20px; padding-top: 20px;
text-align: center; text-align: center;
margin-right: 20px; margin-right: 20px;
visibility: hidden; visibility: hidden;
background:white;
font-weight: bold;
} }
#points { #points {
height: 98px; height: 98px;

BIN
static/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 489 KiB

View File

@ -43,16 +43,16 @@ var set_atout = function(){
var coulprop = jeu['played'][0]; var coulprop = jeu['played'][0];
$('#atout').html(`<img src="/static/cards/${coulprop}.png" width=100% />`); $('#atout').html(`<img src="/static/cards/${coulprop}.png" width=100% />`);
if (jeu['turn']<-4 && (jeu['turn']+jeu['first_player']+8)%4 == jeu['nr']){ if (jeu['turn']<-4 && (jeu['turn']+jeu['first_player']+8)%4 == jeu['nr']){
$('#prispar').html(`<input type="submit" onclick="javascript:choixcouleur('${coulprop[1]}')" value="Prendre" />`); $('#preneur').html(`<input type="submit" onclick="javascript:choixcouleur('${coulprop[1]}')" value="Prendre" />`);
$('#preneur').html(`<input type="submit" onclick="javascript:choixcouleur(null)" value="Passer" />`); $('#prispar').html(`<input type="submit" onclick="javascript:choixcouleur(null)" value="Passer" />`);
}else if((jeu['turn']+jeu['first_player']+8)%4 == jeu['nr']){ }else if((jeu['turn']+jeu['first_player']+8)%4 == jeu['nr']){
$('#prispar').html(`<input type="submit" onclick="javascript:choixcouleur('P')" value="Pique" /> $('#preneur').html(`<input type="submit" onclick="javascript:choixcouleur('P')" value="Pique" />
<input type="submit" onclick="javascript:choixcouleur('C')" value="Coeur" /> <input type="submit" onclick="javascript:choixcouleur('C')" value="Coeur" />
<br /> <br />
<input type="submit" onclick="javascript:choixcouleur('T')" value="Trèfle" /> <input type="submit" onclick="javascript:choixcouleur('T')" value="Trèfle" />
<input type="submit" onclick="javascript:choixcouleur('F')" value="Carreau" /> <input type="submit" onclick="javascript:choixcouleur('F')" value="Carreau" />
`); `);
$('#preneur').html(`<input type="submit" onclick="javascript:choixcouleur(null)" value="Passer" />`); $('#prispar').html(`<input type="submit" onclick="javascript:choixcouleur(null)" value="Passer" />`);
}else{ }else{
$('#prispar').html(`Pris par`); $('#prispar').html(`Pris par`);
$('#preneur').html(`----`); $('#preneur').html(`----`);
@ -92,7 +92,7 @@ var set_jeu = function(){
console.log(jeu['monjeu']); console.log(jeu['monjeu']);
for(i=0;i<jeu['monjeu'].length;i++){ for(i=0;i<jeu['monjeu'].length;i++){
if (jeu['monjeu'][i]==null){ if (jeu['monjeu'][i]==null || jeu['monjeu'][i]==''){
$('#carte-'+i).html(''); $('#carte-'+i).html('');
}else{ }else{
$('#carte-'+i).html(`<a href="javascript:jouer('${jeu['monjeu'][i]}', ${i})"><img src="/static/cards/${jeu['monjeu'][i]}.png" width=100% /></a>`); $('#carte-'+i).html(`<a href="javascript:jouer('${jeu['monjeu'][i]}', ${i})"><img src="/static/cards/${jeu['monjeu'][i]}.png" width=100% /></a>`);
@ -102,14 +102,14 @@ var set_jeu = function(){
var set_cartes = function(){ var set_cartes = function(){
first_player = jeu['first_player'] first_player = jeu['first_player']
if (jeu['turn']%4==0 && 'lastfirstplayer' in jeu){ if (jeu['turn']%4==0 && 'lastfirstplayer' in jeu && jeu['turn']>0){
first_player = jeu['lastfirstplayer'] first_player = jeu['lastfirstplayer']
} }
if (jeu['preneur'] == null){ if (jeu['atout'] == null || jeu['atout']==''){
$('#jeu-0').html('');
$('#jeu-1').html(''); $('#jeu-1').html('');
$('#jeu-2').html(''); $('#jeu-2').html('');
$('#jeu-3').html(''); $('#jeu-3').html('');
$('#jeu-4').html('');
}else{ }else{
for(i=first_player;i<first_player+4;i++){ for(i=first_player;i<first_player+4;i++){
j = i-first_player j = i-first_player
@ -124,7 +124,7 @@ var set_cartes = function(){
} }
var set_derpli = function(){ var set_derpli = function(){
if(jeu['last_played'].length >0){ if(jeu['last_played'].length >0 && jeu['turn']>0){
for(i=0;i<4;i++){ for(i=0;i<4;i++){
$('#der-pli-'+i).html(`<img src="/static/cards/${jeu['last_played'][i]}.png" width=100% />`); $('#der-pli-'+i).html(`<img src="/static/cards/${jeu['last_played'][i]}.png" width=100% />`);
} }
@ -140,9 +140,11 @@ var set_players = function(){
var set_current_player = function(){ var set_current_player = function(){
for(i=0;i<4;i++){ for(i=0;i<4;i++){
$('#joueur-'+i).css('font-weight', 'normal'); $('#joueur-'+i).css('font-weight', 'normal');
$('#joueur-'+i).css('text-decoration', 'none');
} }
i = (jeu['turn']+jeu['first_player']+8)%4; i = (jeu['turn']+jeu['first_player']+8)%4;
$('#joueur-'+i).css('font-weight', 'bold'); $('#joueur-'+i).css('font-weight', 'bold');
$('#joueur-'+i).css('text-decoration', 'underline overline');
if((jeu['turn']+jeu['first_player']+8)%4 == jeu['nr']){ if((jeu['turn']+jeu['first_player']+8)%4 == jeu['nr']){
$('#a-vous').css('visibility', 'visible'); $('#a-vous').css('visibility', 'visible');
}else{ }else{
@ -152,6 +154,9 @@ var set_current_player = function(){
if(jeu['turn']==32 && jeu['admin']==jeu['players'][jeu['nr']]){ if(jeu['turn']==32 && jeu['admin']==jeu['players'][jeu['nr']]){
$('#suivant').show(); $('#suivant').show();
} }
if(jeu['turn']==0 && (jeu['atout'] == null||jeu['atout']=='') && jeu['admin']==jeu['players'][jeu['nr']]){
$('#suivant').show();
}
} }
@ -166,9 +171,6 @@ set_derpli();
set_players(); set_players();
set_current_player(); set_current_player();
for (e in jeu){
$('#jeu').append(`${e} : ${jeu[e]} <br />`)
}
if((jeu['turn']+jeu['first_player'] + 8)%4 == jeu['nr']){ if((jeu['turn']+jeu['first_player'] + 8)%4 == jeu['nr']){
$('#a-vous').css('visibility', 'visible'); $('#a-vous').css('visibility', 'visible');
} }
@ -252,6 +254,10 @@ socket.on('play', function(data){
set_current_player(); set_current_player();
}); });
socket.on('disconnect', function() {
$('#chat').prepend('<b>Souci technique</b> : Vous avez été déconnecté<br />Une tentative de reconnexion va avoir lieu<br />');
setTimeout(function(){window.location.reload()}, 5000);
});
$('#texte-msg').pressEnter(function(e){ $('#texte-msg').pressEnter(function(e){
sendtext(); sendtext();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 849 B

BIN
static/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

@ -1,6 +1,7 @@
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="/static/favicon.ico">
{% include ['head-perso.html', 'head.html'] %} {% include ['head-perso.html', 'head.html'] %}
{% block head %} {% block head %}
<title>{% block title %}{% endblock %} - Belote</title> <title>{% block title %}{% endblock %} - Belote</title>
@ -11,7 +12,7 @@
<!-- ENTETE --> <!-- ENTETE -->
<div id="entete" class="clearfix-head"> <div id="entete" class="clearfix-head">
<div id="logo"> <div id="logo">
<img src="/static/logo.gif" /> <img src="/static/logo.png" height=100% width=100% />
</div><!-- logo --> </div><!-- logo -->
<div id="titre"> <div id="titre">
{% block titre %} {% endblock %} {% block titre %} {% endblock %}

View File

@ -8,9 +8,9 @@
<div id="jeu-1" class="carte"></div><!-- jeu-1 --> <div id="jeu-1" class="carte"></div><!-- jeu-1 -->
<div id="jeu-2" class="carte"></div><!-- jeu-2 --> <div id="jeu-2" class="carte"></div><!-- jeu-2 -->
<div id="jeu-3" class="carte"></div><!-- jeu-3 --> <div id="jeu-3" class="carte"></div><!-- jeu-3 -->
<form id="suivant"> <div id="suivant">
<input type="submit" name="suivant" value="Recommencer" onclick="javascript:restart_jeu()"> <input type="submit" name="suivant" value="Recommencer" onclick="javascript:restart_jeu()">
</form><!-- suivant --> </div><!-- suivant -->
</div><!-- plateau --> </div><!-- plateau -->
<div id="ov"> <div id="ov">
<table id="table-atout"> <table id="table-atout">
@ -40,7 +40,7 @@
</div><!-- choix --> </div><!-- choix -->
</div><!-- ov --> </div><!-- ov -->
<div id="jeu-en-main" class="clearfix"> <div id="jeu-en-main" class="clearfix">
<div id="a-vous">A vous de jouer ! <div id="a-vous">À vous de jouer !
</div> </div>
<div id="carte-0" class="carte carte-en-main"> <div id="carte-0" class="carte carte-en-main">
</div> </div>

View File

@ -6,7 +6,9 @@
{% block contenu %} {% block contenu %}
<div id="zone-de-contenu"> <div id="zone-de-contenu">
<fieldset class="fieldset"><legend style="font-size:25px;">Bienvenue</legend>
<p> Bienvenue sur le jeu de belote !</p> <p> Bienvenue sur le jeu de belote !</p>
<p> Vous devez vous identifier pour jouer, rendez vous sur <a href="/login">la page de login</a></p> <p> Vous devez vous identifier pour jouer, rendez vous sur <a href="/login">la page de login</a></p>
</fieldset>
</div> </div>
{% endblock %} {% endblock %}