Exemple #1
0
        public static Package ParsePackageString(string CommandString)
        {
            Package myPackage = new Package();

            char[] paths = {'<','>'};
            string[] commands = CommandString.Split(paths);

            for(int i = 0; i < commands.Length; i++)
            {
                if (commands[i] == "type")
                {
                    myPackage.Type = commands[i + 1];
                }
                if (commands[i] == "to")
                {
                    myPackage.To = commands[i + 1];
                }
                if (commands[i] == "from")
                {
                    myPackage.From = commands[i + 1];
                }
                if (commands[i] == "data")
                {
                    myPackage.Data = commands[i + 1];
                }
            }

            return myPackage;
        }
Exemple #2
0
 public static void ShowGamePlan(Package InCommingPackage)
 {
     ServerConnectForm.ServerConnectFormref.BeginInvoke(new Action(delegate()
     {
         Gamearea ga = new Gamearea(InCommingPackage.Data);
         ga.OpponentIp = InCommingPackage.From;
         ga.Show();
     }));
 }
Exemple #3
0
 public static string MakePackageString(Package package)
 {
     string CommandString = "";
     CommandString += "<type>" + package.Type + "</type>";
     CommandString += "<to>" + package.To + "</to>";
     CommandString += "<from>" + package.From + "</from>";
     CommandString += "<data>" + package.Data + "</data>";
     return CommandString;
 }
Exemple #4
0
 public static void UpdateUserListListBox(Package InCommingPackage,string LocalIpAddress)
 {
     ServerConnectForm.ListBox1ref.BeginInvoke(new Action(delegate()
     {
         ServerConnectForm.userlist = InCommingPackage.Data.Split(';');
         for (int i = 0; i < ServerConnectForm.userlist.Length; i++)
         {
             if (ServerConnectForm.userlist[i] == LocalIpAddress)
             {
                 ServerConnectForm.userlist[i] += " YOU";
             }
         }
         ServerConnectForm.ListBox1ref.DataSource = ServerConnectForm.userlist;
     }));
 }
Exemple #5
0
 public static void UpdateGameAreaForm(Package InCommingPackage)
 {
     Gamearea.GameAreaFormref.BeginInvoke(new Action(delegate()
     {
         // place an O where the opponent put his X
         switch (InCommingPackage.Data[InCommingPackage.Data.Length - 1])
         {
             case '1':
                 Gamearea.button1ref.Text = "O";
                 break;
             case '2':
                 Gamearea.button2ref.Text = "O";
                 break;
             case '3':
                 Gamearea.button3ref.Text = "O";
                 break;
             case '4':
                 Gamearea.button4ref.Text = "O";
                 break;
             case '5':
                 Gamearea.button5ref.Text = "O";
                 break;
             case '6':
                 Gamearea.button6ref.Text = "O";
                 break;
             case '7':
                 Gamearea.button7ref.Text = "O";
                 break;
             case '8':
                 Gamearea.button8ref.Text = "O";
                 break;
             case '9':
                 Gamearea.button9ref.Text = "O";
                 break;
             case '0':
                 MessageBox.Show("LOOSE");
                 Gamearea.GameAreaFormref.Close();
                 break;
         }
         // Make the player able to play when he recived a O from his opponent.
         Gamearea.turn = true;
     }));
 }
Exemple #6
0
 public void StartGameWithOpponent(string opponent,string UserName)
 {
     Package StartGamePackage = new Package("newgame", Connection.LocalIpAddress,
         opponent,UserName);
     Connection.SendPackageToServer(StartGamePackage);
 }
Exemple #7
0
 public void SendGamePatternToOpponent(string opponentIp,string num)
 {
     Package GamePattern = new Package("gamepattern",Connection.LocalIpAddress,
         opponentIp,num);
     Connection.SendPackageToServer(GamePattern);
 }
Exemple #8
0
 /// <summary>
 /// When the user starts a new game with an opponent.
 /// We have to send a new game command to the user so that his gameplan 
 /// gets started too. 
 /// </summary>
 /// <param name="opponent">Ip of the opponent</param>
 public void StartGameWithSelf(string opponent)
 {
     Package StartGameWithSelfPackage = new Package("newgame", opponent,
         Connection.LocalIpAddress,"None");
     Connection.SendPackageToServer(StartGameWithSelfPackage);
 }
Exemple #9
0
 public void SendPackageToServer(Package PackageToServer)
 {
     try
     {
         ClientStream = tcpClient.GetStream();
         ClientStreamWriter = new StreamWriter(ClientStream);
         ClientStreamWriter.AutoFlush = true;
         ClientStreamWriter.WriteLine(PacketParser.MakePackageString(PackageToServer));
     }
     catch (Exception e)
     {
         Console.WriteLine("send package: " + e.Message);
     }
 }