예제 #1
0
파일: Form1.cs 프로젝트: szopenfx/code
 /// <summary>
 /// Constructor for chess form
 /// </summary>
 /// <param name="TheChessGame">Reference to chess game object</param>
 public ChessForm(ChessGame TheChessGame)
 {
     InitializeComponent();
     _Game = TheChessGame;
     Lbl_MyColor.Text = _Game.MyColor.ToString();
     if (_Game.MyColor == PlayerColor.Black)
     {
         Lbl_MyColor.ForeColor = Color.White;
         Lbl_MyColor.BackColor = Color.Black;
     }
     else
     {
         Lbl_MyColor.ForeColor = Color.Black;
         Lbl_MyColor.BackColor = Color.White;
     }
 }
예제 #2
0
 /// <summary>
 /// Connect to remote chess server
 /// </summary>
 /// <param name="RemoteIP">IP address of remote peer</param>
 /// <param name="RemotePort">Port of remote peer</param>
 public ChessProtocol(IPAddress RemoteIP, int RemotePort)
 {
     IPEndPoint RemoteIPEndPoint = new IPEndPoint(RemoteIP, RemotePort);
     TcpClient ProtocolClient = new TcpClient();
     ProtocolClient.Connect(RemoteIPEndPoint);
     if (ProtocolClient.Connected)
     {
         _ChessNetworkStream = ProtocolClient.GetStream();
         _ChessStreamWriter = new StreamWriter(_ChessNetworkStream);
         _ChessStreamReader = new StreamReader(_ChessNetworkStream);
         _ChessGame = new ChessGame(this, PlayerColor.Black);
         _ChessGame.CreateChessInterface();
         new Thread(new ThreadStart(Read)).Start();
     }
     else
     {
         throw new Exception("Connection to client timed out");
     }
 }
예제 #3
0
 /// <summary>
 /// Creates a chessform
 /// </summary>
 /// <param name="TheChessGame">Pointer to the Chessgame</param>
 public void CreateChessForm(ChessGame TheChessGame)
 {
     ChessForm TheChessForm = new ChessForm(TheChessGame);
     TheChessForm.Show();
     TheChessGame.SetChessInterface(TheChessForm);
 }
예제 #4
0
 /// <summary>
 /// Listen method to be executed by thread
 /// </summary>
 public void Listen()
 {
     TcpListener ChessListener = new TcpListener(_ListenPort);
     ChessListener.Start();
     Socket ChessSocket = ChessListener.AcceptSocket();
     if (ChessSocket.Connected)
     {
         _ChessNetworkStream = new NetworkStream(ChessSocket);
         _ChessStreamReader = new StreamReader(_ChessNetworkStream);
         _ChessStreamWriter = new StreamWriter(_ChessNetworkStream);
         _ChessGame = new ChessGame(this, PlayerColor.White);
         _Nexus.CreateChessFormForChessGame(_ChessGame);
         new Thread(new ThreadStart(Read)).Start();
     }
 }
예제 #5
0
파일: Nexus.cs 프로젝트: szopenfx/code
 /// <summary>
 /// Create a chess form in the main thread using a wretched delegate.
 /// </summary>
 /// <param name="cg">ChessGame</param>
 public void CreateChessFormForChessGame(ChessGame cg)
 {
     CreateChessFormDelegate CreateChessForm
         = new CreateChessFormDelegate(_Interface.CreateChessForm);
     _Interface.Invoke(CreateChessForm, new object[] { cg });
 }