Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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!");
            }
        }
Exemplo n.º 3
0
 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.");
 }
Exemplo n.º 4
0
		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;
		}
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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;

        }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
        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();
        }
Exemplo n.º 10
0
 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)));
 }
Exemplo n.º 11
0
 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);
         }
     }
 }
Exemplo n.º 12
0
		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);
			}
		}
Exemplo n.º 13
0
        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();
            }
        }
Exemplo n.º 14
0
		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;
		}
Exemplo n.º 15
0
 public TestGUI()
 {
     UserAccount user = new UserAccount("testUser", 0);
     lobbyWindow = new LobbyWindow(user, this, new WCFTCPConnectionFactory());
     messageUpdated = 0;
     logUpdated = 0;
 }
Exemplo n.º 16
0
 public void endGame(UserAccount winner, string connectionStringLobby)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 17
0
 public void updateField(UserAccount user, Field field, FieldStatus fieldStatus)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 18
0
 public void shoot(UserAccount user, Field field)
 {
     gameWindow.shoot(user, field);
 }
Exemplo n.º 19
0
 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);
 }
Exemplo n.º 20
0
 void ILobbyCallback.updateUserAccount(UserAccount user)
 {
     lobbyWindow.user = user;
 }
Exemplo n.º 21
0
 public void shoot(UserAccount user, Field field)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 22
0
 public void endGame(UserAccount winner, string connectionStringLobby)
 {
     gameGUI.endGame(winner, connectionStringLobby);
 }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
0
 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);
 }
Exemplo n.º 25
0
 public GameConsole(UserAccount user, String connString)
 {
     this.user = user;
     //gameWindow = new GameWindow(user, connString, this);
 }
Exemplo n.º 26
0
 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);
 }
Exemplo n.º 27
0
 public void MyTestCleanup()
 {
     owner = null;
     user2 = null;
     window = null;
 }
Exemplo n.º 28
0
 public UserSession(UserAccount user, List<ShipPosition> shipPositions)
 {
     this.user = user;
     this.shipPositions = shipPositions;
 }
Exemplo n.º 29
0
 public void endGame(UserAccount winner, string connectionStringLobby)
 {
     Console.WriteLine("End game! Winner is: " + winner.username + "!");
     gameEnded = true;
 }
Exemplo n.º 30
0
 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);
 }