diff --git a/.gitignore b/.gitignore index ecb1e52..bfa661c 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,8 @@ venv.bak/ # Secret configuration settings.cfg +settings.py +*.sqlite # Personal conf static/jquery.js diff --git a/app.py b/app.py new file mode 100644 index 0000000..7f37644 --- /dev/null +++ b/app.py @@ -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) + diff --git a/belote.wsgi b/app.wsgi similarity index 100% rename from belote.wsgi rename to app.wsgi diff --git a/belote.py b/belote.py index 8d0e9a7..34bc852 100644 --- a/belote.py +++ b/belote.py @@ -8,6 +8,7 @@ import datetime from db import db, User, Game, Player, levels_users from belote_jeu import N_TURN, N_PLAYERS import belote_ws +import settings login_manager = fll.LoginManager() @@ -19,7 +20,7 @@ app.config.from_pyfile('settings.cfg') ####################################################################### # SocketIO -socketio = SocketIO(app) +socketio = SocketIO(app, cors_allowed_origins=settings.PUBLIC_URL) login_manager.init_app(app) # Database management @@ -362,5 +363,5 @@ def delete_game(user=None, game=None): 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 ) diff --git a/belote_ws.py b/belote_ws.py index 63c3fd8..bdb18d4 100644 --- a/belote_ws.py +++ b/belote_ws.py @@ -20,7 +20,7 @@ class CustomNamespacePlay(fio.Namespace): if len(self.users)==1: fio.emit('text', {'text': '{} est là !'.format(self.users[0]), 'username':None, 'name':NAME_BONJOUR}) 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) fio.emit('text', {'text': '{} vient d\'arriver !'.format(current_user.name), 'username':None, 'name':NAME_BONJOUR}, broadcast=True) pass @@ -28,7 +28,7 @@ class CustomNamespacePlay(fio.Namespace): def on_disconnect(self): if current_user.name in self.users: 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 def on_join(self, data): @@ -69,7 +69,7 @@ class CustomNamespacePlay(fio.Namespace): card = data['card'] 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}) return # C'est mon tour ? @@ -99,7 +99,7 @@ class CustomNamespacePlay(fio.Namespace): def on_restart(self, data): game = self.game() 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() fio.emit('restart', game.serialize_state_anonymous(), broadcast=True) else: diff --git a/db.py b/db.py index 65e59b3..feb015b 100644 --- a/db.py +++ b/db.py @@ -53,11 +53,11 @@ class Game(db.Model): id = db.Column(db.Integer, primary_key=True) - name = db.Column(db.String(100)) + name = db.Column(db.String(200)) players = relationship("Player") turn = db.Column(db.Integer, default=-8) 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')) cards_to_distribute = db.Column(db.String(200)) first_player = db.Column(db.Integer) @@ -305,7 +305,7 @@ class Game(db.Model): return False, -1 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.atout = None self.preneur = None @@ -315,7 +315,8 @@ class Game(db.Model): self.cumul_1 += self.points_1 self.points_0 = 0 self.points_1 = 0 - self.partie +=1 + if self.turn>0: + self.partie +=1 self.first_player = 0 self.distribute() db.session.commit() diff --git a/settings.example.py b/settings.example.py new file mode 100644 index 0000000..04cef2f --- /dev/null +++ b/settings.example.py @@ -0,0 +1,3 @@ +# The public url for preventing +# Cross_origin bugs +PUBLIC_URL='127.0.0.1' diff --git a/static/belote.css b/static/belote.css index 4cc6aa1..bf45c45 100644 --- a/static/belote.css +++ b/static/belote.css @@ -270,11 +270,13 @@ position: absolute; #a-vous { float: left; width: 90px; - height: 79px; + height: 59px; padding-top: 20px; text-align: center; margin-right: 20px; visibility: hidden; + background:white; + font-weight: bold; } #points { height: 98px; diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100644 index 0000000..46ff9c8 Binary files /dev/null and b/static/favicon.ico differ diff --git a/static/game_script.js b/static/game_script.js index b73a436..acd8c11 100644 --- a/static/game_script.js +++ b/static/game_script.js @@ -43,16 +43,16 @@ var set_atout = function(){ var coulprop = jeu['played'][0]; $('#atout').html(``); if (jeu['turn']<-4 && (jeu['turn']+jeu['first_player']+8)%4 == jeu['nr']){ - $('#prispar').html(``); - $('#preneur').html(``); + $('#preneur').html(``); + $('#prispar').html(``); }else if((jeu['turn']+jeu['first_player']+8)%4 == jeu['nr']){ - $('#prispar').html(` + $('#preneur').html(`
`); - $('#preneur').html(``); + $('#prispar').html(``); }else{ $('#prispar').html(`Pris par`); $('#preneur').html(`----`); @@ -92,7 +92,7 @@ var set_jeu = function(){ console.log(jeu['monjeu']); for(i=0;i`); @@ -102,14 +102,14 @@ var set_jeu = function(){ var set_cartes = function(){ 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'] } - if (jeu['preneur'] == null){ + if (jeu['atout'] == null || jeu['atout']==''){ + $('#jeu-0').html(''); $('#jeu-1').html(''); $('#jeu-2').html(''); $('#jeu-3').html(''); - $('#jeu-4').html(''); }else{ for(i=first_player;i0){ + if(jeu['last_played'].length >0 && jeu['turn']>0){ for(i=0;i<4;i++){ $('#der-pli-'+i).html(``); } @@ -140,9 +140,11 @@ var set_players = function(){ var set_current_player = function(){ for(i=0;i<4;i++){ $('#joueur-'+i).css('font-weight', 'normal'); + $('#joueur-'+i).css('text-decoration', 'none'); } i = (jeu['turn']+jeu['first_player']+8)%4; $('#joueur-'+i).css('font-weight', 'bold'); + $('#joueur-'+i).css('text-decoration', 'underline overline'); if((jeu['turn']+jeu['first_player']+8)%4 == jeu['nr']){ $('#a-vous').css('visibility', 'visible'); }else{ @@ -152,6 +154,9 @@ var set_current_player = function(){ if(jeu['turn']==32 && jeu['admin']==jeu['players'][jeu['nr']]){ $('#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_current_player(); -for (e in jeu){ - $('#jeu').append(`${e} : ${jeu[e]}
`) -} if((jeu['turn']+jeu['first_player'] + 8)%4 == jeu['nr']){ $('#a-vous').css('visibility', 'visible'); } @@ -252,6 +254,10 @@ socket.on('play', function(data){ set_current_player(); }); +socket.on('disconnect', function() { + $('#chat').prepend('Souci technique : Vous avez été déconnecté
Une tentative de reconnexion va avoir lieu
'); + setTimeout(function(){window.location.reload()}, 5000); +}); $('#texte-msg').pressEnter(function(e){ sendtext(); diff --git a/static/logo.gif b/static/logo.gif deleted file mode 100644 index b8f3ab9..0000000 Binary files a/static/logo.gif and /dev/null differ diff --git a/static/logo.png b/static/logo.png new file mode 100644 index 0000000..16beb6e Binary files /dev/null and b/static/logo.png differ diff --git a/templates/base.html b/templates/base.html index 4f532df..43b63a3 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,6 +1,7 @@ + {% include ['head-perso.html', 'head.html'] %} {% block head %} {% block title %}{% endblock %} - Belote @@ -11,7 +12,7 @@
{% block titre %} {% endblock %} diff --git a/templates/game_zone_jeu.html b/templates/game_zone_jeu.html index a00cbae..37ae26c 100644 --- a/templates/game_zone_jeu.html +++ b/templates/game_zone_jeu.html @@ -8,9 +8,9 @@
-
+
- +
@@ -40,7 +40,7 @@
-
A vous de jouer ! +
À vous de jouer !
diff --git a/templates/index.html b/templates/index.html index c668c5e..ac7f082 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,7 +6,9 @@ {% block contenu %}
-

Bienvenue sur le jeu de belote !

-

Vous devez vous identifier pour jouer, rendez vous sur la page de login

+
Bienvenue +

Bienvenue sur le jeu de belote !

+

Vous devez vous identifier pour jouer, rendez vous sur la page de login

+
{% endblock %}