Exemplo n.º 1
0
        private bool RegisterGame(OthelloPlayerServer emitter, SaveFile saveFile)
        {
            // Test if the player is known
            if (!IsKnown(emitter))
            {
                throw new Exception("Unknown client");
            }

            // Generate the "savefile"
            LoadRequest loadRequest = new LoadRequest(emitter, saveFile);
            int         requestID   = loadRequest.GetHashCode();

            // Verifiy that the game does not exist
            if (loadedGames.ContainsKey(requestID))
            {
                throw new Exception("Game already loaded");
            }

            // Add it to the list
            loadedGames.TryAdd(requestID, loadRequest);

            // Send the id to the emitter
            emitter.LoadSuccessful(requestID);

            return(true);
        }
Exemplo n.º 2
0
        private void StartNewMatch(LoadRequest loadRequest)
        {
            // Informs clients that an opponent has be found
            loadRequest.Player1.OpponentFound(loadRequest.Player2.Name, loadRequest.Player2.PlayerType);
            loadRequest.Player2.OpponentFound(loadRequest.Player1.Name, loadRequest.Player1.PlayerType);

            // GameManager will now handle clients and put them as InGame
            CreateMatch(loadRequest.Player1, loadRequest.Player2).Load(loadRequest.SaveFile);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Assign player and handle their orders
 /// </summary>
 /// <param name="loadRequest"></param>
 internal GameHandler(LoadRequest loadRequest)
     : this(loadRequest.Player1, loadRequest.Player2)
 {
     Load(loadRequest.SaveFile);
 }