Beispiel #1
0
        public void InitLogic(Dictionary <byte, NetworkPlayer> players)
        {
            PlayerCount     = players.Count;
            Mediator        = MainForm.Instance.Mediator;
            DoAfterGameLoop = new List <Action>();
            PlayerPaddles   = new Dictionary <byte, Paddle>();
            ArenaBalls      = new Dictionary <byte, IBall>();
            ArenaObjects    = new Dictionary <byte, ArenaObject>();

            float deltaAngle = SharedUtilities.PI * 2 / PlayerCount;
            float angle      = (-SharedUtilities.PI + deltaAngle) / 2f;

            foreach (var player in players.Values)
            {
                PaddleType pType  = player.PaddleType;
                Paddle     paddle = PaddleFactory.CreatePaddle(pType, player.Id);
                paddle.SetPosition(SharedUtilities.RadToDeg(angle));
                PlayerPaddles.Add(player.Id, paddle);
                player.SetLife(paddle.Life);
                if (Mediator.GetBool("IdMatches", player.Id))
                {
                    LocalPaddle = paddle;
                }
                paddle.AddClampAngles(SharedUtilities.RadToDeg(angle - deltaAngle / 2), SharedUtilities.RadToDeg(angle + deltaAngle / 2));
                angle += deltaAngle;
            }
            AlivePaddleCount         = PlayerPaddles.Count;
            StartingAlivePaddleCount = AlivePaddleCount;



            UpdatableRoot = new UpdateComposite();
            UpdatableRoot.Add(LocalPaddle.Id, LocalPaddle);

            UpdateComponent spawnerBranch = new UpdateComposite();

            spawnerBranch.Add(spawnerBranch.GetNextId(), new ObstacleSpawner(GameData.ObstacleSpawnerParams, ArenaObjectFactories.Values.ToArray()));
            spawnerBranch.Add(spawnerBranch.GetNextId(), new PowerUpSpawner(GameData.PowerUpSpawnerParams, ArenaObjectFactories.Values.ToArray()));
            UpdatableRoot.Add(UpdatableRoot.GetNextId(), spawnerBranch);

            UpdateComponent objectBranch = new UpdateComposite();

            ObjectBranchId = UpdatableRoot.GetNextId();
            UpdatableRoot.Add(ObjectBranchId, objectBranch);

            UpdateComponent ballBranch = new UpdateComposite();

            BallBranchId = UpdatableRoot.GetNextId();
            UpdatableRoot.Add(BallBranchId, ballBranch);

            BallType bType = RoomSettings.Instance.BallType;
            Ball     ball  = Ball.CreateBall(0, bType, ArenaDimensions.Center, GameData.DefaultBallSpeed, Vector2.RandomInUnitCircle(), GameData.DefaultBallSize);

            ArenaBalls.Add(0, ball);
            ballBranch.Add(0, ball);

            IsInitted = true;
            PauseGame(false);
        }
Beispiel #2
0
        public MainForm()
        {
            Instance = this;
            new GameStateObserver(GameManager.Instance, this);
            Mediator = new ConcreteMediator();
            InitializeComponent();
            GameLoop.Tick += new EventHandler(GameLoop_Tick);
            SyncLoop.Tick += new EventHandler(SyncLoop_Tick);

            SafeInvoke.Instance.Setup(this);
            MainMenu.ConnectToServerButton.Text = Constants.ConnectToServer;
            GameManager.Instance.SetGameState(GameState.InMainMenu_NotConnected);

            SpeedAnalysis.DoFlyweightSpeedAnalysis();
            //tests
            //UnitTests.NetworkMessageUnitTests.TestBallSyncEncodingAndDecoding();
        }