[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [gcompris] src/activities/chess: chess, add support for 2 players
From:       Bruno Coudoin <bruno.coudoin () gcompris ! net>
Date:       2015-08-23 23:25:06
Message-ID: E1ZTedO-0003rV-LH () scm ! kde ! org
[Download RAW message or body]

Git commit fed9b0315a470419d7515e373d67b3a5af35624f by Bruno Coudoin.
Committed on 23/08/2015 at 23:24.
Pushed by bcoudoin into branch 'master'.

chess, add support for 2 players

M  +3    -0    src/activities/chess/Chess.qml
M  +4    -2    src/activities/chess/chess.js

http://commits.kde.org/gcompris/fed9b0315a470419d7515e373d67b3a5af35624f

diff --git a/src/activities/chess/Chess.qml b/src/activities/chess/Chess.qml
index abc7a6f..dae2675 100644
--- a/src/activities/chess/Chess.qml
+++ b/src/activities/chess/Chess.qml
@@ -30,6 +30,8 @@ import "chess.js" as Activity
 ActivityBase {
     id: activity
 
+    property bool twoPlayers: false
+
     onStart: focus = true
     onStop: {}
 
@@ -54,6 +56,7 @@ ActivityBase {
             property alias bonus: bonus
             property int cellSize: Math.min(background.width / (8 + 1),
                                             background.height / (8 + 3))
+            property bool twoPlayer: activity.twoPlayers
             property var viewstate
             property int from
             property bool blackTurn
diff --git a/src/activities/chess/chess.js b/src/activities/chess/chess.js
index 7211ecf..e4ba543 100644
--- a/src/activities/chess/chess.js
+++ b/src/activities/chess/chess.js
@@ -203,9 +203,11 @@ function moveTo(from, to) {
     var move = state.move(viewPosToEngine(from), viewPosToEngine(to))
     if(move.ok) {
         refresh()
-        randomMove()
+        if(!items.twoPlayer)
+            randomMove()
     }
     items.from = -1;
+    items.blackTurn = state.to_play // 0=w 1=b
 }
 
 function undo() {
@@ -225,7 +227,7 @@ function clearAcceptMove() {
 
 
 function showPossibleMoves(from) {
-    var result = Engine.p4_parse(state, 0, 0, 0)
+    var result = Engine.p4_parse(state, state.to_play, 0, 0)
     clearAcceptMove()
     if(items.whiteAtBottom)
         from = 63 - from

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic