📄 messagedistribute.svc.cs
字号:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Utility;
using System.Windows.Controls;
namespace KillingClientUI
{
// NOTE: If you change the class name "MessageDistribute" here, you must also update the reference to "MessageDistribute" in Web.config.
[ServiceBehavior]
public partial class MessageDistribute : IMessageDistribute
{
//Server host->Player client
[OperationBehavior]
public bool ReceiveNewsMsg(string strMsg)
{
App.IsNewChatMsg = true;
App.ChatMsg = strMsg;
ReceiveNewsMsgController();
Console.WriteLine(strMsg);
return true;
//TODO:Append this message to textbox board.
//throw new System.NotImplementedException("ReceiveNewsMsg is not implemented");
}
private void ReceiveNewsMsgController()
{
var lstGame = App.gameMainWindow.labelClientName;
if (!lstGame.CheckAccess())
{
lstGame.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new System.Threading.ThreadStart(this.ReceiveNewsMsgController));
}
else
{
App.gameMainWindow.richTextBoxChat.AppendText(App.ChatMsg + "\n\r");
}
}
private void GameStartControllers()
{
var lstGame = App.gameMainWindow.labelClientName;
if (!lstGame.CheckAccess())
{
lstGame.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new System.Threading.ThreadStart(this.GameStartControllers));
}
else
{
//if (App.gameInfo.YourRole == RoleFlag.Killer)
//{
App.gameMainWindow.labelClientRole.Content = App.gameInfo.YourRole.ToString();
//}
//else if(App.gamei
//{
// App.gameMainWindow.labelClientRole.Content = RoleFlag.Civilian.ToString() ;
//}
ChangeTimeImageToDay(TimeFlag.DayTime);
//App.gameMainWindow.PlayerList.DataContext = gameStar2t.listPlayers;
foreach (string playerName in App.gameInfo.listPlayers)
{
ListViewItem playerListItem = new ListViewItem();
playerListItem.Content = playerName + " -Alive";
App.gameMainWindow.PlayerList.Items.Add(playerListItem);
ComboBoxItem targetListItem = new ComboBoxItem();
targetListItem.Content = playerName;
App.gameMainWindow.TargetList.Items.Add(targetListItem);
}
//Don't hid the current client user ( client himself) from the targit list, in other word, can kill himself.
//foreach (ComboBoxItem targetListItem in App.gameMainWindow.TargetList.Items)
//{
// if (App.currentClientName == targetListItem.Content.ToString())
// {
// targetListItem.Visibility = System.Windows.Visibility.Hidden;
// }
//}
//App.gameMainWindow.Show();
}
}
[OperationBehavior]
public bool GameStart(GameInfo gameInfo)
{
App.IsGameStart = true;
App.gameInfo = gameInfo;
GameStartControllers();
return true;
}
private void ChangeTimeImageToDay(Utility.TimeFlag timeFlag)
{
if (timeFlag == TimeFlag.DayTime)
{
App.gameMainWindow.imageTimeFlagSun.Visibility = System.Windows.Visibility.Visible;
App.gameMainWindow.imageTimeFlagMoon.Visibility = System.Windows.Visibility.Hidden;
}
else if (timeFlag == TimeFlag.Night)
{
App.gameMainWindow.imageTimeFlagSun.Visibility = System.Windows.Visibility.Hidden;
App.gameMainWindow.imageTimeFlagMoon.Visibility = System.Windows.Visibility.Visible;
}
//App.gameMainWindow.imageTimeFlagSun.Visibility = (timeFlag == Utility.TimeFlag.DayTime) ? (System.Windows.Visibility.Visible) : (System.Windows.Visibility.Hidden);
//App.gameMainWindow.imageTimeFlagMoon.Visibility = (timeFlag == Utility.TimeFlag.Night) ? (System.Windows.Visibility.Visible) : (System.Windows.Visibility.Hidden);
}
[OperationBehavior]
public bool ReceiveVoteResult(VoteResult voteResult)
{
App.voteResult = voteResult;
App.IsVoteResult = true;
ReceiveVoteResultControllers();
return true;
}
private void ReceiveVoteResultControllers()
{
var lstGame = App.gameMainWindow.TargetList.Items;
var playerList = App.gameMainWindow.PlayerList.Items;
int targetListItemID = 0;
if (!lstGame.CheckAccess())
{
lstGame.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new System.Threading.ThreadStart(this.ReceiveVoteResultControllers));
}
else
{
if (App.voteResult.IsThisVoteValid == true)
{
foreach (ListViewItem listViewItemKilledPerson in playerList)
{
if (listViewItemKilledPerson.Content.ToString().Contains(App.voteResult.KilledPlayer))
{
listViewItemKilledPerson.Content = listViewItemKilledPerson.Content.ToString().Replace("Alive", "Dead");
}
}
ChangeTimeImageToDay(App.voteResult.TimeFlag);
//Enable Kill button.
foreach (ListViewItem listViewItemAlivePerson in playerList)
{
string PlayerItemName = listViewItemAlivePerson.Content.ToString();
string currentClientName = App.gameMainWindow.labelClientName.Content.ToString();
string currentClientRole = App.gameMainWindow.labelClientRole.Content.ToString();
if ((PlayerItemName.Contains(currentClientName)) && (PlayerItemName.Contains("Alive")) && (App.voteResult.TimeFlag == TimeFlag.DayTime))
{
App.gameMainWindow.Kill.IsEnabled = true;
}
else if ((PlayerItemName.Contains(currentClientName)) && (PlayerItemName.Contains("Alive")) && (App.voteResult.TimeFlag == TimeFlag.Night) && ((currentClientRole.Contains(RoleFlag.Killer.ToString()))) && (App.voteResult.ActiveTypeFlag == ActivityTypeFlag.Kill))
{
App.gameMainWindow.Kill.IsEnabled = true;
}
else if ((PlayerItemName.Contains(currentClientName)) && (PlayerItemName.Contains("Alive")) && (App.voteResult.TimeFlag == TimeFlag.Night) && ((currentClientRole.Contains(RoleFlag.Police.ToString()))) && (App.voteResult.ActiveTypeFlag == ActivityTypeFlag.Investigate))
{
App.gameMainWindow.Kill.IsEnabled = true;
}
}
}
else
{
//Enable Kill button.
foreach (ListViewItem listViewItemAlivePerson in playerList)
{
string PlayerItemName = listViewItemAlivePerson.Content.ToString();
string currentClientName = App.gameMainWindow.labelClientName.Content.ToString();
string currentClientRole = App.gameMainWindow.labelClientRole.Content.ToString();
if ((PlayerItemName.Contains(currentClientName)) && (PlayerItemName.Contains("Alive")) && (App.voteResult.TimeFlag == TimeFlag.DayTime))
{
App.gameMainWindow.Kill.IsEnabled = true;
}
else if ((PlayerItemName.Contains(currentClientName)) && (PlayerItemName.Contains("Alive")) && (App.voteResult.TimeFlag == TimeFlag.Night) && ((currentClientRole.Contains(RoleFlag.Killer.ToString()))) && (App.voteResult.ActiveTypeFlag == ActivityTypeFlag.Kill))
{
App.gameMainWindow.Kill.IsEnabled = true;
}
else if ((PlayerItemName.Contains(currentClientName)) && (PlayerItemName.Contains("Alive")) && (App.voteResult.TimeFlag == TimeFlag.Night) && ((currentClientRole.Contains(RoleFlag.Police.ToString()))) && (App.voteResult.ActiveTypeFlag == ActivityTypeFlag.Investigate))
{
App.gameMainWindow.Kill.IsEnabled = true;
}
}
}
}
}
//connect to server, when server host works as a client, this will be used.
private MessageDistribution ConnectToServer(string strEndPointAddr)
{
NetTcpBinding tcpBinding = new NetTcpBinding();
tcpBinding.TransactionFlow = false;
tcpBinding.Security.Transport.ProtectionLevel =
System.Net.Security.ProtectionLevel.EncryptAndSign;
tcpBinding.Security.Transport.ClientCredentialType =
TcpClientCredentialType.Windows;
tcpBinding.Security.Mode = SecurityMode.None;
EndpointAddress endpointAddress =
new EndpointAddress(strEndPointAddr);
MessageDistribution proxy =
ChannelFactory<MessageDistribution>.CreateChannel(tcpBinding, endpointAddress);
return proxy;
}
}
//For initialize game on client end
[DataContract]
public class GameInfo
{
[DataMember]
public List<string> listPlayers
{ get; set; }
[DataMember]
public RoleFlag YourRole
{ get; set; }
[DataMember]
public List<string> listKillers
{ get; set; }
//Currently no use
[DataMember]
public List<string> listPolicemen
{ get; set; }
}
[DataContract]
public class VoteResult
{
[DataMember]
public string KilledPlayer
{ get; set; }
[DataMember]
public bool IsThisVoteValid
{ get; set; }
[DataMember]
public TimeFlag TimeFlag
{ get; set; }
[DataMember]
public ActivityTypeFlag ActiveTypeFlag
{ get; set;}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -