Exemplo n.º 1
0
        private void PlaceStone(Stone stone)
        {
            GoNode node = null;

            foreach (var child in Game.CurrentNode.ChildNodes)
            {
                if (child is GoMoveNode)
                {
                    if ((child as GoMoveNode).Stone.X == stone.X &&
                        (child as GoMoveNode).Stone.Y == stone.Y)
                    {
                        node    = child;
                        message = string.Empty;
                        break;
                    }
                }
            }
            if (node != null)
            {
                Game.ToMove(node);
                if (Game.CurrentNode is GoMoveNode)
                {
                    SoundUtils.Play("Stone");
                }
                var count = node.ChildNodes.Count;
                if (count > 0)
                {
                    var variant = random.Next(0, count - 1);
                    Game.ToMove(node.ChildNodes[variant]);
                    if (Game.CurrentNode is GoMoveNode)
                    {
                        SoundUtils.Play("Stone");
                    }
                    playerTurn = true;
                }
                else
                {
                    playerTurn = false;
                }

                if (!Game.CurrentNode.HasChildren)
                {
                    if (format.IsRightVariant(Game.CurrentNode))
                    {
                        message = "Solved";
                    }
                    else
                    {
                        message = "Wrong";
                    }
                }

                Invalidate();
                SetComment();
            }
            else
            {
                message = "No path";
                Invalidate();
            }
        }