Ejemplo n.º 1
0
        private void Enqueue(ChessAction action)
        {
            if (action is EndGameAction)
                this.Sensors.Stop();

            this.actions.Enqueue(action);
            this.OnActionAvailable();
        }
Ejemplo n.º 2
0
        private void Persist(ChessAction action)
        {
            lock (this)
            {
                int delay = (int)(sw.ElapsedMilliseconds - lastAction);
                if (action.TimeDelay >= 0)
                    writer.Write(action.TimeDelay);
                else
                    writer.Write(delay);

                this.lastAction = sw.ElapsedMilliseconds;
                writer.Write(action.OpCode);
                action.Write(this, writer);
                writer.Flush();

                if (action is EndGameAction)
                    ((IDisposable)this).Dispose();
            }
        }
Ejemplo n.º 3
0
        private void ProcessAction(Board board, ChessAction action)
        {
            if (action is MoveAction)
            {
                var move = (MoveAction)action;
                if (!board.Move(move.Source, move.Target, move.PromotePawnTo))
                {
                    throw new InvalidOperationException("Bad message.");
                }
            }

            if (action is SensorAction)
            {
                var sensorAction = action as SensorAction;
                var mouseData = sensorAction.Data as Chess.Sensors.MouseSensorData;
                if (mouseData != null)
                    this.boardControl.SetMousePosition(mouseData.Location);

                var eyeTracker = sensorAction.Data as Chess.Sensors.TobiiEyeTracker.EyeTrackerSensorData;
                if (eyeTracker != null)
                    this.boardControl.SetEyePosition(eyeTracker.LeftPosition);

            }
        }