Exemple #1
0
        //Criar um documento TxT de Estatisticas com a cotação deste jogo
        static public void CriarEstatisticas(Jogador Jogadora, Jogador Jogadorb)
        {
            List <Estatisticas> ListaEstatisticas = new List <Estatisticas>();

            //Lê todas as linhas do ficheiro TXT "EstatisticasJogo.txt"
            string[] LinhasTxt    = File.ReadAllLines("EstatisticasJogo.txt", Encoding.Default);
            int      numLinhasTxt = LinhasTxt.Length - 1;
            int      j            = 0;

            while (j < numLinhasTxt)
            {
                //Adiciona uma lista de  estatistica
                ListaEstatisticas.Add(new Estatisticas(LinhasTxt[j], Convert.ToInt32(LinhasTxt[j + 1])));
                j = j + 2;
            }

            int  i = 0;
            bool SelecaoJogador1 = false;
            bool SelecaoJogador2 = false;

            StreamWriter writer = new StreamWriter("EstatisticasJogo.txt");

            //Verefica se existe algum Jogador com o nome dos Jogadores que jogaram neste jogo e se houver atualiza a cotação do mesmo
            //Adiciona a lista a um novo ficheiro TXT.
            while (i < ListaEstatisticas.Count)
            {
                if (String.Equals(Jogadora.Nome, ListaEstatisticas[i].Nome))
                {
                    ListaEstatisticas[i].Cotacao = ListaEstatisticas[i].Cotacao + Jogadora.Cotacao;
                    SelecaoJogador1 = true;
                    i++;
                }
                if (String.Equals(Jogadorb.Nome, ListaEstatisticas[i].Nome))
                {
                    ListaEstatisticas[i].Cotacao = ListaEstatisticas[i].Cotacao + Jogadorb.Cotacao;
                    SelecaoJogador2 = true;
                    i++;
                }
                i++;
            }

            if (!SelecaoJogador1)
            {
                writer.WriteLine(Jogadora.Nome);
                writer.WriteLine(Jogadora.Cotacao);
            }

            if (!SelecaoJogador2)
            {
                writer.WriteLine(Jogadorb.Nome);
                writer.WriteLine(Jogadorb.Cotacao);
            }

            j = 0;
            while (j < ListaEstatisticas.Count)
            {
                writer.WriteLine(Convert.ToString(ListaEstatisticas[j].Nome));
                if (j == ListaEstatisticas.Count - 1)
                {
                    writer.Write(Convert.ToString(ListaEstatisticas[j].Cotacao));
                }
                else
                {
                    writer.WriteLine(Convert.ToString(ListaEstatisticas[j].Cotacao));
                }

                j++;
            }

            writer.Close();
            return;
        }
Exemple #2
0
        // Performa o ataque do Jogador
        // [true] se o jogo acabou, já não há mais veículos para serem abatidos / [false] se ainda à veículos que não foram destruidos.
        static public bool PerformAttack(int cellX, int cellY, Jogador attacker, Jogador other)
        {
            string attackerLogNote = "--> " + String.Format("{0:000}", roundCount) + ".ronda: " + attacker.Nome + ", atacou o veículo da célula [" +
                                     letterLabels[cellY] + "," + numberLables[cellX] + "]. ";

            attacker.Hits     = attacker.Hits++;
            attacker.Misseis  = attacker.Misseis - 1;
            attacker.HitRatio = Convert.ToDouble(attacker.Hits) / Convert.ToDouble(Game.roundCount);

            // O ataque foi realizado com sucesso
            if (TabGame.CombSituacao[cellX, cellY] == 0)
            {
                if (SwitchJogador)
                {
                    TabGame.CombSituacao[cellX, cellY] = 1;
                }
                else
                {
                    TabGame.CombSituacao[cellX, cellY] = 2;
                }

                // Marca a célula atingida como trancada
                TabGame.CellsTrancadas[cellX, cellY]            = true;
                TabGame.CellsTrancadasDepoisJogar[cellX, cellY] = true;

                for (int i = 0; i < 9; i++)
                {
                    for (int j = 0; j < 9; j++)
                    {
                        TabGame.CellsTrancadasDepoisJogar[i, j] = true;
                    }
                }

                for (int i = 0; i < 9; i++)
                {
                    if (TabGame.CombSituacao[i, cellY] == 0)
                    {
                        TabGame.CellsTrancadasDepoisJogar[i, cellY] = false;
                    }
                    else
                    {
                        TabGame.CellsTrancadasDepoisJogar[i, cellY] = true;
                    }
                }

                // Marca a última célula trancada
                TabGame.LastCellsTrancadas[0] = cellX;
                TabGame.LastCellsTrancadas[1] = cellY;

                // Aumenta a contagem de hits do atacante.
                attacker.Hits++;

                // Decresce o número de veiculos que restam
                TabGame.VeiculosLeft--;

                // O jogo acabou?
                if (TabGame.VeiculosLeft == 0)
                {
                    string last = "--> " + String.Format("{0:000}", roundCount) + ".ronda: " + other.Nome.ToString() + " ganhou o jogo!" + " O " + attacker.Nome + " Destruiu o último veículo do Jogo!";
                    TabGame.BattleLog = TabGame.BattleLog + attackerLogNote + "\n" + last;

                    return(true);
                }
                else
                {
                    //verifica se os misseis do Jogaor acabam quando o ataque
                    if (attacker.Misseis == 0 || TabGame.VeiculosLeft == 0)
                    {
                        string last = "--> " + String.Format("{0:000}", roundCount) + ".ronda: " + other.Nome.ToString() + " ganhou o jogo!" + " O " + attacker.Nome + " Não tem mais misséis para jogar e ainda faltam destruir 2 ou mais veículos!";
                        TabGame.BattleLog = TabGame.BattleLog + attackerLogNote + "\n" + last;
                        return(true);
                    }
                    else
                    {
                        // Returna false se ainda houverem veiculos a serem destruidos
                        TabGame.BattleLog = TabGame.BattleLog + attackerLogNote + "\n";
                        return(false);
                    }
                }
            }
            else
            {
                TabGame.BattleLog = TabGame.BattleLog + attackerLogNote + "\n";

                return(false);
            }
        }