public void Move(MoveAction action) { var(from, to) = action.Action; var(whoseTurn, winner, board, lastMove) = _gameInfo; var newBoard = board.ToList(); newBoard.Remove(_gameInfo.GetSquare(from)); newBoard.Add(new Square { Color = GetPlayer(), Position = to, King = (GetPlayer() == Player.Red && to >= 29) || (GetPlayer() == Player.Black && to <= 4) }); _gameInfo = _gameInfo with { WhoseTurn = whoseTurn == Player.Black ? Player.Red : Player.Black, Winner = (_gameInfo.GetPlayerSquares(Player.Black).Count, _gameInfo.GetPlayerSquares(Player.Red).Count) switch { (0, _) => Player.Red, (_, 0) => Player.Black, _ => null },
public override void OnShow(object param = null) { // UIManager.I.ShowView<ResultView> (true); var allAudio = GetComponents <AudioSource> (); _audioHit = allAudio[0]; _audioHit.Stop(); _audioWin = allAudio[1]; _audioWin.Stop(); _initGameInfo = param as GameInfoData; _curCaTrans = SceneLoadManager.I.GetSceneNodeTrans(SaveData.curCheckPoint, "Camera"); _curBridge = SceneLoadManager.I.GetSceneNodeTrans(SaveData.curCheckPoint, "Bridge"); _curWater1 = SceneLoadManager.I.GetSceneNodeTrans(SaveData.curCheckPoint, "Water1"); _curWater2 = SceneLoadManager.I.GetSceneNodeTrans(SaveData.curCheckPoint, "Water2"); _initWaterPos = _curWater1.localPosition; this.StartCoroutine(_TranslateWater()); _caInitPos = _curCaTrans.localPosition; _rigidbody = transform.GetComponent <Rigidbody> (); _myAnimator = transform.GetComponent <Animator> (); _initPos = new Vector3(_initGameInfo.X, _initGameInfo.Y, _initGameInfo.Z); obFlag = 1; _InitInfo(); EventUtils.AddListener("EnemyIsDie", _EnemyIsDie); EventUtils.AddListener("Start", _CanStart); EventUtils.AddListener("MainRoleBeForce", _MainRoleBeForce); EventUtils.AddListener("InitMainPos", _InitMainPos); #if UNITY_ANDROID if (_shakeActivity == null) { AndroidJavaClass jc = new AndroidJavaClass("com.Uqee.LittleGame.ClickShake"); _shakeActivity = jc.GetStatic <AndroidJavaObject> ("_mClickShake"); } #endif }
// Function to launch the game directly (no shim, no force quitting) void launchGameDirect(GameInfoData launchInfo, string Args) { Process launchedGame = new Process(); // Use to create no window when running from shell launchedGame.StartInfo.UseShellExecute = true; launchedGame.StartInfo.CreateNoWindow = true; launchedGame.StartInfo.WindowStyle = ProcessWindowStyle.Maximized; // Set game launch parameters launchedGame.StartInfo.WorkingDirectory = Path.GetFullPath(Path.Combine(launchInfo._GameFolderPath, launchInfo.ExeFolder)); launchedGame.StartInfo.FileName = launchInfo.ExeName; launchedGame.StartInfo.Arguments = Args; // Start the game Application.runInBackground = true; launchedGame.Start(); //UI will halt until game is finished launchedGame.WaitForExit(); // Restore the resolution from before Screen.SetResolution(1920, 1200, true); UnityEngine.Debug.Log(Screen.width.ToString() + "x" + Screen.height.ToString()); // Check for new high scores or etc. extra data. DataManager.instance.ReloadExtraData(launchInfo._GameGuid); DisplayManager.instance.SetInfo(launchInfo._GameGuid, true); }
public static Dictionary <string, List <GameInfoData> > LoadSceneJsonFromFile(string json_name) { string text = GetTextForStreamingAssets(json_name); JsonData jsonInfo = JsonMapper.ToObject(text); Dictionary <string, List <GameInfoData> > game_info = new Dictionary <string, List <GameInfoData> >(); foreach (var item in jsonInfo) { var game_info_part1 = (KeyValuePair <string, JsonData>)item; List <GameInfoData> game_info_part3 = new List <GameInfoData>(); foreach (JsonData game_info_part2 in game_info_part1.Value) { GameInfoData info = new GameInfoData(); info.EnemyID = (string)game_info_part2["EnemyID"]; info.X = (float)((double)game_info_part2["X"]); info.Y = (float)((double)game_info_part2["Y"]); //UnityEngine.Debug.LogError(game_info_part1.Key + ", " +info.EnemyID + ", "+info.X + ", "+info.Y); info.Z = (float)((double)game_info_part2["Z"]); info.Speed = (float)((double)game_info_part2["Speed"]); info.VolumeCoefficient = (float)((double)game_info_part2["VolumeCoefficient"]); info.Radius = (float)((double)game_info_part2["Radius"]); info.Rounds = (int)game_info_part2["Rounds"]; game_info_part3.Add(info); } game_info[game_info_part1.Key] = game_info_part3; } return(game_info); }
private void UpdateAndSendStats(double delta) { _sendStatsTimer += delta; if (_sendStatsTimer >= GConfig.D.SendStatsEachMilliseconds) { _sendStatsTimer = 0; } else { return; } var stats = new GameInfoData { IncomeTimer = (int)Math.Floor((_session.Setting.RoundSeconds) - (_incomeTimer / GConfig.D.GameSimulationTime)), MobsOnWorld = _session.GameMobs.Count, HPTeam1 = _session.GameData.TeamHp[0], HPTeam2 = _session.GameData.TeamHp[1], HPTeam3 = _session.GameData.TeamHp[2], HPTeam4 = _session.GameData.TeamHp[3], AllIncome = _session.Players.Select(x => x.User.Id + "," + x.TeamId + "," + x.Income).ToArray(), HighestIncome = _session.Teams.OrderByDescending(x => _session.Teams[x.Key].Sum(v => v.Income)).First().Key, }; _session.Players.ForEach(p => { stats.TeamIncomeTotal = _session.Teams[p.TeamId].Sum(x => x.Income); stats.OwneIncome = p.Income; stats.OwneMoney = p.Money; p.User.Send(RequestNames.GameDataInfo, stats); }); }
public bool ReloadExtraData(System.Guid searchGuid) { GameInfoData gameMetadata = gameInfoDataDict[searchGuid]; if (gameMetadata == null) { Debug.LogError("Failed to retrieve game info in \"ReloadExtraData\"."); return(false); } if (gameMetadata.HasExtraData) { string ExtraDataLocation = gameMetadata._GameFolderPath + "\\CabinetData\\" + gameMetadata.ExtraDataName; if (File.Exists(ExtraDataLocation)) { gameMetadata._ExtraData = System.IO.File.ReadAllText(ExtraDataLocation); gameInfoDataDict[searchGuid] = gameMetadata; return(true); } else { Debug.LogWarning("A request to reload extra data has failed because the file doesn't exist."); return(false); } } return(false); }
public void SetInfo(System.Guid gameInfoHandle, bool forceUpdate = false) { // Don't reload the game info if it's already being displayed. // Requires some extra checks to make sure prepared videos replay. if (lastGameInfo != null) { if (gameInfoHandle == lastGameInfo._GameGuid && !forceUpdate) { if (enableVideoPlayback && lastGameInfo.HasVideo && !GameVideoPreview.isPlaying) { GameVideoPreview.time = 0.0; GameVideoPreview.Play(); GameScreenshotImage.enabled = false; } return; } } lastGameInfo = DataManager.instance.GetInfo(gameInfoHandle); Sprite retrievedShot = DataManager.instance.GetScreenshot(gameInfoHandle); // Set some text GameNameText.text = lastGameInfo.GameName; GameDescriptionText.text = "<b>" + lastGameInfo.Author + "</b>\n\n" + lastGameInfo.Description; ExtraDataText.text = lastGameInfo._ExtraData; // Video or screenshot? string videoPath = System.IO.Path.Combine(System.IO.Path.Combine(lastGameInfo._GameFolderPath, "CabinetData"), lastGameInfo.VideoName); if (lastGameInfo.HasVideo && enableVideoPlayback && System.IO.File.Exists(videoPath)) { GameVideoPreview.url = videoPath; GameScreenshotImage.enabled = false; } else { GameVideoPreview.Pause(); GameScreenshotImage.sprite = retrievedShot; GameScreenshotImage.enabled = true; } // Update controls // Set icon visibility. OnePlayerIcon.SetActive(lastGameInfo.MaxPlayers == 1 ? true : false); TwoPlayerIcon.SetActive(lastGameInfo.MaxPlayers == 2 ? true : false); ThreePlayerIcon.SetActive(lastGameInfo.MaxPlayers == 3 ? true : false); FourPlayerIcon.SetActive(lastGameInfo.MaxPlayers == 4 ? true : false); CabinetControlsIcon.SetActive(lastGameInfo.SupportsCabinetControls ? true : false); XboxControlsIcon.SetActive(lastGameInfo.SupportsXboxControls ? true : false); UnityIcon.SetActive(lastGameInfo.EngineUsed.StartsWith("Unity") ? true : false); UnrealIcon.SetActive(lastGameInfo.EngineUsed.StartsWith("Unreal") ? true : false); GameMakerIcon.SetActive(lastGameInfo.EngineUsed.StartsWith("Game Maker") ? true : false); Love2DIcon.SetActive(lastGameInfo.EngineUsed.StartsWith("LÖVE") ? true : false); GameJamIcon.SetActive(lastGameInfo.IsGameJam ? true : false); RGSIcon.SetActive(lastGameInfo.IsRGS ? true : false); WIPIcon.SetActive(lastGameInfo.IsWIP ? true : false); }
public GameInfoData GetInfo(System.Guid searchGuid) { GameInfoData returnInfo = gameInfoDataDict[searchGuid]; if (returnInfo == null) { Debug.LogWarning("Failed to retrieve game info in \"GetInfo\"."); } return(returnInfo); }
public void requestLaunch(GameInfoData launchInfo) { if (currentDisplayManager.currentState != InfoPanelState.ControlsPanel) { currentControlInfo.LoadControls(launchInfo); currentDisplayManager.SetInfoPanelState(InfoPanelState.ControlsPanel); } else { if (launchDirectly) { launchGameDirect(launchInfo, ""); } else { launchGameShim(launchInfo, ""); } currentDisplayManager.SetInfoPanelState(InfoPanelState.GamePanel); } }
public void LoadControls(GameInfoData newData) { // Don't reload controls (slow) if (newData._GameGuid == currentDataHandle) { return; } currentDataHandle = newData._GameGuid; // Change every text value GameName.text = newData.GameName; LoadControl(PlayerOneText, newData.PlayerOneControlLabel); LoadControl(PlayerTwoText, newData.PlayerTwoControlLabel); // Player 1 LoadControl(PlayerOneJoyUp, newData.KeyW); LoadControl(PlayerOneJoyLeft, newData.KeyA); LoadControl(PlayerOneJoyDown, newData.KeyS); LoadControl(PlayerOneJoyRight, newData.KeyD); LoadControl(PlayerOneTopLeft, newData.Key1); LoadControl(PlayerOneTopMiddle, newData.Key2); LoadControl(PlayerOneTopRight, newData.Key3); LoadControl(PlayerOneBottomLeft, newData.KeyZ); LoadControl(PlayerOneBottomMiddle, newData.KeyX); LoadControl(PlayerOneBottomRight, newData.KeyC); LoadControl(PlayerOneStart, newData.Key5); // Player Two LoadControl(PlayerTwoJoyUp, newData.KeyI); LoadControl(PlayerTwoJoyLeft, newData.KeyJ); LoadControl(PlayerTwoJoyDown, newData.KeyK); LoadControl(PlayerTwoJoyRight, newData.KeyL); LoadControl(PlayerTwoTopLeft, newData.Key7); LoadControl(PlayerTwoTopMiddle, newData.Key8); LoadControl(PlayerTwoTopRight, newData.Key9); LoadControl(PlayerTwoBottomLeft, newData.KeyB); LoadControl(PlayerTwoBottomMiddle, newData.KeyN); LoadControl(PlayerTwoBottomRight, newData.KeyM); LoadControl(PlayerTwoStart, newData.Key6); }
// Function to launch the game using the AutoHotKey shim (less direct, but allows force quitting) void launchGameShim(GameInfoData launchInfo, string Args) { int CurrentWidth = Screen.width; int CurrentHeight = Screen.height; Process launchedGame = new Process(); // Use to create no window when running from shell launchedGame.StartInfo.UseShellExecute = true; launchedGame.StartInfo.CreateNoWindow = false; launchedGame.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; // Set shim launch parameters. Assuming Shim is in frontend build folder. launchedGame.StartInfo.WorkingDirectory = Path.GetFullPath(Path.Combine(Application.dataPath.Replace('/', '\\'), @"..\")); launchedGame.StartInfo.FileName = "CabinetUIShim.exe"; // Collect arguments // First working directory, then EXE name, then the game's args. // Example: "C:\CabinetUI\Data\Games\Super Toast" "SuperToast.exe" -hardmode -decaf launchedGame.StartInfo.Arguments = "\"" + Path.GetFullPath(Path.Combine(launchInfo._GameFolderPath, launchInfo.ExeFolder)) + "\" "; launchedGame.StartInfo.Arguments += "\"" + launchInfo.ExeName + "\" "; launchedGame.StartInfo.Arguments += Args; // Start the game Application.runInBackground = true; launchedGame.Start(); // UI will halt until shim script is finished launchedGame.WaitForExit(); // Restore the resolution from before. Screen.SetResolution(CurrentWidth, CurrentHeight, true); // Check for new high scores or etc. extra data. DataManager.instance.ReloadExtraData(launchInfo._GameGuid); DisplayManager.instance.SetInfo(launchInfo._GameGuid, true); }
public static List <Square> GetPlayerSquares(this GameInfoData gameInfoData, Player player) { return(gameInfoData.Board.Where(square => square.Color == player).ToList()); }
public static Square GetSquare(this GameInfoData gameInfoData, int position) { return(gameInfoData.Board.FirstOrDefault(square => square.Position == position)); }
public MapState(GameInfoData gameInfoData) { _gameInfo = gameInfoData; }
public CheckersGame(GameInfoData initialState) { _initialState = new MapState(initialState); }
void InitializeIcons() { string PathToGames; string[] gameFolders; #if (UNITY_EDITOR_OSX) PathToGames = Path.GetFullPath("Games"); #else PathToGames = Path.GetFullPath(Path.Combine(Application.dataPath.Replace('/', '\\'), @"..\Games")); #endif gameFolders = Directory.GetDirectories(PathToGames); foreach (string folderPath in gameFolders) { string cabinetDataPath = Path.Combine(folderPath, "CabinetData"); string metaFilePath = Path.Combine(cabinetDataPath, "metadata.json");; if (File.Exists(metaFilePath)) { GameObject newGameIcon = Instantiate(gameIconPrefab, gameListContent); GameObject newGameIconBadge = newGameIcon.transform.GetChild(2).gameObject; GameObject updatedGameIconBadge = newGameIcon.transform.GetChild(3).gameObject; MenuEventTrigger iconTrigger = newGameIcon.GetComponent <MenuEventTrigger>(); System.Guid newGuid = System.Guid.NewGuid(); iconTrigger.SetGuid(newGuid); GameInfoData newMetadata = new GameInfoData(metaFilePath); newMetadata._GameFolderPath = folderPath; newMetadata._GameGuid = newGuid; newGameIcon.name = newMetadata.GameName; if (newMetadata.IsUpdated) { updatedGameIconBadge.SetActive(true); newGameIcon.transform.SetAsFirstSibling(); } else if (newMetadata.IsNew) { newGameIconBadge.SetActive(true); newGameIcon.transform.SetAsFirstSibling(); } // Load extra data if (File.Exists(Path.Combine(cabinetDataPath, newMetadata.ExtraDataName))) //cabinetDataPath + "\\" + newMetadata.ExtraDataName)) { { newMetadata._ExtraData = System.IO.File.ReadAllText(Path.Combine(cabinetDataPath, newMetadata.ExtraDataName)); } // Add new metadata to the metadata dictionary. gameInfoDataDict[newGuid] = newMetadata; // Load new game icon if (File.Exists(Path.Combine(cabinetDataPath, newMetadata.IconName))) { Sprite newIcon = LoadSprite(Path.Combine(cabinetDataPath, newMetadata.IconName)); iconDict[newGuid] = newIcon; iconTrigger.SetIcon(newIcon); } else { Debug.LogWarning("Failed to load icon at " + (Path.Combine(cabinetDataPath, newMetadata.IconName))); } // Load new screenshot if (File.Exists(Path.Combine(cabinetDataPath, newMetadata.ScreenshotName))) { Sprite newScreenshot = LoadSprite(Path.Combine(cabinetDataPath, newMetadata.ScreenshotName)); screenShotDict[newGuid] = newScreenshot; } else { Debug.LogWarning("Failed to load screenshot at " + (Path.Combine(cabinetDataPath, newMetadata.ScreenshotName))); } } else { Debug.LogWarning("Failed to find metadata file at " + metaFilePath); } } // Finally, throw the about icon last in the list. GameObject aboutIcon = GameObject.FindGameObjectWithTag("AboutIcon"); if (aboutIcon != null) { aboutIcon.transform.SetAsLastSibling(); } UnityEngine.EventSystems.EventSystem.current.SendMessage("SelectByIndex", 0, SendMessageOptions.DontRequireReceiver); }