Exemple #1
0
        // Specify what you want to happen when the Elapsed event is raised.
        private void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            using (var db = new dominoeng3Entities())
            {
                int id    = Convert.ToInt32(idPlayer);
                var query = from u in db.partidas
                            where u.player1 == id && (u.estado == 0 || u.estado == 1)
                            select u;

                if (query.Count() > 0)
                {
                    partida p = query.First();
                    if (p.estado == 0)
                    {
                        idGame = Convert.ToString(p.ID);
                    }
                    else if (p.estado == 1)
                    {
                        if (String.IsNullOrEmpty(idGame))
                        {
                            idGame = Convert.ToString(p.ID);
                        }

                        if (idGame.Equals(Convert.ToString(p.ID)))
                        {
                            if (showMePedido)
                            {
                                MessageBox.Show("Seu pedido de jogo foi aceito! Você pode jogar agora!");
                                showMePedido = false;
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void HoldNewGameState4(int idGame)
        {
            while (true)
            {
                using (var db = new dominoeng3Entities())
                {
                    var query = from u in db.partidas
                                where (u.ID == idGame)
                                select u;

                    if (query.Count() > 0)
                    {
                        partida p = query.First();
                        if (p.estado == 5)
                        {
                            MessageBox.Show("O outro jogador aceitou jogar com você! Começando a jogar agora...!");

                            string idGameStr = Convert.ToString(p.ID);
                            string idPlayer1 = Convert.ToString(p.player1);
                            string idPlayer2 = Convert.ToString(p.player2);

                            string idOpponent;

                            if (idPlayer1.Equals(this.idPlayer))
                            {
                                idOpponent = idPlayer2;
                            }
                            else
                            {
                                idOpponent = idPlayer1;
                            }

                            fmdomino fd = new fmdomino(idGameStr, Convert.ToString(this.idPlayer), idOpponent);
                            fd.ShowDialog();
                        }
                        else if (p.estado == 7)
                        {
                            MessageBox.Show("O outro jogador desistiu de jogar o jogo agora! Abortando esta partida agora...!");
                            break;
                        }
                    }
                }
            }
        }
Exemple #3
0
        private void btnPlayAcceptedGame_Click(object sender, EventArgs e)
        {
            try
            {
                using (var db = new dominoeng3Entities())
                {
                    int     id = Convert.ToInt32(idPlayer);
                    partida p  = db.partidas.Single(c => c.player1 == id && c.estado == 1);
                    p.estado = 3;

                    db.SaveChanges();

                    MessageBox.Show("Pedido feito para começar o jogo aceito agora!");
                }
            }
            catch (System.InvalidOperationException)
            {
                MessageBox.Show("Não existem jogos aceitos para pedidos deste jogador!");
            }
        }
Exemple #4
0
        private void btnRejectGameRequest_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedCells.Count > 0)
            {
                int selectedrowindex = dataGridView1.SelectedCells[0].RowIndex;

                DataGridViewRow selectedRow = dataGridView1.Rows[selectedrowindex];

                string email = Convert.ToString(selectedRow.Cells["E-mail"].Value);
                string nome  = Convert.ToString(selectedRow.Cells["Nome"].Value);

                using (var db = new dominoeng3Entities())
                {
                    var id = db.players.Where(x => x.Nome == nome).Select(x => x.ID);
                    if (id.Count() > 0)
                    {
                        MessageBox.Show("Rejeitando novo jogo com o jogador de id: " + id.FirstOrDefault() + " meu id: " + idPlayer);
                        partida p = db.partidas.Single(c => c.player1 == id.FirstOrDefault() && c.player2 == idPlayer && c.estado == 0);

                        p.estado = 2;

                        db.SaveChanges();

                        MessageBox.Show("Pedido de novo jogo rejeitado!");
                        this.UpdateDataGridView();
                    }
                    else
                    {
                        MessageBox.Show("Selecione um pedido válido antes de rejeitá-lo!");
                    }
                }
            }
            else
            {
                MessageBox.Show("Selecione um pedido antes de rejeitá-lo!");
            }
        }
Exemple #5
0
        private void PlayMethod()
        {
            using (var db = new dominoeng3Entities())
            {
                var query = from u in db.partidas
                            where (u.estado == 3 && u.player2 == idPlayer)
                            select u;

                if (query.Count() > 0)
                {
                    DialogResult res = MessageBox.Show("Você quer jogar agora, assim como o Jogador 1?", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

                    if (res == DialogResult.OK)
                    {
                        int     idGame;
                        partida p = query.First();
                        idGame   = p.ID;
                        p.estado = p.estado + 1;
                        db.SaveChanges();
                        MessageBox.Show("Você decidiu jogar agora!");
                        HoldNewGameState4(idGame);
                    }
                    else if (res == DialogResult.Cancel)
                    {
                        partida p = query.First();
                        p.estado = 7;
                        db.SaveChanges();
                        MessageBox.Show("Você decidiu não jogar agora!");
                    }
                }
                else
                {
                    query = from u in db.partidas
                            where (u.estado == 4 && (u.player1 == idPlayer || u.player2 == idPlayer))
                            select u;

                    if (query.Count() > 0)
                    {
                        partida p = query.First();

                        idGame = Convert.ToString(p.ID);
                        string idPlayer1 = Convert.ToString(p.player1);
                        string idPlayer2 = Convert.ToString(p.player2);

                        DialogResult res = MessageBox.Show("O jogo pode ser iniciado agora, mesmo?", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                        if (res == DialogResult.OK)
                        {
                            p.estado = p.estado + 1;
                            db.SaveChanges();

                            List <string> dadosWs = new List <string>();
                            dadosWs.Add(idGame);
                            dadosWs.Add(idPlayer1);
                            dadosWs.Add(idPlayer2);

                            string result = RequisicoesRestWS.CustodiaRequisicao(WsUrlManager.GetUrl("/newgame"), dadosWs);

                            if (String.IsNullOrEmpty(result))
                            {
                                MessageBox.Show("Não foi possível logar-se! Tente novamente, mais tarde!");
                                return;
                            }

                            if (Convert.ToBoolean(result))
                            {
                                string idOpponent;

                                if (idPlayer1.Equals(this.idPlayer))
                                {
                                    idOpponent = idPlayer2;
                                }
                                else
                                {
                                    idOpponent = idPlayer1;
                                }

                                fmdomino fd = new fmdomino(idGame, Convert.ToString(this.idPlayer), idOpponent);
                                fd.ShowDialog();
                            }
                            else
                            {
                                MessageBox.Show("O Web Service retornou um resultado inválido! Abortando a operação de inicio de jogo!");
                            }
                        }
                        else if (res == DialogResult.Cancel)
                        {
                            this.playIt = false;
                            MessageBox.Show("Você decidiu não jogar agora!");
                        }
                    }
                }
            }
        }