Beispiel #1
0
        public async Task ConnectAsync()
        {
            connection = new HubConnection(url);
            hubProxy   = connection.CreateHubProxy("ChatHub");
            hubProxy.On <User>("ParticipantLogin", (u) => ParticipantLoggedIn?.Invoke(u));
            hubProxy.On <string>("ParticipantLogout", (n) => ParticipantLoggedOut?.Invoke(n));
            hubProxy.On <string>("ParticipantDisconnection", (n) => ParticipantDisconnected?.Invoke(n));
            hubProxy.On <string>("ParticipantReconnection", (n) => ParticipantReconnected?.Invoke(n));
            hubProxy.On <string>("BroadcastGameStart", (n) => GameStart?.Invoke(n, MessageType.Broadcast));
            hubProxy.On <string>("BroadcastGameEnd", (n) => GameEnd?.Invoke(n, MessageType.Broadcast));
            hubProxy.On <string, string>("BroadcastSetHost", (n, m) => SetNewHost?.Invoke(n, m, MessageType.Broadcast));
            hubProxy.On <string, string>("BroadcastTextMessage", (n, m) => NewTextMessage?.Invoke(n, m, MessageType.Broadcast));
            hubProxy.On <string, byte[]>("BroadcastPictureMessage", (n, m) => NewImageMessage?.Invoke(n, m, MessageType.Broadcast));
            hubProxy.On <string, byte[]>("BroadcastStrokes", (n, m) => NewStrokesCollected?.Invoke(n, m, MessageType.Broadcast));
            hubProxy.On <string, string>("BraodcastAnswerIsRight", (n, m) => Correct?.Invoke(n, m));
            hubProxy.On <string, string>("UnicastTextMessage", (n, m) => NewTextMessage?.Invoke(n, m, MessageType.Unicast));
            hubProxy.On <string, byte[]>("UnicastPictureMessage", (n, m) => NewImageMessage?.Invoke(n, m, MessageType.Unicast));
            hubProxy.On <string>("ParticipantTyping", (p) => ParticipantTyping?.Invoke(p));

            connection.Reconnecting += Reconnecting;
            connection.Reconnected  += Reconnected;
            connection.Closed       += Disconnected;

            ServicePointManager.DefaultConnectionLimit = 10;
            await connection.Start();
        }
Beispiel #2
0
 private void OnGameEnd()
 {
     if (GameEnd != null)
     {
         GameEnd.Invoke();
     }
 }
Beispiel #3
0
        private void CheckGameStatus()
        {
            int reqNumOfOpnedCells = this.BoardSize.Height * this.BoardSize.Width - this.Parameters.NumOfMines;

            // Counting how many cells are opened.
            int numOfOpenedCells = 0;

            for (int i = 0; i < this.BoardSize.Height; i++)
            {
                for (int j = 0; j < this.BoardSize.Width; j++)
                {
                    if (this.Board[i, j].State == Cell.CellState.Opened)
                    {
                        numOfOpenedCells++;
                    }
                }
            }

            if ((reqNumOfOpnedCells + this.Parameters.NumOfMines) == (numOfOpenedCells + NumFlags))
            {
                GameEndEventArgs args = new GameEndEventArgs();
                args.Message = "Game Is End!, You Win!";
                args.Score   = ComputeScore();

                GameEnd?.Invoke(this, args);
            }
        }
 public static void FinishEndGame()
 {
     GameEnd?.Invoke();
     CurrentGameState = GameState.End;
     if (Instance.debug)
     {
         Debug.Log("End Game");
     }
 }
Beispiel #5
0
 public void DecideWinner()
 {
     if (_Players.Count != 1)
     {
         foreach (Player player in _Players)
         {
             if (player.Hand.Count < 5)
             {
                 throw new ConstraintException("Game is in process.");
             }
         }
     }
     _Winner = GetTopRanking();
     _Winner.WinMoney(_Pot);
     _Pot = 0;
     GameEnd?.Invoke(this, EventArgs.Empty);
 }
Beispiel #6
0
        /// <summary>
        /// Opens all cells when the game is over.
        /// </summary>
        /// <param name="grp"> Graphics object for drawing.</param>
        public void OpenAllCells(Graphics grp)
        {
            Size sizecell = this.GetParameters().CellSize;

            for (int i = 0; i < this.BoardSize.Height; i++)
            {
                for (int j = 0; j < this.BoardSize.Width; j++)
                {
                    if (this.Board[i, j].State == Cell.CellState.Opened)
                    {
                        continue;
                    }

                    var pen   = Pens.Black;
                    var brush = Brushes.Silver;
                    this.Board[i, j].CellBody.Location = new Point(3 + j * sizecell.Height, 3 + i * sizecell.Width);

                    if (this.Board[i, j].Content == Cell.CellContent.Mine)
                    {
                        brush = Brushes.Red;
                        grp.FillRectangle(brush, this.Board[i, j].CellBody);
                        grp.DrawIcon(new Icon(@"..\..\Icons\Be-Os-Be-Box-BeBox-Minesweeper.ico"), this.Board[i, j].CellBody);
                    }
                    else
                    {
                        grp.FillRectangle(brush, this.Board[i, j].CellBody);
                        grp.DrawString(this.Board[i, j].Number.ToString(), new Font(FontFamily.GenericSerif, 12), Brushes.Black, this.Board[i, j].CellBody);
                    }

                    if (this.Board[i, j].State == Cell.CellState.Flag)
                    {
                        grp.DrawIcon(new Icon(@"..\..\Icons\Everaldo-Crystal-Clear-App-kmines-minesweeper.ico"), this.Board[i, j].CellBody);
                    }

                    this.Board[i, j].State = Cell.CellState.Opened;
                    grp.DrawRectangle(pen, this.Board[i, j].CellBody);
                }
            }

            GameEndEventArgs args = new GameEndEventArgs();

            args.Message = "Game Is End! You Dead!";
            args.Score   = ComputeScore();

            GameEnd?.Invoke(this, args);
        }
Beispiel #7
0
 public void StartGameEnd(PlayerType winner)
 {
     GameEnd?.Invoke(winner);
 }
 protected virtual void OnGameEnd()
 {
     GameEnd?.Invoke(this, new GameEndEventArgs());
 }
 protected virtual void OnGameEnd(LeagueEventArgs args) => GameEnd?.Invoke(this, args);
 /// <summary>
 /// Trigger the game over event
 /// </summary>
 public void EndGame()
 {
     GameEnd?.Invoke();
 }
Beispiel #11
0
 private void OnCarDestroyed()
 {
     gameStarted = false;
     GameEnd?.Invoke();
 }
Beispiel #12
0
 public void Notify()
 {
     GameEnd?.Invoke();
 }
Beispiel #13
0
 private static void OnGameEndEvent(bool success)
 {
     GameEnd?.Invoke(success);
 }