/// <summary> /// Load car stuff /// </summary> protected override void Initialize() { base.Initialize(); // Load models carModel = new Cyclist(); Level lvl; try { lvl = (Level)Enum.Parse(typeof(Level), startUpParam.MapName); } catch (Exception) { MessageBox.Show("Unsupported Map: " + startUpParam.MapName, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Exit(); return; } // Load landscape landscape = new Landscape(lvl); brakeTrackMaterial = new Material("track"); gameScreens.Push(new GameScreen(lvl)); netClient.TellReady(); while (!netClient.CanStartGame()) { Thread.Sleep(10); } startUpParam = netClient.DownloadStartUpParameters(); for (int i = 0; i < startUpParam.Players.Length; i++) { if (startUpParam.Players[i].ID != localUID) { RemotePlayer plr = new RemotePlayer(startUpParam.Players[i]); remotePlayers.Add(plr.ID, plr); } else { carOffset = i / (float)startUpParam.Players.Length; landscape.SetCarToStartPosition(); } } remoteModels = new Cyclist[remotePlayers.Count]; for (int i = 0; i < remotePlayers.Count; i++) { remoteModels[i] = new Cyclist(); } }
/// <summary> /// Start game, is in a seperate method for 2 reasons: We want to catch /// any exceptions here, but not for the unit tests and we also allow /// the unit tests to call this method if we don't want to unit test /// in debug mode. /// </summary> public static void StartGame(string uid) { INetInterface netClient = InterfaceFactory.Instance.GetNetwork(); bool result = netClient.Connect(uid); if (!result) { MessageBox.Show("Cannot connect to server.", "RacingGame", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Thread.Sleep(100); StartUpParameters sup = netClient.DownloadStartUpParameters(); #if !XBOX360 try { #endif using (RacingGameManager game = new RacingGameManager(netClient, uid, sup)) { game.Run(); } #if !XBOX360 } catch (NoSuitableGraphicsDeviceException) { MessageBox.Show("Pixel and vertex shaders 2.0 or greater are required.", "RacingGame", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (OutOfVideoMemoryException) { GameSettings.SetMinimumGraphics(); MessageBox.Show("Insufficent video memory.\n\n" + "The graphics settings have been reconfigured to the minimum. " + "Please restart the application. \n\nIf you continue to receive " + "this error message, your system may not meet the " + "minimum requirements.", "RacingGame", MessageBoxButtons.OK, MessageBoxIcon.Error); } #endif netClient.Disconnect(); }
/// <summary> /// Create Racing game /// </summary> public RacingGameManager(INetInterface netCl, string uid, StartUpParameters sup) : base("Virutal Bicycle") { inputInterface = InterfaceFactory.Instance.GetInput(); player = new Player(new Vector3(0, 0, 0)); // Start playing the menu music //Sound.Play(Sound.Sounds.MenuMusic); localUID = uid; startUpParam = sup; netClient = netCl; for (int i = 0; i < sup.Players.Length; i++) { if (sup.Players[i].ID == uid) { LocalPlayerCarColor = sup.Players[i].CarColor; LocalPlayerName = sup.Players[i].Name; break; } } }