// Method that describe what happen when a tile is clicked
        private void onTileClicked(object obj, ButtonPressEventArgs args)
        {
            if (((Gdk.EventButton)args.Event).Type == Gdk.EventType.ButtonPress)
            {
                TileWidget tile = (TileWidget)obj;
                //Console.WriteLine (tile.position.x + ", " + tile.position.y + " " + tile.color + " " + tile.figure);
                if (!this.clicked)
                {
                    this.clickedPosition = new coord(tile.position.x, tile.position.y);

                    if (this.callback(this.clickedPosition, this.clickedPosition))
                    {
                        this.clicked = true;
                        Fixed f      = (Fixed)(tile.Child);
                        Image circle = tile.loadCircle(this.tileSize);
                        f.Add(circle);
                        f.ShowAll();
                    }
                }
                else
                {
                    //remove the ring whenn the user clicks agen on the same tile
                    if (this.callback(this.clickedPosition, tile.position) &&
                        this.clickedPosition.Equals(tile.position))
                    {
                        Fixed f = (Fixed)(tile.Child);
                        if (f.Children.Length > 1)
                        {
                            f.Remove(f.Children [1]);
                        }
                    }
                    this.clicked = false;
                }
            }
        }
Exemple #2
0
 // Method for the opening of popup
 public void open(Player player, coord position)
 {
     close ();
       foreach (Figure fig in this.figures) {
     TileWidget tile = new TileWidget ("", fig.name (), player.ToString (), this.tileSize);
     tile.position = position;
     fig.color = player.ToString ();
     box.PackStart (tile);
     tile.ButtonPressEvent += onTileClicked;
       }
       this.ShowAll ();
 }
Exemple #3
0
 // Method for the opening of popup
 public void open(Player player, coord position)
 {
     close();
     foreach (Figure fig in this.figures)
     {
         TileWidget tile = new TileWidget("", fig.name(), player.ToString(), this.tileSize);
         tile.position = position;
         fig.color     = player.ToString();
         box.PackStart(tile);
         tile.ButtonPressEvent += onTileClicked;
     }
     this.ShowAll();
 }
Exemple #4
0
        // Method that describe the reaction of a tile when it is clicked
        private void onTileClicked(object obj, ButtonPressEventArgs args)
        {
            TileWidget tile  = (TileWidget)obj;
            bool       found = false;

            for (int i = 0; i < ((HBox)tile.Parent).Children.Length && !found; i++)
            {
                if (((HBox)tile.Parent).Children [i].Equals(tile))
                {
                    found = true;
                    this.callback(this.figures [i], tile.position);
                }
            }
            close();
        }
Exemple #5
0
        // Method that draw the board
        private void createBoard()
        {
            //alternating background color for the grid
              string tileBackground = "white";
              for (int x = 0; x < this.game.getSize ().x; x++) {
            tileBackground = (tileBackground == "white") ? "gray" : "white";
            for (int y = 0; y < this.game.getSize ().y; y++) {
              string type = this.game.getFieldFigureName (new coord (x, y));
              string playerColor = this.game.getFieldFigureColor (new coord (x, y));
              tileBackground = (tileBackground == "white") ? "gray" : "white";

              type = (type == "Empty") ? "" : type;
              TileWidget tile = new TileWidget (tileBackground, type, playerColor, this.tileSize);
              tile.position = new coord (x, y);
              tile.ButtonPressEvent += onTileClicked;
              this.addFigure (tile, new coord (x, y));
            }
              }
              this.ShowAll ();
        }
        // Method that draw the board
        private void createBoard()
        {
            //alternating background color for the grid
            string tileBackground = "white";

            for (int x = 0; x < this.game.getSize().x; x++)
            {
                tileBackground = (tileBackground == "white") ? "gray" : "white";
                for (int y = 0; y < this.game.getSize().y; y++)
                {
                    string type        = this.game.getFieldFigureName(new coord(x, y));
                    string playerColor = this.game.getFieldFigureColor(new coord(x, y));
                    tileBackground = (tileBackground == "white") ? "gray" : "white";

                    type = (type == "Empty") ? "" : type;
                    TileWidget tile = new TileWidget(tileBackground, type, playerColor, this.tileSize);
                    tile.position          = new coord(x, y);
                    tile.ButtonPressEvent += onTileClicked;
                    this.addFigure(tile, new coord(x, y));
                }
            }
            this.ShowAll();
        }