⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logon.xaml.cs

📁 经典游戏程序设计:visual c++ 上的杀人游戏源代码
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net;
using ServerLib;
using System.Threading;
using Utility;
using System.Windows.Media.Effects;


namespace KillingClientUI
{
    /// <summary>
    /// Interaction logic for Logon.xaml
    /// </summary>
    public partial class Logon : Window
    {

        public Logon()
        {
            InitializeComponent();

            string name = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
            LogonName.Text = name.Substring(name.IndexOf(@"\") + 1);

            ServiceIP.Text = "157.60.129.95";
        }

        private void LogonButton_Click(object sender, RoutedEventArgs e)
        {
            LogonVerify();
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            System.Media.SoundPlayer soundPlayer = new System.Media.SoundPlayer(Properties.Resources.close);
            soundPlayer.Play();
            System.Threading.Thread.Sleep(1500);
            Application.Current.Shutdown();

        }

        private void LogonName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                LogonVerify();
            }
        }



        private void LogonVerify()
        {
            System.Media.SoundPlayer soundPlayer = new System.Media.SoundPlayer(Properties.Resources.start);
            soundPlayer.Play();

            // Returns a list of ipaddress configuration
            IPHostEntry ips = Dns.GetHostEntry(Dns.GetHostName());

            // Select the first entry. I hope it's this maschines IP
            IPAddress _ipAddress = ips.AddressList[0];

            string urlService = "net.tcp://" + _ipAddress.ToString() + ":8002/KillPersonServerApp.MessageDistribute";

            //Send user name to server host
            LogonFormat logonInfo = new LogonFormat();
            logonInfo.LogonPerson = LogonName.Text.Trim();
            logonInfo.IPPortServiceString = urlService;
            App.currentClientName = this.LogonName.Text;


            App.proxyAddress = "net.tcp://" + this.ServiceIP.Text.Trim() + ":8000/KillPersonServerApp.MessageDistribute";
            MessageDistribution proxy = Service.ConnectToServer(App.proxyAddress);
            IList<string> listCurrentPlayers = proxy.Logon(logonInfo);


            this.LogonButton.Visibility = Visibility.Collapsed;
            this.CancelButton.Visibility = Visibility.Collapsed;

            this.Hide();
            ShowMainDailog();

            Thread workerThread = new Thread(delegate()
                            {
                                while (App.IsGameStart == false)
                                {
                                    Thread.Sleep(200);
                                }
                            });      
            workerThread.Start();

        }

        private void imageCancelButton_ImageFailed(object sender, RoutedEvent e)
        {
            System.Media.SoundPlayer soundPlayer = new System.Media.SoundPlayer(Properties.Resources.close);
            soundPlayer.Play();
            System.Threading.Thread.Sleep(1500);
            Application.Current.Shutdown();
        }

        private void ShowMainDailog()
        {
            var lstGame = App.gameMainWindow;

            if (!lstGame.CheckAccess())
            {
                lstGame.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new System.Threading.ThreadStart(this.ShowMainDailog));
            }
            else
            {
                App.gameMainWindow.Show();
                App.gameMainWindow.labelClientName.Content = App.currentClientName;
                App.gameMainWindow.imageTimeFlagMoon.Visibility = Visibility.Hidden;
                App.gameMainWindow.imageTimeFlagSun.Visibility = Visibility.Hidden;

            }
        }

        private void LogonButton_MouseEnter(object sender, MouseEventArgs e)
        {
            BevelBitmapEffect bevelEffect = new BevelBitmapEffect();
            LogonButton.BitmapEffect = bevelEffect;

        }

        private void LogonButton_MouseLeave(object sender, MouseEventArgs e)
        {
            LogonButton.BitmapEffect = null;

        }

        private void CancelButton_MouseEnter(object sender, MouseEventArgs e)
        {
            BevelBitmapEffect bevelEffect = new BevelBitmapEffect();
            CancelButton.BitmapEffect = bevelEffect;
        }

        private void CancelButton_MouseLeave(object sender, MouseEventArgs e)
        {
            CancelButton.BitmapEffect = null;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -