Example #1
0
        /// <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();
        }
Example #2
0
        /// <summary>
        /// Calls start game method of model and call draw board
        /// method of client.
        /// </summary>
        /// <param name="nameOfGame"> name of game</param>
        /// <param name="rows"> number of rows </param>
        /// <param name="cols"> number of cols </param>
        public void StartGame(string nameOfGame, int rows, int cols)
        {
            ServerModel model = ServerModel.GetInstance();
            // current player
            string clientId = Context.ConnectionId;
            Maze   maze     = model.StartGame(nameOfGame, rows, cols, clientId);

            //calls draw board function in client
            Clients.Client(clientId).drawBoard("myCanvas", maze.ToJSON(),
                                               "playerImg", "exitImg", true);
        }