public PlayerModel(PlayerInfo player, DeckItem deck) : base(player.NickName) { this.Player = player; this.Deck = new ObservableProperty<DeckItem, PlayerModel>(this, deck); this.Ready = new ObservableProperty<bool, PlayerModel>(this, false); }
public SideboardingEditorModel(ServicesProvider servicesProvider, GameInfoItem gameItem, DeckItem deck) { this.ServiceProvider = servicesProvider; this.GameItem = gameItem; this.originalDeck = deck; this.Deck = (DeckItem)deck.Clone(); }
public ClientStarterModel(PlayerInfo playerInfo, DeckItem deck, ServicesProvider servicesProvider) : base(Guid.NewGuid().ToString()) { this.console = new ConsoleModel(Guid.NewGuid().ToString()); this.deck = deck; this.playerInfo = playerInfo; this.players = new ObservableCollection<PlayerAccountData>(); }
public PlayerModel(GameModel parent, string key, PlayerInfo info, DeckItem deck, string password) : base(parent, null, key) { this.Info = info; this.Deck = deck; this.Points = new ObservableProperty<int, PlayerModel>(this, 0); this.Sectors = new ModelCollection(this); this.NumCounters = new ModelCollection(this); this.Password = password; }
public DeckDataContract(DeckItem deck) { this.GameCode = deck.GameCode; this.Category = deck.Category; this.Name = deck.Name; foreach(var card in deck.MainCards) this.MainCards.Add(card); foreach(var card in deck.SideboardCards) this.SideboardCards.Add(card); }
public DeckEditorModel(ServicesProvider servicesProvider, GameInfoItem gameItem, DeckItem deck) { this.ServiceProvider = servicesProvider; this.GameItem = gameItem; if(deck == null) Deck = new DeckItem(gameItem.Code); else { originalDeck = deck; Deck = (DeckItem)deck.Clone(); } }
public TestView() { InitializeComponent(); logicStarter = new LogicHandler(new WinFormsViewFactory()); clientPlayer1 = CreatePlayerInfo("ClientPlayer1"); clientDeck1 = logicStarter.ServicesProvider.DecksService.LoadDeck("Reali", "Samurai"); clientDeck1.MainCards.Shuffle(); clientStarter1 = new ClientStarterModel(clientPlayer1, clientDeck1, logicStarter.ServicesProvider); clientStarter1.Started += new Action<object>(clientStarter1_Started); connector1 = new ClientConnector(clientPlayer1, logicStarter.ServicesProvider); clientPlayer2 = CreatePlayerInfo("ClientPlayer2"); clientDeck2 = logicStarter.ServicesProvider.DecksService.LoadDeck("Reali", "Samurai"); clientDeck2.MainCards.Shuffle(); clientStarter2 = new ClientStarterModel(clientPlayer2, clientDeck2, logicStarter.ServicesProvider); clientStarter2.Started += new Action<object>(clientStarter2_Started); connector2 = new ClientConnector(clientPlayer2, logicStarter.ServicesProvider); serverPlayer = CreatePlayerInfo("ServerPlayer"); serverDeck = logicStarter.ServicesProvider.DecksService.LoadDeck("Reali", "Samurai"); serverDeck.MainCards.Shuffle(); }
public void Save() { originalDeck = (DeckItem)Deck.Clone(); }
public void Save() { if(string.IsNullOrEmpty(Deck.Category)) throw new InvalidDeckCategoryNameException(string.Concat("Category name is empty!")); if(string.IsNullOrEmpty(Deck.Name)) throw new InvalidDeckNameException(string.Concat("Name is empty!")); if(Deck.Category.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) throw new InvalidDeckCategoryNameException(string.Concat("Category name ", Deck.Category, " contains invalid chars!")); if(Deck.Name.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) throw new InvalidDeckNameException(string.Concat("Name ", Deck.Name, " contains invalid chars!")); // new deck? if(originalDeck == null && ServiceProvider.DecksService.DeckExists(Deck.Category, Deck.Name)) throw new DeckAlreadyExistsException(string.Concat("Deck ", Deck.Category, " ", Deck.Name, " already exists!")); // renamed deck? if(originalDeck != null && (originalDeck.Category != Deck.Category || originalDeck.Name != Deck.Name)) if(ServiceProvider.DecksService.DeckExists(Deck.Category, Deck.Name)) throw new DeckAlreadyExistsException(string.Concat("Deck ", Deck.Category, " ", Deck.Name, " already exixts!")); ServiceProvider.DecksService.SaveDeck(Deck); originalDeck = (DeckItem)Deck.Clone(); }
public object Clone() { DeckItem deck = new DeckItem (this.GameCode); deck.Category = this.Category; deck.Name = this.Name; foreach (var card in this.MainCards) deck.MainCards.Add (card); foreach (var card in this.SideboardCards) deck.SideboardCards.Add (card); return deck; }
public void SelectDeck(DeckItem deck) { if(deck != null) { ListViewItem item = listDeck.Items.Find(string.Concat(deck.Category, deck.Name), true).FirstOrDefault(); if(item != null) { ignoreSelectionChanging = true; try { item.Selected = true; } finally { ignoreSelectionChanging = false; } } } }
void listener_PlayerConnected(object sender, ServiceNetClient client, PlayerAccountData connectedPlayer) { if(++playerCounter < 2) return; if(InvokeRequired) Invoke(new Action<object, ServiceNetClient, PlayerAccountData>(listener_PlayerConnected), sender, client, connectedPlayer); else { ServerListener listener = (ServerListener)sender; if(listener.PlayerConnections != null) { listener.Dispose(); clientStarter1.Start(null); clientStarter2.Start(null); PlayerInfo[] players = new PlayerInfo[] { serverPlayer, clientPlayer2, clientPlayer1 }; DeckItem[] decks = new DeckItem[] { serverDeck, clientDeck2, clientDeck1 }; Thread.Sleep(1000); StartGame(listener.PlayerConnections, players.ToList(), decks.ToList(), new string[] { string.Empty, string.Empty, string.Empty }, GameType.Host, false); } } }
void clientStarter2_Started(object sender) { if(opponentData2 != null) { PlayerInfo[] players = new PlayerInfo[] { clientPlayer2, clientPlayer1, serverPlayer }; DeckItem[] decks = new DeckItem[] { clientDeck2, clientDeck1, serverDeck }; StartGame(Enumerable.Repeat(new PlayerConnection() { NetClient = opponentData2.Channel }, 1).ToList(), players.ToList(), decks.ToList(), new string[] { string.Empty, string.Empty, string.Empty}, GameType.Client, false); } }
private void btnStartSolitaire_Click(object sender, EventArgs e) { PlayerInfo[] players = new PlayerInfo[] { serverPlayer, clientPlayer2, clientPlayer1 }; DeckItem[] decks = new DeckItem[] { serverDeck, clientDeck2, clientDeck1 }; StartGame(new List<PlayerConnection>(), players.ToList(), decks.ToList(), new string[] { string.Empty, string.Empty, string.Empty }, GameType.Solitaire, true); }
public void Start(bool passwordRequired, DeckItem deck, GameStartMode startMode) { this.startMode = startMode; this.passwordRequired = passwordRequired; this.deck = deck; netMessageService.ClientConnected += new Action<object, ServiceNetClient>(netMessageService_ClientConnected); netMessageService.Start(); }
public bool Connect(IPAddress address, int port, string password, GameStartMode startMode, DeckItem deck, out string errorMessage, out ServerData opponentData) { bool confirmed = false; errorMessage = string.Empty; opponentData = null; ServiceNetClient client = new ServiceNetClient(address, port); client.Disconnected += new EventHandler(client_Disconnected); connectionMessagesHandler = new ClientConnectionMessagesHandler(client); try { client.Subscribe(); Version clientVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; HandshakeRequest handshake = new HandshakeRequest() { PlayerInfo = playerInfo, Deck = new DeckDataContract(deck), StartMode = startMode, GameDatabaseCRC = servicesProvider.GameDatabaseCrc, CardDatabaseCRC = servicesProvider.CardDatabaseCrc, ClientVersion = clientVersion.ToString(), Password = password, }; Thread.Sleep(100); client.SendMessage(handshake); if(!WaitForHandshakeResponse()) throw new Exception("Opponent handshake not received!"); if(connectionMessagesHandler.Handshake.ConnectionResult != ConnectionResult.Accepted) { switch(connectionMessagesHandler.Handshake.ConnectionResult) { case ConnectionResult.VersionMismatch: errorMessage = servicesProvider.SystemStringsService.GetString("NEW_SERVER_GAME_DIALOG", "MSG_CONNECTIONREFUSED_VERSIONMISMATCH"); break; case ConnectionResult.GameIsRunning: errorMessage = servicesProvider.SystemStringsService.GetString("NEW_SERVER_GAME_DIALOG", "MSG_CONNECTIONREFUSED_GAMEISRUNNING"); break; case ConnectionResult.InvalidStartMode: errorMessage = servicesProvider.SystemStringsService.GetString("NEW_SERVER_GAME_DIALOG", "MSG_CONNECTIONREFUSED_INVALIDSTARTMODE"); break; case ConnectionResult.NicknameDuplicated: errorMessage = servicesProvider.SystemStringsService.GetString("NEW_SERVER_GAME_DIALOG", "MSG_CONNECTIONREFUSED_NICKNAMEDUPLICATED"); break; case ConnectionResult.GameDatabaseMismatch: errorMessage = servicesProvider.SystemStringsService.GetString("NEW_SERVER_GAME_DIALOG", "MSG_CONNECTIONREFUSED_GAMEDATAMISMATCH"); break; case ConnectionResult.CardDatabaseMismatch: errorMessage = servicesProvider.SystemStringsService.GetString("NEW_SERVER_GAME_DIALOG", "MSG_CONNECTIONREFUSED_CARDDATAMISMATCH"); break; case ConnectionResult.PasswordRequired: errorMessage = servicesProvider.SystemStringsService.GetString("NEW_SERVER_GAME_DIALOG", "MSG_CONNECTIONREFUSED_PASSWORDREQUIRED"); break; } } else { Thread.Sleep(100); client.SendMessage(new ConfirmMessage()); opponentData = new ServerData() { Channel = client, Player = connectionMessagesHandler.Handshake.PlayerInfo, Deck = new DeckItem(connectionMessagesHandler.Handshake.Deck) }; confirmed = true; } } catch(Exception ex) { errorMessage = ex.Message; } finally { connectionMessagesHandler.Dispose(); } return confirmed; }