コード例 #1
0
 private void Splash_Load(object sender, EventArgs e)
 {
     Temporizador.Start();
 }
コード例 #2
0
        /// <summary>
        /// Tratamento do evento clicar no botão, a função vai desencadear o fucionamento do jogo consoante o modo de jogo (Modo Normal ou Inverso).
        /// Faz o tratamento do botão esquerdo assim como do botão direito.
        /// </summary>
        /// <param name="sender">Botão</param>
        /// <param name="e">Foi premido rato esquerdo ou direito</param>
        public void OnButtonClicked(object sender, MouseEventArgs e)
        {
            // Se o Jogador se encontra a jogar no Modo normal, os botões funcionam desta maneira...
            if (Program.M_Options.ModoJogo == GameMode.Normal)
            {
                // Botão esquerdo, abre espaço
                if (e.Button == MouseButtons.Left)
                {
                    Temporizador.Start();
                    //// Obter Botão premido e guardar
                    var botaoAtual = (sender as Button);

                    // Obtém as Coordenadas do Tile
                    GetCoordinates(botaoAtual, out int x, out int y);

                    Tile currentTile = GetTile(new System.Drawing.Point(x, y));

                    if (currentTile.TemMina == true)
                    {
                        //	Jogo perdido
                        Temporizador.Stop();

                        V_MineSweeperGame.ChangeButtonBackGround(botaoAtual, Resources.bomb);
                        Reveal();
                        BombaFimJogo();

                        // O jogo acaba
                        V_MineSweeperGame_AskToResetBoard();
                    }
                    else if (currentTile.Vazio == false && currentTile.Aberto == false)
                    {
                        ButtonChangeBackground(botaoAtual, currentTile);

                        currentTile.Aberto = true;
                        if (M_Options.SoundOnOrOFF == true)
                        {
                            Thread soundThread = new Thread(Sound.PlayOpenTile)
                            {
                                IsBackground = true
                            };
                            soundThread.Start();
                        }

                        // Se a condição for verdadeira a condição acaba
                        if (TestarFim(currentTile) == true)
                        {
                            GanhouJogo();
                        }
                        //soundThread.Abort();
                    }
                    // O jogo tem que abrir todos os vazios adjacentes.
                    // Primeira Questão: Como pedir os botões adjacentes ao view?
                    else if (currentTile.Vazio == true && currentTile.Aberto == false)
                    {
                        Flood_Fill(currentTile, V_MineSweeperGame.GetButton(currentTile.Ponto));
                    }
                }

                // Botão direito, coloca flag
                else if (e.Button == MouseButtons.Right)
                {
                    Button botaoAtual = sender as Button;
                    GetCoordinates(botaoAtual, out int x, out int y);

                    // Obtém as Coordenadas do Tile
                    Tile currentTile = GetTile(new System.Drawing.Point(x, y));

                    if (currentTile.Aberto != true)
                    {
                        if (M_Options.SoundOnOrOFF == true)
                        {
                            Thread soundThread = new Thread(Sound.PlayPutFlag)
                            {
                                IsBackground = true
                            };
                            soundThread.Start();
                        }

                        if (currentTile.Flagged == true)
                        {
                            V_MineSweeperGame.ChangeButtonBackGround(botaoAtual, Resources.unopened);
                            currentTile.Flagged = false;
                            M_Grelha.NumFlags--;
                            V_MineSweeperGame.AtualizaNumeroMinasDisponiveis(M_Grelha.NumMinasTotal - M_Grelha.NumFlags);
                        }
                        else if (currentTile.Flagged == false)
                        {
                            V_MineSweeperGame.ChangeButtonBackGround(botaoAtual, Resources.flag1);
                            currentTile.Flagged = true;
                            M_Grelha.NumFlags++;
                            V_MineSweeperGame.AtualizaNumeroMinasDisponiveis(M_Grelha.NumMinasTotal - M_Grelha.NumFlags);
                        }
                        //soundThread.Abort();
                    }
                    else
                    {
                        return;
                    }
                }
            }

            // O jogo funciona em modo inverso, o jogador tem que detetar o posicionamento das minas
            else if (Program.M_Options.ModoJogo == GameMode.Inverso)
            {
                if (e.Button == MouseButtons.Left)
                {
                    Temporizador.Start();

                    Button botaoAtual = sender as Button;
                    GetCoordinates(botaoAtual, out int x, out int y);

                    // Obtém as Coordenadas do Tile
                    Tile currentTile = GetTile(new System.Drawing.Point(x, y));

                    if (currentTile.Aberto != true)
                    {
                        if (M_Options.SoundOnOrOFF == true)
                        {
                            Thread soundThread = new Thread(Sound.PlayPutFlag)
                            {
                                IsBackground = true
                            };
                            soundThread.Start();
                        }

                        if (currentTile.Flagged == true)
                        {
                            V_MineSweeperGame.ChangeButtonBackGround(botaoAtual, Resources.unopened);
                            currentTile.Flagged = false;
                            M_Grelha.NumFlags--;
                            V_MineSweeperGame.AtualizaNumeroMinasDisponiveis(M_Grelha.NumMinasTotal - M_Grelha.NumFlags);
                        }
                        else if (currentTile.Flagged == false)
                        {
                            if (Program.M_Grelha.NumMinasTotal == M_Grelha.NumFlags)
                            {
                                return;
                            }
                            V_MineSweeperGame.ChangeButtonBackGround(botaoAtual, Resources.flag1);
                            currentTile.Flagged = true;
                            M_Grelha.NumFlags++;
                            V_MineSweeperGame.AtualizaNumeroMinasDisponiveis(M_Grelha.NumMinasTotal - M_Grelha.NumFlags);
                        }
                        //soundThread.Abort();
                    }

                    if (TestarFimModoInverso(currentTile) == true)
                    {
                        GanhouJogo();
                    }
                    else
                    {
                        return;
                    }
                }
                else if (e.Button == MouseButtons.Right)
                {
                    return;
                }
            }
        }
コード例 #3
0
 private void Temporizador_Tick(object sender, EventArgs e)
 {
     Temporizador.Stop();
     this.Close();
 }
コード例 #4
0
 private void frmPrincipal_MouseLeave(object sender, EventArgs e)
 {
     Contador             = 0;
     Temporizador.Enabled = false;
     Temporizador.Stop();
 }
コード例 #5
0
ファイル: Form1.cs プロジェクト: schlieter/Lab2-2019
 public Form1()
 {
     InitializeComponent();
     temporizador = new Temporizador();
 }
コード例 #6
0
 public TemporizadorChequerDTO(Temporizador s)
 {
     GrupoId = s.GrupoId;
     Etapa   = s.Etapa;
 }
コード例 #7
0
 public void substituiThreadNoCoreDoProcessador()
 {
     while (existeAlgumCoreRodando())
     {
         while (fila.Count > 0)
         {
             bool bConcluiu = false;
             int  i         = -1;
             // verifica se concluiu quantum do processo p/ colocar outro no core
             for (int k = 0; k < 4; k++)
             {
                 if (aLista[k].ThreadState == ThreadState.Aborted)
                 {
                     frm.mostraMsg("Processo: " + aLista[k].Name + " semi-concluído.", k); Application.DoEvents();
                     bConcluiu = true;
                     i         = k;
                     break;
                 }
             }
             if (bConcluiu && fila.Count > 0)
             {
                 iCoreAtual      = i; // armazena em que Core está o processo iniciado
                 sNumProcessoAnt = aLista[i].Name;
                 // Tira da fila, coloca na lista e starta Thread c/ Processo, como tbém o Timer
                 aLista[i] = null;
                 aLista[i] = fila.ElementAt(0);
                 try
                 {
                     int iNumProcesso = filaIdsProcessos.ElementAt(0);
                     sNumProcesso = aLista[i].Name;
                     // inicia Thread aLista[i]
                     aLista[i].Start();
                     // Inicializa Thread Timer
                     Temporizador temporizador = new Temporizador(aLista[i], aProcessos[iNumProcesso - 1], frm);
                     threadTimer = new Thread(new ThreadStart(temporizador.Start));
                     threadTimer.IsBackground = true;
                     aTimer[iNumProcesso - 1] = threadTimer;
                     aTimer[iNumProcesso - 1].Start();
                     frm.updateNaListViewCores(sNumProcessoAnt, sNumProcesso, i.ToString(), temporizador._intervaloSeg.ToString(),
                                               temporizador._intervaloSeg.ToString(), "executando", aProcessos[iNumProcesso - 1]._prioridade.ToString());
                 }
                 finally
                 {
                     if (fila.Count > 0)
                     {
                         fila.RemoveAt(0); filaIdsProcessos.RemoveAt(0); // remove processo da fila
                         frm.deletaNaListViewAptos(sNumProcesso);
                     }
                 }
             }
         } // Fim <while (fila.Count > 0)>
         if (fila.Count == 0)
         {
             int i = 0;
             while (true)
             {
                 // mostra msg concluído após terminar últimos processos
                 for (int k = 0; k < iNumCoresUtilizados; k++)
                 {
                     if (aLista[k] != null && aLista[k].ThreadState == ThreadState.Aborted)
                     {
                         Thread.Sleep(200);
                         i++;
                         frm.mostraMsg("1)Processo: " + aLista[k].Name + " concluído.", k); Application.DoEvents();
                         frm.deletaNaListViewCores(aLista[k].Name);
                     }
                 }
                 if (i >= iNumCoresUtilizados) // correto
                 {
                     break;
                 }
             }
         } // Fim <if (fila.Count == 0)>
     }     // Fim <while (existeAlgumCoreRodando())>
     stopCores();
     threadAtualizaTela.Abort();
     frm.mostraMsg("Fila vazia. Processos concluídos.");
 }