Exemple #1
0
        public void ConnectTo(System.Net.IPAddress ip, int port)
        {
            DisposeCommunication();
            Client client = new Client(ip, port);
            _communication = client;
            KaroGameManager = new KaroCommunicatedGameManager(_communication);

            // Attach handlers
            KaroGameManager.OnPlayerWin += PlayerWon;
            client.OnConnectionFailed += ConnectionFailed;
            AddGlobalHandlers();

            _communication.StartCommunicating();
            AddGameComponents();
        }
Exemple #2
0
 private void clientToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try {
         InputBox i = new InputBox();
         i.ShowDialog();
         string[] split = i.ResultText.Split(':');
         Client communication = new Client(IPAddress.Parse(split[0]), Int32.Parse(split[1]));
         _manager = new KaroCommunicatedGameManager(communication);
         communication.OnConnectionFailed += CommunicationFailed;
         communication.StartCommunicating();
         _communication = communication;
         karoPanel.NewGame(_manager);
     } catch(Exception) {
         MessageBox.Show("IP incorrect");
     }
 }
 public KaroCommunicatedGameManager(ICommunication communication)
     : base()
 {
     name = "Computer player";
     CurrentPlayer = Players.Min;
     _conversion = new CommunicationProtocolConversionUtility(Game);
     _communication = communication;
     _communication.Connected += Communication_Connected;
     _communication.Disconnected += Communication_Disconnected;
     _communication.RequestFirstMove += Communication_RequestFirstMove;
     _communication.SentMoveInvalid += Communication_SentMoveInvalid;
     _communication.TurnReceived += Communication_TurnReceived;
     _communication.WinAccepted += Communication_WinAccepted;
     _communication.WinDetected += Communication_WinDetected;
     _communication.WinRejected += Communication_WinRejected;
 }
Exemple #4
0
 private void serverToolStripMenuItem_Click(object sender, EventArgs e)
 {
     _communication = new Server(43594);
     _manager = new KaroCommunicatedGameManager(_communication);
     karoPanel.NewGame(_manager);
 }
Exemple #5
0
        private void DisposeCommunication()
        {
            if (_communication == null)
            {
                return;
            }

            _communication.CleanUp();
            _communication = null;
        }
Exemple #6
0
        public void StartOnlineGame(int modus)
        {
            if (modus == 0) // client
            {
                Components.Add(new ConnectComponent(this));
                return;
            }
            if(modus == 1){ // server
                DisposeCommunication();
                _communication = new Server(43594);
                _communication.Connected += ConnectionSucceed;
                AddGlobalHandlers();
                KaroGameManager = new KaroCommunicatedGameManager(_communication);
                KaroGameManager.OnPlayerWin += PlayerWon;
                Components.Add(new MessageComponent(this, "Waiting for opponent...", "Hit enter to cancel", new MenuComponent(this)));
                return;
            }
            if(modus == 2){
                // play with yourself
                DisposeCommunication();
                if(otherMeServer != null){
                    otherMeServer.CleanUp();
                }
                otherMeServer = new Server(43594);
                otherMe = new KaroCommunicatedGameManager(otherMeServer);
                // change number to change openent
                // 0: mimax ai (slowest possible)
                // 1: alfa beta ai
                // 2: moverordering ab ai
                // >=3: move ordering alfa beta transpositiontable ai

                // the other me is configurable but connecto ai always uses the best one
                // the best one is with the longest name
                otherMe.Game.SetAI(0);
                otherMe.name = "Messed up ai";
                ConnectTo(IPAddress.Parse("127.0.0.1"), 43594);
            }
        }