/// <summary> /// Joins the maze. /// </summary> /// <param name="mazeName">Name of the maze.</param> /// <param name="player">The player.</param> /// <returns></returns> /// <exception cref="System.Exception"></exception> public Maze JoinMaze(string mazeName, Player player) { if (!joinableMazes.ContainsKey(mazeName)) { throw new Exception($"there is no such maze with the name {mazeName}"); } try { MazeGame game = JoinableMazes[mazeName]; game.AddPlayer(player); player.MazeName = game.MazeName; //game.NotifyOtherPlayers("a player joined the game", player); if (game.GameCapacity == game.Players.Count) { ActiveMultiPlayerMazes[mazeName] = game; joinableMazes.Remove(mazeName); ReleasePlayerFromWaitingMode(game); //game.NotifyOtherPlayers(game.Maze.ToJSON(), player); //game.NotifyAllPlayers("The Game Has Started"); } return(game.Maze); } catch (Exception exception) { return(null); } }
public void Join(string name) { int x = 0; int y = 0; string clientId = Context.ConnectionId; MazeGame game = this.mazeModel.JoinGame(name, clientId); string hostId = game.Host; MazeLib.Maze maze = game.Maze; string jsonedMaze = game.GameToString(); MazeParam partialMaze = new MazeParam(); partialMaze.Name = maze.Name; partialMaze.Rows = maze.Rows; partialMaze.Cols = maze.Cols; partialMaze.GoalPos = maze.GoalPos.ToString(); Converters.PositionConverter.ConvertPos(ref x, ref y, partialMaze.GoalPos); partialMaze.GoalPosRow = x; partialMaze.GoalPosCol = y; partialMaze.InitialPos = maze.InitialPos.ToString(); Converters.PositionConverter.ConvertPos(ref x, ref y, partialMaze.InitialPos); partialMaze.InitialPosRow = x; partialMaze.InitialPosCol = y; JObject jmaze = JObject.Parse(maze.ToJSON()); partialMaze.AsString = jmaze.GetValue("Maze").ToString(); Clients.Client(clientId).joinGame(partialMaze); Clients.Client(hostId).joinGame(partialMaze); }
/// <summary> /// Plays the specified arguments. /// </summary> /// <param name="args">The arguments.</param> /// <param name="player">The player.</param> /// <returns></returns> public string Play(string [] args, Player player) { string direction = args[0]; if (player.MazeName == null) { return("Error: you are not a part of an active game"); } string mazeName = player.MazeName; if (!ActiveMultiPlayerMazes.ContainsKey(mazeName)) { return($"Error: there is no such maze with the name {mazeName}"); } if (PlayersAndGames[player] == null) { return("Error: you are not a part of a game at this point "); } MazeGame game = ActiveMultiPlayerMazes[mazeName]; JObject jobject = new JObject(); jobject["Name"] = game.MazeName; jobject["Direction"] = direction; game.NotifyOtherPlayers(jobject.ToString(), player); //return ""; return(null); }
static void Main(string[] args) { // Concrete Builder StandardMazeBuilder builder = new StandardMazeBuilder(); // Director MazeGame game = new MazeGame(); game.CreateMaze(builder); // Getting product ... Maze maze = builder.GetMaze(); // Concrete Builder CountingMazeBuilder builderCount = new CountingMazeBuilder(); // Director MazeGame gameCount = new MazeGame(); gameCount.CreateMaze(builderCount); int rooms; int doors; builderCount.GetCounts(out rooms, out doors); Console.WriteLine("The maze has {0} rooms and {1} doors.", rooms, doors); }
public Maze CreateSimpleMazeGame() { MazeGame game = new MazeGame(); MazePrototypeFactory simpleMazeFactory = new MazePrototypeFactory( new Maze(), new Wall(), new Room(), new Door() ); // To change the type of maze, we initialize MazePrototypeFactory with a different // set of prototypes. The following call creates a maze with a BombedDoor // and a RoomWithABomb: //MazePrototypeFactory bombedMazeFactory = new MazePrototypeFactory( // new Maze(), // new BombedWall(), // new RoomWithABomb(), // new Door() //); // An object that can be used as a prototype, such as an instance of Wall, must // support the Clone operation. It must also have a copy constructor for cloning. // It may also need a separate operation for reinitializing internal state. return(game.CreateMaze(simpleMazeFactory)); }
/// <summary> /// Joins the game. /// </summary> /// <param name="request">The join request.</param> /// <exception cref="System.InvalidOperationException"> /// You have already joined other game. /// </exception> public void JoinGame(JoinRequest request) { // find the requested game MazeGame gameToJoin = gameManager.GetGame(request.GameName); // if no game found if (gameToJoin == null) { throw new InvalidOperationException(string. Format("Could not find the game \"{0}\"", request.GameName)); } // if the requested game has already started if (gameToJoin.Started) { throw new InvalidOperationException(string. Format("The game \"{0}\" has already started.", request.GameName)); } // else, the player can join.. // now check that this player is not in any other game: // if the player is already in an unfinished game if (gameManager.ContainsGame(request.Client)) { throw new InvalidOperationException("You have already joined other game."); } // the player is not in any other game. // add him to the game. gameToJoin.AddPlayer(request.Client); }
void OnTriggerEnter(Collider other) { // MazeGame.S.LifeLost(); MazeGame scriptA = Camera.main.GetComponent <MazeGame>(); scriptA.LifeLost(); }
public void Play(int x, int y) { string clientId = Context.ConnectionId; MazeGame game = this.mazeModel.GetGameByClient(clientId); string host = game.Host; string guest = game.Guest; string other = null; // If i'm the guest if ((!(host.Equals(clientId))) && host != null) { other = host; } else { // I'm the host if (guest != null) { other = guest; } } if (other != null) { Clients.Client(other).play(x, y); } }
public void SetOrReset() { mazeGame = new MazeGame(); MazeFactorySingleton.ResetForNUnit(); mazeFactory = null; maze = null; }
void StartBtn_Click(object sender, EventArgs e) { Hide(); Form gameForm = new MazeGame(this, maze); gameForm.FormClosed += Form_Closed; gameForm.ShowDialog(); }
private void ReleasePlayerFromWaitingMode(MazeGame game)//////////////////////////added a change. { foreach (Player p in game.Players) { PlayersAndGames[p] = game; p.NeedToWait = false; } }
public Result() { var commonMaze = new MazeGame().CreateMaze(new MazeFactory()); var enchantedMaze = new MazeGame().CreateMaze(new EnchantedMazeFactory()); var bombedMaze = new MazeGame().CreateMaze(new BombedMazeFactory()); }
/// <summary> /// Removes the players from players and games. /// </summary> /// <param name="mazeName">Name of the maze.</param> private void RemovePlayersFromPlayersAndGames(string mazeName) { MazeGame game = ActiveMultiPlayerMazes[mazeName]; foreach (Player p in game.Players) { PlayersAndGames.Remove(p); } }
/// <summary> /// Adds the game to the container. /// </summary> /// <param name="game">The game.</param> public void AddGame(MazeGame game) { if (container.ContainsGame(game)) { throw new InvalidOperationException("Game already exists."); } AttachHandlers(game); container.AddGame(game); }
public void CreateMaze() { Maze maze; MazeGame game = new MazeGame(); StandardMazeBuilder builder = new StandardMazeBuilder(); game.CreateComplexMaze(builder); maze = builder.GetMaze(); }
static void Main(string[] args) { int rooms, doors; MazeGame game = new MazeGame(); CountingMazeBuilder builder = new CountingMazeBuilder(); game.CreateComplexMaze(builder); builder.GetCounts(out rooms, out doors); }
public MazeGame CreateMazeGameWithBombs() { MazeGame game = new MazeGame(); MazeFactory factory = new BombedMazeFactory(); game.CreateMaze(factory); return(game); }
public IHttpActionResult GetMaze(string name, int rows, int cols) { MazeGame game = (MazeGame)model.GenerateNewGame(name, rows, cols); WebMaze newMaze = new WebMaze(); newMaze.SetMaze(game.maze); //Add to list. mazes.Add(newMaze); return(Ok(newMaze)); }
public MazeGame CreateSimpleMazeGame() { MazeGame game = new MazeGame(); MazeFactory factory = new MazeFactory(); game.CreateMaze(factory); return(game); }
public void CreateBombedMazeGamePrototype() { MazeGame game = new MazeGame(); MazePrototypeFactory bombedMazeFactory = new MazePrototypeFactory(new Maze(), new RoomWithABomb(), new BombedWall(), new Door()); Maze maze = game.CreateMazePrototype(bombedMazeFactory); Assert.IsNotNull(maze.RoomNo(1) as RoomWithABomb); Assert.IsInstanceOfType(maze.RoomNo(1).GetSide(Direction.North), typeof(BombedWall)); Assert.IsNotInstanceOfType(maze.RoomNo(2), typeof(EnchantedRoom)); }
public MazeGame CreateEnchanedMazeGame() { MazeGame game = new MazeGame(); MazeFactory factory = new EnchantedMazeFactory(); game.CreateMaze(factory); return(game); }
/// <summary> /// Closes the game. /// </summary> /// <param name="request">The request.</param> /// <exception cref="System.InvalidOperationException">You did not join any game.</exception> public void CloseGame(CloseRequest request) { MazeGame game = gameManager.GetGame(request.Client); if (game == null) { throw new InvalidOperationException("You did not join any game."); } game.RemovePlayer(request.Client); }
/// <summary> /// Plays the one move int the multiplyer game. /// </summary> /// <param name="request">The request.</param> /// <exception cref="System.InvalidOperationException">You did not join any game.</exception> public void Play(PlayRequest request) { MazeGame game = gameManager.GetGame(request.Client); if (game == null) { throw new InvalidOperationException("You did not join any game."); } game.PlayMove(request.Client, request.Move); }
static void Main(string[] args) { MazeGame mazeGame = new MazeGame(); BombedMazeFactory bombFactory = new BombedMazeFactory(); mazeGame.CreateMaze(bombFactory); EnchantedMazeFactory enchantedFactory = new EnchantedMazeFactory(); mazeGame.CreateMaze(enchantedFactory); }
/// <summary> /// Handles the game started. /// </summary> /// <param name="game">The game.</param> public void HandleGameStarted(MazeGame game) { string json = game.Maze.ToJSON(); Notification notif = new Notification(Notification.Type.GameStarted, json); List <IClient> clients = game.GetAllClients(); foreach (IClient client in clients) { notifier.NotifyClient(client, notif); } }
public void CreateStandartMazeGameBuilder() { MazeGame game = new MazeGame(); MazeBuilder builder; Maze maze; // Configure standard maze builder builder = new StandardMazeBuilder(); maze = game.CreateMazeBuilder(builder); Assert.IsNotNull(maze.RoomNo(1)); Assert.IsNotNull(maze.RoomNo(2)); }
public void CreateCountingMazeGameBuilder() { MazeGame game = new MazeGame(); MazeBuilder builder = new CountingMazeBuilder(); int roomsCount = 0, doorsCount = 0; Maze maze = game.CreateMazeBuilder(builder); ((CountingMazeBuilder)builder).GetCounts(ref roomsCount, ref doorsCount); Assert.AreEqual(roomsCount, 2); Assert.AreEqual(doorsCount, 1); }
public float time; // Time elapsed // Start is called before the first frame update void Start() { S = this; // Define the Singleton level = 0; levelMax = mazes.Length; uiGameOver.enabled = false; // Find start time startTime = Time.time; StartLevel(); }
static void Main(string[] args) { MazeGame mazeGame = new MazeGame(); mazeGame.CreateMaze(); BombedMazeGame bombedMazeGame = new BombedMazeGame(); bombedMazeGame.CreateMaze(); EnchantedMazeGame enchantedMazeGame = new EnchantedMazeGame(); enchantedMazeGame.CreateMaze(); }
public JObject Generate(string name, int rows, int cols) { Maze maze = new DFSMazeGenerator().Generate(rows, cols); maze.Name = name; Single[name] = new MazeGame() { Name = name, Maze = maze }; return(JObject.Parse(maze.ToJSON())); }
public void MazeGameStopped() { ActivateMenu("Main Menu"); state = AppState.Menu; mazeGame = null; }
public GameEngine(MazeGame gameMode) { _gameMode = gameMode; Room = new List<Rooms.Room>(); }
private void StartGame() { mazeGame = InitializeGame(menuSelections.GameName); mazeGame.LoadGame(menuSelections); state = AppState.PlayingGame; }
public void Switch(MazeGame anotherMode) { _gameMode = anotherMode; Room.Clear(); GenerateRooms(); }