コード例 #1
0
ファイル: Connector.cs プロジェクト: kaszuster/BattleShip
        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;
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: kaszuster/BattleShip
        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!");
            }
        }
コード例 #3
0
ファイル: GameTest.cs プロジェクト: kaszuster/BattleShip
 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.");
 }
コード例 #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;
		}
コード例 #5
0
ファイル: GameWindow.cs プロジェクト: kaszuster/BattleShip
 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);
 }
コード例 #6
0
ファイル: LobbyWindow.cs プロジェクト: kaszuster/BattleShip
        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);
        }
コード例 #7
0
ファイル: Connector.cs プロジェクト: kaszuster/BattleShip
        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;

        }
コード例 #8
0
ファイル: GameWindow.cs プロジェクト: kaszuster/BattleShip
 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);
 }
コード例 #9
0
ファイル: Program.cs プロジェクト: kaszuster/BattleShip
        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();
        }
コード例 #10
0
ファイル: WindowTest.cs プロジェクト: kaszuster/BattleShip
 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)));
 }
コード例 #11
0
ファイル: Playfield.cs プロジェクト: kaszuster/BattleShip
 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);
         }
     }
 }
コード例 #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);
			}
		}
コード例 #13
0
ファイル: Lobby.cs プロジェクト: kaszuster/BattleShip
        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();
            }
        }
コード例 #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;
		}
コード例 #15
0
 public TestGUI()
 {
     UserAccount user = new UserAccount("testUser", 0);
     lobbyWindow = new LobbyWindow(user, this, new WCFTCPConnectionFactory());
     messageUpdated = 0;
     logUpdated = 0;
 }
コード例 #16
0
 public void endGame(UserAccount winner, string connectionStringLobby)
 {
     throw new NotImplementedException();
 }
コード例 #17
0
 public void updateField(UserAccount user, Field field, FieldStatus fieldStatus)
 {
     throw new NotImplementedException();
 }
コード例 #18
0
 public void shoot(UserAccount user, Field field)
 {
     gameWindow.shoot(user, field);
 }
コード例 #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);
 }
コード例 #20
0
ファイル: LobbyCallback.cs プロジェクト: kaszuster/BattleShip
 void ILobbyCallback.updateUserAccount(UserAccount user)
 {
     lobbyWindow.user = user;
 }
コード例 #21
0
ファイル: WindowTest.cs プロジェクト: kaszuster/BattleShip
 public void shoot(UserAccount user, Field field)
 {
     throw new NotImplementedException();
 }
コード例 #22
0
ファイル: GameWindow.cs プロジェクト: kaszuster/BattleShip
 public void endGame(UserAccount winner, string connectionStringLobby)
 {
     gameGUI.endGame(winner, connectionStringLobby);
 }
コード例 #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);
        }
コード例 #24
0
ファイル: GameConsole.cs プロジェクト: kaszuster/BattleShip
 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);
 }
コード例 #25
0
ファイル: GameConsole.cs プロジェクト: kaszuster/BattleShip
 public GameConsole(UserAccount user, String connString)
 {
     this.user = user;
     //gameWindow = new GameWindow(user, connString, this);
 }
コード例 #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);
 }
コード例 #27
0
ファイル: WindowTest.cs プロジェクト: kaszuster/BattleShip
 public void MyTestCleanup()
 {
     owner = null;
     user2 = null;
     window = null;
 }
コード例 #28
0
ファイル: UserSession.cs プロジェクト: kaszuster/BattleShip
 public UserSession(UserAccount user, List<ShipPosition> shipPositions)
 {
     this.user = user;
     this.shipPositions = shipPositions;
 }
コード例 #29
0
ファイル: GameConsole.cs プロジェクト: kaszuster/BattleShip
 public void endGame(UserAccount winner, string connectionStringLobby)
 {
     Console.WriteLine("End game! Winner is: " + winner.username + "!");
     gameEnded = true;
 }
コード例 #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);
 }