Пример #1
0
        private async void timer1_Tick(object sender, EventArgs e)
        {
            P1 = await GameFacade.GetPlayerByID(1);

            P2 = await GameFacade.GetPlayerByID(2);

            bullets = await GameFacade.GetAllBulletsFromDatabase();

            if (P1Connected)
            {
                if (P1.points == 0 || P1.points == 100)
                {
                    //textBox1.AppendText("Player speed " + P1.speed + Environment.NewLine);
                }
                if (P1.points == 300)
                {
                    textBox1.AppendText("Player Ammo " + P1.Weapon._kiekKulkuYra + Environment.NewLine);
                }
                setMemento(CurrentPlayer);
                var Random2 = PlayerMovement(P1);
                await GameFacade.UpdatePlayerToDatabase(Random2);
            }

            if (P2Connected)
            {
                var Random = PlayerMovement(P2);
                await GameFacade.UpdatePlayerToDatabase(Random);

                setMemento(CurrentPlayer);
            }

            if (P1 != null && P2 != null)
            {
                if (P1.health_points <= 0)
                {
                    P1.health_points = 100;
                    P1.PosY          = 50;
                    P1.PosX          = 20;
                    await GameFacade.UpdatePlayerToDatabase(P1);

                    textBox1.AppendText("P2 Killed P1 Player2 Score:" + P2.points.ToString() + Environment.NewLine);
                }
                if (P2.health_points <= 0)
                {
                    P2.health_points = 100;
                    P2.PosX          = 200;
                    P2.PosY          = 200;
                    await GameFacade.UpdatePlayerToDatabase(P2);

                    textBox1.AppendText("P1 Killed P2 P1 Score:" + P1.points.ToString() + Environment.NewLine);;
                }
                if (P2.Score == 4 || P1.Score >= 4)
                {
                    if (P2.Score > P1.Score)
                    {
                        textBox1.AppendText("Player2 Wins the game with " + P2.Score);
                        textBox1.AppendText("Player1 points " + P1.Score);
                        timer1.Enabled = false;
                    }
                    else
                    {
                        textBox1.AppendText("Player1 Wins the game with " + P1.Score);
                        textBox1.AppendText("Player2 points " + P2.Score);
                        timer1.Enabled = false;
                    }
                }
            }
            Invalidate();
            Refresh();
        }