private void DrawGameState(LobbyView game) { int index = 0; foreach (var gameplayPlayer in game.Gameplay.Players) { Console.WriteLine($"Player {gameplayPlayer.OwnerId}"); if (game.Gameplay.CurrentPlayersTurn == index) { Console.WriteLine($"(Current players turn)"); } for (int y = 4 - 1; y >= 0; y--) { for (int x = 0; x < gameplayPlayer.Board.Width; x++) { var tile = gameplayPlayer.Board[x, y]; Console.Write(tile.ToChar()); } Console.WriteLine(); } Console.WriteLine(); index++; } Console.WriteLine("======="); }
private void DrawGameState(LobbyView lobby) { lock (Console.Out) { int index = 0; if (lobby.Players == null || lobby.Players.Count == 0) { Console.WriteLine($"No players"); } else { foreach (var lobbyPlayer in lobby.Players) { if (lobby.Gameplay.Players.TryGetPlayer(lobbyPlayer.OwnerId, out var gameplayPlayer)) { Console.WriteLine($"Player {lobbyPlayer.OwnerId}"); if (lobby.Gameplay.CurrentPlayersTurn == index) { Console.WriteLine($" (Current players turn)"); } if (gameplayPlayer.ResourceHand != null && gameplayPlayer.ResourceHand.Count != 0) { foreach (string resource in gameplayPlayer.ResourceHand) { Console.Write('['); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(resource); Console.ResetColor(); Console.Write(']'); } Console.WriteLine(); } for (int y = 4 - 1; y >= 0; y--) { for (int x = 0; x < gameplayPlayer.Board.Width; x++) { var tile = gameplayPlayer.Board[x, y]; Console.Write(tile.ToChar()); } Console.WriteLine(); } Console.WriteLine(); index++; } else { Console.WriteLine($"Player {lobbyPlayer.OwnerId}"); Console.WriteLine($" (waiting for game to start)"); } } } } }
public LobbyScreenPresenter(Main main, LobbyView lobbyView) { this.main = main; this.lobbyView = lobbyView; Observable.FromEvent(h => lobbyView.ConnectButtonClickedEvent += h, h => lobbyView.ConnectButtonClickedEvent -= h) .Subscribe(onNext => ConnectButtonEventHandler()) .AddTo(subscriptions); }
public override void OnSceneLoaded(Scene scene, LoadSceneMode loadMode) { base.OnSceneLoaded(scene, loadMode); Debug.Log("大厅场景加载完成"); if (lobbyView == null) { lobbyView = new LobbyView(); lobbyView.Show(); GamePublisher.Publish(EventType.lobby_music_open); } }
private void Awake() { if (!instance) { instance = this; } else { Destroy(instance); instance = this; } }
private void Enter() { if (mLobbyView == null) { mLobbyView = ResourceManage.Instance.LoadPrefab("LobbyView").AddComponent <LobbyView>(); ResourceManage.Instance.LoadPrefab("LobbyBillboard", mLobbyView.gameObject); } else { mLobbyView.gameObject.SetActive(true); } }
private static void lobby_OnNavigateBack(object sender, NavigationService service) { LobbyView lobby = sender as LobbyView; if (lobby != null) { lobby.OnNavigateBack -= lobby_OnNavigateBack; } Login.Instance._LogOut(); Trace.Assert(service != null); service.Navigate(Login.Instance); }
public void ChangeWindow() { MusicEngine.ButtonSoundEffect(); MusicEngine.StartStop(); var window = Application.Current.Windows.OfType <Window>().SingleOrDefault(w => w.IsActive); LobbyView lobbyView = new LobbyView(); lobbyView.Show(); window.Close(); }
private void JoinLobby() { _screen.Display("Available lobbies:"); var lobbies = _client.ListLobbies(); var count = 0; lobbies.ForEach(l => { _screen.Display($"{count++}: {l.Name}"); }); _screen.Display("Enter the number to join a game, or type a name to create one:"); try { var lobby = CreateOrGetLobby(lobbies); _view = _client.JoinLobby(lobby.Id); } catch (AsciiException ex) { _screen.Display(ex.Message); } }
public void CreateSuccessfully() { Assert.Ignore(); var player1 = LocalId.NewShortId(); var player2 = LocalId.NewShortId(); PackageExplorer explorer = null; var gameView = new LobbyView(); gameView.SetupDependancies(explorer); gameView.Apply(new PlayerJoinedProcedure() { OwnerId = player1, DisplayName = "Player 1" }); gameView.Apply(new PlayerJoinedProcedure() { OwnerId = player2, DisplayName = "Player 2" }); gameView.Apply(new StartGameProcedure() { Gameplay = new GameplayView() { } }); gameView.Apply(new DeclareResourceProcedure() { Player = player1, ResourceIdentifier = "1" }); gameView.Apply(new PlaceResourceProcedure() { Player = player1, ResourceIdentifier = "1", ResourcePosition = new Integer2(1, 1) }); gameView.Apply(new PlaceResourceProcedure() { Player = player2, ResourceIdentifier = "1", ResourcePosition = new Integer2(3, 3) }); gameView.Apply(new EndTurnProcedure() { Player = player1 }); gameView.Apply(new DeclareResourceProcedure() { Player = player2, ResourceIdentifier = "2" }); gameView.Apply(new PlaceResourceProcedure() { Player = player1, ResourceIdentifier = "2", ResourcePosition = new Integer2(2, 1) }); gameView.Apply(new PlaceResourceProcedure() { Player = player2, ResourceIdentifier = "2", ResourcePosition = new Integer2(2, 1) }); gameView.Apply(new EndTurnProcedure() { Player = player2 }); gameView.Apply(new DeclareResourceProcedure() { Player = player1, ResourceIdentifier = "3" }); gameView.Apply(new PlaceResourceProcedure() { Player = player1, ResourceIdentifier = "3", ResourcePosition = new Integer2(1, 2) }); gameView.Apply(new PlaceResourceProcedure() { Player = player2, ResourceIdentifier = "3", ResourcePosition = new Integer2(1, 2) }); DrawGameState(gameView); gameView.Apply(new BuildBuildingProcedure() { Player = player1, BuildingIdentifier = "building", BuildingPosition = new Integer2(2, 2), Offset = new Integer2(1, 1), Orientation = BuildingOrientation.None }); gameView.Apply(new EndTurnProcedure() { Player = player1 }); DrawGameState(gameView); }
private void _startClient() { _userName = tab0UserName.Text; _passWd = tab0Password.Password; Properties.Settings.Default.LastHostName = tab0HostName.Text; Properties.Settings.Default.LastUserName = tab0UserName.Text; Properties.Settings.Default.Save(); #if !DEBUG bool createdNew; if (appMutex == null) { appMutex = new System.Threading.Mutex(true, "Sanguosha", out createdNew); ///if creation of mutex is successful if (!createdNew && tab0HostName.Text != "127.0.0.1") { appMutex = null; _Warn("You already have another Sanguosha running!"); return; } } #endif if (string.IsNullOrEmpty(_userName)) { _Warn("Please provide a username"); return; } busyIndicator.BusyContent = Resources["Busy.ConnectServer"]; busyIndicator.IsBusy = true; ILobbyService server = null; LoginToken token = new LoginToken(); string reconnect = null; _hostName = tab0HostName.Text; if (!_hostName.Contains(":")) { _hostName = _hostName + ":" + DefaultLobbyPort; } BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (o, ea) => { try { ea.Result = LoginStatus.UnknownFailure; _LogOut(); var lobbyModel = LobbyViewModel.Instance; var binding = new NetTcpBinding(); binding.Security.Mode = SecurityMode.None; var endpoint = new EndpointAddress(string.Format("net.tcp://{0}/GameService", _hostName)); _channelFactory = new DuplexChannelFactory <ILobbyService>(lobbyModel, binding, endpoint); server = _channelFactory.CreateChannel(); _channelFactory.Faulted += channelFactory_Faulted; Account ret; var stat = server.Login(Misc.ProtocolVersion, _userName, _passWd, out ret, out reconnect, out token); if (stat == LoginStatus.Success) { LobbyViewModel.Instance.CurrentAccount = ret; if (reconnect != null) { Application.Current.Dispatcher.Invoke((ThreadStart) delegate() { MainGame.BackwardNavigationService = this.NavigationService; busyIndicator.BusyContent = Resources["Busy.Reconnecting"]; }); } } ea.Result = stat; } catch (Exception e) { string s = e.StackTrace; } }; worker.RunWorkerCompleted += (o, ea) => { bool success = false; if ((LoginStatus)ea.Result == LoginStatus.Success) { LobbyView lobby = LobbyView.Instance; LobbyView.Instance.OnNavigateBack += lobby_OnNavigateBack; var lobbyModel = LobbyViewModel.Instance; lobbyModel.Connection = server; lobbyModel.LoginToken = token; if (reconnect == null) { this.NavigationService.Navigate(lobby); busyIndicator.IsBusy = false; } else { lobbyModel.NotifyGameStart(reconnect, token); busyIndicator.IsBusy = true; } success = true; } if (!success) { if ((LoginStatus)ea.Result == LoginStatus.InvalidUsernameAndPassword) { MessageBox.Show("Invalid Username and Password"); busyIndicator.IsBusy = false; } else if ((LoginStatus)ea.Result == LoginStatus.OutdatedVersion) { // MessageBox.Show("Outdated version. Please update"); busyIndicator.BusyContent = Resources["Busy.Updating"]; } else { MessageBox.Show("Cannot connect to server."); busyIndicator.IsBusy = false; } } startButton.IsEnabled = true; }; worker.RunWorkerAsync(); }
public override ProcedureResult Apply(LobbyView view) { view.Gameplay = Gameplay; return(ProcedureResult.Success); }
public abstract ProcedureResult Apply(LobbyView view);
public override void Destroy() { base.Destroy(); lobbyView.Destroy(); lobbyView = null; }