private void loginButton_Click(object sender, EventArgs e)
        {
            if (!ValidLoginInput())
                return;

            try {
                TcpClient client = new TcpClient();
                client.Connect(ipAddress, port);
                Connection conn = new Connection(client, true);

                conn.SendData(new AuthenticationRequest(GetUsername(), GetPassword()));

                AuthenticationResponse authentication = (AuthenticationResponse)conn.ReceiveData();

                if (authentication.Message == null) {
                    ConnectionsRepository.AddConnection(conn, true);
                    conn.DataTransfered += DataProcessor.ProcessData;
                    conn.InitializeDataListener();

                    this.Visible = false;
                    this.ShowInTaskbar = false;

                    GameForm game = new GameForm(conn);
                    conn.ShutdownRequest += ServerDown;
                    game.FormClosed += CloseClient;
                    game.Show();
                } else
                    noteLabel.Text = authentication.Message;

            } catch {
                noteLabel.Text = "No response from server.";
            }
        }
Esempio n. 2
0
 public GameSession(int mapWidth, int bottomMapHeight, int topSideMapHeight, ControlSettings controlSettings)
 {
     this.controlSettings = controlSettings;
     bottomSideState      = new GameState(bottomMapHeight, mapWidth);
     topSideState         = new GameState(topSideMapHeight, mapWidth);
     GameForm             = new GameForm(mapWidth, bottomMapHeight + topSideMapHeight);
     gameInProcess        = false;
 }
Esempio n. 3
0
 public MainForm()
 {
     InitializeComponent();
     btnLogout.Enabled      = false;
     btnSendMessage.Enabled = false;
     btnJoinGame.Enabled    = false;
     btnCreateGame.Enabled  = false;
     btnOfferGame.Enabled   = false;
     btnCancelGame.Enabled  = false;
     gameForm = new GameForm(this);
     authForm = new AuthenticationForm(this);
 }
Esempio n. 4
0
        public void OpenGameForm()
        {
            this.gameForm = new GameForm(this);

            startForm.Hide();
            gameForm.FormClosing += (sender, e) =>
            {
                conClient.Disconnect();
                startForm.Show();
            };
            gameForm.Show();
        }
Esempio n. 5
0
        public void socketReceive()
        {
            int recvLength = 0;

            try
            {
                do
                {
                    recvLength = socketClient.Receive(data);
                    if (recvLength > 0)
                    {
                        string command = Encoding.Default.GetString(data).Trim();
                        Array.Clear(data, 0, data.Length);
                        //MessageBox.Show(command);
                        string[] commands = command.Split('`');
                        for (int i = 1; i < commands.Length; i++)
                        {
                            string[] line = commands[i].Split(',');
                            if (line[0] == "joinSuccess")
                            {
                                my_id = int.Parse(line[1]);
                            }
                            else if (line[0] == "color" && line[1] == "true")
                            {
                                GameForm gameForm = new GameForm();
                                gameForm.Ready(my_id, nowColor, socketClient);
                                this.Hide();
                                gameForm.ShowDialog();
                                this.Close();
                            }
                            else if (line[0] == "color" && line[1] == "false")
                            {
                                MessageBox.Show("Другой участник выбрал этот цвет, попробуйте другой!");
                            }
                        }
                    }
                } while (true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void loginButton_Click(object sender, EventArgs e)
        {
            if (!ValidLoginInput())
            {
                return;
            }

            try {
                TcpClient client = new TcpClient();
                client.Connect(ipAddress, port);
                Connection conn = new Connection(client, true);

                conn.SendData(new AuthenticationRequest(GetUsername(), GetPassword()));

                AuthenticationResponse authentication = (AuthenticationResponse)conn.ReceiveData();

                if (authentication.Message == null)
                {
                    ConnectionsRepository.AddConnection(conn, true);
                    conn.DataTransfered += DataProcessor.ProcessData;
                    conn.InitializeDataListener();

                    this.Visible       = false;
                    this.ShowInTaskbar = false;

                    GameForm game = new GameForm(conn);
                    conn.ShutdownRequest += ServerDown;
                    game.FormClosed      += CloseClient;
                    game.Show();
                }
                else
                {
                    noteLabel.Text = authentication.Message;
                }
            } catch {
                noteLabel.Text = "No response from server.";
            }
        }
Esempio n. 7
0
 public void SetGameForm(GameForm gameform)
 {
     this.gameform = gameform;
 }