Пример #1
0
	// Use this for initialization
	void Start () {
		if(player == true){
			gameObject.AddComponent<Player1>();
			player_1 = gameObject.GetComponent<Player1>();
		}else if(player == false){
			gameObject.AddComponent<Player2>();
			player_2 = gameObject.GetComponent<Player2>();
		}
	}
Пример #2
0
    object ConstructSourceDataJson()
    {
        Player2 player2 = new Player2();
        player2.id = 10001;
        player2.name = "test 001";
        player2.level = 185;
        player2.golds = 1234567;
        player2.attackValue = 5242;

        return player2;
    }
Пример #3
0
	void Awake ()
	{
		if (player == null)
		{
			DontDestroyOnLoad (gameObject);
			player = this;
		}
		else if (player != this)
		{
			Destroy (gameObject);
		}
	}
Пример #4
0
	private IEnumerator BeginGame () {
		myMaze = Instantiate (mazeFab) as Maze;
		yield return StartCoroutine (myMaze.generate ());
		myPlayer = Instantiate (playerFab) as Player;
		myPlayer.SetLocation (myMaze.getCell (myMaze.RandomCoord));

		myPlayer2 = Instantiate (player2Fab) as Player2;
		myPlayer2.SetLocation (myMaze.getCell (myMaze.RandomCoord));

		myPlayer.otherPlayer = myPlayer2;
		myPlayer2.otherPlayer = myPlayer;
	}
	// Actives the power up on the player given (true = player 1, false = player 2)
	public void ActivatePowerup(bool player){
		Debug.Log("SPACE WALK ACTIVATED");
		
		p1_movement = GameObject.Find("Player1").GetComponent<Player1>();
		p2_movement = GameObject.Find("Player2").GetComponent<Player2>();
		
		if(player == true){
			p1_movement.jumpHeight += 5;
		}else{
			p2_movement.jumpHeight += 5;
		}		
	}
Пример #6
0
	// Update is called once per frame
	void Update () {
		// TODO: Eventually remove this input check, this is for development use only
		if(Input.GetKeyUp(KeyCode.Escape)){
			RespawnBall();
		}
		if(player_1 == null){
			player1 = GameObject.Find ("Player1");
			player_1 = player1.GetComponent<Player1> ();
		}
		if(player_2 == null){
			player2 = GameObject.Find ("Player2");
			player_2 = player2.GetComponent<Player2> ();
		}
	}
Пример #7
0
	// Use this for initialization
	void Start () {
		// Find and assign all relevent vars
		player1 = GameObject.Find ("Player1");
		player2 = GameObject.Find ("Player2");
		racket_p1 = GameObject.Find ("racket_p1");
		racket_p2 = GameObject.Find ("racket_p2");
		ball = GameObject.Find ("Ball").transform;
		ballMovement = ball.GetComponent<BallMovement> ();
		PauseGame ();
		player1_spawn = GameObject.Find ("player1_spawn").transform.position;
		player2_spawn = GameObject.Find ("player2_spawn").transform.position;
		player_1 = player1.GetComponent<Player1> ();
		player_2 = player2.GetComponent<Player2> ();
		
		stinger_source = gameObject.GetComponentInChildren<AudioSource>();
	}
Пример #8
0
	// Update is called once per frame
	void Update () {
		if(player_1 == null){
			player_1 = GameObject.Find("Player1").GetComponent<Player1>();
		}
		
		if(player_2 == null){
			player_2 = GameObject.Find("Player2").GetComponent<Player2>();
		}
		
		if(anim1 == null){
			// Load player 1's character (default = Dennis)
			if(savedSelections.selected_p1 == "S. Racks"){
				anim1 = (RuntimeAnimatorController)RuntimeAnimatorController.Instantiate(Resources.Load("Anims/SRacks", typeof(RuntimeAnimatorController)));
			}else if(savedSelections.selected_p1 == "SH1-V4"){
				anim1 = (RuntimeAnimatorController)RuntimeAnimatorController.Instantiate(Resources.Load("Anims/SH1V4", typeof(RuntimeAnimatorController)));
			}else if(savedSelections.selected_p1 == "Colonel Topspin"){
				anim1 = (RuntimeAnimatorController)RuntimeAnimatorController.Instantiate(Resources.Load("Anims/ColonelTopspin", typeof(RuntimeAnimatorController)));
			}else{
				anim1 = (RuntimeAnimatorController)RuntimeAnimatorController.Instantiate(Resources.Load("Anims/Dennis", typeof(RuntimeAnimatorController)));
			}
		}else{
			// Set the animator controller
			player_1._animator.runtimeAnimatorController = anim1;
		}
	
		if(anim2 == null){
			// Load player 2's character (default = S. Racks)
			if(savedSelections.selected_p2 == "Dennis"){
				anim2 = (RuntimeAnimatorController)RuntimeAnimatorController.Instantiate(Resources.Load("Anims/Dennis", typeof(RuntimeAnimatorController)));
			}else if(savedSelections.selected_p2 == "SH1-V4"){
				anim2 = (RuntimeAnimatorController)RuntimeAnimatorController.Instantiate(Resources.Load("Anims/SH1V4", typeof(RuntimeAnimatorController)));
			}else if(savedSelections.selected_p2 == "Colonel Topspin"){
				anim2 = (RuntimeAnimatorController)RuntimeAnimatorController.Instantiate(Resources.Load("Anims/ColonelTopspin", typeof(RuntimeAnimatorController)));
			}else{
				anim2 = (RuntimeAnimatorController)RuntimeAnimatorController.Instantiate(Resources.Load("Anims/SRacks", typeof(RuntimeAnimatorController)));
			}
		}else{
			// Set the animator controller
			player_2._animator.runtimeAnimatorController = anim2;
		}
	}
 private void Awake()
 {
     instance = this;
 }
Пример #10
0
 void Start()
 {
     player = gameObject.GetComponentInParent <Player2> ();
 }
Пример #11
0
        public void Play()
        {
            // Declare the DateTime variables which will be compared for the gamespeed
            DateTime dtLoopStart;
            DateTime dtWaiting;

            // set the console width and height
            Console.WindowHeight = Height + 10;
            Console.WindowWidth  = Width;

            // Set the ball to a random start location and direction
            SetRandomBallProperties();

            // Clear the console
            Console.Clear();

            // Ensure black color
            Console.BackgroundColor = ConsoleColor.Black;

            // Set the title of the window
            Console.Title = $"First to: {MaxScore}";

            // enter a do while loop which will continue until 'GameOver' is True
            do
            {
                // Clear and redraw components
                Console.Clear();
                DrawPlayArea();
                DrawPaddles();
                DrawBall();
                DrawScore();

                // check whether the ball has passed a players paddle
                if (Ball.Position.XCoordinate < Player1.Left)
                {
                    // Increment Player2's score
                    Player2.Score++;

                    // Set the ball to a random start location and direction
                    SetRandomBallProperties();
                }
                else if (Ball.Position.XCoordinate > Player2.Left)
                {
                    // Increment Player1's score
                    Player1.Score++;

                    // Set the ball to a random start location and direction
                    SetRandomBallProperties();
                }

                // If ball touches edge, invert y direction
                if (Ball.Position.YCoordinate <= 1)
                {
                    switch (Ball.Direction)
                    {
                    case EnumDirection.NorthWest:
                        Ball.Direction = EnumDirection.SouthWest;
                        break;

                    case EnumDirection.NorthEast:
                        Ball.Direction = EnumDirection.SouthEast;
                        break;

                    case EnumDirection.North:
                        Ball.Direction = EnumDirection.West;
                        break;
                    }
                }
                else if (Ball.Position.YCoordinate >= Height - 1)
                {
                    switch (Ball.Direction)
                    {
                    case EnumDirection.SouthWest:
                        Ball.Direction = EnumDirection.NorthWest;
                        break;

                    case EnumDirection.SouthEast:
                        Ball.Direction = EnumDirection.NorthEast;
                        break;

                    case EnumDirection.South:
                        Ball.Direction = EnumDirection.West;
                        break;
                    }
                }

                // If it's gameover - break
                if (GameOver)
                {
                    break;
                }

                #region Determine the Ball's future position
                Vector posBallFuture = new Vector(Ball.Position.XCoordinate, Ball.Position.YCoordinate);

                switch (Ball.Direction)
                {
                case EnumDirection.NorthWest:
                    posBallFuture.XCoordinate--;
                    posBallFuture.YCoordinate--;
                    break;

                case EnumDirection.SouthWest:
                    posBallFuture.XCoordinate--;
                    posBallFuture.YCoordinate++;
                    break;

                case EnumDirection.NorthEast:
                    posBallFuture.XCoordinate++;
                    posBallFuture.YCoordinate--;
                    break;

                case EnumDirection.SouthEast:
                    posBallFuture.XCoordinate++;
                    posBallFuture.YCoordinate++;
                    break;

                case EnumDirection.East:
                    posBallFuture.XCoordinate++;
                    break;

                case EnumDirection.West:
                    posBallFuture.XCoordinate--;
                    break;
                }
                #endregion

                // Instantiate the DateTime variables which will be compared for the gamespeed
                dtLoopStart = DateTime.Now;
                dtWaiting   = DateTime.Now;

                // While the difference in time is less that the desired game speed
                while (dtWaiting.Subtract(dtLoopStart).TotalMilliseconds <= GameSpeed)
                {
                    // Refresh the DateTime Waiting to Now
                    dtWaiting = DateTime.Now;

                    // if there is a keyinfo object in the input stream
                    if (Console.KeyAvailable)
                    {
                        // get the key that has been pressed and intercept this so it doesn't right to the console
                        ConsoleKeyInfo keyPressed = Console.ReadKey(true);

                        // Set the respective player's direction based on the key pressed or pauses the game
                        if (keyPressed.Key.Equals(ConsoleKey.UpArrow))
                        {
                            Player2.Direction = EnumDirection.North;
                        }
                        else if (keyPressed.Key.Equals(ConsoleKey.DownArrow))
                        {
                            Player2.Direction = EnumDirection.South;
                        }
                        else if (keyPressed.Key.Equals(ConsoleKey.W))
                        {
                            Player1.Direction = EnumDirection.North;
                        }
                        else if (keyPressed.Key.Equals(ConsoleKey.S))
                        {
                            Player1.Direction = EnumDirection.South;
                        }
                        else if (keyPressed.Key.Equals(ConsoleKey.P))
                        {
                            Pause();
                        }
                        else if (keyPressed.Key.Equals(ConsoleKey.Escape))
                        {
                            Environment.Exit(0);
                        }
                    }

                    #region check whether it is possible for the player's paddle to move in the desired direction
                    int iBottom = Player1.Bottom;
                    switch (Player1.Direction)
                    {
                    case EnumDirection.South:
                        if (iBottom + 2 < Height)
                        {
                            Player1.Move();
                        }
                        break;

                    case EnumDirection.North:
                        if (iBottom - Player1.Pixels.Length > 0)
                        {
                            Player1.Move();
                        }
                        break;
                    }

                    iBottom = Player2.Bottom;
                    switch (Player2.Direction)
                    {
                    case EnumDirection.South:
                        if (iBottom + 2 < Height)
                        {
                            Player2.Move();
                        }
                        break;

                    case EnumDirection.North:
                        if (iBottom - Player2.Pixels.Length > 0)
                        {
                            Player2.Move();
                        }
                        break;
                    }
                    #endregion

                    #region If the ball reaches a player's paddle - reverse the direction
                    if (Player1.Contains(posBallFuture))
                    {
                        if (Player1.Direction == EnumDirection.North && Ball.Direction == EnumDirection.NorthWest)
                        {
                            Ball.Direction = EnumDirection.East;
                        }
                        else if (Player1.Direction == EnumDirection.South && Ball.Direction == EnumDirection.SouthWest)
                        {
                            Ball.Direction = EnumDirection.East;
                        }
                        else if (Player1.Direction == EnumDirection.North && Ball.Direction == EnumDirection.West)
                        {
                            Ball.Direction = EnumDirection.SouthEast;
                        }
                        else if (Player1.Direction == EnumDirection.South && Ball.Direction == EnumDirection.West)
                        {
                            Ball.Direction = EnumDirection.NorthEast;
                        }
                        else if (Player1.Direction == EnumDirection.Unknown)
                        {
                            string sBallDirection = Ball.Direction.ToString();

                            if (sBallDirection.Contains("South"))
                            {
                                Ball.Direction = EnumDirection.SouthEast;
                            }
                            else if (sBallDirection.Contains("North"))
                            {
                                Ball.Direction = EnumDirection.NorthEast;
                            }
                            else
                            {
                                Ball.Direction = EnumDirection.East;
                            }
                        }
                    }

                    if (Player2.Contains(posBallFuture))
                    {
                        if (Player2.Direction == EnumDirection.North && Ball.Direction == EnumDirection.NorthEast)
                        {
                            Ball.Direction = EnumDirection.West;
                        }
                        else if (Player2.Direction == EnumDirection.South && Ball.Direction == EnumDirection.SouthEast)
                        {
                            Ball.Direction = EnumDirection.West;
                        }
                        else if (Player2.Direction == EnumDirection.North && Ball.Direction == EnumDirection.East)
                        {
                            Ball.Direction = EnumDirection.SouthWest;
                        }
                        else if (Player2.Direction == EnumDirection.South && Ball.Direction == EnumDirection.East)
                        {
                            Ball.Direction = EnumDirection.NorthWest;
                        }
                        else if (Player2.Direction == EnumDirection.Unknown)
                        {
                            string sBallDirection = Ball.Direction.ToString();

                            if (sBallDirection.Contains("South"))
                            {
                                Ball.Direction = EnumDirection.SouthWest;
                            }
                            else if (sBallDirection.Contains("North"))
                            {
                                Ball.Direction = EnumDirection.NorthWest;
                            }
                            else
                            {
                                Ball.Direction = EnumDirection.West;
                            }
                        }
                    }
                    #endregion

                    // reset player's directions to stop them from moving infinitely
                    Player1.Direction = EnumDirection.Unknown;
                    Player2.Direction = EnumDirection.Unknown;
                }

                // Set the ball's position to the future position
                Ball.Position = posBallFuture;
            } while (!GameOver);

            // Display GameOverScreen
            DisplayGameOverScreen();
        }
Пример #12
0
 public static bool ButtonPressed2Player(Buttons pButton)
 {
     return((Player1.ButtonPressed(pButton) || Player2.ButtonPressed(pButton)) ? true : false);
 }
Пример #13
0
	// Reset ALL THE THINGS!
	void ResetRound(){
		PauseGame ();
		RespawnPlayers ();
		RespawnBall ();
		player_1 = player1.GetComponent<Player1> ();
		player_2 = player2.GetComponent<Player2> ();
		player_1.SendMessage ("ResetRound");
		player_2.SendMessage ("ResetRound");
		ballMovement.numHits = 0; // Reset the number of volleys
		stinger_source.Play(); // Play the end of round stinger
	}
Пример #14
0
 // Use this for initialization
 void Start()
 {
     clone  = GetComponent <Rigidbody2D> ();
     player = FindObjectOfType <Player2> ();
 }
Пример #15
0
 void Awake()
 {
     _player2 = GameObject.FindGameObjectWithTag("Player2").GetComponent <Player2>();
 }
Пример #16
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="gameMode">Selected game mode</param>
        /// <param name="P1">Player1 information</param>
        /// <param name="P2">Player2 information</param>
        public frmGameForm(string gameMode, Player1 P1, Player2 P2)
        {
            InitializeComponent();
            GameModeSelection(gameMode);
            this.P1  = P1;
            this.P2  = P2;
            starting = enStarting.None;

            if (this.gameMode == enGameMode.Socket_Create || this.gameMode == enGameMode.Socket_Connect)
            {
                lblNameDraw.Hide();
                lblScoreDraw.Hide();
                lblScoreP1.Hide();
                lblScoreP2.Hide();

                while (true)
                {
                    byte[] message = new byte[256];
                    string incomingMsg;
                    frmEntryForm.socket.Send(Encoding.UTF8.GetBytes(" Client?"));
                    frmEntryForm.socket.Receive(message);
                    incomingMsg = Edit_IncomingMessage(message);

                    if (incomingMsg == " C=2")
                    {
                        if (this.gameMode == enGameMode.Socket_Create)
                        {
                            message = new byte[256];
                            frmEntryForm.socket.Send(Encoding.UTF8.GetBytes(" Name?P2"));
                            frmEntryForm.socket.Receive(message);
                            incomingMsg  = Edit_IncomingMessage(message);
                            this.P2.name = incomingMsg;

                            message = new byte[256];
                            frmEntryForm.socket.Send(Encoding.UTF8.GetBytes(" Choice?P2"));
                            frmEntryForm.socket.Receive(message);
                            incomingMsg    = Edit_IncomingMessage(message);
                            this.P2.choice = incomingMsg;
                        }

                        else if (this.gameMode == enGameMode.Socket_Connect)
                        {
                            message = new byte[256];
                            frmEntryForm.socket.Send(Encoding.UTF8.GetBytes(" Name?P1"));
                            frmEntryForm.socket.Receive(message);
                            incomingMsg  = Edit_IncomingMessage(message);
                            this.P1.name = incomingMsg;

                            message = new byte[256];
                            frmEntryForm.socket.Send(Encoding.UTF8.GetBytes(" Choice?P1"));
                            frmEntryForm.socket.Receive(message);
                            incomingMsg    = Edit_IncomingMessage(message);
                            this.P1.choice = incomingMsg;

                            if (incomingMsg == "X")
                            {
                                this.P2.choice = "O";
                            }
                            else
                            {
                                this.P2.choice = "X";
                            }
                        }

                        else
                        {
                        }

                        break;
                    }//(Number of client = 2)?

                    else
                    {
                        DialogResult dr;
                        dr = MetroMessageBox.Show(this, "Waiting Player2", "", MessageBoxButtons.OKCancel, 100);
                        if (dr == DialogResult.Cancel)
                        {
                            this.Close();
                            break;
                        }
                    }
                }
            }// Socket game mode control

            lblNameP1.Text = P1.name;
            lblNameP2.Text = P2.name;

            lblChoiceP1.Text = P1.choice;
            lblChoiceP2.Text = P2.choice;

            OnNewGame();
        }
Пример #17
0
 void Start()
 {
     player1    = FindObjectOfType <Player1>();
     player2    = FindObjectOfType <Player2>();
     updateText = FindObjectOfType <RaceClock>();
 }
Пример #18
0
 // Start is called before the first frame update
 void Start()
 {
     instance = this;
 }
Пример #19
0
 void Start()
 {
     animator = gameObject.GetComponent <Animator>();
     player   = GameObject.FindGameObjectWithTag("Player").GetComponent <Player2>();
     gm       = GameObject.FindGameObjectWithTag("gamemaster").GetComponent <gamemaster>();
 }
Пример #20
0
 public void SettingPlayers()
 {
     P1 = FindObjectOfType(typeof(Player1)) as Player1;
     P2 = FindObjectOfType(typeof(Player2)) as Player2;
 }
Пример #21
0
 // Use this for initialization
 void Start()
 {
     gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
     GameObject rightUser = GameObject.Find("rightUser").gameObject;
     GameObject leftUser = GameObject.Find("leftUser").gameObject;
     is_right_user = true;
     if(is_right_user)
     {
         rightUser.AddComponent<Player1>();
         leftUser.AddComponent<Player2>();
         player1 = rightUser.GetComponent<Player1>();
         player2 = leftUser.GetComponent<Player2>();
         player1.is_right_user = true;
         player2.is_right_user = false;
         player = rightUser;
     }
     else
     {
         rightUser.AddComponent<Player2>();
         leftUser.AddComponent<Player1>();
         player1 = leftUser.GetComponent<Player1>();
         player2 = rightUser.GetComponent<Player2>();
         player1.is_right_user = false;
         player2.is_right_user = true;
         player = leftUser;
     }
     gameManager.SettingPlayers();
     touchFrame = new TouchFrame();
     bt_left = GameObject.Find("leftButton");
     bt_right = GameObject.Find("rightButton");
     joystick_bar = GameObject.Find("Joystick");
     joystick_bg = GameObject.Find("Joystick_background");
     bt_spike = GameObject.Find("Joystick_spikeButton");
     sprite_bt_left = GameObject.Find("leftButton").GetComponent<tk2dSprite>();
     sprite_bt_right = GameObject.Find("rightButton").GetComponent<tk2dSprite>();
     touchEffect = GameObject.Find("TouchMotionEffect").GetComponent<TouchMotionEffect>();
     if(controller != TouchControllerType.BUTTON)
     {
         GameObject.DestroyObject(bt_left as Object);
         GameObject.DestroyObject(bt_right as Object);
     }
     if(controller != TouchControllerType.JOYPAD)
     {
         GameObject.DestroyObject(bt_spike as Object);
         GameObject.DestroyObject(joystick_bg as Object);
         GameObject.DestroyObject(joystick_bar as Object);
     }
     cam = GameObject.Find("VollyBallCamera").GetComponent<tk2dCamera>();
     SetJoyPadPos();
 }
 public void FindPlayer()
 {
     player       = GameObject.FindGameObjectWithTag("Player2");
     playerScript = player.GetComponent <Player2>();
 }
Пример #23
0
        public void NotifyPlayMade()
        {
            if (Player1.CurrentMove != 0 && Player2.CurrentMove != 0)
            {
                switch (Player1.CurrentMove)
                {
                case (Move)1:
                    if (Player2.CurrentMove == (Move)1)
                    {
                    }
                    else if (Player2.CurrentMove == (Move)2)
                    {
                        Player2.Points++;
                    }
                    else if (Player2.CurrentMove == (Move)3)
                    {
                        Player1.Points++;
                    }
                    break;


                case (Move)2:
                    if (Player2.CurrentMove == (Move)1)
                    {
                        Player1.Points++;
                    }
                    else if (Player2.CurrentMove == (Move)2)
                    {
                    }
                    else if (Player2.CurrentMove == (Move)3)
                    {
                        Player2.Points++;
                    }
                    break;


                case (Move)3:
                    if (Player2.CurrentMove == (Move)1)
                    {
                        Player2.Points++;
                    }
                    else if (Player2.CurrentMove == (Move)2)
                    {
                        Player1.Points++;
                    }
                    else if (Player2.CurrentMove == (Move)3)
                    {
                    }
                    break;
                }

                string points1 = "points-" + Player1.Points.ToString() + "+" + Player2.Points.ToString() + "";
                string points2 = "points-" + Player2.Points.ToString() + "+" + Player1.Points.ToString() + "";
                Player1.SendMessageToClient(points1);
                Player2.SendMessageToClient(points2);

                if (Player1.Points > 2)
                {
                    Player1.SendMessageToClient("gamewon");
                    Player2.SendMessageToClient("gamelost");
                    ServerLogic.RemoveMatchFromList(this);
                }

                else if (Player2.Points > 2)
                {
                    Player2.SendMessageToClient("gamewon");
                    Player1.SendMessageToClient("gamelost");
                    ServerLogic.RemoveMatchFromList(this);
                }

                Player1.CurrentMove = 0;
                Player2.CurrentMove = 0;
            }
        }
Пример #24
0
        /// <summary>
        /// Draw a card from each player's pile, determine who wins the round
        /// </summary>
        public void Deal()
        {
            TotalRounds++;

            // each player puts a card onto the table, face up
            Card player1Card = Player1.Deal(true);

            if (player1Card != null) // should only happen when user is out of cards
            {
                GameTable.AddCard(1, player1Card);
            }
            Card player2Card = Player2.Deal(true);

            if (player2Card != null)
            {
                GameTable.AddCard(2, player2Card);
            }

            // which player's card wins?
            switch (Rank(player1Card, player2Card))
            {
            case CardRanking.Equal:

                // if one player has won (i.e. out of cards), end game now, otherwise go to war
                if (!CheckWinner())
                {
                    this._Report(player1Card.ToString() + " and " + player2Card.ToString() + ". THIS MEANS WAR!");
                    TotalWars++;

                    //  If one player only has one card left, don't draw it, save until next round
                    if (Player1.Hand.Count > 1)
                    {
                        player1Card = Player1.Deal(false);     // draw face-down card
                        GameTable.AddCard(1, player1Card);
                    }
                    if (Player2.Hand.Count > 1)
                    {
                        player2Card = Player2.Deal(false);
                        GameTable.AddCard(2, player2Card);
                    }

                    Deal();
                }
                break;

            case CardRanking.More:
                this._Report(player1Card.ToString() + " beats " + player2Card.ToString() + "." + Environment.NewLine + Player1.Name + " wins this round.");
                GameTable.Award(Player1);
                CheckWinner();
                break;

            case CardRanking.Less:
                this._Report(player2Card.ToString() + " beats " + player1Card.ToString() + "." + Environment.NewLine + Player2.Name + " wins this round.");
                GameTable.Award(Player2);
                CheckWinner();
                break;
            }

            // periodically re-shuffle each players' hands so we don't get caught in infinite loops
            _reshuffleCounter++;
            if (_reshuffleCounter >= ReShuffleLimit)
            {
                Player1.Hand      = CardDeck.Shuffle(Player1.Hand);
                Player2.Hand      = CardDeck.Shuffle(Player2.Hand);
                _reshuffleCounter = 0;
            }
        }
Пример #25
0
 private void Awake()
 {
     instance = this;
     gameObject.SetActive(true);
 }
Пример #26
0
    void Update()
    {
        // checks which players turn it is
        if (GameManager.instance.p1Turn)
        {
            playerScript = GameObject.Find("Player1").GetComponent <Player1> ();
        }
        else if (GameManager.instance.p2Turn)
        {
            playerScript2 = GameObject.Find("Player2").GetComponent <Player2> ();
        }

        // adds a click listener for each weapon
        weaponButton.onClick.AddListener(delegate { ChooseWeapon(weaponButton); });
        weaponButton2.onClick.AddListener(delegate { ChooseWeapon(weaponButton2); });
        //weaponButton3.onClick.AddListener (delegate{ChooseWeapon(weaponButton3);});
        //weaponButton4.onClick.AddListener (delegate{ChooseWeapon(weaponButton4);});

        // For Final Presentation
        // This restricts the players touches to only spawn and throw the grenade to the top half
        // of the users screen, so it will persist on any device
        if (Input.mousePosition.y > Screen.height / 2)
        {
            if (Input.GetMouseButtonDown(0) && !isAiming && !isThrown)
            {
                if (objectCount == 1)
                {
                    Destroy(previousWeapon);
                    objectCount = 0;
                }

                if (!isThrown)
                {
                    Spawn();
                    objectCount++;
                }
            }
            else if (Input.GetMouseButtonDown(0) && isAiming)
            {
                launch();
            }
        }

        // if the player is aiming then allow the player to rotate the grenade around them
        if (isAiming)
        {
            weaponScript = GameObject.FindGameObjectWithTag(currentWeapon.tag).GetComponent <WeaponAction>();

            move = 0;
            move = CrossPlatformInputManager.GetAxis("Horizontal");

            if (GameManager.instance.p1Turn)
            {
                if (playerScript.isFacingLeft && move > 0 && !weaponScript.maxRight)
                {
                    previousWeapon.transform.RotateAround(playerTrans.position, Vector3.forward, -rotateSpeed * Time.deltaTime);
                }
                else if (playerScript.isFacingLeft && move < 0 && !weaponScript.maxLeft)
                {
                    previousWeapon.transform.RotateAround(playerTrans.position, Vector3.forward, rotateSpeed * Time.deltaTime);
                }
                else if (!playerScript.isFacingLeft && move > 0 && !weaponScript.maxRight)
                {
                    previousWeapon.transform.RotateAround(playerTrans.position, Vector3.forward, -rotateSpeed * Time.deltaTime);
                }
                else if (!playerScript.isFacingLeft && move < 0 && !weaponScript.maxLeft)
                {
                    previousWeapon.transform.RotateAround(playerTrans.position, Vector3.forward, rotateSpeed * Time.deltaTime);
                }
            }
            else if (GameManager.instance.p2Turn)
            {
                if (playerScript2.isFacingLeft && move > 0 && !weaponScript.maxRight)
                {
                    previousWeapon.transform.RotateAround(playerTrans2.position, Vector3.forward, -rotateSpeed * Time.deltaTime);
                }
                else if (playerScript2.isFacingLeft && move < 0 && !weaponScript.maxLeft)
                {
                    previousWeapon.transform.RotateAround(playerTrans2.position, Vector3.forward, rotateSpeed * Time.deltaTime);
                }
                else if (!playerScript2.isFacingLeft && move > 0 && !weaponScript.maxRight)
                {
                    previousWeapon.transform.RotateAround(playerTrans2.position, Vector3.forward, -rotateSpeed * Time.deltaTime);
                }
                else if (!playerScript2.isFacingLeft && move < 0 && !weaponScript.maxLeft)
                {
                    previousWeapon.transform.RotateAround(playerTrans2.position, Vector3.forward, rotateSpeed * Time.deltaTime);
                }
            }
        }
    }
Пример #27
0
    void Start()
    {
        turn = -1;
        socks = new Sockets();
        takingTurn = false;
        moveCommands = 1;

        pawnObjects = new GameObject[4];
        playerPositions = new int[4];

        gui = GameObject.Find("Gui").GetComponent<Gui>();

        p1 = GameObject.Find("Player1").GetComponent<Player1>();
        p2 = GameObject.Find("Player2").GetComponent<Player2>();
        p3 = GameObject.Find("Player3").GetComponent<Player3>();
        p4 = GameObject.Find("Player4").GetComponent<Player4>();

        winningMove = 0;

        pawnObjects[0] = GameObject.Find("Green1").GetComponent<Green1>().gameObject;
        pawnObjects[1] = GameObject.Find("Red1").GetComponent<Red1>().gameObject;
        pawnObjects[2] = GameObject.Find("Blue1").GetComponent<Blue1>().gameObject;
        pawnObjects[3] = GameObject.Find("Yellow1").GetComponent<Yellow1>().gameObject;
    }
Пример #28
0
    void Start()
    {
        GameObject player2 = GameObject.FindGameObjectWithTag("Player2");

        p2script = player2.GetComponent <Player2>();
    }
Пример #29
0
        public GameViewModel()
        {
            Messenger.Default.Register <GameMessage>(this, message =>
            {
                Game     = message.Game;
                isReplay = message.IsReplay;
                RaisePropertyChanged("IsEnabled");
                InitializeGame();

                if (isReplay)
                {
                    Game.RewindGame();
                    ReplayGame();
                }
            });

            ActionCommand = new RelayCommand <TileViewModel>(tileViewModel =>
            {
                // If it is a selection.
                if (SelectedUnit == null && tileViewModel.HasUnit && Game.GetCurrentPlayer().Units.Contains(tileViewModel.Units[0].Unit))
                {
                    CleanReachablePositions();
                    CleanBestMoves();
                    SelectedUnit = tileViewModel.Units[0];

                    // Sets the new reachable positions.
                    var positions = SelectedUnit.Unit.FindReachablePositions(Game.Map);
                    // Selected unit Position
                    var sP = SelectedUnit.Unit.Position;
                    foreach (var position in positions)
                    {
                        var index      = position.X * Game.Map.Size + position.Y;
                        bool canAttack = sP.IsClose(position);
                        var ennemy     = Game.GetCurrentPlayer() == Game.Players[0] ? Game.Players[1] : Game.Players[0];
                        var ennemyHere = false;
                        foreach (var u in ennemy.Units)
                        {
                            if (!u.IsDead() && u.Position.Equals(position))
                            {
                                ennemyHere = true;
                            }
                        }

                        if ((canAttack && ennemyHere) || !ennemyHere)
                        {
                            Tiles[index].IsReachable = true;
                        }
                        else
                        {
                            Tiles[index].IsReachable = false;
                        }

                        Tiles[index].RaisePropertyChanged("IsReachable");
                    }
                    MoveManager moveManager    = new MoveManager(Game);
                    IList <Position> bestMoves = moveManager.GetBestMove(Game.GetCurrentPlayer(), SelectedUnit.Unit);
                    foreach (var position in bestMoves)
                    {
                        var index = position.X * Game.Map.Size + position.Y;
                        Tiles[index].IsBestMove = true;
                        Tiles[index].RaisePropertyChanged("IsBestMove");
                    }
                }
                // If it is an action.
                else if (SelectedUnit != null && tileViewModel.IsReachable)
                {
                    var index = Tiles.IndexOf(tileViewModel);

                    // Attack action.
                    if (tileViewModel.HasUnit && !Game.GetCurrentPlayer().Units.Contains(tileViewModel.Units[0].Unit))
                    {
                        // Selects the best defender.
                        var defender = tileViewModel.Units[0];
                        for (var i = 1; i < tileViewModel.Units.Count; i++)
                        {
                            if (tileViewModel.Units[i].Unit.GetRealDefensePoints() > defender.Unit.GetRealDefensePoints())
                            {
                                defender = tileViewModel.Units[i];
                            }
                        }
                        var attack = new AttackAction(Game.Map, SelectedUnit.Unit, defender.Unit);
                        Game.DoAction(attack);

                        var loser           = attack.Loser;
                        var winnerViewModel = loser == SelectedUnit.Unit ? defender : SelectedUnit;
                        if (loser.IsDead())
                        {
                            foreach (var t in Tiles)
                            {
                                for (int i = 0; i < t.Units.Count; i++)
                                {
                                    if (t.Units[i].Unit == loser)
                                    {
                                        t.Units.RemoveAt(i);
                                        t.Units.Add(winnerViewModel);
                                    }
                                    else if (t.Units[i].Unit == winnerViewModel.Unit)
                                    {
                                        t.Units.RemoveAt(i);
                                    }
                                }
                                t.RaisePropertyChanged("Units");
                            }
                        }

                        foreach (var unitViewModel in Player1.Units)
                        {
                            unitViewModel.RaisePropertyChanged("");
                        }
                        foreach (var unitViewModel in Player2.Units)
                        {
                            unitViewModel.RaisePropertyChanged("");
                        }
                    }
                    // Move action.
                    else
                    {
                        var mapSize = Game.Map.Size;
                        var posDest = new Position(index / mapSize, index % mapSize);


                        var path = SelectedUnit.Unit.GetWay(Game.Map, posDest);
                        Game.DoAction(new MoveAction(Game.Map, SelectedUnit.Unit, posDest));
                        SelectedUnit.RaisePropertyChanged("Unit");
                        AnimateUnitMove(SelectedUnit, path);
                    }

                    SelectedUnit = null;
                    CleanReachablePositions();
                    CleanBestMoves();
                }
                else
                {
                    CleanReachablePositions();
                    CleanBestMoves();
                    SelectedUnit = null;
                }
            });

            NextTurnCommand = new RelayCommand(async() =>
            {
                if (Game.NextPlayer())
                {
                    RaisePropertyChanged("Game");
                    Player1.RaisePropertyChanged("Player");
                    Player2.RaisePropertyChanged("Player");
                    Messenger.Default.Send(new CurrentPlayerMessage(Game.GetCurrentPlayer()));
                }
                else
                {
                    var dialog         = new Views.Dialogs.WinnerDialog();
                    dialog.DataContext = new Dialogs.WinnerDialogViewModel(Game.GetWinner().Name);

                    var path = (string)await DialogHost.Show(dialog, "RootDialog");
                    if (path != null)
                    {
                        ;
                    }

                    ExitGame();
                }
            });

            SaveGameDialogCommand = new RelayCommand(async() =>
            {
                var dialog = new Views.Dialogs.SaveGameDialog();

                var path = (string)await DialogHost.Show(dialog, "RootDialog");
                if (path != null)
                {
                    var directoryPath = $"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}/Saves";
                    if (!Directory.Exists(directoryPath))
                    {
                        Directory.CreateDirectory(directoryPath);
                    }
                    Game.SaveGame($"{directoryPath}/{path}.o");
                }
            });

            LoadGameDialogCommand = new RelayCommand(async() =>
            {
                var dialog = new Views.Dialogs.LoadGameDialog();

                var path = (string)await DialogHost.Show(dialog, "RootDialog");
                if (path != null)
                {
                    Game = Game.LoadGame(path);
                    InitializeGame();
                }
            });

            ExitGameDialogCommand = new RelayCommand(async() =>
            {
                if (!isReplay)
                {
                    var dialog = new Views.Dialogs.ConfirmDialog();

                    if (await DialogHost.Show(dialog, "RootDialog") != null)
                    {
                        ExitGame();
                    }
                }
                else
                {
                    ExitGame();
                }
            });
        }
Пример #30
0
 // Use this for initialization
 void Start()
 {
     animator = gameObject.GetComponent <Animator>();
     Move     = this.transform.position;
     player   = GameObject.FindGameObjectWithTag("Player").GetComponent <Player2>();
 }
Пример #31
0
        public void Init()
        {
            int i, j, flag = 0;
            int w, h, type;

            isMultiplayer = RoomSetting.Instance.MultiplayerMode;

            if (isMultiplayer)
            {
                player.Load(RoomSetting.Instance.PlayerType, mapGenerator.Map[19, 19].Rect, 19, 19, "PLAYER 1");
                Player2.Load(RoomSetting.Instance.Player2Type, mapGenerator.Map[1, 1].Rect, 1, 1, "PLAYER 2");
            }
            else
            {
                //Đọc dữ liệu từ UserSetting.Instance.NumOfBots để biết số con bot
                if (RoomSetting.Instance.MapName != "random_map")
                {
                    if (MatchStorage.Instance.NeedToLoadDataHere)
                    {
                        var characterData = MatchStorage.Instance.CharacterData;
                        player.LoadData(characterData[0]);
                        for (int index = 1; index < characterData.Length; index++)
                        {
                            var bot = new Character();
                            bot.LoadData(characterData[index]);
                            bots.Add(bot);
                        }
                        MatchStorage.Instance.NeedToLoadDataHere = false;
                    }
                    else
                    {
                        player.Load(RoomSetting.Instance.PlayerType, mapGenerator.Map[1, 1].Rect, 1, 1, "PLAYER");

                        int divide = RoomSetting.Instance.MapSize / RoomSetting.Instance.NumOfBot;
                        for (i = 0; i < RoomSetting.Instance.NumOfBot; i++)
                        {
                            //random position
                            do
                            {
                                w = rand.Next(3, RoomSetting.Instance.MapSize - 3);
                                h = rand.Next(divide * i, divide * i + divide);
                            } while (!mapGenerator.IsValidLocation(h, w));

                            do
                            {
                                type = rand.Next(0, 3);
                            } while (type == RoomSetting.Instance.PlayerType);

                            bots.Add(new Character());
                            bots[i].Load(type, mapGenerator.Map[h, w].Rect, h, w);
                        }
                    }
                }
                else
                {
                    if (MatchStorage.Instance.NeedToLoadDataHere)
                    {
                        var characterData = MatchStorage.Instance.CharacterData;
                        player.LoadData(characterData[0]);
                        for (int index = 1; index < characterData.Length; index++)
                        {
                            var bot = new Character();
                            bot.LoadData(characterData[index]);
                            bots.Add(bot);
                        }
                        MatchStorage.Instance.NeedToLoadDataHere = false;
                    }
                    else
                    {
                        for (i = 0; i < RoomSetting.Instance.MapSize; i++)
                        {
                            for (j = 0; j < RoomSetting.Instance.MapSize; j++)
                            {
                                if (mapGenerator.IsValidLocation(i, j))
                                {
                                    player.Load(RoomSetting.Instance.PlayerType, mapGenerator.Map[i, j].Rect, i, j, "PLAYER");
                                    flag = 1;
                                    break;
                                }
                            }
                            if (flag == 1)
                            {
                                break;
                            }
                        }
                        bots = RoomSetting.Instance.MyBot.Select(bot =>
                        {
                            var newBot = new Character();
                            newBot.Load(bot[2], mapGenerator.Map[bot[0], bot[1]].Rect, bot[0], bot[1]);
                            return(newBot);
                        }).ToList();
                    }
                }

                astar = new Astar(this);
                if (RoomSetting.Instance.MapSize > 21)
                {
                    miniMap.Load(MapGenerator.Instance.LogicMap, RoomSetting.Instance.MapSize);
                }
            }
        }
Пример #32
0
 public static void KillPlayer2(Player2 player)
 {
     Destroy(player.gameObject);
     gm.StartCoroutine(gm.Respawn());
 }
Пример #33
0
        private void tmrGame_Tick(object sender, EventArgs e)
        {
            //detect if ball hits a paddle
            if (picLeftPaddle.Bounds.IntersectsWith(picBall.Bounds) ||
                picRightPaddle.Bounds.IntersectsWith(picBall.Bounds))
            {
                //we have a collision
                //set max speed
                if (Speed < 11)
                {
                    Velocity.X = -1.1f * Velocity.X;
                    Velocity.Y = 1.1f * Velocity.Y;
                    Speed      = (float)Velocity.Length();
                }
                else
                {
                    Velocity.X = -1 * Velocity.X;
                }
            }


            //detect if the ball hits top or bottom wall
            if (picBall.Top <= 0 || picBall.Bottom >= ClientSize.Height)
            {
                Velocity.Y = -1 * Velocity.Y;
            }

            //check if ball scores
            if (picBall.Left <= 0)
            {
                Player2++;
                lblPlayer2.Text = Player2.ToString();
                Reset();
            }
            else if (picBall.Right >= ClientSize.Width)
            {
                Player1++;
                lblPlayer1.Text = Player1.ToString();
                Reset();
            }


            //move the ball
            Position     = Position + Velocity;
            picBall.Left = (int)Position.X;
            picBall.Top  = (int)Position.Y;

            //move the paddles
            if (LeftPaddle == PaddleState.Up)
            {
                picLeftPaddle.Top -= 5;
            }
            if (LeftPaddle == PaddleState.Down)
            {
                picLeftPaddle.Top += 5;
            }
            if (RightPaddle == PaddleState.Up)
            {
                picRightPaddle.Top -= 5;
            }
            if (RightPaddle == PaddleState.Down)
            {
                picRightPaddle.Top += 5;
            }
        }
Пример #34
0
    // Use this for initialization
    void Start()
    {
        sockets = new Sockets();
        client = new Client();
        opPosY = 128;
        ballPosX = 0;
        ballPosY = 0;
        buffer = new byte[6];
        gameStart = false;
        player1Score = 0;
        player2Score = 0;

        gui = GameObject.Find("GUI").GetComponent<GUIScript>();

        p1 = (Player1) GameObject.Find ("Player1").GetComponent ("Player1");
        p2 = (Player2) GameObject.Find ("Player2").GetComponent ("Player2");
        bscript = (BallScript) GameObject.Find ("GameBall").GetComponent("BallScript");
        lPaddle = GameObject.Find ("Goal2");
        bWall = GameObject.Find ("BottomWall");
        paddleRatio = (250.0f / (GameObject.Find("Goal1").transform.position.x - GameObject.Find("Goal2").transform.position.x));
        wallRatio = (250.0f / (GameObject.Find ("TopWall").transform.position.y - bWall.transform.position.y));
    }
Пример #35
0
        /// <summary>Runs a LAN game, here this computer is the client.</summary>
        public override void RunGame()
        {
            string buf = "";

            Console.CursorVisible = true;
            IPAddress hostIP = null;

            do
            {
                Console.Clear();
                Console.Write("Enter the ip of the host:");
                try
                {
                    hostIP = IPAddress.Parse(Console.ReadLine());
                    if (hostIP != null)
                    {
                        break;
                    }
                }
                catch (Exception ex) {
                    continue;
                }
            }while(true);
            Console.CursorVisible = false;

            TcpClient client = new TcpClient(hostIP.ToString(), Program.Port);

            if ((buf = LanHost.GetData(client)).Equals(""))
            {
                return;
            }

            string[] inps = buf.Split(LanHost.FieldDelimiter.ToCharArray());

            bool clientSalvo    = bool.Parse(inps[0]);
            bool clientBonus    = bool.Parse(inps[1]);
            bool clientAdvanced = bool.Parse(inps[2]);

            SetUpMap temp = new SetUpMap(Player2, clientAdvanced);

            if (!LanHost.SendData(temp.ManualSetUp("Client", ShipList, PlaneList), client))
            {
                return;
            }

            Console.Clear();
            Console.WriteLine("Waiting for Host to finish setting up map.");

            if ((buf = LanHost.GetData(client)).Equals(""))
            {
                return;
            }
            temp = new SetUpMap(Player1, clientAdvanced);
            temp.TextSetUp(buf, ShipList, PlaneList);

            Turn t;

            do
            {
                Console.Clear();
                Console.WriteLine("It's time for the host to play, please wait.");
                if ((buf = LanHost.GetData(client)).Equals(""))
                {
                    return;
                }
                if (clientAdvanced)
                {
                    t = new AdvancedTurn(clientBonus, clientSalvo, Player1, Player2);
                }
                else
                {
                    t = new Turn(clientBonus, clientSalvo, Player1, Player2);
                }

                t.DoTextTurnSequence(buf);
                if (Player2.hasLost())
                {
                    PauseGame("The client has lost the game, press ESC to return to main menu.");
                    client.Close();
                    return;
                }

                if (clientAdvanced)
                {
                    t = new AdvancedTurn(clientBonus, clientSalvo, Player2, Player1);
                }
                else
                {
                    t = new Turn(clientBonus, clientSalvo, Player2, Player1);
                }
                PauseGame("It's time for the client to play, press ESC to continue.");
                if (!LanHost.SendData(t.DoManualTurnSequence(), client))
                {
                    return;
                }
                if (Player1.hasLost())
                {
                    PauseGame("The client has won the game, press ESC to return to main menu.");
                    client.Close();
                    return;
                }
            } while (true);
        }
Пример #36
0
 // Use this for initialization
 void Start()
 {
     Move   = this.transform.position;
     player = GameObject.FindGameObjectWithTag("Player").GetComponent <Player2>();
     pausep = GameObject.FindGameObjectWithTag("MainCamera").GetComponentInParent <PauseMenu>();
 }
Пример #37
0
        private void Play()
        {
            Gamelog = new Logger("LOG von Spiel zwischen " + Player1.Username + " und " + Player2.Username);

            for (int i = 0; i < MaxRounds; i++)
            {
                Console.WriteLine("-------------------------------------------------\n");
                Gamelog.AddEntry(String.Format("Spielrunde: {0}", i + 1));
                Console.WriteLine("Spielrunde: {0}", i + 1);
                Console.WriteLine("Anzahl Karten Spieler 1: " + Player1.Deck.Count);
                Console.WriteLine("Anzahl Karten Spieler 2: " + Player2.Deck.Count);
                ICard chosenCardP1 = Player1.PickCardFromDeck();
                ICard chosenCardP2 = Player2.PickCardFromDeck();

                Console.WriteLine("\nGewählte Karten: ");
                Console.WriteLine("Spieler 1: {0}, {1}, {2}", chosenCardP1.Name, chosenCardP1.Damage, chosenCardP1.ElementType);
                Console.WriteLine("Spieler 2: {0}, {1}, {2}", chosenCardP2.Name, chosenCardP2.Damage, chosenCardP2.ElementType);

                Gamelog.AddEntry(String.Format("{0}: {1}, {2}, {3}", Player1.Username, chosenCardP1.Name, chosenCardP1.Damage, chosenCardP1.ElementType));
                Gamelog.AddEntry(String.Format("{0}: {1}, {2}, {3}", Player2.Username, chosenCardP2.Name, chosenCardP2.Damage, chosenCardP2.ElementType));

                //HasPlayer1WonRound?
                // YES: player1 bekommt card p2 von player2! (zu deck von player1 hinzufügen: card p2), (aus deck von player2 entfernen: card p2)
                // NO: player2 bekommt card p1 von player1! (zu deck von player2 hinzufügen: card p1), (aus deck von player1 entfernen: card p1)

                // can return 3 cases: 3 values present that: if 1 returns
                int result = HasPlayer1WonRound(chosenCardP1, chosenCardP2);

                switch (result)
                {
                case 1:
                    Gamelog.AddEntry("" + Player1.Username + " gewinnt.");
                    Console.WriteLine("Spieler 1 gewinnt.");
                    Player1.AddCardToDeck(chosenCardP2);
                    Player2.RemoveCardFromDeck(chosenCardP2);
                    break;

                case 2:
                    Gamelog.AddEntry("" + Player2.Username + " gewinnt.");
                    Console.WriteLine("Spieler 2 gewinnt.");
                    Player2.AddCardToDeck(chosenCardP1);
                    Player1.RemoveCardFromDeck(chosenCardP1);
                    break;

                case 3:
                    Gamelog.AddEntry("Unentschieden.");
                    Console.WriteLine("Unentschieden.");
                    break;
                }


                // Deck is updated

                // Game ends if one user has no cards
                if (Player1.Deck.IsNullOrEmpty() || Player2.Deck.IsNullOrEmpty())
                {
                    if (Player2.Deck.IsNullOrEmpty())
                    {
                        Gamelog.AddEntry("SPIELENDE. " + Player2.Username + " hat keine Karten mehr. " + Player1.Username + " hat das Battle gewonnen.");
                        Gamelog.Winner = Player1.Username;
                        Console.WriteLine("Spieler 1 hat das Spiel gewonnen.");
                        Winner = Player1;
                    }
                    else
                    {
                        Gamelog.AddEntry("SPIELENDE. " + Player1.Username + " hat keine Karten mehr. " + Player2.Username + " hat das Battle gewonnen.");
                        Gamelog.Winner = Player2.Username;
                        Console.WriteLine("SPIELENDE. Spieler 1 hat keine Karten mehr. Spieler 2 hat das Spiel gewonnen.");
                        Winner = Player2;
                    }
                    EndGame();
                    Console.WriteLine("\n-------------------------------------------------\n");
                    return;
                }
                Console.WriteLine("\n-------------------------------------------------\n");
            }

            // if there is no final result after maxRound --> DRAW!

            EndGame();
            // Winner is null --> DRAW
            Gamelog.AddEntry("Das Spiel ist unentschieden ausgegangen!");
        }
Пример #38
0
 // Use this for initialization
 void Start()
 {
     player = GameObject.FindGameObjectWithTag("Player").GetComponent <Player2>();
 }
Пример #39
0
 private void Start()
 {
     inventario.SetBool("desligado", true);
     player02 = GameObject.FindGameObjectWithTag("Player02").GetComponent <Player2>();
 }
Пример #40
0
        private async void MqttConnection_OnContentReceived(object Sender, MqttContent Content)
        {
            try
            {
                BinaryInput Input   = Content.DataInput;
                byte        Command = Input.ReadByte();

                switch (Command)
                {
                case 0:                         // Hello
                    string ApplicationName = Input.ReadString();
                    if (ApplicationName != this.applicationName)
                    {
                        break;
                    }

                    Player Player = this.Deserialize(Input);
                    if (Player is null)
                    {
                        break;
                    }

#if LineListener
                    Console.Out.WriteLine("Rx: HELLO(" + Player.ToString() + ")");
#endif
                    IPEndPoint ExpectedEndpoint = Player.GetExpectedEndpoint(this.p2pNetwork);

                    lock (this.remotePlayersByEndpoint)
                    {
                        this.remotePlayersByEndpoint[ExpectedEndpoint] = Player;
                        this.remotePlayerIPs[ExpectedEndpoint.Address] = true;
                        this.playersById[Player.PlayerId] = Player;

                        this.UpdateRemotePlayersLocked();
                    }

                    MultiPlayerEnvironmentPlayerInformationEventHandler h = this.OnPlayerAvailable;
                    if (h != null)
                    {
                        try
                        {
                            h(this, Player);
                        }
                        catch (Exception ex)
                        {
                            Events.Log.Critical(ex);
                        }
                    }
                    break;

                case 1:                             // Interconnect
                    ApplicationName = Input.ReadString();
                    if (ApplicationName != this.applicationName)
                    {
                        break;
                    }

                    Player = this.Deserialize(Input);
                    if (Player is null)
                    {
                        break;
                    }

#if LineListener
                    Console.Out.Write("Rx: INTERCONNECT(" + Player.ToString());
#endif
                    int Index = 0;
                    int i, c;
                    LinkedList <Player> Players = new LinkedList <Player>();
                    bool LocalPlayerIncluded    = false;

                    Player.Index = Index++;
                    Players.AddLast(Player);

                    c = (int)Input.ReadUInt();
                    for (i = 0; i < c; i++)
                    {
                        Player = this.Deserialize(Input);
                        if (Player is null)
                        {
#if LineListener
                            Console.Out.Write("," + this.localPlayer.ToString());
#endif
                            this.localPlayer.Index = Index++;
                            LocalPlayerIncluded    = true;
                        }
                        else
                        {
#if LineListener
                            Console.Out.Write("," + Player.ToString());
#endif
                            Player.Index = Index++;
                            Players.AddLast(Player);
                        }
                    }

#if LineListener
                    Console.Out.WriteLine(")");
#endif
                    if (!LocalPlayerIncluded)
                    {
                        break;
                    }

                    this.mqttConnection.Dispose();
                    this.mqttConnection = null;

                    lock (this.remotePlayersByEndpoint)
                    {
                        this.remotePlayersByEndpoint.Clear();
                        this.remotePlayerIPs.Clear();
                        this.remotePlayersByIndex.Clear();
                        this.playersById.Clear();

                        this.remotePlayersByIndex[this.localPlayer.Index] = this.localPlayer;
                        this.playersById[this.localPlayer.PlayerId]       = this.localPlayer;

                        foreach (Player Player2 in Players)
                        {
                            ExpectedEndpoint = Player2.GetExpectedEndpoint(this.p2pNetwork);

                            this.remotePlayersByIndex[Player2.Index]       = Player2;
                            this.remotePlayersByEndpoint[ExpectedEndpoint] = Player2;
                            this.remotePlayerIPs[ExpectedEndpoint.Address] = true;
                            this.playersById[Player2.PlayerId]             = Player2;
                        }

                        this.UpdateRemotePlayersLocked();
                    }

                    this.State = MultiPlayerState.ConnectingPlayers;
                    await this.StartConnecting();

                    break;

                case 2:                             // Bye
                    ApplicationName = Input.ReadString();
                    if (ApplicationName != this.applicationName)
                    {
                        break;
                    }

                    Guid PlayerId               = Input.ReadGuid();
                    lock (this.remotePlayersByEndpoint)
                    {
                        if (!this.playersById.TryGetValue(PlayerId, out Player))
                        {
                            break;
                        }

#if LineListener
                        Console.Out.WriteLine("Rx: BYE(" + Player.ToString() + ")");
#endif
                        ExpectedEndpoint = Player.GetExpectedEndpoint(this.p2pNetwork);

                        this.playersById.Remove(PlayerId);
                        this.remotePlayersByEndpoint.Remove(ExpectedEndpoint);
                        this.remotePlayersByIndex.Remove(Player.Index);

                        IPAddress ExpectedAddress = ExpectedEndpoint.Address;
                        bool      AddressFound    = false;

                        foreach (IPEndPoint EP in this.remotePlayersByEndpoint.Keys)
                        {
                            if (IPAddress.Equals(EP.Address, ExpectedAddress))
                            {
                                AddressFound = true;
                                break;
                            }
                        }

                        if (!AddressFound)
                        {
                            this.remotePlayerIPs.Remove(ExpectedAddress);
                        }

                        this.UpdateRemotePlayersLocked();
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                Log.Critical(ex);
            }
        }
Пример #41
0
 void Start()
 {
     player  = FindObjectOfType <Player> ();
     player2 = FindObjectOfType <Player2> ();
 }
Пример #42
0
 public static bool ButtonReleased2Player(Buttons pButton)
 {
     return((Player1.ButtonReleased(pButton) && Player2.ButtonReleased(pButton)) ? true : false);
 }
Пример #43
0
        public PlayControlModel2(DispatcherTimer timer, MPlaylistSettings mplaylistSettings, Player2 player)
        {
            _timer = timer;

            _timer.Tick += Timer_Tick;

            _player = player; // new Player2(mplaylistSettings);
            _player.StatusChanged += Player_StatusChanged;

            _playCommand  = new DelegateCommand(Play, CanPlay);
            _pauseCommand = new DelegateCommand(Pause, CanPause);
            _stopCommand  = new DelegateCommand(Stop, CanStop);

            _setInCommand  = new DelegateCommand(SetIn, CanSetIn);
            _setOutCommand = new DelegateCommand(SetOut, CanSetOut);

            _goInCommand  = new DelegateCommand(GoIn, CanGoIn);
            _goOutCommand = new DelegateCommand(GoOut, CanGoOut);

            _nextFrameCommand     = new DelegateCommand(GoNextFrame, CanGoNextFrame);
            _previousFrameCommand = new DelegateCommand(GoPreviousFrame, CanGoPreviousFrame);
        }
Пример #44
0
	void Start(){
		source = GameObject.FindObjectOfType<Camera2D>().audio;
		source2 = this.audio;
		player = GameObject.FindObjectOfType<Player2>();
	}
Пример #45
0
 private void Awake()
 {
     _player1Script = FindObjectOfType <Player1>();
     _player2Script = FindObjectOfType <Player2>();
 }