Click here to Skip to main content
15,887,477 members
Home / Discussions / C#
   

C#

 
GeneralRe: Query on Delegate Pin
ashish711-Jul-12 23:13
ashish711-Jul-12 23:13 
GeneralRe: Query on Delegate Pin
Pete O'Hanlon11-Jul-12 23:23
mvePete O'Hanlon11-Jul-12 23:23 
GeneralRe: Query on Delegate Pin
BobJanova11-Jul-12 23:41
BobJanova11-Jul-12 23:41 
GeneralRe: Query on Delegate Pin
Pete O'Hanlon11-Jul-12 22:50
mvePete O'Hanlon11-Jul-12 22:50 
GeneralRe: Query on Delegate Pin
OriginalGriff11-Jul-12 22:56
mveOriginalGriff11-Jul-12 22:56 
GeneralRe: Query on Delegate Pin
DaveyM6911-Jul-12 22:57
professionalDaveyM6911-Jul-12 22:57 
GeneralRe: Query on Delegate Pin
Wayne Gaylard11-Jul-12 23:02
professionalWayne Gaylard11-Jul-12 23:02 
GeneralRe: Query on Delegate Pin
ashish712-Jul-12 2:15
ashish712-Jul-12 2:15 
I have gone through all the replies but I am not able to convert the code in the simple understandable format.

I am pasting the the two .cs file below, if someone can help putting it in the simple fashion for all the 3 eventhandler delegates.

1) PuzzleGame.cs

C#
using Mosaic;

namespace WindowsPhonePuzzle
{
    public class PieceUpdatedEventArgs : EventArgs
    {
        public int PieceId { get; set; }
        public Point NewPosition { get; set; }
    }

    public class GameOverEventArgs : EventArgs
    {
        public int TotalMoves { get; set; }
    }

    public class PuzzleGame
    {        
                
        public EventHandler GameStarted;        
        public EventHandler<PieceUpdatedEventArgs> PieceUpdated;
        public EventHandler<GameOverEventArgs> GameOver;

        ////// More code below

                 if (this.GameStarted != null)
            {
                this.GameStarted(this, null);
            }
        }


        ////// More code below

                if (this.GameOver != null)
                {
                    this.GameOver(this, new GameOverEventArgs { TotalMoves = this.totalMoves });
                }
            }
        }

        ////// More code below


            if (this.PieceUpdated != null)
            {
                this.PieceUpdated(this, new PieceUpdatedEventArgs {PieceId = pieceId, NewPosition = newPosition});
            }
        }
    }
}



2) PuzzlePage.xaml.cs
<pre lang="c#">
using WindowsPhonePuzzle;

 

namespace Mosaic
{
    public partial class PuzzlePage  : PhoneApplicationPage
    {

      
        public PuzzlePage()
        {
            InitializeComponent();
            SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape;

            // Puzzle Game
            this.game = new PuzzleGame(3);


            this.game.GameStarted += delegate
            {
                this.ResetWinTransition.Begin();
                this.StatusPanel.Visibility = Visibility.Visible;
                this.TapToContinueTextBlock.Opacity = 0;
                this.TotalMovesTextBlock.Text = this.game.TotalMoves.ToString();
            };       

            this.game.GameOver += delegate
            {
                this.WinTransition.Begin();
                this.TapToContinueTextBlock.Opacity = 1;
                this.StatusPanel.Visibility = Visibility.Visible;
                this.TotalMovesTextBlock.Text = this.game.TotalMoves.ToString();
            };

            this.game.PieceUpdated +=  delegate(object sender, PieceUpdatedEventArgs args)
            {
                int pieceSize = ImageSize / this.game.ColsAndRows;
                this.AnimatePiece(this.puzzlePieces[args.PieceId], Canvas.LeftProperty, (int)args.NewPosition.X * pieceSize);
                this.AnimatePiece(this.puzzlePieces[args.PieceId], Canvas.TopProperty, (int)args.NewPosition.Y * pieceSize);
                this.TotalMovesTextBlock.Text = this.game.TotalMoves.ToString();
            };

            this.InitBoard();
        }


modified 12-Jul-12 8:40am.

GeneralRe: Query on Delegate Pin
OriginalGriff12-Jul-12 2:23
mveOriginalGriff12-Jul-12 2:23 
GeneralRe: Query on Delegate Pin
ashish712-Jul-12 2:32
ashish712-Jul-12 2:32 
GeneralRe: Query on Delegate Pin
ashish712-Jul-12 2:44
ashish712-Jul-12 2:44 
QuestionRe: Query on Delegate Pin
DaveyM6912-Jul-12 3:22
professionalDaveyM6912-Jul-12 3:22 
AnswerRe: Query on Delegate Pin
ashish712-Jul-12 3:31
ashish712-Jul-12 3:31 
GeneralRe: Query on Delegate Pin
DaveyM6912-Jul-12 7:38
professionalDaveyM6912-Jul-12 7:38 
GeneralRe: Query on Delegate Pin
ashish712-Jul-12 7:53
ashish712-Jul-12 7:53 
GeneralRe: Query on Delegate Pin
OriginalGriff12-Jul-12 3:48
mveOriginalGriff12-Jul-12 3:48 
GeneralRe: Query on Delegate Pin
ashish712-Jul-12 3:58
ashish712-Jul-12 3:58 
GeneralRe: Query on Delegate Pin
OriginalGriff12-Jul-12 4:11
mveOriginalGriff12-Jul-12 4:11 
GeneralRe: Query on Delegate Pin
DaveyM6912-Jul-12 4:32
professionalDaveyM6912-Jul-12 4:32 
AnswerRe: Query on Delegate Pin
Abhinav S11-Jul-12 21:53
Abhinav S11-Jul-12 21:53 
QuestionConfusion Pin
nitish_0711-Jul-12 21:02
nitish_0711-Jul-12 21:02 
AnswerRe: Confusion Pin
Abhinav S11-Jul-12 21:41
Abhinav S11-Jul-12 21:41 
AnswerRe: Confusion Pin
OriginalGriff11-Jul-12 21:41
mveOriginalGriff11-Jul-12 21:41 
AnswerRe: Confusion Pin
BillWoodruff14-Jul-12 15:17
professionalBillWoodruff14-Jul-12 15:17 
General[SOLVED] Adding Forms to TabControl Pin
AmbiguousName11-Jul-12 18:27
AmbiguousName11-Jul-12 18:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.