public void InitModel() { // this delegate is needed for the multi media timer defined // in the TimerQueueTimer class. _ballTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(BallMMTimerCallback); _paddelTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(PaddelMMTimerCallback); // create our multi-media timers _ballHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _ballHiResTimer.Create(4, 4, _ballTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create Ball timer. Error from GetLastError = {0}", ex.Error); } _paddelHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _paddelHiResTimer.Create(4, 4, _paddelTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create Paddel timer. Error from GetLastError = {0}", ex.Error); } }
public static Task TQTDelay(int millisecondsDelay, CancellationToken token = default) { if (millisecondsDelay < 0) { throw new ArgumentOutOfRangeException("millisecondsDelay", millisecondsDelay, "The value cannot be less than 0."); } if (millisecondsDelay == 0) { return(Task.CompletedTask); } token.ThrowIfCancellationRequested(); var completionSource = new TaskCompletionSource <object>(); //WaitOrTimerCallback callback = (object s, bool timedout) => { completionSource.TrySetResult(null); }; //var timerId = NativeMethods.CreateTimerQueueTimer(out IntPtr handle, IntPtr.Zero, callback, IntPtr.Zero, (uint)millisecondsDelay, (uint)0, 0x00000008); //if (!timerId) //{ // int error = Marshal.GetLastWin32Error(); // throw new Win32Exception(error); //} TimerQueueTimer timer = new TimerQueueTimer(); TimerQueueTimer.WaitOrTimerDelegate callback = new TimerQueueTimer.WaitOrTimerDelegate((IntPtr s, bool timedout) => { completionSource.TrySetResult(null); }); timer.Delay((uint)millisecondsDelay, callback); return(completionSource.Task); }
public void InitModel() { // this delegate is needed for the multi media timer defined // in the TimerQueueTimer class. _ballTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(BallMMTimerCallback); // create our multi-media timers _ballHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _ballHiResTimer.Create(4, 4, _ballTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create Ball timer. Error from GetLastError = {0}", ex.Error); } //*********************************** // START THE PADDLE THREAD HERE //*********************************** if (_threadPaddle == null) { _threadPaddleStart = new ThreadStart(paddleThreadFunction); _threadPaddle = new Thread(_threadPaddleStart); _threadPaddle.Start(); } }
public void InitModel() { if (_threadPaddle == null) { _threadPaddleStart = new ThreadStart(paddleThreadFunction); _threadPaddle = new Thread(_threadPaddleStart); _threadPaddle.Start(); } if (_bulletCallbackDelegate == null) { _bulletCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(BulletMMTimerCallback); } if (_bulletHiResTimer == null) { _bulletHiResTimer = new TimerQueueTimer(); try { _bulletHiResTimer.Create(100, 10, _bulletCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create bullet timer. Error from GetLastError = {0}", ex.Error); } if (_enemyCallbackDelegate == null) { _enemyCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(EnemyMMTimerCallback); } } if (_enemyHiResTimer == null) { _enemyHiResTimer = new TimerQueueTimer(); try { _enemyHiResTimer.Create(100, 10, _enemyCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create enemy timer. Error from GetLastError = {0}", ex.Error); } } }
public void InitModel() { // note that the brick hight, number of brick columns and rows // must match our window demensions. double _brickHeight = 25; double _brickWidth = _windowWidth / _numBrickColumns; // create brick collection // place them manually at the top of the item collection in the view BrickCollection = new ObservableCollection <Brick>(); for (int outer = 0; outer < _numBrickRows; outer++) { for (int inner = 0; inner < _numBrickColumns; inner++) { BrickCollection.Add(new Brick() { Fill = System.Windows.Media.Brushes.Red, BrickHeight = _brickHeight, BrickWidth = _brickWidth, BrickVisibility = System.Windows.Visibility.Visible, BrickCanvasLeft = inner * _brickWidth, BrickCanvasTop = _brickHeight * outer }); } } _ballTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(BallMMTimerCallback); _ballHiResTimer = new TimerQueueTimer(); try { _ballHiResTimer.Create(8, 8, _ballTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create Ball timer. Error from GetLastError = {0}", ex.Error); } _paddleTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(paddleMMTimerCallback); _paddleHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _paddleHiResTimer.Create(4, 4, _paddleTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create paddle timer. Error from GetLastError = {0}", ex.Error); } }
public void InitModel() { // this delegate is needed for the multi media timer defined // in the TimerQueueTimer class. _ballTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(BallMMTimerCallback); _paddleTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(paddleMMTimerCallback); //_brickTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(brickMMTimerCallback); // create our multi-media timers _ballHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _ballHiResTimer.Create(1, 1, _ballTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create Ball timer. Error from GetLastError = {0}", ex.Error); } _paddleHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _paddleHiResTimer.Create(2, 2, _paddleTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create paddle timer. Error from GetLastError = {0}", ex.Error); } UpdateRects(); for (int i = 0; i < _numBricks; i++) { Console.WriteLine(BrickCollection[i].BrickRectangle.Location); } StartTimer(); }
public void Start(uint period, Action action) { _action = action; if (Environment.OSVersion.Version.Major > 5)//>xp { qt = new TimerQueueTimer(); TimerQueueTimer.WaitOrTimerDelegate CallbackDelete = new TimerQueueTimer.WaitOrTimerDelegate(QueueTimerCallback); qt.Start(0, period, CallbackDelete); usingTimerQueue = true; } else if (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1)//xp { usingTimerQueue = false; mt = new MMTimer(); mt.Start(period, true, _action); } else { throw new HighResolutionTimerException("Could Not Creat 1ms Timer!"); } }
public void InitModel() { GameWin = Visibility.Hidden; BuildBricks(); //Start_Click(); // this delegate is needed for the multi media timer defined // in the TimerQueueTimer class. _ballTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(BallMMTimerCallback); _paddleTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(paddleMMTimerCallback); // create our multi-media timers _ballHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _ballHiResTimer.Create(1, 1, _ballTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create Ball timer. Error from GetLastError = {0}", ex.Error); } _paddleHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _paddleHiResTimer.Create(2, 2, _paddleTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create paddle timer. Error from GetLastError = {0}", ex.Error); } UpdateRects(); }
public void InitModel() { // this delegate is needed for the multi media timer defined // in the TimerQueueTimer class. _ballTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(BallMMTimerCallback); _paddleTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(paddleMMTimerCallback); // create our multi-media timers _ballHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _ballHiResTimer.Create(2, 2, _ballTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create Ball timer. Error from GetLastError = {0}", ex.Error); } _paddleHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _paddleHiResTimer.Create(2, 2, _paddleTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create paddle timer. Error from GetLastError = {0}", ex.Error); } _brickWidth = (_windowWidth - 20) / 15; Create_Brick(); NETTimerTimerStart(true); }
public bool InitModel() { //try //{ // // *********************************************** // // set up generic UDP socket and bind to local port // // *********************************************** // _dataSocket = new UdpClient((int)_localPort); //} //catch (Exception ex) //{ // Debug.Write(ex.ToString()); // return false; //} // this delegate is needed for the multi media timer defined // in the TimerQueueTimer class. _ballTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(BallMMTimerCallback); // create our multi-media timers _ballHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _ballHiResTimer.Create(10, 10, _ballTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create Ball timer. Error from GetLastError = {0}", ex.Error); } _paddleTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(paddleMMTimerCallback); _paddleHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _paddleHiResTimer.Create(10, 8, _paddleTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create paddle timer. Error from GetLastError = {0}", ex.Error); } // reset help text //HelpText = ""; ThreadStart threadFunction; threadFunction = new ThreadStart(SynchWithOtherPlayer); _syncWithOtherPlayerThread = new Thread(threadFunction); return true; }
public void InitModel() { // create brick collection // place them manually at the top of the item collection in the view BrickCollection = new ObservableCollection <Brick>(); for (int i = 0; i < _numBrickRows; i++) { for (int brick = 0; brick < _numBricksColumns; brick++) { BrickCollection.Add(new Brick() { BrickCanvasTop = i * _brickHeight, BrickCanvasLeft = brick * _brickWidth, BrickFill = FillColorRed, BrickHeight = _brickHeight, BrickWidth = _brickWidth, BrickVisible = System.Windows.Visibility.Visible, BrickName = brick.ToString(), }); //BrickCollection[brick].BrickCanvasLeft = _windowWidth / 2 - _brickWidth / 2; //BrickCollection[brick].BrickCanvasTop = brick * _brickHeight + 150; // offset the bricks from the top of the screen by a bitg } } //ELAPSED TIMER GOES HERE _mytimer = new DispatcherTimer(); _mytimer.Tick += new EventHandler(BallTimerCallback); _mytimer.Interval = new TimeSpan(0, 0, 1); // this delegate is needed for the multi media timer defined // in the TimerQueueTimer class. _ballTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(BallMMTimerCallback); _paddleTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(paddleMMTimerCallback); // create our multi-media timers _ballHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _ballHiResTimer.Create(1, 1, _ballTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create Ball timer. Error from GetLastError = {0}", ex.Error); } _paddleHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _paddleHiResTimer.Create(2, 2, _paddleTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create paddle timer. Error from GetLastError = {0}", ex.Error); } }
public void InitModel() { //_threadPaddle = new Thread(new ThreadStart(paddleThreadCall)); //_threadBall = new Thread(new ThreadStart(ballThreadCall)); //_threadPaddle.Start(); //_threadBall.Start(); _ballTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(BallMMTimerCallback); _paddleTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(paddleMMTimerCallback); Score = 0; // create our multi-media timers _ballHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _ballHiResTimer.Create(3, 3, _ballTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create Ball timer. Error from GetLastError = {0}", ex.Error); } _paddleHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _paddleHiResTimer.Create(2, 2, _paddleTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create paddle timer. Error from GetLastError = {0}", ex.Error); } // create brick collection // place them manually at the top of the item collection in the view BrickCollection = new ObservableCollection <Brick>(); int i = 0; double curLeft = 0; for (int brick = 0; brick < _numBricks; brick++) { BrickCollection.Add(new Brick() { BrickHeight = _brickHeight, BrickWidth = _brickWidth, BrickVisible = System.Windows.Visibility.Visible, BrickName = brick.ToString(), }); //for creating the collection //{ if (WindowWidth < curLeft) { i++; curLeft = 0; } BrickCollection[brick].BrickCanvasLeft = curLeft; BrickCollection[brick].BrickCanvasTop = i * _brickHeight; curLeft += _brickWidth; //} // offset the bricks from the top of the screen by a bitg } UpdateRects(); }
public void InitModel() { GameOver = Visibility.Hidden; // this delegate is needed for the multi media timer defined // in the TimerQueueTimer class. _ballTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(BallMMTimerCallback); _paddleTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(paddleMMTimerCallback); ScoreCounter = 0; // create our multi-media timers _ballHiResTimer = new TimerQueueTimer(); hitBottom = 0; // restart the counter for number times we have hit the bottom side of the game try { // create a Multi Media Hi Res timer. _ballHiResTimer.Create(1, 1, _ballTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create Ball timer. Error from GetLastError = {0}", ex.Error); } _paddleHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _paddleHiResTimer.Create(2, 2, _paddleTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create paddle timer. Error from GetLastError = {0}", ex.Error); } // create brick collection // place them manually at the top of the item collection in the view BrickCollection = new ObservableCollection <Brick>(); int counter = 0; //counter for number of rows for (int brick = 0; brick < _numBricks; brick++) { BrickCollection.Add(new Brick() { BrickHeight = _brickHeight, BrickWidth = _brickWidth, BrickVisible = System.Windows.Visibility.Visible, BrickName = brick.ToString(), }); if (brick == 0) { BrickCollection[brick].BrickCanvasLeft = 0; BrickCollection[brick].BrickCanvasTop = brick * _brickHeight; // offset the bricks from the top } else if (brick % 11 == 1 && (brick - 1) != 0) //shift down one and reset side { BrickCollection[brick].BrickCanvasLeft = BrickCollection[brick - 1].BrickCanvasLeft; BrickCollection[brick].BrickCanvasTop = counter * _brickHeight; } else if ((BrickCollection[brick - 1].BrickCanvasLeft + 160) < _windowWidth) { BrickCollection[brick].BrickCanvasLeft = BrickCollection[brick - 1].BrickCanvasLeft + 80; BrickCollection[brick].BrickCanvasTop = BrickCollection[brick - 1].BrickCanvasTop; } else if ((BrickCollection[brick - 1].BrickCanvasLeft + 160) > _windowWidth) { counter++; BrickCollection[brick].BrickCanvasLeft = 0; BrickCollection[brick].BrickCanvasTop = counter * _brickHeight; } } NETTimerStart(true); UpdateRects(); }
public void InitModel() { // this delegate is needed for the multi media timer defined // in the TimerQueueTimer class. _ballTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(BallMMTimerCallback); _paddleTimerCallbackDelegate = new TimerQueueTimer.WaitOrTimerDelegate(paddleMMTimerCallback); _timerAllDelegate = new TimerQueueTimer.WaitOrTimerDelegate(allTimeMMTimerCallback); //--------------------------------- _timerAll = new TimerQueueTimer(); // we need to show the runtime for the game try { _timerAll.Create(5, 5, _ballTimerCallbackDelegate); // tick++; //if (tick > 1000) { // GameTime++; // Gametimed = GameTime.ToString(); } } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create Ball timer. Error from GetLastError = {0}", ex.Error); } // create our multi-media timers _ballHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _ballHiResTimer.Create(5, 5, _ballTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create Ball timer. Error from GetLastError = {0}", ex.Error); } _paddleHiResTimer = new TimerQueueTimer(); try { // create a Multi Media Hi Res timer. _paddleHiResTimer.Create(2, 2, _paddleTimerCallbackDelegate); } catch (QueueTimerException ex) { Console.WriteLine(ex.ToString()); Console.WriteLine("Failed to create paddle timer. Error from GetLastError = {0}", ex.Error); } BrickCollection = new ObservableCollection <Brick>(); for (int i = 0; i < numCol; i++) { for (int j = 0; j < numRow; j++) { BrickCollection.Add(new Brick() { //BrickRectangle BrickHeight = _brickHeight, BrickFill = FillColorRed, BrickWidth = _brickWidth, BrickName = i.ToString(), BrickVisible = System.Windows.Visibility.Visible, BrickBackground = System.Windows.Media.Brushes.Red, BrickCanvasLeft = i * _brickWidth, BrickCanvasTop = j * _brickHeight, // offset the bricks from the top of the screen by a bitg BrickRectangle = new Rectangle(i * _brickWidth, j * _brickHeight, _brickWidth - 1, _brickHeight - 1) }); } } UpdateRects(); }