-3

i have some execution issues, where the same function is not working in the same way

while(mano.Count != 0)    // inizio partita
            {
                int count = 0;
                scelta = Convert.ToInt32(Console.Read()) -48;
                string res = cl.Colleziona(mano[scelta - 1], ID);                    
                while (res == "Non e' il tuo turno" || res.StartsWith("Il tuo avversario ha giocato: "))
                {
                    if (res.StartsWith("Il tuo avversario ha giocato: "))
                    {
                        Console.WriteLine(res + ", seleziona di nuovo una carta: ");                           
                        scelta = Convert.ToInt32(Console.Read());  //here gives the error
                        res = cl.Colleziona(mano[scelta-1], ID);
                        Console.WriteLine(res);
                        break;
                    }
                    else if (count == 0)
                    {
                        Console.WriteLine(res);
                        count++;
                    }                        
                    System.Threading.Thread.Sleep(200);
                    res = cl.Colleziona(mano[scelta - 1], ID);
                }                    
                mano.Remove(mano[scelta-1]);
                ris = cl.partita();
                while (ris == null)
                {                      
                    System.Threading.Thread.Sleep(200);
                    ris = cl.partita();              
                }

The commented function returns 13 instead of letting me input something, giving OutOfRangeException on the successive function, any solution?

Thanks

1 Answers1

0

It looks like you wanted to call Console.ReadLine. This returns the whole line as a string whereas Console.Read returns an int that represents one character at a time.

In this case, 13 represents the carriage return - you likely hit enter after typing your first bit of input.

This question covers the difference between the various Console.ReadX methods in more detail.

Community
  • 1
  • 1
Charles Mager
  • 25,735
  • 2
  • 35
  • 45