public GameProps RegisterClient(ClientInfo client) { ServerPuppet.Instance.Wait(); lock (pacManClients) { if (tolerenceServer.IsMaster) { tolerenceServer.AddClient(client); ThreadStart updateClient = UpdateConnectedClients; var updateThread = new Thread(updateClient); updateThread.Start(); } var clientId = pacManClients.Count + 1; var pacManClient = (IPacManClient)Activator.GetObject(typeof(IPacManClient), client.Url + "/PacManClient"); var clientWithInfo = new ClientWithInfo <IPacManClient>(pacManClient, client.Url, clientId); pacManClients.Add(clientWithInfo); var props = new GameProps(gameSpeed, numberPlayers, pacManClients.Count); if (pacManClients.Count == numberPlayers) { game.Start(); if (tolerenceServer.IsMaster) { UpdatePacManServers(tolerenceServer.Servers); gameTimer.Enabled = true; } } return(props); } }
public void MustReversePathAfterReset() { var gameProps = new GameProps { Width = 4, Height = 4, MyId = 0 }; _console.Record("...."); _console.Record(".xx."); _console.Record(".xx."); _console.Record("...."); var mapScanner = new MapScanner(gameProps, _console); PreComputedSpiralNavigator sut = new PreComputedSpiralNavigator(mapScanner, _console, false, gameProps); Assert.IsNull(sut.Next((0, 1))); sut.Reset(); Assert.AreEqual('S', sut.Next((0, 1)).Direction); Assert.AreEqual('S', sut.Next((0, 2)).Direction); Assert.AreEqual('E', sut.Next((0, 3)).Direction); Assert.AreEqual('E', sut.Next((1, 3)).Direction); Assert.AreEqual('E', sut.Next((2, 3)).Direction); Assert.AreEqual('N', sut.Next((3, 3)).Direction); Assert.AreEqual('N', sut.Next((3, 2)).Direction); Assert.AreEqual('N', sut.Next((3, 1)).Direction); Assert.AreEqual('W', sut.Next((3, 0)).Direction); Assert.AreEqual('W', sut.Next((2, 0)).Direction); Assert.AreEqual('W', sut.Next((1, 0)).Direction); Assert.IsNull(sut.Next((0, 0))); sut.Reset(); Assert.AreEqual('E', sut.Next((0, 0)).Direction); }
public void MustReturnCorrectOrderOfPositions_ReversedMode() { var gameProps = new GameProps { Width = 4, Height = 4, MyId = 0 }; _console.Record("...."); _console.Record("...."); _console.Record("...."); _console.Record("...."); var mapScanner = new MapScanner(gameProps, _console); PreComputedSpiralNavigator sut = new PreComputedSpiralNavigator(mapScanner, _console, true, gameProps); var firstPosition = sut.First(); Assert.AreEqual((1, 2), firstPosition); Assert.AreEqual('E', sut.Next((1, 2)).Direction); Assert.AreEqual('N', sut.Next((2, 2)).Direction); Assert.AreEqual('W', sut.Next((2, 1)).Direction); Assert.AreEqual('W', sut.Next((1, 1)).Direction); Assert.AreEqual('S', sut.Next((0, 1)).Direction); Assert.AreEqual('N', sut.Next((3, 3)).Direction); Assert.AreEqual('W', sut.Next((3, 0)).Direction); Assert.AreEqual('W', sut.Next((2, 0)).Direction); Assert.AreEqual('W', sut.Next((1, 0)).Direction); Assert.IsNull(sut.Next((0, 0))); }
public void Setup() { _console = new ConsoleMock(); _gameProps = new GameProps { Width = 15, Height = 15, MyId = 0 }; _console.Record(".............xx"); _console.Record(".............xx"); _console.Record("......xx......."); _console.Record("......xx......."); _console.Record("..............."); _console.Record("..............."); _console.Record("..............."); _console.Record("..............."); _console.Record("..............."); _console.Record("..............."); _console.Record("..............."); _console.Record("..............."); _console.Record("..............."); _console.Record("..............."); _console.Record("..............."); _mapScanner = new MapScanner(_gameProps, _console); _sut = new HeadPositionReducer(_gameProps, _mapScanner); }
public EnemyTracker(GameProps gameProps, int[,] map, IConsole console, HeadPositionReducer headPositionReducer) { _gameProps = gameProps; _console = console; _headPositionReducer = headPositionReducer; map.CloneMap(); _binaryMap = BinaryTrack.FromCartesian(gameProps, map); _currentTrack = BinaryTrack.StartEmptyTrack(gameProps); }
public void FromAllZero() { var gameProps = new GameProps { Height = 4, Width = 15, MyId = 0 }; var position = (1, 1); var actual = BinaryTrack.FromAllZeroExcept(gameProps, new List <(int, int)> { position }, position);
private EnemyTracker(GameProps gameProps, BinaryTrack binaryMap, BinaryTrack currentTrack, BinaryTrack exactTrack, IConsole console, HeadPositionReducer headPositionReducer, char lastMoveDirection) { _console = console; _headPositionReducer = headPositionReducer; _gameProps = gameProps; _binaryMap = binaryMap; _currentTrack = currentTrack; _exactEnemyTrack = exactTrack; _lastMoveMoveDirection = lastMoveDirection; binaryMap.ToCartesian(); }
public void LoadLevel(string levelName) { Debug.Log(levelName); level = LevelDic[levelName]; int x = level.X; int y = level.Y; mapPosList = level.mapPosList; mapTypeList = level.MapTypeList; if (!Global.instance.SoundManager.isPlayingBGM) { int order = (int)Random.Range(1f, 4f); string BGMName = "GamePlay0" + order.ToString(); Global.instance.SoundManager.PlayBGM(BGMName); } GridController.Instance.InitXandY(x, y); for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { GameObject grid = Instantiate(Resources.Load("Prefabs/Grid")) as GameObject; GridUnit mgrid = grid.AddComponent <GridUnit>(); mgrid.GridId = GridController.Instance.GetGridID(i, j); grid.transform.SetParent(GridController.Instance.GridControllerTransform, false); GridController.Instance.DicGrid[mgrid.GridId] = mgrid; mgrid.GridType = GridController.Instance.GetNewType(mgrid.GridId); mgrid.Init(); } } GridController.Instance.PlayKey = true; for (int i = 0; i < mapPosList.Count; i++) { GridController.Instance.DicGrid[mapPosList[i]].ChangeTypeTo(mapTypeList[i]); } /*GameObject[] UIsGo = GameObject.FindGameObjectsWithTag("UIElement"); * List<Vector2> UIsPos=level.UIsPos; * List<Vector2> UIsWH=level.UIsWH; * for(int i=0;i<UIsPos.Count;i++) * { * RectTransform rt = UIsGo[i].GetComponent<RectTransform>(); * rt.localPosition = UIsPos[i]; * rt.sizeDelta = UIsWH[i]; * }*/ gameProps = GameObject.Find("Tools/GamePropManager").GetComponent <GameProps>(); gameProps.ShowTioPropCount = level.PropsGetTip; gameProps.ResetMapCount = level.PropsMapReset; }
public void Setup() { _console = new ConsoleMock(); _gameProps = new GameProps { Width = 15, Height = 4, MyId = 0 }; _console.Record(".............xx"); _console.Record(".............xx"); _console.Record("......xx......."); _console.Record("......xx......."); var mapScanner = new MapScanner(_gameProps, _console); _headPositionReducer = new HeadPositionReducer(_gameProps, mapScanner); _sut = new EnemyTracker(_gameProps, mapScanner.GetMapOrScan(), _console, _headPositionReducer); _defaultEnemyLife = 6; }
private void Awake() { results = new Hashtable(); results.Add(Status.Healthy, 0); results.Add(Status.Social, 0); results.Add(Status.Money, 0); results.Add(Status.Knowledge, 0); currentProps = Resources.Load <GameProps>("Props/default"); Card[] array = Resources.LoadAll <Card>("Cards/"); cards = new Stack <Card>(); while (cards.Count < currentProps.numberOfTurns) { cards.Push(array[UnityEngine.Random.Range(0, 100) % currentProps.numberOfTurns]); } }
public void MustAvoidDeadEnd_MovingNorth() { var gameProps = new GameProps { Width = 4, Height = 4, MyId = 0 }; _console.Record("...."); _console.Record(".x.."); _console.Record("...."); _console.Record("...."); var mapScanner = new MapScanner(gameProps, _console); PreComputedSpiralNavigator sut = new PreComputedSpiralNavigator(mapScanner, _console, false, gameProps); Assert.AreEqual('E', sut.Next((0, 2)).Direction); Assert.AreEqual((1, 2), sut.Next((0, 2)).Position); }
public void CanRepresentAllEmptyCells() { var gameProps = new GameProps { Width = 4, Height = 4, MyId = 0 }; string[] shape = { "....", "....", "....", "...." }; BinaryTrack sut = BinaryTrack.FromString(gameProps, shape); int[,] map = sut.ToCartesian(); MapAssert.AllCoordinatesAreZero(map); }
public void Shift_South_edge() { var gameProps = new GameProps { Width = 15, Height = 4, MyId = 0 }; string[] shape = { "...............", "...............", ".x.............", ".....x........." }; BinaryTrack sut = BinaryTrack.FromString(gameProps, shape); bool canMoveSouth = sut.TryShiftSouth(out var output); Console.WriteLine(output); Assert.IsFalse(canMoveSouth); Assert.IsNull(output); }
public void MustAvoidIslandsInMiddle() { var gameProps = new GameProps { Width = 4, Height = 4, MyId = 0 }; _console.Record("...."); _console.Record(".xx."); _console.Record(".xx."); _console.Record("...."); var mapScanner = new MapScanner(gameProps, _console); PreComputedSpiralNavigator sut = new PreComputedSpiralNavigator(mapScanner, _console, false, gameProps); var firstPosition = sut.First(); Assert.AreEqual((0, 0), firstPosition); Assert.AreEqual('E', sut.Next((0, 0)).Direction); Assert.AreEqual('S', sut.Next((3, 0)).Direction); Assert.AreEqual('S', sut.Next((3, 2)).Direction); Assert.AreEqual('N', sut.Next((0, 3)).Direction); Assert.IsNull(sut.Next((0, 1))); }
public void CanRepresentMixedFreeAndIslandCells() { var gameProps = new GameProps { Width = 4, Height = 4, MyId = 0 }; string[] shape = { "x..x", ".xx.", "....", "...." }; BinaryTrack sut = BinaryTrack.FromString(gameProps, shape); int[,] map = sut.ToCartesian(); Assert.AreEqual(gameProps.Width, map.GetLength(0)); Assert.AreEqual(gameProps.Height, map.GetLength(1)); MapAssert.AllCoordinatesAreZeroExcept(map, (0, 0), (3, 0), (1, 1), (2, 1)); }
public void Shift_East() { var gameProps = new GameProps { Width = 15, Height = 4, MyId = 0 }; string[] shape = { ".x.............", "x..............", "...............", "..............." }; BinaryTrack sut = BinaryTrack.FromString(gameProps, shape); sut.TryShiftEast(out var output); Console.WriteLine(output); var map = output.ToCartesian(); MapAssert.AllCoordinatesAreZeroExcept(map, (1, 1), (2, 0)); }
public void Setup() { _console = new ConsoleMock(); _gameProps = new GameProps { Width = 15, Height = 15, MyId = 0 }; var mapData = new short[] { 0, 3867, 3867, 7680, 7168, 7168, 30720, 30720, 28672, 25008, 25008, 1, 1, 24576, 24576, }; BinaryTrack binaryMap = BinaryTrack.FromDebug(_gameProps, mapData, null); var currentData = new short[] { 16384, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; BinaryTrack currentTrack = BinaryTrack.FromDebug(_gameProps, currentData, (0, 0)); var filterData = new short[] { 32767, 32767, 32767, 32767, 32767, 31775, 31775, 31775, 31775, 32191, 32767, 32767, 32767, 32767, 32767, }; BinaryTrack filterTrack = BinaryTrack.FromDebug(_gameProps, filterData, null); var headPositionReducer = new HeadPositionReducer(_gameProps, binaryMap.ToCartesian(), filterTrack); _sut = EnemyTracker.FromDebug(_gameProps, binaryMap, currentTrack, null, _console, headPositionReducer, Direction.South); var moveProps = new MoveProps { OpponentOrders = "SILENCE|SURFACE 5", OpponentLife = 5, MyPosition = (2, 11), TorpedoCooldown = 0, MineCooldown = 3, SilenceCooldown = 5 }; _sut.Next(moveProps); var nextMoveProps = new MoveProps { OpponentOrders = "MOVE S", OpponentLife = 5, MyPosition = (2, 11), TorpedoCooldown = 0, SilenceCooldown = 2, MineCooldown = 1 }; _sut.Next(nextMoveProps); } } }
public void SetUp() { _gameProps = new GameProps { Width = 15, Height = 4, MyId = 0 }; }
public static int GetGameProps(GameProps gameProps) { int number = PlayerPrefs.GetInt(gameProps + "Number", 0); return(number); }
public static void UseGameProps(GameProps gameProps, int value) { int number = PlayerPrefs.GetInt(gameProps + "LiveNumber", 0); PlayerPrefs.GetInt(gameProps + "LiveNumber", number - value); }
public MapScanner(GameProps gameProps, IConsole console) { _gameProps = gameProps; _console = console; }
public PreComputedSpiralNavigator(MapScanner mapScanner, IConsole console, bool reversedModeOn, GameProps gameProps) { _path = new ComputedPath(mapScanner.GetMapOrScan(), console, reversedModeOn, gameProps); }