Wednesday, April 22, 2015

reusing Ifs anywere without typing it over and over

I creater a way to automatically initiate the "quit", "about" commands by using a separate method, and still have functioning gotos

Thanks guys for your time in this question.

               public static void PlayerResponse(string WL, string W)
                {
                Repeat:
                        if(WL == null)
                        {
                                
                        }
                        else
                        {
                                Text.WriteLine(WL);
                        }
                        
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write(W);
                        PlayerInfo.PlayerReply = Console.ReadLine();
                        if (List.Quit.Contains(PlayerInfo.PlayerReply.ToLower()))
                        {
                        QuitCommand:
                                Console.Write("Are you sure you want to quit? Theres something shiny there. (Y/N): ");
                                PlayerInfo.PlayerReply = Console.ReadLine();
                                if(List.affirmative.Contains(PlayerInfo.PlayerReply.ToLower()))
                                {
                                        Text.WriteLine("Goodbye, come back again.");
                                        Console.ReadLine();
                                        Environment.Exit(0);
                            }
                                else if (List.negative.Contains(PlayerInfo.PlayerReply.ToLower()))
                                {
                                        Text.WriteLine("I'd knew you lost your mind there for a second. :)");
                                        Console.ReadLine();
                                        goto Repeat;
                                }
                                else
                                {
                                        Text.WriteLine("I don't understand you...");
                                        Console.ReadLine();
                                        goto QuitCommand;
                                }
                                
                        }
                        else if (List.About.Contains(PlayerInfo.PlayerReply.ToLower()))
                        {
                                MessageBox.Show("Created by: Derrick Timmermans\nProgramming by: Derrick Timmermans\nStoryboard by: ...");
                                goto Repeat;
                        }
                }


No comments:

Post a Comment