예제 #1
0
 public BlfContent(string mapInfoFileName, byte[] mapInfo, TargetGame targetGame)
 {
     MapInfoFileName     = mapInfoFileName;
     MapInfo             = mapInfo;
     TargetGame          = targetGame;
     BlfContainerEntries = new List <BlfContainerEntry>();
 }
예제 #2
0
 public BlfContent(string mapInfoFileName, byte[] mapInfo, TargetGame targetGame)
 {
     MapInfoFileName = mapInfoFileName;
     MapInfo = mapInfo;
     TargetGame = targetGame;
     BlfContainerEntries = new List<BlfContainerEntry>();
 }
예제 #3
0
        static void Server_Connected(object sender, Server <SnakePlayer> .ConnectionEventArgs e)
        {
            SnakeGame TargetGame = null;

            e.Client.Socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
            foreach (SnakeGame G in Games)
            {
                if (G.Status == GameStatus.WaitingForOpponent)
                {
                    TargetGame = G; break;
                }
            }
            if (TargetGame == null)
            {
                CurrentID++;
                TargetGame = new SnakeGame(Map);
                TargetGame.AddPlayer(e.Client);
                TargetGame.ID             = CurrentID;
                TargetGame.GameOver      += new SnakeGame.GameOverDelegate(TargetGame_GameOver);
                TargetGame.MessageLogged += new SnakeGame.LogMessageDelegate(TargetGame_MessageLogged);
                Games.Add(TargetGame);
                TargetGame_MessageLogged(TargetGame, new SnakeGame.LogEventArgs("First player connected"));
            }
            else
            {
                TargetGame.AddPlayer(e.Client);
            }
        }
예제 #4
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            // Set up status
            updateHitsStatus();

            // Set cursor
            mainPictureBox.Cursor = Cursors.Cross;

            // Lambda statement for game reset
            resetToolStripMenuItem.Click += (from, ea) =>
            {
                _hits = 0;
                _level = 1;
                _targetGame.NumberOfTargets = 1;
                updateHitsStatus();
                _targetGame.Reset();
            };

            // Exit event lambda expressions
            exitToolStripMenuItem.Click += (from, ea) => this.Close();

            // PictureBox Mouseup lambda expression
            mainPictureBox.MouseUp += (from, ea) => _targetGame.Select(ea.Location);

            // Create target game obj
            _targetGame = new TargetGame(boardSize: mainPictureBox.ClientSize);

            // lambda delegates for Hit
            _targetGame.Hit += (from, ea) => ++_hits;
            _targetGame.Hit += (from, ea) =>
            {
                if (_hits == _hitsPerLevel * _targetGame.NumberOfTargets)
                {
                    _hits = 0;
                    _level++;
                    _targetGame.NumberOfTargets++;
                }
            };

            // Lambda delegates for TimerExpired in Project
            _targetGame.TimerExpired += (from, ea) =>
            {
                _hits = 0;
                updateHitsStatus();
            };

            _targetGame.Hit += (from, ea) => updateHitsStatus();

            // Set up PictureBox Paint Event
            mainPictureBox.Paint += (from, ea) =>
            {
                _targetGame.Update(ea.Graphics, _level);
            };

            // Set up Time Tick event
            gameTimer.Tick += (from, ea) => mainPictureBox.Invalidate();
            gameTimer.Start();

            // Lambda event handlers for Project
            pauseToolStripMenuItem.Click += (from, ea) =>
            {
                if (!_paused)
                {
                    _paused = true;
                    gameTimer.Stop();
                    pauseToolStripMenuItem.Text = "Unpause";
                }
                else
                {
                    _paused = false;
                    gameTimer.Start();
                    pauseToolStripMenuItem.Text = "Pause";
                }
            };
        }