private void OnEventFlipNewCard(GameEventArgs gameEventArgs) { if (_client.Id == gameEventArgs.ClientId) { var cardInfo = CardInfo.Get(gameEventArgs.CardId); Console.WriteLine("{0} open {1}", _client, cardInfo); } }
private void OnEventTakeNewCard(GameEventArgs gameEventArgs) { var id = gameEventArgs.ClientId; if (_client.Id == id) { var cardInfo = CardInfo.Get(gameEventArgs.CardId); Console.WriteLine("{0} got {1}", _client, cardInfo); } }
private void Check(Task task) { if (_client.Data.PrivateData.Unknown.Count <= 0) { throw new Exception(); } var cardId = _client.Data.PrivateData.Unknown.ElementAt(0).Key; Console.WriteLine($"{_client} open {CardInfo.Get(cardId)}"); _client.Dispatcher.PublicDispatcher.Dispatch(new GameEventArgs(EventType.OpenCard, _client.Id, cardId)); }
private void ShuffleCard() { var count = CardInfo.Count; var list = new List <int>(count); for (var i = 1; i <= count; i++) { list.Add(i); } var rnd = new Random(); var shuffle = list.OrderBy(a => rnd.Next()); var pridata = _host.Data.PrivateData; foreach (var i in shuffle) { pridata.Unknown.Add(i, CardInfo.Get(i)); } _host.Dispatcher.PublicDispatcher.Dispatch(new GameEventArgs(EventType.ShuffleCard)); }
private void OnEventOpenCard(GameEventArgs args) { var cardId = args.CardId; var clientId = args.ClientId; var pubdata = _host.Data.PublicData; var pridata = _host.Data.PrivateData; var clientdata = _host.Data.GetClientData(clientId); if (!clientdata.Unknown.ContainsKey(cardId)) { throw new ArgumentException(); } clientdata.Unknown.Remove(cardId); pubdata.HostKnown.Add(cardId, CardInfo.Get(cardId)); var flip = pridata.Unknown.ElementAt(pridata.Unknown.Count - 1).Value; pridata.Unknown.Remove(flip.Id); pubdata.HostKnown.Add(flip.Id, flip); _host.Dispatcher.PublicDispatcher.Dispatch(new GameEventArgs(EventType.FlipNewCard, clientId, flip.Id)); }
private void OnEventFlipNewCard(GameEventArgs args) { Console.WriteLine($"{_host} flip {CardInfo.Get(args.CardId)}"); _host.ChangeState(new StateCheckScore(_host)); }
private void PassingCard() { int GetLastCardInfo() { var unknown = _host.Data.PrivateData.Unknown; return(unknown.Keys.ElementAt(unknown.Count - 1)); } int GetNextId(int current, bool forward) { var c = _host.Data.GetClientCount(); if (forward) { current++; return(current == c ? 0 : current); } if (current == 0) { return(c - 1); } return(current - 1); } void Flip(int num) { for (var i = 0; i < num; i++) { var id = GetLastCardInfo(); _host.Data.PrivateData.Unknown.Remove(id); _host.Data.PublicData.HostKnown.Add(id, CardInfo.Get(id)); _host.Dispatcher.PublicDispatcher.Dispatch(new GameEventArgs(EventType.FlipNewCard, -1, id)); } } void Take(int client, int num) { for (var i = 0; i < num; i++) { var id = GetLastCardInfo(); _host.Data.PrivateData.Unknown.Remove(id); _host.Data.GetClientData(client).Unknown.Add(id, CardInfo.Get(id)); _host.Dispatcher.PublicDispatcher.Dispatch(new GameEventArgs(EventType.TakeNewCard, client)); _host.Dispatcher.PrivateDispatchers[client].Dispatch(new GameEventArgs(EventType.TakeNewCard, client, id)); } } var count = _host.Data.GetClientCount(); var leader = _host.Data.Leader; var order = (count == 2) ? new[] { 4, 5, 4, 5 } : new[] { 3, 4, 3, 3 }; Flip(order[0]); var turn = GetNextId(leader, false); for (var j = 0; j < count; j++) { Take(turn, order[1]); turn = GetNextId(turn, false); } Flip(order[2]); turn = leader; for (var j = 0; j < count; j++) { Take(turn, order[3]); turn = GetNextId(turn, true); } }