示例#1
0
 //
 // BattleShipGrid interaction
 //
 private void select_ship(object sender, MouseEventArgs e)
 {
     selected = ((Tile)sender);
     if (selected.getType() == typeof(Tile))
     {
         selected.clear();
     }
     clicks = 0;
 }
示例#2
0
        //
        // PersonalGrid interaction
        //
        private void personalGrid_MouseDown(object sender, MouseEventArgs e)
        {
            if (this.battleShipsGRID.tiles[selected.x, selected.y].ships == 0)
            {
                selected.type = null;
            }

            if (selected.getType() != null)
            {
                Console.WriteLine(" ----- EVENT PUSHED -----");

                this.eventStates.Push(new EventState(this.personalGrid, this.battleShipsGRID, clicks));
            }

            if (clicks == 0)
            {
                if (selected.getType() == null)
                {
                    clicks = 0;
                    return;
                }

                if (this.battleShipsGRID.tiles[selected.x, selected.y].ships > 0)
                {
                    if (((Tile)sender).state == TileState.UNTOUCHED)
                    {
                        clicks++;
                        ((Tile)sender).inheritTileInfo(selected); // place boat
                        prev = ((Tile)sender);
                    }
                    else
                    {
                        //dialog box
                        MessageBox.Show("You can't place boats on top of eachother...");
                    }
                }
            }
            else if (clicks == 1)
            {
                if (((Tile)sender).x - prev.x < ((Tile)sender).y - prev.y && (((Tile)sender).y - prev.y) > 0)
                {
                    addTilesOnYaxis();
                }
                else if (((Tile)sender).x - prev.x > ((Tile)sender).y - prev.y && (((Tile)sender).x - prev.x) > 0)
                {
                    addTilesOnXaxis();
                }
                else if (((Tile)sender).x - prev.x == ((Tile)sender).y - prev.y && (((Tile)sender).x - prev.x) > 0)
                {
                    if (columns - prev.x >= this.battleShipsGRID.tiles[selected.x, selected.y].ships)
                    {
                        addTilesOnXaxis();
                    }
                    else if (rows - prev.y >= this.battleShipsGRID.tiles[selected.x, selected.y].ships)
                    {
                        addTilesOnYaxis();
                    }
                    else
                    {
                        prev.clear();
                    }
                }
                else if (Math.Abs(((Tile)sender).x - prev.x) < Math.Abs(((Tile)sender).y - prev.y) && (((Tile)sender).y - prev.y) < 0)
                {
                    addTilesOnNegativeYaxis();
                }
                else if (Math.Abs(((Tile)sender).x - prev.x) > Math.Abs(((Tile)sender).y - prev.y) && (((Tile)sender).x - prev.x) < 0)
                {
                    addTilesOnNegativeXaxis();
                }
                else if (Math.Abs(((Tile)sender).x - prev.x) == Math.Abs(((Tile)sender).y - prev.y) && (((Tile)sender).x - prev.x) < 0)
                {
                    addTilesOnNegativeXaxis();
                }

                if (selected.getType() == typeof(PatrolBoat))
                {
                    this.patrolNumberLabel.Text = battleShipsGRID.tiles[selected.x, selected.y].ships.ToString();
                }
                if (selected.getType() == typeof(CruiserBoat))
                {
                    this.cruiserNumberLabel.Text = battleShipsGRID.tiles[selected.x, selected.y].ships.ToString();
                }
                if (selected.getType() == typeof(ValvetShellBoat))
                {
                    this.valvetNumberLabel.Text = battleShipsGRID.tiles[selected.x, selected.y].ships.ToString();
                }
                if (selected.getType() == typeof(RedCrowBoat))
                {
                    this.redNumberLabel.Text = battleShipsGRID.tiles[selected.x, selected.y].ships.ToString();
                }
                if (selected.getType() == typeof(VDragonBoat))
                {
                    this.dragonNumberLabel.Text = battleShipsGRID.tiles[selected.x, selected.y].ships.ToString();
                }


                clicks = 0;
            }
        }