Example #1
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (_successfulEnemyHits == 20 || _successfulHits == 20)
            {
                GameOver = true;
                return;
            }

            ConnectionTimer.Update(gameTime);

            HandleGameReady();

            if (_gameReady)
            {
                if (_myTurn)
                {
                    _opponentBoard.MouseHoverEnabled = true;
                    _opponentBoard.DisabledOverlay   = false;
                    _playerBoard.DisabledOverlay     = true;
                }
                else
                {
                    _opponentBoard.MouseHoverEnabled = false;
                    _playerBoard.DisabledOverlay     = false;
                    _opponentBoard.DisabledOverlay   = true;
                }
            }

            _playerBoard.Update(gameTime);
            _opponentBoard.Update(gameTime);
        }
Example #2
0
        public async void Start()
        {
            if (!CanStart())
            {
                return;
            }

            WrapperProcess = new Process();

            var processStartInfo = new ProcessStartInfo(ExecutablePath);

            processStartInfo.UseShellExecute        = false;
            processStartInfo.RedirectStandardOutput = true;
            processStartInfo.RedirectStandardInput  = true;
            processStartInfo.RedirectStandardError  = true;
            processStartInfo.CreateNoWindow         = true;
            WrapperProcess.StartInfo   = processStartInfo;
            processStartInfo.Arguments = "--config-file configs/BloodDonationCoin.conf";
            WrapperProcess.Start();

            await Task.Factory.StartNew(() => ReadNextLine(false));

            await Task.Factory.StartNew(() => ReadNextLine(true));

            PingTimer.Start();
            ConnectionTimer.Start();
        }
Example #3
0
        private void tlsbExit_Click(object sender, EventArgs e)
        {
            //Stop trying to receive datas
            ConnectionTimer.Stop();
            //cancel server task
            this.client.sendData(new Packet(Station, PacketType.CloseConnection, 1));
            this.client.Disconnect();

            if (server != null)
            {
                if (server.IsRunning && !cts.IsCancellationRequested)
                {
                    server.SendData(new Packet(Sender.Server, PacketType.CloseConnection, 1));
                    cts.Cancel();
                    try
                    {
                        runServer.Wait();
                    }
                    catch (AggregateException ex)
                    { }
                    finally
                    {
                        cts.Dispose();
                    }
                }
            }

            this.Close();
        }
Example #4
0
        public override void Exit()
        {
            HandleLines = false;

            PingTimer.Stop();
            ConnectionTimer.Stop();

            base.Exit();
        }
Example #5
0
        private void btnClient_Click(object sender, EventArgs e)
        {
            if (GameRunning == true)
            {
                return;
            }

            int port = 0;


            if (!ipParser.IsMatch(tbAddressConnect.Text))
            {
                MessageBox.Show("Non valid IP address", "Problem", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            try
            {
                int.TryParse(tbPortConnect.Text, out port);

                //Connexion
                client = new Client(tbAddressConnect.Text, port);
            }
            catch (Exception ex)
            {
                return;
            }



            RX_Packet = new Packet();

            while (RX_Packet.Empty())
            {
                client.RecvData(ref RX_Packet);
            }

            List <string> PlayersInfos = RX_Packet.GetPayload <List <string> >();


            lbConnected.Items.Clear();

            for (int i = 0; i < PlayersInfos.Count; i++)
            {
                lbConnected.Items.Add(PlayersInfos[i]);
            }
            PanelConnections.Visible = false;

            Station = Sender.Player2;

            ConnectionTimer.Start();
            TimerDelayKeyDown.Elapsed += TimerDelayKeyDown_Elapsed;
        }
Example #6
0
        private void Client_Load(object sender, EventArgs e)
        {
            var items = new MenuItem[1];

            ReadCaps();
            items[0] = new MenuItem("Exit", ExitHandler);
            backgroundNotifyIcon.ContextMenu = new ContextMenu(items);
            backgroundNotifyIcon.Visible     = true;
            ConnectionTimer.Interval         = 2000;
            ConnectionTimer.Start();
            SendTimer.Interval      = 60000;
            GuiUpdateTimer.Interval = 5000;
            GuiUpdateTimer.Start();
            SendTimer.Start();
        }
Example #7
0
        private void ConnectionTimer_Tick(object sender, EventArgs e)
        {
            var check = CheckForArduinoPort();

            if (check == "")
            {
                _connected = false;
                return;
            }
            ConnectionTimer.Stop();
            _serial = new Serial(check, 9600, Parity.None, 8, StopBits.One);
            _serial.Open();
            _serial.DataReceived  += SerialPort_DataReceived;
            _serial.ErrorReceived += SerialPort_ErrorReceived;
            _connected             = true;
        }
Example #8
0
        private void GuiUpdateTimer_Tick(object sender, EventArgs e)
        {
            if (!_connected)
            {
                return;
            }

            var test = _serial.IsOpen;

            if (!test)
            {
                ConnectionTimer.Start();
                return;
            }
            if (_hum == null || _temperature == null || _ppm == null || _pressure == null)
            {
                return;
            }
            TemperatureLabel.Invoke((Action)UpdateUi);
        }
Example #9
0
 private void SerialPort_ErrorReceived(object sender, SerialErrorReceivedEventArgs args)
 {
     ConnectionTimer.Start();
 }
Example #10
0
        //Close properly
        private void Lobby_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.DialogResult == DialogResult.Cancel)
            {
                //Stop trying to receive datas
                ConnectionTimer.Stop();
                //cancel server task
                if (client != null)
                {
                    if (this.client.GetConnectionState())
                    {
                        this.client.sendData(new Packet(Sender.Server, PacketType.CloseConnection, 1));
                        Thread.Sleep(50);
                        this.client.Disconnect();
                    }
                }
                if (server != null)
                {
                    if (server.IsRunning && !cts.IsCancellationRequested)
                    {
                        cts.Cancel();
                        try
                        {
                            runServer.Wait();
                        }
                        catch (AggregateException ex) { }
                        finally { cts.Dispose(); }
                    }
                }
            }

            //Exited via game exit button
            if (e.CloseReason == CloseReason.UserClosing)
            {
                MessageBox.Show("Lobby exited.");
            }
            else
            {
                //Stop trying to receive datas
                ConnectionTimer.Stop();
                //cancel server task
                this.client.sendData(new Packet(Station, PacketType.CloseConnection, 1));

                Thread.Sleep(50);
                this.client.Disconnect();

                if (server != null)
                {
                    if (server.IsRunning && !cts.IsCancellationRequested)
                    {
                        this.server.SendData(new Packet(Sender.Server, PacketType.CloseConnection, 1));
                        cts.Cancel();
                        try
                        {
                            runServer.Wait();
                        }
                        catch (AggregateException ex) { }
                        finally { cts.Dispose(); }
                    }
                }
            }
        }
Example #11
0
        private void btnServer_Click(object sender, EventArgs e)
        {
            if (GameRunning == true)
            {
                return;
            }

            int port = 30000;

            try
            {
                int.TryParse(tbPortConnect.Text, out port);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erreur : " + ex.Message, "Problème", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }


            server = new Server(port);

            cts = new CancellationTokenSource();
            string fileName = tbGameToLoad.Text;

            //If there's a game to load
            if (fileName.Length > 0)
            {
                runServer = Task.Run(() => server.Launch(cts.Token, fileName), cts.Token);
            }
            else
            {
                //Default
                runServer = Task.Run(() => server.Launch(cts.Token), cts.Token);
            }

            lbServerOnline.Visible   = true;
            PanelConnections.Visible = false;


            //Make a local connection the server
            client = new Client("127.0.0.1", 3000);

            Station = Sender.Player1;

            RX_Packet = new Packet();

            //Wait till data
            while (RX_Packet.Empty())
            {
                client.RecvData(ref RX_Packet);
            }

            List <string> PlayersInfos = RX_Packet.GetPayload <List <string> >();


            lbConnected.Items.Clear();

            for (int i = 0; i < PlayersInfos.Count; i++)
            {
                lbConnected.Items.Add(PlayersInfos[i]);
            }



            //Start timer to check for incoming packet on the server
            ConnectionTimer.Start();
        }