Beispiel #1
0
        public BruGoView(Size size, GoGame game, GameRenderer renderer) :
            base(size, game, renderer)
        {
            cache = new BruGoCache();

            AllowCursor     = true;
            AllowNavigation = false;

            statusLabel = new Label()
            {
                Dock = DockStyle.Bottom,
            };

            using (var graphics = CreateGraphics())
            {
                var textSize = graphics.MeasureString("Text", statusLabel.Font);
                statusLabel.Height = (int)textSize.Height;
            }

            Controls = new List <Control>()
            {
                statusLabel
            };

            OnResize();

            requestTimer = new Timer()
            {
                Interval = 15000
            };
            requestTimer.Tick += Timeout;
            ToStart();
        }
Beispiel #2
0
        public PlayedGameView(Size size,
                              ObservedGame game,
                              GameRenderer renderer,
                              IGSPlayer gamePlayer) : base(size, game, renderer, gamePlayer)
        {
            this.gamePlayer = gamePlayer;

            AllowNavigation = false;
            AllowCursor     = true;

            MenuItem menuItem = new MenuItem()
            {
                Text = "Pass"
            };

            menuItem.Click += new EventHandler(OnPassClick);
            menu.MenuItems.Add(menuItem);

            menuItem = new MenuItem()
            {
                Text = "Ask undo"
            };
            menuItem.Click += new EventHandler(OnAskUndoClick);
            menu.MenuItems.Add(menuItem);

            menuItem = new MenuItem()
            {
                Text = "Undo"
            };
            menuItem.Click += new EventHandler(OnUndoClick);
            menu.MenuItems.Add(menuItem);

            menuItem = new MenuItem()
            {
                Text = "Done"
            };
            menuItem.Click += new EventHandler(OnDoneClick);
            menu.MenuItems.Add(menuItem);

            menuItem = new MenuItem()
            {
                Text = "Adjourn"
            };
            menuItem.Click += new EventHandler(OnAdjournClick);
            menu.MenuItems.Add(menuItem);

            menuItem = new MenuItem()
            {
                Text = "Resign"
            };
            menuItem.Click += new EventHandler(OnResignClick);
            menu.MenuItems.Add(menuItem);

            menuItem = new MenuItem()
            {
                Text = "Handicap"
            };
            menuItem.Click += new EventHandler(OnHandicapClick);
            menu.MenuItems.Add(menuItem);
        }
Beispiel #3
0
 public GameBrowseView(Size size,
                       GoGame game, GameRenderer renderer) :
     base(size, game, renderer)
 {
     CreateCommentBox();
     AllowCursor = false;
 }
Beispiel #4
0
        public TsumegoView(Size size, IEnumerator <GoGame> games,
                           GameRenderer renderer) :
            base(size)
        {
            if (!games.MoveNext())
            {
                throw new ArgumentException("No games found");
            }
            if (renderer == null)
            {
                throw new ArgumentException("Renderer cannot be null");
            }

            AllowNavigation = false;
            AllowCursor     = true;

            Renderer  = renderer;
            gamesEnum = games;

            GetProblem();

            CreateCommentBox();
            format = TsumegoFormat.GetFormatFor(Game);

            random = new Random((int)(DateTime.Now.Ticks % Int32.MaxValue));
            ToStart();
        }
Beispiel #5
0
 private static void RenderShadow(this GoGame goGame, GameRenderer renderer, GoNode node)
 {
     if ((node != goGame.currentNode) && (node is GoMoveNode))
     {
         var nodeStone = (node as GoMoveNode).Stone;
         renderer.DrawShadow(nodeStone.X, nodeStone.Y, nodeStone.IsBlack);
     }
 }
Beispiel #6
0
 public ObservedGameView(Size size,
                         ObservedGame game,
                         GameRenderer renderer,
                         IGSObserver gameObserver) : base(size, game, renderer, gameObserver)
 {
     this.gameObserver = gameObserver;
     AllowNavigation   = true;
     AllowCursor       = true;
 }
Beispiel #7
0
        public static void Render(this GoGame goGame, GameRenderer renderer)
        {
            renderer.ClearBoard(goGame.board.Size);

            for (byte x = 0; x < goGame.board.Size; x++)
            {
                for (byte y = 0; y < goGame.board.Size; y++)
                {
                    if (goGame.board.Black[x, y])
                    {
                        renderer.DrawStone(x, y, true);
                    }
                    else if (goGame.board.White[x, y])
                    {
                        renderer.DrawStone(x, y, false);
                    }
                }
            }

            if (goGame.currentNode is GoMoveNode)
            {
                var stone = (goGame.currentNode as GoMoveNode).Stone;

                renderer.DrawMoveMark(stone.X, stone.Y, goGame.board.HasStone(stone.X, stone.Y, false));
                if (goGame.showVariants == Variants.Siblings)
                {
                    goGame.currentNode.ParentNode.ChildNodes.
                    ForEach(n => RenderShadow(renderer, n));
                }
            }

            if (goGame.showVariants == Variants.Children)
            {
                goGame.currentNode.ChildNodes.
                ForEach(n => RenderShadow(renderer, n));
            }

            if (goGame.currentNode.Markup != null)
            {
                RenderMarkup(renderer, goGame.currentNode.Markup);
            }

            if (goGame.currentNode is GoMoveNode)
            {
                var stone = (goGame.currentNode as GoMoveNode).Stone;
                if (stone.X > 19)
                {
                    renderer.DrawMessage((stone.IsBlack ? "Black" : "White")
                                         + " passes");
                }
            }
        }
Beispiel #8
0
        public GameView(Size size, GoGame game, GameRenderer renderer) : base(size)
        {
            if ((game == null) || (renderer == null))
            {
                throw new ArgumentException("GoGame and Renderer arguments cannot be null");
            }

            Game     = game;
            Renderer = renderer;

            Cursor = new Point(Game.BoardSize / 2,
                               Game.BoardSize / 2);

            AllowCursor     = true;
            AllowNavigation = true;

            OnResize();
            EnableButtons();
        }
Beispiel #9
0
        public IGSGameView(Size size,
                           ObservedGame game,
                           GameRenderer renderer,
                           IGSGameListener gameListener) : base(size, game, renderer)
        {
            if (gameListener == null)
            {
                throw new ArgumentException("IGSGameListener argument cannot be null");
            }

            gameListener.GameChanged += new IGSGameEventHandler(GameChanged);
            gameListener.GameEnded   += new IGSGameEventHandler(GameEnded);

            timeLabel = new Label();

            SizeF textSize;

            using (var graphics = CreateGraphics())
            {
                textSize = graphics.MeasureString("Refresh", timeLabel.Font);
            }

            timeLabel.Height = (int)textSize.Height;
            timeLabel.Dock   = DockStyle.Bottom;

            timer = new Timer()
            {
                Interval = 1000,
                Enabled  = true
            };
            timer.Tick += new EventHandler(OnTick);

            BoardPosition = new Rectangle(0, 0, Size.Width, Size.Height - timeLabel.Height);

            Controls = new List <Control>()
            {
                timeLabel
            };

            lastMove = game.MoveNumber;
        }
Beispiel #10
0
        public GnuGoView(Size size, GoGame game, GameRenderer renderer,
                         GTP gtp, GnuGoColor gnugoColor, GTPReset reset) :
            base(size, game, renderer)
        {
            this.gtp        = gtp;
            this.reset      = reset;
            this.gnugoColor = gnugoColor;
            blackToPlay     = true;

            AllowCursor     = true;
            AllowNavigation = false;

            timer = new Timer()
            {
                Interval = 50,
            };
            timer.Tick += (s, e) => this.gtp.Update();

            Close += (s, e) => CloseGTP();

            statusLabel = new Label()
            {
                Dock = DockStyle.Bottom,
            };

            using (var graphics = CreateGraphics())
            {
                var textSize = graphics.MeasureString("Text", statusLabel.Font);
                statusLabel.Height = (int)textSize.Height;
            }

            OnResize();

            Controls = new List <Control>()
            {
                statusLabel
            };

            Init();
        }
Beispiel #11
0
        public GameEditView(Size size,
                            GoGame game, GameRenderer renderer) :
            base(size, game, renderer)
        {
            editMode             = new MoveMode();
            comment.ReadOnly     = false;
            comment.TextChanged += delegate
            {
                game.CurrentNode.Comment = comment.Text;
            };
            var names = new string[]
            {
                "Move",
                "Add black",
                "Add white",
                "Remove stone",
                "Circle",
                "Square",
                "Triangle",
                "Mark",
                "Select",
                "Label",
                "Clear markup"
            };

            var actions = new EventHandler[]
            {
                delegate { editMode = new MoveMode(); },
                delegate { editMode = new AddStoneMode(true); },
                delegate { editMode = new AddStoneMode(false); },
                delegate { editMode = new RemoveStoneMode(); },
                delegate { editMode = new MarkupMode(MarkType.Circle); },
                delegate { editMode = new MarkupMode(MarkType.Square); },
                delegate { editMode = new MarkupMode(MarkType.Triangle); },
                delegate { editMode = new MarkupMode(MarkType.Mark); },
                delegate { editMode = new MarkupMode(MarkType.Selected); },
                delegate { editMode = new LabelMode(); },
                delegate { editMode = new ClearMarkupMode(); }
            };

            var breaks = new List <int>()
            {
                1, 4, 10
            };

            for (var i = 0; i < names.Length; i++)
            {
                if (breaks.Count > 0 && i == breaks[0])
                {
                    modeMenu.MenuItems.Add(
                        new MenuItem()
                    {
                        Text = "-"
                    });
                    breaks.RemoveAt(0);
                }
                var item = new MenuItem()
                {
                    Text = names[i]
                };
                item.Click += actions[i];
                modeMenu.MenuItems.Add(item);
            }

            modeMenu.MenuItems[0].Checked = true;

            for (var j = 0; j < modeMenu.MenuItems.Count; j++)
            {
                var item = modeMenu.MenuItems[j];
                if (item.Text != "-")
                {
                    item.Click += delegate
                    {
                        for (var i = 0; i < modeMenu.MenuItems.Count; i++)
                        {
                            modeMenu.MenuItems[i].Checked = false;
                        }
                        item.Checked = true;
                    };
                }
            }

            var menuItem = new MenuItem()
            {
                Text = "Game Info"
            };

            menuItem.Click += OnGameInfoClick;

            actionMenu.MenuItems.Add(menuItem);
            actionMenu.MenuItems.Add(new MenuItem()
            {
                Text = "-"
            });

            menuItem = new MenuItem()
            {
                Text = "Delete node"
            };
            menuItem.Click += OnDeleteClick;

            actionMenu.MenuItems.Add(menuItem);
            actionMenu.MenuItems.Add(new MenuItem()
            {
                Text = "-"
            });

            blackItem = new MenuItem()
            {
                Text = "Black to play"
            };
            whiteItem = new MenuItem()
            {
                Text = "White to play"
            };
            passItem = new MenuItem()
            {
                Text = "Pass"
            };

            blackItem.Click += delegate
            {
                if (Game.CurrentNode is GoSetupNode)
                {
                    (Game.CurrentNode as GoSetupNode).BlackToPlay = true;
                    SetPlayer();
                }
            };

            whiteItem.Click += delegate
            {
                if (Game.CurrentNode is GoSetupNode)
                {
                    (Game.CurrentNode as GoSetupNode).BlackToPlay = false;
                    SetPlayer();
                }
            };

            passItem.Click += delegate
            {
                Game.PlaceStone(new Stone(20, 20, Game.BlackToPlay()));
                Invalidate();
            };

            actionMenu.MenuItems.Add(blackItem);
            actionMenu.MenuItems.Add(whiteItem);

            actionMenu.MenuItems.Add(new MenuItem()
            {
                Text = "-"
            });

            actionMenu.MenuItems.Add(passItem);

            actionMenu.MenuItems.Add(new MenuItem()
            {
                Text = "-"
            });

            var commentItem = new MenuItem()
            {
                Text = "Expand comment"
            };

            commentItem.Click += delegate(object sender, EventArgs args)
            {
                if (!commentItem.Checked)
                {
                    comment.Height = Size.Height;
                }
                else
                {
                    comment.Height = Size.Height - Size.Width;
                }
                commentItem.Checked = !commentItem.Checked;
            };
            actionMenu.MenuItems.Add(commentItem);

            SetPlayer();
            AllowCursor = true;
        }
Beispiel #12
0
        private static void RenderMarkup(this GoGame goGame, GameRenderer renderer, BoardMarkup markup)
        {
            foreach (TextLabel label in markup.Labels)
            {
                renderer.DrawString(label.X, label.Y, label.Text,
                                    goGame.board.HasStone(label.X, label.Y, false));
            }

            foreach (Mark mark in markup.Marks)
            {
                switch (mark.MarkType)
                {
                case MarkType.Square:
                    renderer.DrawSquare(mark.X, mark.Y, goGame.board.HasStone(mark.X, mark.Y, false));
                    break;

                case MarkType.Circle:
                    renderer.DrawCircle(mark.X, mark.Y, goGame.board.HasStone(mark.X, mark.Y, false));
                    break;

                case MarkType.Triangle:
                    renderer.DrawTriangle(mark.X, mark.Y, goGame.board.HasStone(mark.X, mark.Y, false));
                    break;

                case MarkType.Mark:
                    renderer.DrawMark(mark.X, mark.Y, goGame.board.HasStone(mark.X, mark.Y, false));
                    break;

                case MarkType.Selected:
                    renderer.DrawSelected(mark.X, mark.Y, goGame.board.HasStone(mark.X, mark.Y, false));
                    break;
                }
            }

            if (markup.Territory != null)
            {
                for (byte x = 0; x < markup.Territory.Black.Width; x++)
                {
                    for (byte y = 0; y < markup.Territory.Black.Width; y++)
                    {
                        if (markup.Territory.Black[x, y])
                        {
                            renderer.DrawTerritory(x, y, true);
                        }
                    }
                }

                for (byte x = 0; x < markup.Territory.White.Width; x++)
                {
                    for (byte y = 0; y < markup.Territory.White.Width; y++)
                    {
                        if (markup.Territory.White[x, y])
                        {
                            renderer.DrawTerritory(x, y, false);
                        }
                    }
                }
            }

            if (markup.DeadStones != null)
            {
                for (byte x = 0; x < markup.DeadStones.Width; x++)
                {
                    for (byte y = 0; y < markup.DeadStones.Width; y++)
                    {
                        if (markup.DeadStones[x, y])
                        {
                            renderer.DrawMark(x, y, goGame.board.HasStone(x, y, false));
                        }
                    }
                }
            }
        }