コード例 #1
0
ファイル: GameHub.cs プロジェクト: EdenShuker/MazeGameWeb
        /// <summary>
        /// Calls close game method of model and post results in
        /// both players.
        /// </summary>
        /// <param name="nameOfGame"></param>
        /// <param name="playerId"></param>
        private void Close(string nameOfGame, string playerId)
        {
            ServerModel model      = ServerModel.GetInstance();
            string      opponentId = model.GetCompetitorOf(Context.ConnectionId);

            model.Close(nameOfGame);
            // close both players
            Clients.Client(opponentId).closeGame(false);
            Clients.Client(playerId).closeGame(true);
        }
コード例 #2
0
ファイル: GameHub.cs プロジェクト: EdenShuker/MazeGameWeb
        /// <summary>
        /// Calls play game of model. draw player in opponent board,
        /// and check if player reached the end.
        /// </summary>
        /// <param name="direction"></param>
        public void Play(string direction)
        {
            ServerModel model      = ServerModel.GetInstance();
            string      playerId   = Context.ConnectionId;
            string      gameName   = model.Play(ToDirectionStr(direction), playerId);
            string      opponentId = model.GetCompetitorOf(playerId);

            // draw new player location in opponent board.
            Clients.Client(opponentId).moveOtherPlayer(direction);
            // check if player reached goal position.
            if (model.IsPlayerReachedExit(playerId))
            {
                Close(gameName, playerId);
            }
        }
コード例 #3
0
ファイル: GameHub.cs プロジェクト: EdenShuker/MazeGameWeb
        /// <summary>
        /// Calls join to function of model and call draw board on
        /// clients in game.
        /// </summary>
        /// <param name="nameOfGame">name of game</param>
        public void JoinTo(string nameOfGame)
        {
            ServerModel model = ServerModel.GetInstance();
            // current player
            string clientId = Context.ConnectionId;
            Maze   maze     = model.JoinTo(nameOfGame, Context.ConnectionId);

            // my boards
            Clients.Client(clientId).drawBoard("myCanvas", maze.ToJSON(),
                                               "playerImg", "exitImg", true);
            Clients.Client(clientId).drawBoard("competitorCanvas", maze.ToJSON(),
                                               "competitorImg", "exitImg", false);
            // competitor
            string opponentId = model.GetCompetitorOf(clientId);

            Clients.Client(opponentId).drawBoard("competitorCanvas", maze.ToJSON(),
                                                 "competitorImg", "exitImg", false);
            // notify other player
            Clients.Client(opponentId).gameStarted();
        }