コード例 #1
0
        public bool Delete(Eroe eroe)
        {
            string nome = eroe.Nome;

            using (SqlConnection connection = new SqlConnection(connectionstring))
            {
                //Aprire la connessione
                connection.Open();

                //Comando
                SqlCommand command = new SqlCommand();
                command.Connection  = connection;
                command.CommandType = System.Data.CommandType.Text;
                command.CommandText = "DELETE FROM Eroe WHERE Nome = @nome";

                //Aggiunta parametri
                command.Parameters.AddWithValue("@Nome", eroe.Nome);

                //Esecuzione comando
                SqlDataReader reader = command.ExecuteReader();

                //Chiusura
                reader.Close();
                connection.Close();
            }
            return(true);
        }
コード例 #2
0
        public bool Update(Eroe obj)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                try
                {
                    //Aprire la connessione
                    connection.Open();

                    //Creo il comando
                    SqlCommand command = new SqlCommand();
                    command.Connection  = connection;
                    command.CommandType = System.Data.CommandType.Text;
                    command.CommandText = "UPDATE Eroi SET Livello = @livello, PuntiVita = @puntiVita, PuntiAccumulati = @puntiAccumulati WHERE NomeEroe = @nome";

                    //Valori
                    command.Parameters.AddWithValue("@nome", obj.Nome);
                    command.Parameters.AddWithValue("@livello", obj.Livello);
                    command.Parameters.AddWithValue("@puntiVita", obj.PuntiVita);
                    command.Parameters.AddWithValue("@puntiAccumulati", obj.PuntiAccumulati);

                    command.ExecuteNonQuery();
                    return(true);
                }
                catch (Exception)
                {
                    Console.WriteLine("Siamo spiacenti, è stato rilevato un errore");
                    return(false);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
コード例 #3
0
        public bool Delete(Eroe obj)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                try
                {
                    //Aprire connessione
                    connection.Open();

                    //Comando
                    string     deleteFromStatistiche = "DELETE FROM Statistiche WHERE NomeEroe = @nomeEroe";
                    string     deleteFromEroe        = " DELETE FROM Eroi WHERE NomeEroe = @nomeEroe";
                    SqlCommand command = new SqlCommand();
                    command.Connection  = connection;
                    command.CommandType = System.Data.CommandType.Text;
                    command.CommandText = deleteFromStatistiche + deleteFromEroe;

                    command.Parameters.AddWithValue("@nomeEroe", obj.Nome);

                    //Eseguo

                    command.ExecuteNonQuery();
                    return(true);
                }
                catch (SqlException)
                {
                    Console.WriteLine("Siamo spiacenti, è stato rilevato un errore");
                    return(false);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Implementazione del metodo <c>Delete</c> per eliminare dal database un eroe dato un oggetto di tipo Eroe
        /// Viene eliminato il record con ID corrispondente all'ID dell'oggetto passato (ID univoco)
        /// </summary>
        /// <param name="obj">oggetto di tipo Eroe</param>
        /// <returns>Restituisce un booleano: true se è andata a buon fine l'eliminazione, false se viene generata un'eccezione </returns>
        public bool Delete(Eroe obj)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                try
                {
                    //Aprire connessione
                    connection.Open();

                    //Creare comando
                    SqlCommand deleteCommand = new SqlCommand();
                    deleteCommand.Connection  = connection;
                    deleteCommand.CommandType = System.Data.CommandType.Text;
                    deleteCommand.CommandText = "DELETE FROM Eroe WHERE ID=@Id ";


                    //Creare il parametro
                    deleteCommand.Parameters.AddWithValue("@Id", obj.ID);

                    //Esecuzione dei comandi

                    deleteCommand.ExecuteNonQuery();
                    connection.Close();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    connection.Close();
                    return(false);
                }


                return(true);
            }
        }
コード例 #5
0
        public static Mostro SceltaMostro(Eroe eroe, List <Mostro> listaMostri)
        {
            //in base al livello dell'eroe che gioca viene scelto il livello del mostro
            int           count   = 0;
            int           livello = eroe.LivelloID;
            List <Mostro> lista   = new List <Mostro>();

            //mi salvo su una lista i mostri con il livello < o = a quello del eroe
            foreach (var item in listaMostri)
            {
                if (item.LivelloID <= livello)
                {
                    lista.Add(item);
                    count++;
                }
            }
            //con un valore random viene scelto il mostro
            Random random = new Random();
            int    a      = random.Next(1, count);
            Mostro mostro = mostroService.GetMostroByID(a);

            mostro.Arma    = armaService.GetArmaByID(mostro.ArmaID);
            mostro.Classe  = classeService.GetClasseByID(mostro.ClasseID);
            mostro.Livello = livelloService.GetLivello(mostro.LivelloID);

            return(mostro);
        }
コード例 #6
0
        public bool Update(Eroe eroe)
        {
            using (SqlConnection connection = new SqlConnection(connectionstring))
            {
                //Aprire la connessione
                connection.Open();

                //Comando
                SqlCommand command = new SqlCommand();
                command.Connection  = connection;
                command.CommandType = System.Data.CommandType.Text;
                command.CommandText = "UPDATE Eroe SET PuntiAccumulati = @PuntiAccumulati, LivelloID = @LivelloID, TempoDiGioco = @TempoDiGioco, Vittoria = @Vittoria WHERE ID = @ID";

                //Aggiunta parametri
                command.Parameters.AddWithValue("@PuntiAccumulati", eroe.PuntiAccumulati);
                command.Parameters.AddWithValue("@LivelloID", eroe.LivelloID);
                command.Parameters.AddWithValue("@TempoDiGioco", eroe.TempoDiGioco);
                command.Parameters.AddWithValue("@Vittoria", eroe.Vittoria);
                command.Parameters.AddWithValue("@ID", eroe.ID);

                //Esecuzione comando
                SqlDataReader reader = command.ExecuteReader();

                //Chiusura
                reader.Close();
                connection.Close();
            }
            return(true);
        }
コード例 #7
0
        public bool UpdateTempo(Eroe eroe, int millisecondi)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                try
                {
                    //Aprire la connessione
                    connection.Open();

                    //Creo il comando
                    SqlCommand command = new SqlCommand();
                    command.Connection  = connection;
                    command.CommandType = System.Data.CommandType.Text;
                    command.CommandText = "UPDATE Statistiche SET TempoTotaleGioco += @millisecondi WHERE NomeEroe = @nome";

                    //Valori
                    command.Parameters.AddWithValue("@millisecondi", millisecondi);
                    command.Parameters.AddWithValue("@nome", eroe.Nome);


                    command.ExecuteNonQuery();
                    return(true);
                }
                catch (Exception)
                {
                    Console.WriteLine("Siamo spiacenti, è stato rilevato un errore");
                    return(false);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
コード例 #8
0
        //non finito
        public void Create(Eroe eroe)
        {
            using (SqlConnection connection = new SqlConnection(connectionstring))
            {
                //Aprire la connessione
                connection.Open();

                //Comando
                SqlCommand command = new SqlCommand();
                command.Connection  = connection;
                command.CommandType = System.Data.CommandType.Text;
                command.CommandText = "INSERT INTO Eroe VALUES (@Nome, @GiocatoreID, @ClasseID,@LivelloID,@ArmaID, @PuntiAccumulati,@Vittoria,@TempoDiGioco)";

                //Aggiunta parametri
                command.Parameters.AddWithValue("@Nome", eroe.Nome);
                command.Parameters.AddWithValue("@GiocatoreID", eroe.GiocatoreID);
                command.Parameters.AddWithValue("@ClasseID", eroe.ClasseID);
                command.Parameters.AddWithValue("@LivelloID", eroe.LivelloID);
                command.Parameters.AddWithValue("@ArmaID", eroe.ArmaID);
                command.Parameters.AddWithValue("@PuntiAccumulati", eroe.PuntiAccumulati);
                command.Parameters.AddWithValue("@Vittoria", eroe.Vittoria);
                command.Parameters.AddWithValue("@TempoDiGioco", eroe.TempoDiGioco);

                //Esecuzione comando
                //SqlDataReader reader =
                command.ExecuteNonQuery();

                //Chiusura
                //reader.Close();
                connection.Close();
            }
        }
コード例 #9
0
        //Dato un eroe (e quindi il suo livello)
        //prende la lista completa di tutti i mostri con il livello minore o ugale a quello dell'eroe e sorteggia un mostro
        //Restituisceil mostro sorteggiato
        public static Mostro SorteggioMostro(Eroe eroe)
        {
            MostroService mostroService  = serviceProvider.GetService <MostroService>();
            var           mostri         = mostroService.GetMostriByLivello(eroe.Livello).ToList();
            Random        x              = new Random();
            int           indiceEstratto = x.Next(0, mostri.Count());

            return(mostri[indiceEstratto]);
        }
コード例 #10
0
        public static bool TurnoEroe(Eroe eroe, Mostro mostro)
        {
            //ritorna true se la battaglia è finita, ritorna false se è il turno del mostro

            Console.WriteLine("Scegli:");
            Console.WriteLine("1 - Attaccare il Mostro");
            Console.WriteLine("Premi un tasto per Tentare la fuga");

            char a = Console.ReadKey().KeyChar;

            Console.WriteLine();

            switch (a)
            {
            case '1':
                bool z = eroe.AttaccareMostro(eroe, mostro);
                if (z == true)
                {
                    Console.WriteLine("Il Mostro è morto");
                    //hai vinto la battaglia
                    eroe.PuntiAccumulati += (mostro.Livello.Num * 10);
                    //Controllo sul livello
                    eroe.LivelloID = eroe.Livello.DefinizioneLivello(eroe.PuntiAccumulati);
                    eroeservice.Update(eroe);
                    if (eroe.PuntiAccumulati >= 200)
                    {
                        //l'eroe ha vinto inserire un flag
                        eroe.Vittoria = true;
                        Console.WriteLine("Vittoria!!!!!!");
                        return(true);
                    }
                    return(true);
                }
                else
                {
                    //la battaglia continua
                    return(false);
                }

            default:
                bool x = eroe.TentareFuga();
                if (x == true)
                {
                    Console.WriteLine("Tentativo riuscito sei scappato!");
                    eroe.PuntiAccumulati -= (mostro.Livello.Num * 5);
                    //battaglia finita
                    return(true);
                }
                else
                {
                    Console.WriteLine("Tentativo fallito! Turno del Mostro");
                    return(false);
                }
            }
        }
コード例 #11
0
        //METODI richiamati nel Menu Principale

        //Dato un eroe
        //Gestisce la partita dell'eroe
        public static void Partita(Eroe eroePartita)
        {
            Stopwatch watch = new Stopwatch();

            //Parte il watch
            watch.Start();
            bool continua;

            do
            {
                //Sorteggio mostro per la battaglia
                var mostro = RegoleGioco.SorteggioMostro(eroePartita);
                //Battaglia che mi restituisce l'eroe
                eroePartita = Battaglia(eroePartita, mostro);

                //Se l'eroe è morto, lo elimino dal database e termina la partita
                if (eroePartita.PuntiVita <= 0)
                {
                    RegoleGioco.EliminaEroe(eroePartita);
                    break;
                }

                //Salvo l'attuale livello dell'eroe
                int livello = eroePartita.Livello;

                //Check per il passaggio di livello viene fatto solo se il livello attuale è diverso
                //dal massimo livello disponibile (questo copre anche il caso in cui un eroe abbia già vinto)
                if (livello != livelli[livelli.Count - 1].Numero)
                {
                    eroePartita = RegoleGioco.CheckPassaggioDiLivello(eroePartita, livelli);
                }

                //Se il livello è cambiato
                if (livello != eroePartita.Livello)
                {
                    Console.WriteLine("Complimenti! Sei passato al livello {0}! \n Ora hai {1} punti vita!", eroePartita.Livello, eroePartita.PuntiVita);
                }

                if (eroePartita.PuntiAccumulati >= 200)
                {
                    Console.WriteLine("Complimenti!! HAI VINTO!!!");
                    Console.WriteLine("Puoi continuare a giocare con il tuo eroe, ma non potrai più salire di livello");
                }

                //Menu fine battaglia
                continua = ContinuaPartita(eroePartita);
            }while (continua == true);
            watch.Stop();
            int milliSecondi = (int)watch.ElapsedMilliseconds;

            if (eroePartita.PuntiVita > 0)
            {
                RegoleGioco.AggiornaStatistica(eroePartita, milliSecondi);
            }
        }
コード例 #12
0
 public void DeleteEroe(Eroe e)
 {
     if (e != null)
     {
         _repo.Delete(e);
     }
     else
     {
         Console.WriteLine("Eroe non valido");
     }
 }
コード例 #13
0
 public Eroe CreateEroe(Eroe e)
 {
     if (e != null)
     {
         _repo.Create(e);
         return(e);
     }
     else
     {
         return(null);
     }
 }
コード例 #14
0
 public Eroe GetByName(string name)
 {
     Eroe eroe = new Eroe();
     foreach (var item in eroi)
     {
         if (item.Nome == name)
         {
             eroe = item;
         }
     }
     return eroe;
 }
コード例 #15
0
 //Dato l'eroe (e quindi il suo livello) e la lista totale di livelli
 //controllo se l'eroe ha abbastanza punti accumulati per il passaggio di livello
 //Restituisce l'eroe con il passaggio di livello e il refill di punti vita
 //(se non c'è stato il passaggio di livello, restituisce l'eroe che c'è come parametro)
 public static Eroe CheckPassaggioDiLivello(Eroe eroe, List <Livello> livelli)
 {
     foreach (Livello livello in livelli)
     {
         if (livello.Numero > eroe.Livello && eroe.PuntiAccumulati >= livello.PuntiPerPassaggio)
         {
             eroe.Livello   = livello.Numero;
             eroe.PuntiVita = livello.PuntiVita;
         }
     }
     return(eroe);
 }
コード例 #16
0
 public Eroe CreateEroe(Eroe m, string nom, string u)
 {
     if (m != null)
     {
         _repo.CreateER(m, nom, u);
         return(m);
     }
     else
     {
         return(null);
     }
 }
コード例 #17
0
        //Dato un oggetto eroe come parametro
        //Crea l'eroe nel db
        public static void CreaEroe(Eroe eroe)
        {
            EroeService       eroeService       = serviceProvider.GetService <EroeService>();
            StatisticaService statisticaService = serviceProvider.GetService <StatisticaService>();

            eroeService.CreateNewEroe(eroe);
            var statistica = new Statistica(eroe)
            {
            };

            statisticaService.CreateNewStatistica(statistica);
        }
コード例 #18
0
        public bool CheckPower(FieldElement[,] field, int x, int y, int power)
        {
            if (field[x, y] == FieldElement.Diamond)
            {
                field[x, y] = FieldElement.Empty;
                Eroe.ModPower();
                return(true);
            }

            else
            {
                return(false);
            }
        }
コード例 #19
0
 public bool Update(Eroe e)
 {
     IEnumerable<Eroe> lista = GetAll();
     foreach(var item in lista)
     {
         if (item.ID == e.ID)
         {
             Delete(item);
             Create(e);
             return true;
         }
     }
     return false;
 }
コード例 #20
0
        public static Eroe Battaglia(Eroe eroe, Mostro mostro)
        {
            Console.BackgroundColor = ConsoleColor.Red;
            Console.ForegroundColor = ConsoleColor.Black;
            Console.WriteLine($"\nUn {mostro.Classe} ti blocca la strada!");
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("\nInizio battaglia!");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine($"{eroe.Nome}, {eroe.Classe}, Livello: {eroe.Livello} \tVS \t{mostro.Nome}, {mostro.Classe}, Livello: {mostro.LivelloMostro.Numero}");
            Console.ResetColor();

            bool fuga;

            do
            {
                Console.WriteLine($"\n{eroe.Nome} PV: {eroe.PuntiVita} \t\tVS\t\t {mostro.Nome} PV: {mostro.LivelloMostro.PuntiVita}");
                fuga = SceltaTurno(eroe, mostro);

                //Se non riesce la fuga/eroe attacca e se il mostro è sopravvissuto all'attacco dell'eroe
                if (fuga == false && mostro.LivelloMostro.PuntiVita > 0)
                {
                    //Attacca il mostro
                    int attaccoMostro = mostro.Attacca();
                    eroe.PuntiVita         -= attaccoMostro;
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine($"{mostro.Nome} attacca con {mostro.ArmaScelta.NomeArma}! Danno: {mostro.ArmaScelta.PuntiDanno}");
                    Console.ResetColor();
                }
            }//Si ripete finchè l'eroe e il mostro sono vivi e l'eroe non riesce nella fuga
            while ((fuga == false) && (eroe.PuntiVita > 0 && mostro.LivelloMostro.PuntiVita > 0));

            //Se l'eroe è stato sconfitto
            if (eroe.PuntiVita <= 0)
            {
                Console.WriteLine("Il tuo eroe è stato scofitto da " + mostro.Nome);
            }
            //Se il mostro è stato sconfitto
            else if (mostro.LivelloMostro.PuntiVita <= 0)
            {
                Console.WriteLine("Complimenti! Hai sconfitto " + mostro.Nome);
                //L'eroe vince punti
                int puntiVinti = mostro.LivelloMostro.Numero * 10;
                Console.WriteLine("Hai guadagnato {0} punti", puntiVinti);
                eroe.PuntiAccumulati += puntiVinti;
                Console.WriteLine("Ora hai {0} punti accumulati", eroe.PuntiAccumulati);
            }
            return(eroe);
        }
コード例 #21
0
        public static int Battaglia(Eroe eroe, Mostro mostro)
        {
            //faccio partite il conteggio del tempo di gioco dell'eroe
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            int x = 0;

            do
            {
                bool y = Partita.TurnoEroe(eroe, mostro);
                //ritorna true se la battaglia è finita, ritorna false se è il turno del mostro
                if (y == true)
                {
                    Console.WriteLine("Vuoi salvare i tuoi progressi? Premi 1, altrimenti esci dal gioco");
                    char ex = Console.ReadKey().KeyChar;
                    Console.WriteLine();
                    //stoppo il tempo e lo inserisco nel tempo di gioco dell'eroe
                    stopWatch.Stop();
                    eroe.TempoDiGioco += stopWatch.Elapsed;
                    switch (ex)
                    {
                    case '1':
                        eroeservice.Update(eroe);
                        x = 1;
                        break;

                    default: x = 1;
                        break;
                    }
                }
                else
                {
                    bool z = Partita.TurnoMostro(eroe, mostro);
                    if (z == true)
                    {
                        //la battaglia è terminata e l'eroe è morto
                        x = 1;
                    }
                    else
                    {
                        //è il turno dell'eroe
                        x = 0;
                    }
                }
            } while (x == 0);
            return(0);
        }
コード例 #22
0
        public static bool TurnoMostro(Eroe eroe, Mostro mostro)
        {
            //ritorna true se la battaglia è finita e false se è il turno del eroe

            bool y = mostro.Attacco(eroe, mostro);

            if (y == true)
            {
                //non sei morto continua la battaglia
                return(false);
            }
            //se y==false sei morto
            eroeservice.DeleteEroe(eroe);
            return(true);
        }
コード例 #23
0
ファイル: EroeTests.cs プロジェクト: ilcomand/DiamondToEscape
        public void Move(Direction direction, int startX, int startY, int expectedX, int expectedY)
        {
            Eroe eroe = new Eroe("", startX, startY);

            var field = new[, ] {
                { FieldElement.Empty, FieldElement.Empty, FieldElement.Empty },
                { FieldElement.Empty, FieldElement.Wall, FieldElement.Wall },
                { FieldElement.Wall, FieldElement.Empty, FieldElement.Empty },
                { FieldElement.Diamond, FieldElement.Diamond, FieldElement.Empty },
                { FieldElement.Empty, FieldElement.Empty, FieldElement.Diamond },
            };

            eroe.Move(direction, field);
            Assert.AreEqual(expectedX, eroe.X);
            Assert.AreEqual(expectedY, eroe.Y);
        }
コード例 #24
0
 public bool Delete(Eroe obj)
 {
     bool x = false;
     foreach(var item in eroi)
     {
         if(item == obj)
         {
             x = true;
         }
     }
     if (x == true)
     {
         eroi.Remove(obj);
     }
     return x;
     
 }
コード例 #25
0
        public static Eroe SceltaEroe(Giocatore giocatore)
        {
            var eroi       = RegoleGioco.EroiDelGiocatore(giocatore);
            var eroeScelto = new Eroe()
            {
            };

            if (eroi.Count == 0)
            {
                Console.WriteLine("Non hai ancora eroi! Torna al menù principale e creane uno!");
                return(null);
            }
            bool check;

            do
            {
                Console.WriteLine("Questi sono i tuoi eroi:\n ");
                for (int i = 1; i <= eroi.Count; i++)
                {
                    Console.WriteLine(i + " - " + eroi[i - 1].ToString());
                }
                Console.WriteLine("\nPer scegliere un eroe digita il numero corrispondente e premi invio");

                string scelta = Console.ReadLine();
                check = Int32.TryParse(scelta, out int res);
                int indiceEroe = res - 1;

                //Se il cast ha funzionato
                if (check == true)
                {
                    //Potrebbe essere un intero ma non tra gli indici
                    try
                    {
                        eroeScelto = eroi[indiceEroe];
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Scelta non valida");
                        check = false;
                    }
                }
            } while (check == false);
            return(eroeScelto);
        }
コード例 #26
0
        public static Eroe SceltaEroe(List <Eroe> eroi, Giocatore giocatore, List <Classe> listaClassi, List <Arma> listaArmi)
        {
            RicercaEroiGiocatore(giocatore, eroi);

            if (giocatore.ListaEroi.Count == 0)
            {
                Console.WriteLine("Non ci sono eroi nella tua lista, crea un eroe per giocare");
                Eroe eroe1 = CreazioneEroe(giocatore, listaClassi, listaArmi, eroi);

                return(eroe1);
            }
            else
            {
                Console.WriteLine("Gli eroi nella tua lista sono:");
                foreach (var item in giocatore.ListaEroi)
                {
                    Console.WriteLine(item.Nome);
                }
                Console.WriteLine("Scegli tra:");
                Console.WriteLine("1 - usa un eroe dalla tua lista");
                Console.WriteLine("2 - crea un eroe");
                char a = Console.ReadKey().KeyChar;
                Console.WriteLine();
                switch (a)
                {
                case '1':
                    Console.WriteLine("inserisci il nome");
                    string Nome = Console.ReadLine();
                    Eroe   eroe = eroeservice.GetEroeByName(Nome);
                    return(eroe);

                case '2':
                    Eroe eroe1 = CreazioneEroe(giocatore, listaClassi, listaArmi, eroi);
                    Eroe eroe2 = eroeservice.CreateEroe(eroe1);
                    return(eroe2);

                default:
                    Console.WriteLine("Scelta non disponibile! Torna al menù");
                    return(null);
                }
            }
        }
コード例 #27
0
        /// <summary>
        /// Implementazione del metodo <c>Create</c> per creare un nuovo eroe nel database dato un oggetto di tipo Eroe
        /// </summary>
        /// <param name="obj">oggetto di tipo Eroe</param>
        /// <returns>Restituisce un booleano: true se è andata a buon fine la creazione, false se viene generata un'eccezione</returns>
        public bool Create(Eroe obj)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                try {
                    //Aprire connessione
                    connection.Open();

                    //Creare comando
                    SqlCommand insertCommand = new SqlCommand();
                    insertCommand.Connection  = connection;
                    insertCommand.CommandType = System.Data.CommandType.Text;
                    insertCommand.CommandText = "INSERT INTO Eroe VALUES(@Nome,@IDGiocatore, @IDClasse, @IDArma, @IDLivello, @PuntiVita, @PuntiAccumulati, @TempodiGioco, @HasWon)";


                    //Creare param
                    insertCommand.Parameters.AddWithValue("@Nome", obj.Nome);
                    insertCommand.Parameters.AddWithValue("@IDGiocatore", obj.Giocatore.ID);
                    insertCommand.Parameters.AddWithValue("@IDClasse", obj.Classe.ID);
                    insertCommand.Parameters.AddWithValue("@IDArma", obj.Arma.ID);
                    insertCommand.Parameters.AddWithValue("@IDLivello", obj.Livello.ID);
                    insertCommand.Parameters.AddWithValue("@PuntiVita", obj.PuntiVita);
                    insertCommand.Parameters.AddWithValue("@PuntiAccumulati", obj.PuntiAccumulati);
                    insertCommand.Parameters.AddWithValue("@TempodiGioco", obj.TempoDiGioco);
                    insertCommand.Parameters.AddWithValue("@HasWon", obj.HasWon);

                    //Esecuzione dei comandi

                    insertCommand.ExecuteNonQuery();
                    connection.Close();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    connection.Close();
                    return(false);
                }

                return(true);
            }
        }
コード例 #28
0
        public static bool ContinuaPartita(Eroe eroe)
        {
            bool check = true;

            do
            {
                //Scelte possibili
                Console.WriteLine("\nCosa vuoi fare?");
                Console.WriteLine("1 - Salvare");
                Console.WriteLine("2 - Continuare");
                Console.WriteLine("3 - Tornare al Menù Principale (SENZA SALVARE)");

                char key = (char)Console.ReadKey().Key;

                switch (key)
                {
                case '1':
                    //Salva
                    RegoleGioco.SalvaEroe(eroe);
                    break;

                case '2':
                    //Continua
                    return(true);

                case '3':
                    break;

                default:
                    Console.WriteLine("Scelta non valida\n");
                    check = false;
                    break;
                }
            } while (check == false);

            return(false);
        }
コード例 #29
0
        public Eroe GetByName(string nome)
        {
            Eroe eroe = new Eroe();

            using (SqlConnection connection = new SqlConnection(connectionstring))
            {
                //Aprire la connessione
                connection.Open();

                //Comando
                SqlCommand command = new SqlCommand();
                command.Connection  = connection;
                command.CommandType = System.Data.CommandType.Text;
                command.CommandText = "SELECT * FROM Eroe WHERE Nome = @nome";

                //Creare il parametro
                SqlParameter param = new SqlParameter();
                param.ParameterName = "@nome";
                param.Value         = nome;
                command.Parameters.Add(param);


                //Esecuzione comando
                SqlDataReader reader = command.ExecuteReader();

                //Lettura dati
                while (reader.Read())
                {
                    eroe = reader.ToEroe();
                }

                //Chiusura
                reader.Close();
                connection.Close();
            }
            return(eroe);
        }
コード例 #30
0
        public void Create(Eroe obj)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                try
                {
                    //Aprire la connessione
                    connection.Open();

                    //Creo il comando
                    SqlCommand command = new SqlCommand();
                    command.Connection  = connection;
                    command.CommandType = System.Data.CommandType.Text;
                    command.CommandText = "INSERT INTO Eroi (NomeEroe, Classe, Arma, Livello, PuntiVita, PuntiAccumulati, NomeGiocatore) VALUES (@nome, @classe, @arma, @livello, @puntiVita, @puntiAccumulati, @giocatore)";

                    //Valori
                    command.Parameters.AddWithValue("@nome", obj.Nome);
                    command.Parameters.AddWithValue("@classe", obj.Classe);
                    command.Parameters.AddWithValue("@arma", obj.ArmaScelta.NomeArma);
                    command.Parameters.AddWithValue("@livello", obj.Livello);
                    command.Parameters.AddWithValue("@puntiVita", obj.PuntiVita);
                    command.Parameters.AddWithValue("@puntiAccumulati", obj.PuntiAccumulati);
                    command.Parameters.AddWithValue("@giocatore", obj.GiocatoreAssegnato);

                    command.ExecuteNonQuery();
                }
                catch (SqlException)
                {
                    Console.WriteLine("Siamo spiacenti, è stato rilevato un errore");
                }
                finally
                {
                    connection.Close();
                }
            }
        }