Beispiel #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            Name f = new Name();
            f.ShowDialog();
            if (f.DialogResult == DialogResult.Cancel)
                return;
            if (f.DialogResult == DialogResult.OK)
                this.Visible = false;

            Human player1 = new Human();
            Human player2 = new Human();

            this.Visible = false;
            PrepareToGame prepare1 = new PrepareToGame();
            prepare1.ShowDialog();

            if (prepare1.DialogResult == DialogResult.OK)
            {
                player1 = prepare1.ReturnPlayer();
                player1.name = f.ReturnName();
                f = new Name();
                f.ShowDialog();
                if (f.DialogResult == DialogResult.Cancel)
                {
                    this.Visible = true;
                    return;
                }
                if (f.DialogResult == DialogResult.OK)
                    this.Visible = false;
                PrepareToGame prepare2 = new PrepareToGame();
                foreach (Button obj in prepare2.Controls)
                {
                    if (obj.Name == "ButtonBack")
                    {
                        obj.Visible = false;
                        break;
                    }
                }
                prepare2.ShowDialog();

                if (prepare2.DialogResult == DialogResult.OK)
                {
                    player2 = prepare2.ReturnPlayer();
                    player2.name = f.ReturnName();
                }
                else
                    Application.Exit();
                Game game = new Game(player1, player2);
                game.ShowDialog();
                if (game.DialogResult == DialogResult.OK)
                {
                    UpdateRecords(game.ReturnWinner(), player1, player2);
                    this.Visible = true;
                }
                if (game.DialogResult == DialogResult.Cancel)
                    Application.Exit();
            }
            else
                this.Visible = true;
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Human player = new Human();
            Bot bot = new Bot();
            Name f = new Name();
            f.ShowDialog();
            if (f.DialogResult == DialogResult.Cancel)
                return;
            if (f.DialogResult == DialogResult.OK)
                this.Visible = false;
            bot.FillField();
            this.Visible = false;

            PrepareToGame prepare = new PrepareToGame();
            prepare.ShowDialog();

            if (prepare.DialogResult == DialogResult.OK)
            {
                player = prepare.ReturnPlayer();
                player.name = f.ReturnName();
                Game game = new Game(player, bot);
                game.ShowDialog();
                if (game.DialogResult == DialogResult.Cancel)
                    Application.Exit();
                if (game.DialogResult == DialogResult.OK)
                {
                    UpdateRecords(game.ReturnWinner(), player, bot);
                }
            }
            this.Visible = true;
        }
Beispiel #3
0
 public Game(Human player, Bot bot)
 {
     InitializeComponent();
     pl1 = player;
     bt = bot;
     GameWithBot = true;
 }
Beispiel #4
0
 public Game(Human player1, Human player2)
 {
     InitializeComponent();
     //players = new Human[2];
     //players[0] = pl1;
     //players[1] = pl2;
     pl1 = player1;
     pl2 = player2;
     pl = 0;
     GameWithFriend = true;
 }
 public PrepareToGame()
 {
     InitializeComponent();
     Player1 = new Human();
     ButtonBack.Image = new Bitmap(battleships.Properties.Resources.back, ButtonBack.Width, ButtonBack.Height);
     RotateButton.Image = new Bitmap(battleships.Properties.Resources.turn, RotateButton.Width, RotateButton.Height);
     NextButton.Image = new Bitmap(battleships.Properties.Resources.next, NextButton.Width, NextButton.Height);
     this.MouseMove += Player1.Fleet_Move;
     this.MouseDown += Player1.Fleet_Down;
     this.MouseUp += Player1.Fleet_Up;
 }
Beispiel #6
0
        private void GameWithFr(MouseEventArgs e, Human player1, Human player2)
        {
            if (e.X > 360 && e.X < 560 && e.Y > 60 && e.Y < 260)
            {
                Point p = new Point();
                p.X = (e.X - 360) / 20;
                p.Y = (e.Y - 60) / 20;
                if (player2.IsHit(p.X, p.Y))
                {
                    player1.LastHit = new Point(p.X, p.Y);
                    player1.MakeStep(p.X, p.Y, 2);
                    player2.ownfield[p.X, p.Y] = 2;
                    if (player2.IsDead(p.X, p.Y))
                    {
                        player1.Kill(p.X, p.Y);
                        player1.DeleteDeadShip();

                        if (player1.CheckWin())
                        {
                            winner = player1;
                            DialogResult result = MessageBox.Show("Поздравляем вы победили! Можете сыграть еще и подтвердить свое звание чемпиона :)", "Победа", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            if (result == DialogResult.OK)
                            {
                                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                                this.Hide();
                                return;
                            }
                        }
                        else
                            winner = player2;
                    }
                }
                else
                {
                    player1.MakeStep(p.X, p.Y, 3);
                    player2.ownfield[p.X, p.Y] = 3;
                    pl ^= 1;
                    this.Visible = false;
                    DialogResult result = MessageBox.Show("Игрок сделал ход. Ходит игрок " + player2.name, "Ход другого игрока", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    if (result == DialogResult.OK)
                    {
                        this.Visible = true;
                    }
                }
            }
        }