public Console GetConsole(CONSOLE consoleType)
    {
        switch (consoleType)
        {
        case CONSOLE.NINTENDO:
            return(nintendo);

        case CONSOLE.SONY:
            return(sony);

        case CONSOLE.MICROSOFT:
            return(microsoft);

        case CONSOLE.SEGA:
            return(sega);

        case CONSOLE.PC:
            return(pc);

        case CONSOLE.OTHER:
            return(other);

        default:
            Debug.LogError("Unknown console " + consoleType);
            return(null);
        }
    }
Пример #2
0
        /// <summary>
        /// Removes the current Player from its Team
        /// </summary>
        /// <param name="player">Player to remove</param>
        private void RemovePlayer(Player player)
        {
            // Little verification : we ask the user to validate his action
            if (Choice_Prefabs.CHOICE_REMOVEPLAYER.GetChoice() == 0)
            {
                // Asking to remove the Player
                Instructions instruction = Instructions.Team_RemovePlayer;
                Net.COMMUNICATION.Send(comm.GetStream(), new Communication(instruction, player));

                // We receive whether it work or not
                if (Net.BOOL.Receive(comm.GetStream()))
                {
                    // We remove the Player from its Team
                    player.team.players.Remove(player);

                    // We display a message accordingly
                    CONSOLE.WriteLine(ConsoleColor.Green, "Player " + player.name + " removed !");
                }
                else
                {
                    // We display a message accordingly
                    CONSOLE.WriteLine(ConsoleColor.Red, "Player " + player.name + "was not removed...");
                }
                CONSOLE.WaitForInput();
            }
        }
Пример #3
0
        /// <summary>
        /// 播放MadeWithDestroy的动画
        /// </summary>
        /// <param name="center">是否居中显示</param>
        /// <param name="x">横向坐标</param>
        /// <param name="y">纵向坐标</param>
        /// <param name="consoleKey">按键</param>
        public static void MadeWithDestroy(bool center, short x, short y, ConsoleKey consoleKey = ConsoleKey.Enter)
        {
            string logo = "Made with Destroy";

            if (center)
            {
                x  = (short)(CONSOLE.WindowWidth / 2);
                x -= (short)(logo.Length / 2);
                y  = (short)(CONSOLE.WindowHeight / 2);
            }
            CONSOLE.SetCursorPosition(x, y);
            CONSOLE.ForegroundColor = Colour.Black;
            CONSOLE.BackgroundColor = Colour.White;
            CONSOLE.Write(logo);
            CONSOLE.ResetColor();
            CONSOLE.SetCursorPosition(0, 0);
            //窗口透明度渐变
            for (int i = 0; i < 256; i++)
            {
                //按下回车键直接恢复透明度并且退出渐变阶段
                if (CONSOLE.GetKey(consoleKey))
                {
                    KERNEL.SET_WINDOW_ALPHA(255);
                    break;
                }
                KERNEL.SET_WINDOW_ALPHA((byte)i);
                KERNEL.SLEEP(10);
            }
            KERNEL.SLEEP(1000);
            CONSOLE.Clear();
        }
Пример #4
0
        /// <summary>
        /// 构建控制台
        /// </summary>
        /// <param name="consoleType">控制台类型</param>
        /// <param name="bold">字体粗细</param>
        /// <param name="maximum">最大化</param>
        /// <param name="width">宽度</param>
        /// <param name="height">高度</param>
        /// <param name="title">标题</param>
        /// <returns>是否成功</returns>
        public static void Construct(ConsoleType consoleType, bool bold, bool maximum,
                                     short width, short height, string title = "Destroy")
        {
            SetConsoleSetting(title);

            switch (consoleType)
            {
            case ConsoleType.Default:
                SetFontAndWindow("Consolas", bold, 16, 16, maximum, width, height);
                break;

            case ConsoleType.Chinese:
                SetFontAndWindow("新宋体", bold, 16, 16, maximum, width, height);
                break;

            case ConsoleType.Pixel:
                SetFontAndWindow("Terminal", bold, 8, 8, maximum, width, height);
                break;

            case ConsoleType.HignQuality:
                SetFontAndWindow("MS Gothic", bold, 1, 1, maximum, width, height);
                break;
            }

            if (maximum)
            {
                KERNEL.SET_WINDOW_POS(0, 0);
            }
            else
            {
                CONSOLE.CenterConsoleWindowPosition();
            }
            CONSOLE.CursorVisible = false;
        }
Пример #5
0
        /// <summary>
        /// Sends a Coach of which we know the id
        /// </summary>
        /// <param name="id">Id of the Coach we seek</param>
        public void GetCoachById(Guid id)
        {
            // Writing a Log in the Console
            CONSOLE.WriteLine(ConsoleColor.Yellow, "Coach's id : " + id);

            // We send the default Coach if no match was found / the correct one if a match was found
            Net.COACH.Send(comm.GetStream(), Database.COACH.GetById(id));
        }
Пример #6
0
        /// <summary>
        /// Sends a Coach of which we know the name
        /// </summary>
        /// <param name="name">name of the Coach we seek</param>
        public void GetCoachByName(string name)
        {
            // Writing a Log in the Console
            CONSOLE.WriteLine(ConsoleColor.Yellow, "Coach's name : " + name);

            // We send the default Coach if no match was found / the correct one if a match was found
            Net.COACH.Send(comm.GetStream(), Database.COACH.GetByName(name));
        }
Пример #7
0
        /// <summary>
        /// When a Client logs off
        /// </summary>
        /// <param name="communication"> communication Logged Off </param>
        private void LogOut(TcpClient communication)
        {
            // A client has logged off, but is still present
            CONSOLE.WriteLine(ConsoleColor.Red, "Logged Out @" + communication);

            cptCoachessLoggedIn--;

            DisplaySituation();
        }
Пример #8
0
        /// <summary>
        /// When a Coach logs in
        /// </summary>
        /// <param name="communication"> communication Logged in </param>
        private void LogIn(TcpClient communication)
        {
            // A client has logged in
            CONSOLE.WriteLine(ConsoleColor.Green, "Logged In @" + communication);

            cptCoachessLoggedIn++;

            DisplaySituation();
        }
Пример #9
0
 /// <summary>
 /// 设置控制台设置
 /// </summary>
 /// <param name="title">控制台标题</param>
 public static void SetConsoleSetting(string title)
 {
     //以下2方法必须在设置字体前使用:
     //设置标准调色盘
     CONSOLE.SetStdConsolePalette(CONSOLE.OutputHandle);
     //设置标准控制台模式
     CONSOLE.SetStdConsoleMode(CONSOLE.OutputHandle, CONSOLE.InputHandle);
     CONSOLE.InputEncoding  = Encoding.UTF8;
     CONSOLE.OutputEncoding = Encoding.UTF8;
     CONSOLE.Title          = title;
 }
Пример #10
0
        public void Start()
        {
            Console.Write(" Server launched !\n\n");

            // We create and initialize a Listener
            TcpListener listener = new TcpListener(new IPAddress(new byte[] { 127, 0, 0, 1 }), port);

            listener.Start();


            cptCoachessLoggedIn = 0;
            receivers           = new List <Receiver>();


            // Filling the database
            // Database.FillDatabase();


            while (true)
            {
                // Coucou, j'écoute si un Client se connecte
                TcpClient comm = listener.AcceptTcpClient();

                // Oh tiens, un client s'est connecté
                CONSOLE.WriteLine(ConsoleColor.DarkGreen, "Connection established @" + comm);


                // Je récupère ses infos...
                Receiver receiver = new Receiver(this, comm);

                // ... J'initialise quelques events...
                receiver.When_Server_Exit   += EndingCommunication;
                receiver.When_Server_LogIn  += LogIn;
                receiver.When_Server_LogOff += LogOut;

                receiver.When_Coach_Create    += CoachCreate;
                receiver.When_Team_Create     += TeamCreate;
                receiver.When_Player_Create   += PlayerCreate;
                receiver.When_Player_Remove   += PlayerRemove;
                receiver.When_Player_LevelsUp += PlayerLevelsUp;


                // ... et je lance une connexion avec le serveur
                new Thread(receiver.DoOperation).Start();

                // Je garde la connexion en mémoire dans une Liste de Receiver
                receivers.Add(receiver);

                // On affiche les informations dans la console
                DisplaySituation();

                // Et hop, je retourne écouter si un Client se connecte...
            }
        }
Пример #11
0
        /// <summary>
        /// Manage a given Player
        /// </summary>
        /// <param name="player">Player we are managing</param>
        private void ManagePlayer(Player player)
        {
            bool continuingPlayer = true;

            while (continuingPlayer)
            {
                // CHOICE
                // We dynamically create a List containing all the players names
                List <string> choiceString = new List <string>();
                choiceString.Add("See Data");

                if (player.hasNewLevel)
                {
                    choiceString.Add("New Level !");
                }

                // We add another choice : "Remove Player"
                choiceString.Add("Remove Player");

                // We add a last choice: "Go Back"
                choiceString.Add("Go Back");

                // We create the Choice
                Choice c     = new Choice("please Select an action for " + player.name + " (last one = leave) : ", choiceString);
                int    index = c.GetChoice();


                // Since we have a dynamic attribution of choices, the on-going program is quite... messy

                // If it is the first choice : SEE DATA
                if (index == 0)
                {
                    Console.WriteLine(player);
                    CONSOLE.WaitForInput();
                }
                // If it is the second choice AND the player has a new level : NEW LEVEL
                else if (index == 1 && player.hasNewLevel)
                {
                    PlayerLevelsUp(player);
                }
                // If it is the last choice : GO BACK
                else if (index == choiceString.Count - 1)
                {
                    continuingPlayer = false;
                }
                // Otherwise : REMOVE PLAYER
                else
                {
                    RemovePlayer(player);
                }
            }
        }
Пример #12
0
        /// <summary>
        /// Ensures the user Logs Out of the Softare (but remains to the Log In / Sign In menu)
        /// </summary>
        private void LogOut()
        {
            // Display a Farewell message
            CONSOLE.WriteLine(ConsoleColor.Blue, "\n\n     Goodbye ! We hope to see you soon :)\n\n");

            // Resetting the user's Data : no user is logged in anymore
            userData = new Coach();

            // Warning the server we log out
            Instructions instruction = Instructions.LogOut;
            Object       content     = null;

            Net.COMMUNICATION.Send(comm.GetStream(), new Communication(instruction, content));
        }
Пример #13
0
        /// <summary>
        /// A panel saying goodbye to the user
        /// </summary>
        private void PanelExitSoftware()
        {
            // Displaying a farewell message
            Console.Clear();
            CONSOLE.WriteLine(ConsoleColor.Blue, "\n\n\n      Goodbye !! We hope to see you soon :)");

            // Warning the server we leave the software
            Instructions instruction = Instructions.Exit_Software;
            Object       content     = null;

            Net.COMMUNICATION.Send(comm.GetStream(), new Communication(instruction, content));


            // Environment.Exit(0);
        }
Пример #14
0
 private void CONSOLE_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
 {
     if (BUT.IsEnabled == false)
     {
         if (e.Key == System.Windows.Input.Key.Return)
         {
             Button_Click_1(sender, e);
             CONSOLE.ScrollToEnd();
         }
     }
     else
     {
         MessageBox.Show("먼저 서버에 연결해 주세요");
         CONSOLE.Text = "";
     }
 }
Пример #15
0
        /// <summary>
        /// When a Client stops the communication with the server
        /// </summary>
        /// <param name="communication"></param>
        private void EndingCommunication(TcpClient communication)
        {
            // A client has disconnected the software
            CONSOLE.WriteLine(ConsoleColor.DarkRed, "Connection stopped @" + communication);

            // We remove the Receiver communication from our list
            foreach (Receiver receiver in receivers)
            {
                if (receiver.comm == communication)
                {
                    receivers.Remove(receiver);
                    break;
                }
            }

            DisplaySituation();
        }
Пример #16
0
        /// <summary>
        /// A panel displaying all options a user can perform while logged to the program (Topic / Chat)
        /// </summary>
        private void PanelConnected()
        {
            bool continuingConnection = true;

            while (continuingConnection)
            {
                int choice = Choice_Prefabs.CHOICE_CONNECTED.GetChoice();
                switch (choice)
                {
                // COACH
                case 0:
                    DisplayCoach(userData);
                    break;

                // LEAGUE
                case 1:
                    CONSOLE.WriteLine(ConsoleColor.Magenta, "Not yet implemented !");
                    break;

                case 2:
                    CONSOLE.WriteLine(ConsoleColor.Magenta, "Not yet implemented !");
                    break;

                // TEAM
                case 3:
                    PanelTeams();
                    break;

                case 4:
                    NewTeam();
                    break;

                // LOG OUT
                case 5:
                    LogOut();
                    continuingConnection = false;
                    break;

                default:
                    Console.WriteLine("Error at the Main menu");
                    break;
                }

                CONSOLE.WaitForInput();
            }
        }
Пример #17
0
        /// <summary>
        /// 构建控制台
        /// </summary>
        /// <param name="fontName">字体名字</param>
        /// <param name="bold">字体粗细</param>
        /// <param name="fontWidth">字体宽度</param>
        /// <param name="fontHeight">字体高度</param>
        /// <param name="maximum">最大化</param>
        /// <param name="width">宽度</param>
        /// <param name="height">高度</param>
        /// <param name="title">标题</param>
        public static void Construct(string fontName, bool bold, short fontWidth, short fontHeight,
                                     bool maximum, short width, short height, string title = "Destroy")
        {
            SetConsoleSetting(title);

            SetFontAndWindow(fontName, bold, fontWidth, fontHeight, maximum, width, height);

            if (maximum)
            {
                KERNEL.SET_WINDOW_POS(0, 0);
            }
            else
            {
                CONSOLE.CenterConsoleWindowPosition();
            }
            CONSOLE.CursorVisible = false;
        }
Пример #18
0
        internal static void CheckMouseState()
        {
            bool r = KERNEL.READ_CONSOLE_INPUT(CONSOLE.InputHandle,
                                               out short cursorPosX, out short cursorPosY);

            if (r)
            {
                CursorPosition = new Vector2(cursorPosX, cursorPosY);
            }

            KERNEL.GET_CURSOR_POS(out int mousePosX, out int mousePosY);

            MousePosition  = new Vector2(mousePosX, mousePosY);
            ConsoleInFocus = KERNEL.GET_WINDOW_IN_FOCUS();
            //判断鼠标是否则在控制台窗口内
            KERNEL.GET_WINDOW_POS(out int windowPosX, out int windowPosY);
            KERNEL.GET_WINDOW_SIZE(out int width, out int height);
            if (mousePosX >= windowPosX && mousePosX < windowPosX + width &&
                mousePosY >= windowPosY && mousePosY < windowPosY + height)
            {
                MouseInConsole = true;
            }
            else
            {
                MouseInConsole = false;
            }

            //鼠标坐标=>控制台坐标
            if (MouseInConsole)
            {
                KERNEL.SCREEN_TO_CLIENT(CONSOLE.ConsoleWindowHandle, ref mousePosX, ref mousePosY);

                CONSOLE.GetConsoleFont(CONSOLE.OutputHandle, out bool bold,
                                       out short fontWidth, out short fontHeight, out string fontName);

                MousePositionInConsole = new Vector2(mousePosX / fontWidth, mousePosY / fontHeight);
            }
        }
Пример #19
0
        /// <summary>
        /// A panel displaying all options a user can perform while logged to the program (Topic / Chat)
        /// </summary>
        private void PanelTeam(Team team)
        {
            bool continuingTeam = true;

            while (continuingTeam)
            {
                int choice = Choice_Prefabs.CHOICE_TEAM.GetChoice();
                switch (choice)
                {
                // display data
                case 0:
                    DisplayTeam(team);
                    break;

                // manage Players
                case 1:
                    ManagePlayers(team);
                    break;

                // buy Players
                case 2:
                    NewPlayer(team);
                    break;

                // Go Back
                case 3:
                    continuingTeam = false;
                    break;

                default:
                    Console.WriteLine("Error at the detailled Team menu");
                    break;
                }

                CONSOLE.WaitForInput();
            }
        }
Пример #20
0
        public static void SetFontAndWindow(string fontName, bool bold, short fontWidth, short fontHeight, bool maximum, short width, short height)
        {
            CONSOLE.SetConsoleFont(CONSOLE.OutputHandle, bold, fontWidth, fontHeight, fontName);

            KERNEL.GET_LARGEST_CONSOLE_WINDOW_SIZE(CONSOLE.OutputHandle,
                                                   out short largestWidth, out short largestHeight);

            if (maximum)
            {
                width  = largestWidth;
                height = largestHeight;
            }
            else if (width > largestWidth || height > largestHeight)
            {
                Error.Pop("specific width/height is too big!");
            }

            //如果发生报错, 尝试使用或禁用下面这行代码
            KERNEL.SET_CONSOLE_WINDOW_SIZE(CONSOLE.OutputHandle, 1, 1);
            CONSOLE.BufferWidth  = width;
            CONSOLE.WindowWidth  = width;
            CONSOLE.BufferHeight = height;
            CONSOLE.WindowHeight = height;
        }
Пример #21
0
        /// <summary>
        /// Creates a new Team
        /// </summary>
        private void NewTeam()
        {
            bool   continueNewTeam = true;
            string errorMessage    = "";

            while (continueNewTeam)
            {
                // Displaying some messages
                Console.Clear();
                CONSOLE.WriteLine(ConsoleColor.Blue, "\n   Enter empty fields to leave the Creation of the new TEAM");


                // Displays a message if the credentials are incorrect
                CONSOLE.WriteLine(ConsoleColor.Red, errorMessage);


                // NAME
                Console.Write("\n Please enter the name of the Team : ");
                string name = Console.ReadLine();


                // DESCRIPTION
                Console.Write("\n Please enter the description of the Team  : ");
                string description = Console.ReadLine();


                // All the fields are empty : go back to the menu
                if (name.Length == 0 && description.Length == 0)
                {
                    continueNewTeam = false;
                }
                // One of the field is empty : error
                else if (name.Length == 0 || description.Length == 0)
                {
                    errorMessage = PrefabMessages.INCOMPLETE_FIELDS;
                }
                else if (name.Length > PrefabMessages.INPUT_MAXSIZE_STRUCTURE_NAME ||
                         description.Length > PrefabMessages.INPUT_MAXSIZE_STRUCTURE_DESCRIPTION)
                {
                    errorMessage = PrefabMessages.INCORRECT_INPUT_SIZE;
                }
                // If at least one field has one incorrect character : ERROR
                else if (!Util.CorrectInput(name) || !Util.CorrectInput(description))
                {
                    errorMessage = PrefabMessages.INCORRECT_INPUT_CHARACTER;
                }
                // Otherwise : continue the protocol by choosing a Race
                else
                {
                    // We create a list of all the Races
                    List <Race> races = RaceStuff.GetAllRaces();

                    // CHOICE
                    // We dynamically create a List containing all the Race's name
                    List <string> choiceString = new List <string>();
                    races.ForEach(r => choiceString.Add(r.name()));

                    // We add as a last choice the option to cancel the protocol
                    choiceString.Add("Cancel the creation");


                    // We create the Choice
                    Choice choice = new Choice("please Select a Race (last one = cancel) : ", choiceString);
                    int    index  = choice.GetChoice();

                    // The user chose a Race
                    if (index != choiceString.Count - 1)
                    {
                        // We get the race chose by the user
                        Race race = races[index];

                        // Sending the new Team
                        Instructions instruction = Instructions.Team_New;
                        Team         newTeam     = new Team(name, description, race, userData);
                        Net.COMMUNICATION.Send(comm.GetStream(), new Communication(instruction, newTeam));

                        // We receive the id of the Team from the server
                        Guid idReceived = Net.GUID.Receive(comm.GetStream());

                        // We see if the id received is valid
                        if (idReceived != Guid.Empty)
                        {
                            // We set the received id
                            newTeam.id = idReceived;

                            // We add the Player to the user's team
                            userData.teams.Add(newTeam);

                            // We display a success message
                            CONSOLE.WriteLine(ConsoleColor.Green, PrefabMessages.TEAM_CREATION_SUCCESS);

                            // Ending the loop
                            continueNewTeam = false;
                        }
                        else
                        {
                            errorMessage = PrefabMessages.TEAM_CREATION_FAILURE;
                        }
                    }
                    // The user chose to leave
                    else
                    {
                        continueNewTeam = false;
                    }
                }
            }
        }
Пример #22
0
        /// <summary>
        /// Server's HUB : it does stuff.
        /// </summary>
        public void DoOperation()
        {
            while (true)
            {
                // We receive a Communication from the client
                Communication communication = Net.COMMUNICATION.Receive(comm.GetStream());

                // We extract the data
                Instructions instruction = communication.instruction;
                Object       content     = communication.content;

                // We display the instruction
                CONSOLE.WriteLine(ConsoleColor.Cyan, "\nINSTRUCTION : " + instruction);

                // According to the instruction, we'll do a specific action
                switch (instruction)
                {
                case Instructions.Exit_Software:
                    // We raise the event : a user left the software
                    When_Server_Exit?.Invoke(comm);
                    break;



                // CREDENTIALS
                case Instructions.LogIn:
                    if (LogIn((Credentials)content))
                    {
                        // We raise the event : a user has logged in
                        When_Server_LogIn?.Invoke(comm);
                    }
                    break;

                case Instructions.SignIn:
                    // We get the profile Signed In
                    CoachWithPassword newCoach = SignIn((CoachWithPassword)content);

                    // If the Profile's ID is not Empty (means that the Sign In was successful)
                    if (newCoach.id != Guid.Empty)
                    {
                        // We raise the event : a user has logged in
                        When_Server_LogIn?.Invoke(comm);

                        // We raise the event : a Profile has been created
                        When_Coach_Create(newCoach);
                    }
                    break;

                case Instructions.LogOut:
                    LogOut();
                    // We raise the event : a user has logged off
                    When_Server_LogOff?.Invoke(comm);
                    break;



                // COACH
                case Instructions.Coach_GetById:
                    GetCoachById((Guid)content);
                    break;



                // TEAM
                case Instructions.Team_New:
                    // We get the newly created Team
                    Team newTeam = NewTeam((Team)content);

                    // If the Team can be created (ID is not empty)
                    if (newTeam.IsComplete)
                    {
                        // We raise the event : a Team has been created
                        When_Team_Create?.Invoke(newTeam);
                    }
                    break;

                case Instructions.Team_AddPlayer:
                    // We get the newly created Player
                    Player newPlayer = NewPlayer((Player)content);

                    // If the Player can be created (ID is not empty)
                    if (newPlayer.IsComplete)
                    {
                        // We raise the event : a Player has been created
                        When_Player_Create?.Invoke(newPlayer);
                    }
                    break;

                case Instructions.Team_RemovePlayer:
                    // We get the Player to remove
                    Player playerToRemove = (Player)content;

                    // We remove him from the database
                    playerToRemove = RemovePlayer(playerToRemove);

                    // If the removal was successful)
                    if (playerToRemove.IsComplete)
                    {
                        // We raise the event : a Player has been removed
                        When_Player_Remove?.Invoke(playerToRemove);
                    }
                    break;



                // PLAYER
                case Instructions.Player_LevelUp:
                    // We get the Player to remove
                    Player player = (Player)content;

                    // We add a new Effect to the player
                    Effect?newEffect = PlayerLevelsUp(player);

                    // If a new effect was chosen
                    if (newEffect != null)
                    {
                        // We add the effect to the Player
                        player.effects.Add((Effect)newEffect);

                        // We raise the event : an Effect has been added
                        When_Player_LevelsUp?.Invoke(player);
                    }
                    break;


                // otherwise : Error (should not occur, but we're not taking any chance)
                default:
                    CONSOLE.WriteLine(ConsoleColor.Red, "Message instruction not understood : " + instruction);
                    break;
                }
            }
        }
Пример #23
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Context.User.Identity.GetUserId() != "190d22ec-44a8-4bf4-9579-0365a6b5af3e")
            {
                Response.Redirect("/Publib");
                return;
            }

            string CONSOLE;
            string qs = "";

            try
            {
                qs      = Request.QueryString["c"];
                CONSOLE = qs;
            }
            catch (Exception)
            {
                CONSOLE = "GBC";
                return;
            }


            HtmlDocument basepage = new HtmlAgilityPack.HtmlDocument();
            WebClient    cli      = new WebClient();

            cli.Encoding = System.Text.Encoding.UTF8;       // Atenção ao encoding!
            if (CONSOLE.Equals("NES"))
            {
                basepage.LoadHtml(cli.DownloadString("http://nintendo.wikia.com/wiki/List_of_Nintendo_Entertainment_System_games"));                            // Seleção de consola
            }
            else if (CONSOLE.Equals("GB"))
            {
                basepage.LoadHtml(cli.DownloadString("http://nintendo.wikia.com/wiki/List_of_Game_Boy_games"));
            }
            else if (CONSOLE.Equals("GBC"))
            {
                basepage.LoadHtml(cli.DownloadString("http://nintendo.wikia.com/wiki/List_of_Game_Boy_Color_games"));
            }
            else if (CONSOLE.Equals("GBA"))
            {
                basepage.LoadHtml(cli.DownloadString("http://nintendo.wikia.com/wiki/List_of_Game_Boy_Advance_games"));
            }
            else if (CONSOLE.Equals("SMS"))
            {
                basepage.LoadHtml(cli.DownloadString("http://segaretro.org/List_of_Master_System_games"));
            }

            int           count      = 0;
            List <string> gametitles = new List <string>();

            if (CONSOLE.Equals("NES") || CONSOLE.Equals("GBC") || CONSOLE.Equals("GB") || CONSOLE.Equals("GBA"))              // Se for selecionada uma consola da nintendo, então utilizar a fonte nintendo.wikia.com
            {
                foreach (HtmlNode game_table in basepage.DocumentNode.SelectNodes("//table[@class='wikitable sortable']/tr")) // Percorrer todas as linhas das tabelas
                {
                    HtmlNodeCollection nodes     = game_table.ChildNodes;
                    string             gametitle = HttpUtility.HtmlDecode(nodes[1].InnerText);
                    System.Diagnostics.Debug.WriteLine(gametitle);
                    string  gameurl     = "";
                    int     gameurl_len = 0;
                    Boolean updated     = false;

                    HtmlAttributeCollection attribs = (nodes[1].ChildNodes)[0].Attributes;
                    foreach (HtmlAttribute attrib in attribs)
                    {
                        if (attrib.Name.Equals("href"))
                        {
                            gameurl     = attrib.Value;
                            gameurl_len = gameurl.Length;
                            break;
                        }
                    }

                    if (gameurl_len > 8 && gameurl.Substring(gameurl_len - 9).Equals("redlink=1"))
                    {
                        continue;                                                                            // Ignorar se se tratar de um redlink (página não existente na wiki)
                    }
                    if (gameurl.Equals(""))
                    {
                        continue;
                    }
                    if (gametitles.Contains(gametitle.Replace('é', 'e')))
                    {
                        continue;
                    }
                    gametitles.Add(gametitle.Replace('é', 'e'));

                    List <string> genres = new List <string>();

                    try
                    {
                        genres  = fetchGenre(gameurl, "nintendo");      // Obter o género
                        updated = true;
                    }
                    catch (Exception)
                    { }


                    if (!updated)               // Caso não tenha sido possível, então iremos alterar ligeiramente o URL
                    {
                        try
                        {
                            if (CONSOLE.Equals("NES"))
                            {
                                genres  = fetchGenre(gameurl + "_(NES)", "nintendo");
                                gameurl = gameurl + "_(NES)";
                            }
                            else if (CONSOLE.Equals("GBC"))
                            {
                                genres  = fetchGenre(gameurl + "_(GBC)", "nintendo");
                                gameurl = gameurl + "_(GBC)";
                            }
                            else if (CONSOLE.Equals("GB"))
                            {
                                genres  = fetchGenre(gameurl + "_(GB)", "nintendo");
                                gameurl = gameurl + "_(GB)";
                            }
                            else if (CONSOLE.Equals("GBA"))
                            {
                                genres  = fetchGenre(gameurl + "_(GBA)", "nintendo");
                                gameurl = gameurl + "_(GBA)";
                            }
                            updated = true;
                        }
                        catch (Exception) { }
                    }

                    if (!updated)        // Caso não tenha sido possível, então iremos alterar novamente o URL
                    {
                        try
                        {
                            if (CONSOLE.Equals("NES"))
                            {
                                genres  = fetchGenre(gameurl + "_(Famicom)", "nintendo");
                                gameurl = gameurl + "_(Famicom)";
                            }
                            else if (CONSOLE.Equals("GB"))
                            {
                                genres  = fetchGenre(gameurl + "_(Game_Boy)", "nintendo");
                                gameurl = gameurl + "_(Game_Boy)";
                            }
                            else if (CONSOLE.Equals("GBC"))
                            {
                                genres  = fetchGenre(gameurl + "_(Game_Boy_Color)", "nintendo");
                                gameurl = gameurl + "_(Game_Boy_Color)";
                            }
                            else if (CONSOLE.Equals("GBA"))
                            {
                                genres  = fetchGenre(gameurl + "_(Game_Boy_Advance)", "nintendo");
                                gameurl = gameurl + "_(Game_Boy_Advance)";
                            }
                            updated = true;
                        }
                        catch (Exception) { }
                    }

                    if (!updated)               // e novamente
                    {
                        try
                        {
                            genres  = fetchGenre(gameurl + "_(video_game)", "nintendo");
                            gameurl = gameurl + "_(video_game)";
                            updated = true;
                        }
                        catch (Exception) { }
                    }

                    if (!updated)
                    {
                        try
                        {
                            genres  = fetchGenre(gameurl + "_(game)", "nintendo");
                            gameurl = gameurl + "_(game)";
                            updated = true;
                        }
                        catch (Exception) { }
                    }



                    String genrestring;
                    if (!updated)
                    {
                        continue;               // Se não tiver sido encontrada informação, passar para o próximo elemento da tabela.
                    }
                    else if (genres.Count == 1 && genres[0].Equals("") || (genres.Count == 0 && CONSOLE.Equals("GB")))
                    {
                        genrestring = "unavailable";
                    }
                    else
                    {
                        genrestring = "";
                        foreach (string g in genres)
                        {
                            genrestring += (g + " & ");
                        }
                        genrestring = genrestring.Remove(genrestring.Length - 3);
                    }


                    gametitle = fixGameTitle(gametitle);

                    if (CONSOLE.Equals("NES"))  // Lista de jogos da NES cujo formato dos metadados não respeita o regular
                    {
                        if (gameurl.Equals("/wiki/Mother") || gameurl.Equals("/wiki/Dark_Lord") || gameurl.Equals("/wiki/Tecmo_Super_Bowl") || gameurl.Equals("/wiki/DuckTales_2") ||
                            gameurl.Equals("/wiki/Monster_Party") || gameurl.Equals("/wiki/Bigfoot") || gameurl.Equals("/wiki/Snake%27s_Revenge") || gameurl.Equals("/wiki/The_Simpsons:_Bart_vs._the_Space_Mutants") ||
                            gameurl.Equals("/wiki/Blackjack")
                            )
                        {
                            continue;
                        }
                    }

                    else if (CONSOLE.Equals("GB")) // Lista de jogos de Gameboy cujo formato dos metadados não respeita o regular
                    {
                        if (gameurl.Equals("/wiki/Tetris_(Game_Boy)") || gameurl.Equals("/wiki/Game_Boy_Camera") || gameurl.Equals("/wiki/Who_Framed_Roger_Rabbit") ||
                            gameurl.Equals("/wiki/Exodus:_Journey_to_the_Promised_Land") || gameurl.Equals("/wiki/Star_Trek:_25th_Anniversary") || gameurl.Equals("/wiki/Swamp_Thing") ||
                            gameurl.Equals("/wiki/Disney%27s_The_Little_Mermaid") || gameurl.Equals("/wiki/Robin_Hood:_Prince_of_Thieves") || gameurl.Equals("/wiki/Top_Rank_Tennis") ||
                            gameurl.Equals("/wiki/Earthworm_Jim_(handheld)") || gameurl.Equals("/wiki/NHL_Hockey_%2795") || gameurl.Equals("/wiki/Super_Star_Wars:_Return_of_the_Jedi") ||
                            gameurl.Equals("/wiki/NHL_96_(Game_Boy)") || gameurl.Equals("/wiki/Pinocchio") || gameurl.Equals("/wiki/Popeye") || gameurl.Equals("/wiki/Hatris") ||
                            gameurl.Equals("/wiki/R-Type") || gameurl.Equals("/wiki/World_Ice_Hockey") || gameurl.Equals("/wiki/Spy_vs._Spy") || gameurl.Equals("/wiki/Alfred_Chicken") ||
                            gameurl.Equals("/wiki/Pocket_Bomberman"))
                        {
                            continue;
                        }
                    }


                    else if (CONSOLE.Equals("GBC")) // Lista de jogos de Gameboy Color cujo formato dos metadados não respeita o regular
                    {
                        if (gameurl.Equals("/wiki/Hugo") || gameurl.Equals("/wiki/Scrabble") || gameurl.Equals("/wiki/Checkmate"))
                        {
                            continue;
                        }
                        if (gameurl.Equals("/wiki/Rayman"))
                        {
                            gameurl = "/wiki/Rayman_(video_game)";
                        }
                    }

                    else if (CONSOLE.Equals("GBA")) // Lista de jogos de Gameboy Advance cujo formato dos metadados não respeita o regular
                    {
                        if (gameurl.Equals("/wiki/Golden_Sun") || gameurl.Equals("/wiki/NFL_Blitz_20-03") || gameurl.Equals("/wiki/Rocky") ||
                            gameurl.Equals("/wiki/Wade_Hixton%27s_Counter_Punch") || gameurl.Equals("/wiki/The_Ant_Bully"))
                        {
                            continue;
                        }
                    }


                    addtoDB(gametitle.Trim(), gameurl, genres, CONSOLE);
                    Tuple <string, string, string, string> gamedata = scrapGameData(gameurl, CONSOLE);
                    gamedata = fixExceptions(gamedata, gametitle, gameurl);

                    datacontainer.InnerHtml += "<tr><td>" + gametitle + "</td><td>" + gameurl + "</td><td>" + genrestring + "</td><td>" + gamedata.Item3 + "</td><td>" + gamedata.Item4 + "</td><td>" + gamedata.Item2 + "</td><td><img src=\"" + gamedata.Item1 + "\"/></td></tr>";

                    count++;
                }
            }
            else if (CONSOLE.Equals("SMS"))             // Obter lista de jogos da Sega Master System. Fonte: segaretro.org
            {
                foreach (HtmlNode game_table in basepage.DocumentNode.SelectNodes("//table[@class='prettytable sortable'][1]/tr[position()>1]"))
                {
                    string gameurl   = "";
                    string gametitle = "";

                    HtmlNodeCollection nodes = game_table.ChildNodes[1].ChildNodes;
                    foreach (HtmlNode node in nodes)
                    {
                        HtmlNodeCollection subnodes = node.ChildNodes;
                        foreach (HtmlNode subnode in subnodes)
                        {
                            foreach (HtmlAttribute attr in subnode.Attributes)
                            {
                                if (attr.Name.Equals("href"))
                                {
                                    gameurl = attr.Value;
                                }
                            }
                            gametitle = subnode.InnerText;
                        }
                    }
                    List <string> genres = fetchGenre(gameurl, "sega");

                    String genrestring;
                    if (genres.Count == 1 && genres[0].Equals(""))
                    {
                        genrestring = "unavailable";
                    }
                    else
                    {
                        genrestring = "";
                        foreach (string g in genres)
                        {
                            genrestring += (g + " & ");
                        }
                        genrestring = genrestring.Remove(genrestring.Length - 3);
                    }

                    //addtoDB(gametitle.Trim(), gameurl, genres, CONSOLE);
                    datacontainer.InnerHtml += "<tr><td>" + gametitle + "</td><td>" + gameurl + "</td><td>" + genrestring + "</td></tr>";
                }
            }
            System.Diagnostics.Debug.WriteLine("Scraped " + count.ToString() + " games.");
        }
Пример #24
0
    public static void Main()
    {
        // create an int array
        int[] array = new int[31];

        // create a double array
        double[] doubleArray = new double[10];

        array[0]  = 1;
        array[1]  = 2;
        array[2]  = 3;
        array[3]  = 4;
        array[4]  = 5;
        array[5]  = 6;
        array[6]  = 7;
        array[7]  = 8;
        array[8]  = 9;
        array[9]  = 10;
        array[10] = 11;
        array[11] = 12;
        array[12] = 13;
        array[13] = 14;
        array[14] = 15;
        array[15] = 16;
        array[16] = 17;
        array[17] = 18;
        array[18] = 19;
        Array 45;
        array[19]                         = 20
                                array[20] = 21;
        array[21]                         = 22;
        array[22]                         = 23;

        // printthe array element

        Console.WriteLine(array[0]);
        Console.WriteLine(array[1]);
        Console.WriteLine(array[2]);
        Console.WriteLine(array[3]);
        Console.WriteLine(array[4]);
        Console.WriteLine(array[5]);
        Console.WriteLine(array[6]);
        Console.WriteLine(array[7]);
        Console.WriteLine(array[8]);
        Console.WriteLine(array[9]);
        Console.WriteLine(array[10]);
        Console.WriteLine(array[11]);
        Console.WriteLine(array[12]);
        Console.WriteLine(array[13]);
        Console.WriteLine(array[14]);
        Console.WriteLine(array[15]);
        Console.WriteLine(array[16]);
        Console.WriteLine(array[17]);
        Console.WriteLine(array[18]);
        Console.WriteLine(array[19]);
        Console.WriteLine(array[20]);
        Console.WriteLine(array[21]);
        Console.WriteLine(array[22]);
        Console.WriteLine(array[23]);
        Console.WriteLine(array[24]);
        Console.WriteLine(array[25]);
        Console.WriteLine(arrray[26]);
        Console.WriteLine(arrray[27]);
        Console.WriteLine(arrray[28]);
        Console.WriteLine(arrray[29]);
        Console.WriteLine(array[30]);
        Console.WriteLine(array[31]);
        Console.Writelibe(array[32]);
        Console.WriteLine(array[33]);
        Console.WriteLine(array[34]);
        Console.WriteLine(array[35]);
        Console.WriteLine(array[36]);
        CONSOLE.writeline(array[37]);
    }
Пример #25
0
        // METHODS - CONNECTION

        /// <summary>
        /// Gets the Credentials of the user, and connects him / makes him retry accordingly
        /// </summary>
        private void LogIn()
        {
            bool   continueLogin = true;
            string errorMessage  = "";

            do
            {
                // Displaying some messages
                Console.Clear();
                CONSOLE.WriteLine(ConsoleColor.Blue, "\n   Enter empty fields to leave the LOGIN");


                // Displays a message if the credentials are incorrect
                CONSOLE.WriteLine(ConsoleColor.Red, errorMessage);


                // USERNAME
                Console.Write("\n Please enter your name : ");
                string name = Console.ReadLine();


                // PASSWORD
                Console.Write("\n Please enter your password : ");
                string password = Console.ReadLine();


                // All the fields are empty : go back to the menu
                if (name.Length == 0 && password.Length == 0)
                {
                    continueLogin = false;
                }
                // If at least one field is empty : ERROR
                else if (name.Length == 0 || password.Length == 0)
                {
                    errorMessage = PrefabMessages.INCOMPLETE_FIELDS;
                }
                // If at least one field is too long : ERROR
                else if (name.Length > PrefabMessages.INPUT_MAXSIZE_COACH_NAME || password.Length > PrefabMessages.INPUT_MAXSIZE_COACH_PASSWORD)
                {
                    errorMessage = PrefabMessages.INCORRECT_INPUT_SIZE;
                }
                // If at least one field has one incorrect character : ERROR
                else if (!Util.CorrectInput(name) || !Util.CorrectInput(password))
                {
                    errorMessage = PrefabMessages.INCORRECT_INPUT_CHARACTER;
                }
                // Otherwise : verify with the server
                else
                {
                    // Sending the credentials
                    Instructions instruction = Instructions.LogIn;
                    Object       content     = new Credentials(name, password);
                    Net.COMMUNICATION.Send(comm.GetStream(), new Communication(instruction, content));

                    // Receiving the response ID
                    userData = Net.COACH.Receive(comm.GetStream());

                    // Match found, we proceed forward
                    if (userData.IsComplete)
                    {
                        continueLogin = false;
                    }
                    // If the ID is Empty : there was no match found, we reset the login
                    else
                    {
                        errorMessage = PrefabMessages.LOGIN_FAILURE;
                    }
                }
            }while (continueLogin);
        }
Пример #26
0
        /// <summary>
        /// Creates a new Player
        /// </summary>
        /// <param name="team">Team the Player is in</param>
        private void NewPlayer(Team team)
        {
            bool   continueNewPlayer       = true;
            bool   continueNewPlayerInputs = true;
            string errorMessage            = "";

            do
            {
                // CHOICE
                // We dynamically create a List containing all the roles names
                List <string> choiceString = new List <string>();
                team.race.roles().ForEach(role => choiceString.Add(role.ToStringCustom()));

                // We add as a last choice the option to "Cancel"
                choiceString.Add("Cancel");

                // We create the Choice
                Choice c     = new Choice("please Select a Role (last one = cancel) : ", choiceString);
                int    index = c.GetChoice();

                if (index != choiceString.Count - 1)
                {
                    // We save the Role
                    Role role = team.race.roles()[index];

                    // if the role chosen is too cost-expensive
                    if (role.price() > team.money)
                    {
                        CONSOLE.WriteLine(ConsoleColor.Red, PrefabMessages.NOT_ENOUGH_MONEY);
                        CONSOLE.WaitForInput();
                    }
                    // if the player can afford it : continue
                    else
                    {
                        // Inputs
                        do
                        {
                            Console.Clear();

                            // Displays a message if the credentials are incorrect
                            CONSOLE.WriteLine(ConsoleColor.Red, errorMessage);

                            // NAME
                            Console.Write("\n Please enter the {0}'s name (empty = go back) : ", role.name());
                            string name = Console.ReadLine();


                            // All the fields are empty : go back to the menu
                            if (name.Length == 0)
                            {
                                continueNewPlayerInputs = false;
                            }
                            // If at least one field is too long : ERROR
                            else if (name.Length > PrefabMessages.INPUT_MAXSIZE_COACH_NAME)
                            {
                                errorMessage = PrefabMessages.INCORRECT_INPUT_SIZE;
                            }
                            // If at least one field has one incorrect character : ERROR
                            else if (!Util.CorrectInput(name))
                            {
                                errorMessage = PrefabMessages.INCORRECT_INPUT_CHARACTER;
                            }
                            // Otherwise : verify with the server
                            else
                            {
                                // Sending the new Player
                                Instructions instruction = Instructions.Team_AddPlayer;
                                Player       newPlayer   = new Player(name, role, team);
                                Net.COMMUNICATION.Send(comm.GetStream(), new Communication(instruction, newPlayer));

                                // We receive the id of the Player from the server
                                Guid idReceived = Net.GUID.Receive(comm.GetStream());

                                // We see if the id received is valid
                                if (idReceived != Guid.Empty)
                                {
                                    // We set the received id
                                    newPlayer.id = idReceived;

                                    // We add the Player to the user's team
                                    team.players.Add(newPlayer);

                                    // We make the transaction (the team has less money now)
                                    team.money -= role.price();

                                    // We display a success message
                                    CONSOLE.WriteLine(ConsoleColor.Green, PrefabMessages.PLAYER_CREATION_SUCCESS);

                                    // Ending the loops
                                    continueNewPlayerInputs = false;
                                    continueNewPlayer       = false;
                                }
                                else
                                {
                                    errorMessage = PrefabMessages.PLAYER_CREATION_FAILURE;
                                }
                            }
                        }while (continueNewPlayerInputs);
                    }
                }
                else
                {
                    continueNewPlayer = false;
                }
            }while (continueNewPlayer);
        }
Пример #27
0
 /// <summary>
 /// 获取按键
 /// </summary>
 /// <param name="consoleKey"></param>
 /// <returns>是否成功</returns>
 public static bool GetKey(ConsoleKey consoleKey)
 {
     return(CONSOLE.GetKey(consoleKey));
 }
Пример #28
0
 /// <summary>
 /// 获取鼠标
 /// </summary>
 /// <param name="mouseButton">鼠标按键</param>
 /// <returns>是否成功</returns>
 public static bool GetMouseButton(MouseButton mouseButton)
 {
     return(CONSOLE.GetKey((ConsoleKey)mouseButton));
 }
Пример #29
0
        /// <summary>
        /// When a Player levels up
        /// </summary>
        /// <param name="player"></param>
        private void PlayerLevelsUp(Player player)
        {
            // Asking to level up a Player
            Instructions instruction = Instructions.Player_LevelUp;

            Net.COMMUNICATION.Send(comm.GetStream(), new Communication(instruction, player));


            // We receive / define some variables
            int dice1 = Net.INT.Receive(comm.GetStream());
            int dice2 = Net.INT.Receive(comm.GetStream());

            dice1 = 5;
            dice2 = 6;
            List <EffectType> types = EffectStuff.GetEffectTypesForLevelUp(player.role, dice1, dice2);


            // There are 2 steps :
            // PART 1 - display some useful info to the user
            // PART 2 - Wait for the user to choose a new Effect for his Player

            // PART 1 - display some useful info to the user
            Console.Clear();
            Console.WriteLine("New level !\n\n\n\nyou rolled {0} - {1} !", dice1, dice2);

            Console.WriteLine("You can level up in any category :");
            types.ForEach(type => Console.WriteLine(" - " + type));
            CONSOLE.WaitForInput();


            // PART 2 - Wait for the user to choose a new Effect for his Player
            // We initialize our variables
            List <List <Effect> > effects = EffectStuff.GetEffectsForLevelUp(types);
            bool   continuing             = true;
            Effect chosenEffect           = effects[0][0];
            int    currentType            = 0;
            int    currentEffect          = 0;



            // While the user doesn't press Enter, the loop continues
            do
            {
                // We clear the console, and display a given message
                Console.Clear();

                // We display all our Types
                for (int t = 0; t < types.Count; t++)
                {
                    // Display the current EffectType
                    Console.WriteLine("\n" + types[t]);

                    // Display all its Effects (with an arrow if it is the current one)
                    for (int e = 0; e < effects[t].Count; e++)
                    {
                        // Initialize some variables
                        Effect       effect = effects[t][e];
                        string       arrow  = (currentType == t && currentEffect == e) ? "\t --> " : "\t     ";
                        ConsoleColor color  = (player.effectsAll.Contains(effect)) ? ConsoleColor.Red : ConsoleColor.Blue;

                        // Display the result
                        CONSOLE.WriteLine(color, arrow + effect.name());
                    }
                }


                // We read the input
                ConsoleKeyInfo input          = Console.ReadKey();
                bool           goToLastEffect = false;


                // If it is an Array key (UP or DOWN), we modify our index accordingly
                if (input.Key == ConsoleKey.UpArrow)
                {
                    currentEffect--;

                    // If the index goes too low, we change type
                    if (currentEffect < 0)
                    {
                        currentType--;
                        goToLastEffect = true;
                    }
                }
                if (input.Key == ConsoleKey.DownArrow)
                {
                    currentEffect++;

                    // If the index goes too high, we change type
                    if (currentEffect > effects[currentType].Count - 1)
                    {
                        currentType++;
                        currentEffect = 0;
                    }
                }
                // If it is a LEFT Array key : go to the previous type
                if (input.Key == ConsoleKey.LeftArrow)
                {
                    currentType--;
                    currentEffect = 0;
                }
                // If it is a RIGHT Array key : go to the next type
                if (input.Key == ConsoleKey.RightArrow)
                {
                    currentType++;
                    currentEffect = 0;
                }



                // If the type is too high / too low, we change it accordingly
                if (currentType < 0)
                {
                    currentType = types.Count - 1;
                }
                if (currentType > types.Count - 1)
                {
                    currentType = 0;
                }

                // If needed : we replace the effect counter to the last index of the current list
                if (goToLastEffect)
                {
                    currentEffect = effects[currentType].Count - 1;
                }


                // We check if we end the loop
                if (input.Key == ConsoleKey.Enter)
                {
                    // We set the chosen Effect
                    chosenEffect = effects[currentType][currentEffect];

                    Console.Clear();
                    // We display a message, whether the Effect can be chosen or not
                    if (player.effectsAll.Contains(chosenEffect))
                    {
                        CONSOLE.WriteLine(ConsoleColor.Red, "You cannot choose the Effect " + chosenEffect.name() + " :\n\nyour Player already has it !!");
                        CONSOLE.WaitForInput();
                    }
                    else
                    {
                        continuing = false;
                    }
                }
            }while (continuing);

            // Small message
            CONSOLE.WriteLine(ConsoleColor.Green, "You have chosen the Effect " + chosenEffect.name() + " !!");

            // Sending the chosen Effect
            Net.EFFECT.Send(comm.GetStream(), chosenEffect);

            // If the Effect was validated : add it to the Player
            if (Net.BOOL.Receive(comm.GetStream()))
            {
                CONSOLE.WriteLine(ConsoleColor.Green, "\n\n\tEffect validated !!");
                player.effects.Add(chosenEffect);
            }
            else
            {
                CONSOLE.WriteLine(ConsoleColor.Red, "\n\n\tEffect refused...");
            }

            CONSOLE.WaitForInput();
        }
Пример #30
0
 public static extern bool GetConsoleDisplayMode(ref CONSOLE lpModeFlags);
Пример #31
0
        /// <summary>
        /// Gets the newly created Coach's data of the user, and connects him / makes him retry accordingly
        /// </summary>
        private void SignIn()
        {
            bool   continueSignin = true;
            string errorMessage   = "";

            while (continueSignin)
            {
                // Displaying some messages
                Console.Clear();
                CONSOLE.WriteLine(ConsoleColor.Blue, "\n   Enter empty fields to leave the SIGN-IN");


                // Displays a message if the credentials are incorrect
                CONSOLE.WriteLine(ConsoleColor.Red, errorMessage);


                // USERNAME
                Console.Write("\n Please enter your username : "******"\n Please enter your password : "******"\n Please verify your password : "******"\n Please enter your email : ");
                string email = Console.ReadLine();


                // All the fields are empty : go back to the menu
                if (name.Length == 0 && password.Length == 0 && passwordVerif.Length == 0 && email.Length == 0)
                {
                    continueSignin = false;
                }
                // If at least one field is empty : ERROR
                else if (name.Length == 0 || password.Length == 0 || passwordVerif.Length == 0 || email.Length == 0)
                {
                    errorMessage = PrefabMessages.INCOMPLETE_FIELDS;
                }
                // The password and its verification do not match : ERROR
                else if (password != passwordVerif)
                {
                    errorMessage = PrefabMessages.SIGNIN_PASSWORD_DONT_MATCH;
                }
                // NOW, we don't have to verify the PasswordVerif field anymore !
                // If at least one field is too long : ERROR
                else if (name.Length > PrefabMessages.INPUT_MAXSIZE_COACH_NAME ||
                         password.Length > PrefabMessages.INPUT_MAXSIZE_COACH_PASSWORD ||
                         email.Length > PrefabMessages.INPUT_MAXSIZE_COACH_EMAIL)
                {
                    errorMessage = PrefabMessages.INCORRECT_INPUT_SIZE;
                }
                // If at least one field has one incorrect character : ERROR
                else if (!Util.CorrectInput(name) || !Util.CorrectInput(password) || !Util.CorrectInput(email))
                {
                    errorMessage = PrefabMessages.INCORRECT_INPUT_CHARACTER;
                }
                // Otherwise : verify with the server
                else
                {
                    // Sending the new Coach (with password !)
                    Instructions instruction = Instructions.SignIn;
                    Object       content     = new CoachWithPassword(name, password, email);
                    Net.COMMUNICATION.Send(comm.GetStream(), new Communication(instruction, content));

                    // We get the Coach data back
                    // CORRECT :  regular data
                    // INCORRECT : default data
                    userData = Net.COACH.Receive(comm.GetStream());


                    // the data is complete : successful Sign in
                    if (userData.IsComplete)
                    {
                        continueSignin = false;
                    }
                    // If the data is incomplete : the profile's name and/or email is already taken, we reset the sign-in
                    {
                        errorMessage = PrefabMessages.SIGNIN_FAILURE;
                    }
                }
            }
        }