コード例 #1
0
 public void Update(Player win, Player pl1, Player pl2)
 {
     UpdateTable(win, pl1, pl2);
     UpdateFile();
 }
コード例 #2
0
 private void UpdateTable(Player win, Player pl1, Player pl2)
 {
     if (pl2.name == "")
     {
         int ind = Count(pl1.name);
         if (win == pl2)
         {
             if (ind != -1)
                 list[ind].lose++;
             else
                 list.Add(new row(pl1.name + " 0 1"));
         }
         else
         {
             if (ind != -1)
                 list[ind].win++;
             else
                 list.Add(new row(pl1.name + " 1 0"));
         }
     }
     else
     {
         int ind1 = Count(pl1.name);
         int ind2 = Count(pl2.name);
         if (win == pl1)
         {
             if (ind1 != -1)
                 list[ind1].win++;
             else
                 list.Add(new row(pl1.name + " 1 0"));
             if (ind2 != -1)
                 list[ind2].lose++;
             else
                 list.Add(new row(pl2.name + " 0 1"));
         }
         else
         {
             if (ind1 != -1)
                 list[ind1].lose++;
             else
                 list.Add(new row(pl1.name + " 0 1"));
             if (ind2 != -1)
                 list[ind2].win++;
             else
                 list.Add(new row(pl2.name + " 1 0"));
         }
     }
 }
コード例 #3
0
ファイル: Game.cs プロジェクト: IovlevYuliy/battleships
        private void GameWithBt(MouseEventArgs e)
        {
            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 (bt.IsHit(p.X, p.Y))
                {
                    pl1.LastHit = new Point(p.X, p.Y);
                    pl1.MakeStep(p.X, p.Y, 2);
                    bt.ownfield[p.X, p.Y] = 2;
                    if (bt.IsDead(p.X, p.Y))
                    {
                        pl1.Kill(p.X, p.Y);
                        pl1.DeleteDeadShip();

                        if (pl1.CheckWin())
                        {
                            winner = pl1;
                            DialogResult result = MessageBox.Show("Поздравляем вы победили!", "Победа", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            if (result == DialogResult.OK)
                            {
                                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                                this.Hide();
                            }
                        }
                    }
                }
                else
                {
                    if (pl1.alienfield[p.X, p.Y] != 0)
                        return;
                    bt.ownfield[p.X, p.Y] = 3;
                    pl1.MakeStep(p.X, p.Y, 3);

                    p = bt.GetStep();
                    while (pl1.IsHit(p.X, p.Y))
                    {
                        bt.LastHit = new Point(p.X, p.Y);
                        bt.Deny = true;

                        bt.MakeStep(p.X, p.Y, 2);
                        pl1.ownfield[p.X, p.Y] = 2;
                        if (pl1.IsDead(p.X, p.Y))
                        {
                            bt.DeleteDeadShip();
                            if (bt.CheckWin())
                            {
                                winner = bt;
                                DialogResult result = MessageBox.Show("Вы проиграли :(. Не расстраивайтесь. В следующий раз обязательно повезет!", "Поражение", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                                if (result == DialogResult.OK)
                                {
                                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                                    this.Hide();
                                    return;
                                }
                            }
                            bt.Kill(p.X, p.Y);
                            bt.Deny = false;
                        }

                        p = bt.GetStep();
                    }
                    bt.MakeStep(p.X, p.Y, 3);
                    pl1.ownfield[p.X, p.Y] = 3;
                }
            }
        }
コード例 #4
0
ファイル: MainMenu.cs プロジェクト: IovlevYuliy/battleships
 private void UpdateRecords(Player win, Player pl1, Player pl2)
 {
     RecordTable table = new RecordTable();
     table.Update(win, pl1, pl2);
 }
コード例 #5
0
ファイル: Game.cs プロジェクト: IovlevYuliy/battleships
        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;
                    }
                }
            }
        }