Example #1
0
        public Goban(GoRulesBase rulesBase)
        {
            _rulesBase    = rulesBase;
            _grid         = new GameObject[rulesBase[0], rulesBase[0]];
            _scoreObjects = new TextObject[2];
            Vector2u   windowSize = PlayerField.GetGame().MainFrame.Window.Size;
            GameObject back       = new GameObject(new RectangleShape((Vector2f)windowSize));

            back.Shape.FillColor = Color.Blue;
            AddShape(back);
            int        minDimension = (int)Math.Min(windowSize.X, windowSize.Y);
            int        offset       = minDimension / 20;
            int        placeSize    = minDimension - offset;
            GameObject place        = new GameObject(new RectangleShape(new Vector2f(placeSize, placeSize)));

            place.Subscribe = new NotifierSub(place);

            place.Subscribe.AddObserver(new OnPressMessage(((i, i1) =>
            {
                if (!rulesBase.GetActivePerson().IsBot&& !rulesBase.IsFinished)
                {
                    int id = rulesBase.GetActivePerson().Id - 1;
                    Console.WriteLine(id.ToString());
                    _selectedStone = new Stone(_cubeSize / 3f);
                    Color customColor = new Color();
                    customColor.A = 255;
                    customColor.R = (byte)(255 * id);
                    customColor.G = (byte)(255 * id);
                    customColor.B = (byte)(255 * id);
                    _selectedStone.Shape.FillColor = customColor;
                    _selectedStone.ChangeState(new GrabedState(_selectedStone));
                    _selectedStone.Update();
                    AddShape(_selectedStone);
                }
            })));

            place.Subscribe.AddObserver(new OnReleaseMessage(((x, y) =>
            {
                if (!rulesBase.GetActivePerson().IsBot)
                {
                    if (_selectedStone != null)
                    {
                        (bool canPlace, int xStone, int yStone) = CanTookStone(x, y);
                        bool isStepDone = rulesBase.GetActivePerson().MakeStep(xStone, yStone);
                        if (isStepDone)
                        {
                            _selectedStone.ChangeState(null);
                            TookOnGrid(_selectedStone, xStone, yStone);
                            CheckConfirmity();
                        }
                        else
                        {
                            RemoveShape(_selectedStone);
                        }
                        _selectedStone = null;
                    }
                }
            })));

            AddShape(place);
            place.Shape.Position  = new Vector2f(offset / 2.0f, offset / 2.0f);
            place.Shape.FillColor = Color.Green;

            int size = rulesBase[0];

            _cubeSize   = (float)placeSize / size;
            _rectOffset = offset / 2.0f + _cubeSize / 2;
            for (int i = 0; i < size; i++)
            {
                RectangleShape lineHorizontal = new RectangleShape(new Vector2f(placeSize - _cubeSize, 1));
                lineHorizontal.FillColor = Color.Black;
                lineHorizontal.Position  = new Vector2f(_rectOffset, _rectOffset + _cubeSize * i);
                AddShape(new GameObject(lineHorizontal));

                RectangleShape lineVertical = new RectangleShape(new Vector2f(1, placeSize - _cubeSize));
                lineVertical.FillColor = Color.Black;
                lineVertical.Position  = new Vector2f(_rectOffset + _cubeSize * i, _rectOffset);
                AddShape(new GameObject(lineVertical));
            }


            _scoreObjects[0] = new TextObject("Score: 0", new Font("C:/CurrentProjects/LetsGo/Game/FONT.ttf"));
            _scoreObjects[0].Text.FillColor = Color.Black;
            _scoreObjects[1] = new TextObject("Score: 0", new Font("C:/CurrentProjects/LetsGo/Game/FONT.ttf"));
            _scoreObjects[1].Text.FillColor = Color.White;
            Vector2f textSize = new Vector2f(_scoreObjects[0].Text.GetGlobalBounds().Width,
                                             _scoreObjects[0].Text.GetGlobalBounds().Height + 20);

            _scoreObjects[0].Text.Position = (Vector2f)PlayerField.GetGame().MainFrame.Window.Size - textSize;

            textSize = new Vector2f(_scoreObjects[1].Text.GetGlobalBounds().Width,
                                    _scoreObjects[1].Text.GetGlobalBounds().Height);
            _scoreObjects[1].Text.Position =
                new Vector2f((PlayerField.GetGame().MainFrame.Window.Size.X - textSize.X), 0);
            AddShape(_scoreObjects[0]);
            AddShape(_scoreObjects[1]);



            TextObject passText = new TextObject("Pass", new Font("C:/CurrentProjects/LetsGo/Game/FONT.ttf"));
            GameObject pass     = new GameObject(new RectangleShape(new Vector2f(
                                                                        passText.Text.GetGlobalBounds().Width * 1.5f, passText.Text.GetGlobalBounds().Height * 1.5f)));

            //ButtonObject Pass = new ButtonObject("Pass", new Font("C:/CurrentProjects/LetsGo/Game/FONT.ttf"));
            pass.Shape.Position     = new Vector2f(650, 300);
            passText.Text.Position  = new Vector2f(650, 300);
            passText.Text.FillColor = Color.Magenta;
            pass.Subscribe          = new NotifierSub(pass);
            pass.Subscribe.AddObserver(new OnPressMessage(((i, i1) =>
            {
                if (!rulesBase.GetActivePerson().IsBot)
                {
                    ((Player)rulesBase.GetActivePerson()).Pass();
                }

                if (rulesBase.IsFinished)
                {
                    string endText;
                    if (rulesBase.Persons[0].Score < rulesBase.Persons[1].Score)
                    {
                        endText = "WHITE WIN";
                    }
                    else if (rulesBase.Persons[0].Score > rulesBase.Persons[1].Score)
                    {
                        endText = "BLACK WIN";
                    }
                    else
                    {
                        endText = "DRAW";
                    }
                    TextObject finishText = new TextObject(endText, new Font("C:/CurrentProjects/LetsGo/Game/FONT.ttf"));
                    finishText.Text.Position = new Vector2f(250, 250);
                    finishText.Text.FillColor = Color.Blue;

                    AddShape(finishText);
                }
                pass.Shape.FillColor = Color.Green;
            })));
            pass.Subscribe.AddObserver(new OnReleaseMessage(((i, i1) => { pass.Shape.FillColor = Color.White; })));
            AddShape(pass);
            AddShape(passText);
        }
Example #2
0
 public void Setup()
 {
     RulesBase = new GoRulesBase(9);
     player    = new Player(RulesBase);
     player2   = new Player(RulesBase, 2);
 }