示例#1
0
文件: Form1.cs 项目: Kiryjm/CsPOIS
        private void Label_Click_Enemy(object sender, EventArgs e)
        {
            Label a = new Label();

            a = sender as Label;
            Point      homeCoordinates = GetHomeCoordinates(a);
            HomeClient homeClient      = new HomeClient();
            String     message         = homeClient.pointSend(homeCoordinates);

            switch ((string)message)
            {
            case " ": a.Text = Convert.ToString(Chars[1]);
                a.ForeColor  = Color.Black;
                break;

            case "o": a.Text = Convert.ToString(Chars[3]);
                a.ForeColor  = Color.Black;
                break;
            }
        }
示例#2
0
文件: Form1.cs 项目: Kiryjm/CsPOIS
        private void Label_Click_Enemy(object sender, EventArgs e)
        {
            Label a = new Label();

            a = sender as Label;
            Point      enemyCoordinates = GetEnemyCoordinates(a);
            HomeClient homeClient       = new HomeClient();
            Message    message          = new Message(enemyCoordinates, MessageType.pointMessage);

            message = homeClient.SendAndGetAnswer(message);


            switch (message.PointValue)
            {
            case ' ':
                a.Text      = Convert.ToString(Chars[1]);
                a.ForeColor = Color.Black;
                MessageBox.Show("Missed! Wait for your enemy's turn.");
                EnemyShips.Enabled = false;
                HomeClient newHomeClient = new HomeClient();
                newHomeClient.SendAndGetAnswer(new Message()
                {
                    MessageType = MessageType.turnMessage
                });
                break;

            case 'o':
                if (shipsAmount < totalShipsAmount)
                {
                    a.Text      = Convert.ToString(Chars[3]);
                    a.ForeColor = Color.Black;
                    shipsAmount++;
                }
                else
                {
                    MessageBox.Show("Congratulations! You win!");
                }
                break;
            }
        }
示例#3
0
文件: Form1.cs 项目: Kiryjm/CsPOIS
        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;
            }
        }