Ejemplo n.º 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            HomeShips.Controls.Clear();
            for (int i = 0; i < 11; i++)
            {
                for (int j = 0; j < 11; j++)
                {
                    Label homeShip = new Label();
                    homeShip.Dock      = DockStyle.Fill;
                    homeShip.TextAlign = ContentAlignment.MiddleCenter;
                    homeShip.Font      = new Font("Wingdings", 20);
                    homeShip.Text      = Convert.ToString(i) + Convert.ToString(j);
                    homeShip.Text      = " ";
                    HomeShips.Controls.Add(homeShip, j, i);


                    Label enemyShip = new Label();
                    enemyShip.Dock      = DockStyle.Fill;
                    enemyShip.TextAlign = ContentAlignment.MiddleCenter;
                    enemyShip.Font      = new Font("Wingdings", 20);
                    enemyShip.Text      = " ";
                    enemyShip.Text      = Chars.Substring(0, 1);
                    EnemyShips.Controls.Add(enemyShip, j, i);
                    enemyShip.Click += Label_Click_Enemy;
                }
            }

            for (int i = 1; i < 11; i++)
            {
                Label enemyShip = EnemyShips.Controls[i * 11] as Label;
                enemyShip.Font = new Font("Arial", 11);
                enemyShip.Text = Convert.ToString(i);
            }

            for (int j = 1; j < 11; j++)
            {
                Label enemyShip = EnemyShips.Controls[j] as Label;
                enemyShip.Font = new Font("Arial", 11);
                enemyShip.Text = Convert.ToString(Title[j]);
            }

            for (int i = 1; i < 11; i++)
            {
                Label homeShip = HomeShips.Controls[i * 11] as Label;
                homeShip.Font = new Font("Arial", 11);
                homeShip.Text = Convert.ToString(i);
            }

            for (int j = 1; j < 11; j++)
            {
                Label homeShip = HomeShips.Controls[j] as Label;
                homeShip.Font = new Font("Arial", 11);
                homeShip.Text = Convert.ToString(Title[j]);
            }

            GenerateMap(HomeMap);
            ShowMap(HomeMap, HomeShips);
            int         clientProcessId        = Process.GetCurrentProcess().Id;
            Message     clientProcessIdMessage = new Message(clientProcessId, MessageType.startPlayerMessage);
            HomeClient  client      = new HomeClient();
            EnemyServer enemyServer = new EnemyServer(HomeMap, this);

            enemyServer.serverStart();
            Message serverProcessIdMessage = client.SendAndGetAnswer(clientProcessIdMessage);

            if (CompareProcessId(clientProcessIdMessage, serverProcessIdMessage))
            {
                EnemyShips.Enabled = false;
            }
        }
Ejemplo n.º 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            HomeShips.Controls.Clear();
            for (int i = 0; i < 11; i++)
            {
                for (int j = 0; j < 11; j++)
                {
                    Label homeShip = new Label();
                    homeShip.Dock      = DockStyle.Fill;
                    homeShip.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                    homeShip.Font      = new System.Drawing.Font("Wingdings", 22);
                    homeShip.Text      = Convert.ToString(i) + Convert.ToString(j);
                    homeShip.Text      = " ";
                    HomeShips.Controls.Add(homeShip, j, i);
                    homeShip.Click += Label_Click_Home;


                    Label enemyShip = new Label();
                    enemyShip.Dock      = DockStyle.Fill;
                    enemyShip.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                    enemyShip.Font      = new System.Drawing.Font("Wingdings", 22);
                    enemyShip.Text      = " ";
                    enemyShip.Text      = Chars.Substring(0, 1);
                    EnemyShips.Controls.Add(enemyShip, j, i);
                    enemyShip.Click += Label_Click_Enemy;
                }
            }

            for (int i = 1; i < 11; i++)
            {
                Label enemyShip = EnemyShips.Controls[i * 11] as Label;
                enemyShip.Font = new System.Drawing.Font("Arial", 12);
                enemyShip.Text = Convert.ToString(i);
            }

            for (int j = 1; j < 11; j++)
            {
                Label enemyShip = EnemyShips.Controls[j] as Label;
                enemyShip.Font = new System.Drawing.Font("Arial", 12);
                enemyShip.Text = Convert.ToString(Title[j]);
            }

            for (int i = 1; i < 11; i++)
            {
                Label homeShip = HomeShips.Controls[i * 11] as Label;
                homeShip.Font = new System.Drawing.Font("Arial", 12);
                homeShip.Text = Convert.ToString(i);
            }

            for (int j = 1; j < 11; j++)
            {
                Label homeShip = HomeShips.Controls[j] as Label;
                homeShip.Font = new System.Drawing.Font("Arial", 12);
                homeShip.Text = Convert.ToString(Title[j]);
            }

            GenerateMap(HomeMap);
            //GenerateMap(EnemyMap);
            ShowMap(HomeMap, HomeShips);
            //ShowMap(EnemyMap, EnemyShips);
            EnemyServer enemyServer = new EnemyServer(HomeMap);

            enemyServer.serverStart();
        }