public static LobbyWindow lanGame(UserAccount account, ILobbyGUI gui) { DiscoveryClient dc = new DiscoveryClient(new UdpDiscoveryEndpoint()); FindCriteria fc = new FindCriteria(typeof(IDiscoveryTest)); fc.Duration = TimeSpan.FromSeconds(5); FindResponse fr = dc.Find(fc); if (fr.Endpoints.Count > 0) { ip = fr.Endpoints[0].Address.Uri.Host.ToString(); } else { string HostName = System.Net.Dns.GetHostName(); System.Net.IPHostEntry hostInfo = System.Net.Dns.GetHostByName(HostName); string IpAdresse = hostInfo.AddressList[0].ToString(); ip = IpAdresse; Server server = new Server(new WCFTCPServiceFactory(),ip); server.run(); } factory = new WCFTCPConnectionFactory(); lobbyWindow = new LobbyWindow(account, gui, factory); factory.connectToLobby(ip, lobbyWindow); return lobbyWindow; }
public void subscribe(UserAccount user) { IGameCallback callback = OperationContext.Current.GetCallbackChannel<IGameCallback>(); if (strategy.getMaxPlayer() > subscribers.Count) { if (!subscribers.ContainsValue(callback)) { subscribers.Add(user, callback); sendLog(user.username + " joined game: " + gameName + "!"); Console.WriteLine(user.username + " subscribed for " + gameName + "!"); server.updateGames(); } if (strategy.getMaxPlayer() == subscribers.Count) { foreach (IGameCallback c in subscribers.Values) { c.eventShipPlacement(); } } } else { callback.receiveLog("Server full!"); } }
public void shootTest() { Game target = new Game(); UserAccount user = new UserAccount("Player", 1); Field field = new Field(5, 5); target.shoot(user, field); Assert.Inconclusive("A method that does not return a value cannot be verified."); }
public LobbyPage(UserAccount account) { this.Games = new List<GameListItem>(); this.InitializeComponent(); this.account = account; CreateGameDialog.LockElement = LayoutRoot; chat.sendButton.Click += sendButton_Click; chat.message.KeyDown += message_KeyDown; }
public GameWindow(UserAccount owner,string connStr, IGameGUI gameGUI, WCFConnectionFactory connFactory) { this.owner = owner; this.gameGUI = gameGUI; playfields = new List<Playfield>(); this.connFactory = connFactory; this.game = connFactory.connectToGame(connStr, this); game.subscribe(owner); }
public LobbyWindow(UserAccount user, ILobbyGUI lobbyGui, WCFConnectionFactory connFactory) { this.user = user; this.lobbyGui = lobbyGui; this.connFactory = connFactory; lobby = connFactory.connectToLobby(Connector.ip, this); lobby.subscribe(user); }
public static LobbyWindow onlineGame(UserAccount account, ILobbyGUI gui) { ip = "145.93.27.6"; factory = new WCFHTTPConnectionFactory(); lobbyWindow = new LobbyWindow(account, gui, factory); factory.connectToLobby(ip, lobbyWindow); return lobbyWindow; }
public void setFieldStatus(UserAccount user, Field field, FieldStatus status, Ship ship) { foreach (Playfield pf in playfields) { if (pf.user.Equals(user)) { pf.setFieldStatus(field, status, ship); } } gameGUI.updateField(user, field, status); }
private void run() { GameConsole console; Console.WriteLine("Enter a username!"); string name = Console.ReadLine(); UserAccount user = new UserAccount(name, 0); LobbyWindow lobbyWindow = null;//new LobbyWindow(user, this); string command = Console.ReadLine(); String[] context; while (!command.Equals("exit")) { context = command.Split(' '); if (context[0].Equals("create")) { bool ok = lobbyWindow.createGame(context[1], Strategies.SimpleGameStrategy, 2); if (ok) { string connString = lobbyWindow.joinGame(context[1]); console = new GameConsole(lobbyWindow.user, connString); console.run(); lobbyWindow = null; //new LobbyWindow(user, this); } else { Console.WriteLine("Game already exists!"); } } if (context[0].Equals("join")) { string connString = lobbyWindow.joinGame(context[1]); if (connString != null) { IGameGUI game = new GameConsole(lobbyWindow.user, connString); console = (GameConsole)game; console.run(); lobbyWindow = null; //new LobbyWindow(user, this); } else { Console.WriteLine("Game does not exist!"); } } if (context[0].Equals("send")) { lobbyWindow.sendMessage(context[1]); } command = Console.ReadLine(); } lobbyWindow.leave(); }
public void MyTestInitialize() { owner = new UserAccount("Daniel van der Wal", 1); user2 = new UserAccount("Cihad Kirhan", 2); window = new GameWindow(owner, "localhost", new TestGUI(), new WCFHTTPConnectionFactory()); window.owner = owner; window.playfields.Add(new Playfield(6, owner)); window.playfields.Add(new Playfield(6, user2)); window.playfields.Add(new Playfield(6, new UserAccount("Sebastian Hantich", 3))); window.playfields.Add(new Playfield(6, new UserAccount("Kamil Szuster", 4))); window.playfields.Add(new Playfield(6, new UserAccount("Daniel Witkowski", 5))); }
public Playfield(int size, UserAccount user) { this.fieldlist = new Field[size, size]; this.user = user; for (int i = 0; i < fieldlist.GetLength(0); i++) { for (int j = 0; j < fieldlist.GetLength(1); j++) { fieldlist[i, j] = new Field(i, j); } } }
private void startButton_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) { LoginDialogResult result = LoginControl.Show(); if(result == LoginDialogResult.OK) { string username = LoginControl.UserNameTextBox.Text; UserAccount account = new UserAccount(username, 0); LobbyPage lobby = new LobbyPage(account); LobbyWindow window = Connector.lanGame(account, lobby); lobby.register(window); MainWindow.NavigateToPage(lobby); } }
public void subscribe(UserAccount user) { ILobbyCallback callback = OperationContext.Current.GetCallbackChannel<ILobbyCallback>(); if (user.id == 0) { user.id = userCount; userCount++; callback.updateUserAccount(user); } if (!subscribers.ContainsKey(callback)) { subscribers.Add(callback, user); callback.receiveLog("Welcome in Lobby"); Console.WriteLine(user.username + " subscribed!"); updateUsers(); updateGames(); } }
public GameWindowPage(UserAccount account, string connString) { this.InitializeComponent(); user = account; Chat.sendButton.Click += sendButton_Click; Chat.message.KeyDown += message_KeyDown; gameWindow = new BattleShipClient.Windows.GameWindow(user, connString, this, new WCFTCPConnectionFactory()); for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { enemyPanel.Playfield.fieldControl[i, j].PreviewMouseDown += FieldClick; } } myGamePanel.addMouseEvents(); enemyPanel.Disable(); load.Show(); myGamePanel.playerName.Text = user.username; enemyPanel.playerName.Text = ""; myGamePanel.KeyDown += HandleKeyDown; WinnerDialog.LockElement = LayoutRoot; }
public TestGUI() { UserAccount user = new UserAccount("testUser", 0); lobbyWindow = new LobbyWindow(user, this, new WCFTCPConnectionFactory()); messageUpdated = 0; logUpdated = 0; }
public void endGame(UserAccount winner, string connectionStringLobby) { throw new NotImplementedException(); }
public void updateField(UserAccount user, Field field, FieldStatus fieldStatus) { throw new NotImplementedException(); }
public void shoot(UserAccount user, Field field) { gameWindow.shoot(user, field); }
public TestGUI(Server server) { UserAccount owner = new UserAccount("TestUser", 0); String connString = server.joinGame("TestGame"); Assert.AreEqual("http://localhost/Game/TestGame", connString); WCFConnectionFactory factory = new WCFTCPConnectionFactory(); gameWindow = new GameWindow(owner, connString, this,factory); }
void ILobbyCallback.updateUserAccount(UserAccount user) { lobbyWindow.user = user; }
public void shoot(UserAccount user, Field field) { throw new NotImplementedException(); }
public void endGame(UserAccount winner, string connectionStringLobby) { gameGUI.endGame(winner, connectionStringLobby); }
public void endGame(UserAccount winner, string connectionStringLobby) { this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (DispatcherOperationCallback)delegate(object arg) { if(winner.Equals(user)) { WinnerDialog.Show(true); } else { WinnerDialog.Show(false); } gameWindow.unSubscribe(); LobbyPage lobby = new LobbyPage(user); LobbyWindow window = Connector.lanGame(user, lobby); lobby.register(window); MainWindow.NavigateToPage(lobby); return null; }, null); }
public void updateField(UserAccount user, BattleShip.GameWindow.GamePanel.Field field, BattleShip.GameWindow.GamePanel.FieldStatus fieldStatus) { Console.WriteLine("Playfield of User:"******" at Field " + field.xCoordinate + "/" + field.yCoordinate + " was "+ fieldStatus); }
public GameConsole(UserAccount user, String connString) { this.user = user; //gameWindow = new GameWindow(user, connString, this); }
public void updateField(UserAccount user, GameWindow.GamePanel.Field field, GameWindow.GamePanel.FieldStatus fieldStatus) { this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (DispatcherOperationCallback)delegate(object arg) { if (user.Equals(this.user)) { if (fieldStatus == GameWindow.GamePanel.FieldStatus.HIT) { myGamePanel.Playfield.fieldControl[field.xCoordinate - 1, field.yCoordinate - 1].setRed(); } else { myGamePanel.Playfield.fieldControl[field.xCoordinate - 1, field.yCoordinate - 1].setGreen(); } } else if (user.Equals(this.enemy)) { if (fieldStatus == GameWindow.GamePanel.FieldStatus.HIT) { enemyPanel.Playfield.fieldControl[field.xCoordinate - 1, field.yCoordinate - 1].setGreen(); } else { enemyPanel.Playfield.fieldControl[field.xCoordinate - 1, field.yCoordinate - 1].setRed(); } enemyPanel.Playfield.fieldControl[field.xCoordinate - 1, field.yCoordinate - 1].PreviewMouseDown -= FieldClick; } return null; }, null); }
public void MyTestCleanup() { owner = null; user2 = null; window = null; }
public UserSession(UserAccount user, List<ShipPosition> shipPositions) { this.user = user; this.shipPositions = shipPositions; }
public void endGame(UserAccount winner, string connectionStringLobby) { Console.WriteLine("End game! Winner is: " + winner.username + "!"); gameEnded = true; }
public void eventStart(List<UserAccount> users) { this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (DispatcherOperationCallback)delegate(object arg) { foreach (UserAccount account in users) { if (!account.Equals(user)) { enemy = account; enemyPanel.playerName.Text = enemy.username; } } return null; }, null); }