Beispiel #1
0
 public MainForm()
 {
     InitializeComponent();
     cm = new ClientManager(this);
     pl = new PlayersList();
     rf = new RegistrationForm(this);
     CheckForIllegalCrossThreadCalls = false;
 }
Beispiel #2
0
 public AskRequest(string player1, string player2, string gameid, NetworkStream stream, PlayersList playerlist)
 {
     InitializeComponent();
     this.player1    = player1;
     this.player2    = player2;
     this.gameid     = gameid;
     this.playerList = playerlist;
     lRequest.Text   = "Player " + player1 + " invites you to play a game! Accept the invitation?";
     this.stream     = stream;
 }
        public void IteratorDemo()
        {
            Form1.commandLogger.logMessage(AbstractLogger.TEST, "\t\nIterator Test:\n\n");
            List <Player> playerstest = new List <Player>();
            Player        pl1         = new Player
            {
                Name  = "Pirmas",
                Score = 0,
                Life  = 100,
                PosX  = rnd.Next(150, 300),
                PosY  = rnd.Next(150, 300)
            };

            Player pl2 = new Player
            {
                Name  = "Antras",
                Score = 0,
                Life  = 100,
                PosX  = rnd.Next(150, 300),
                PosY  = rnd.Next(150, 300)
            };

            Player pl3 = new Player
            {
                Name  = "Trecias",
                Score = 0,
                Life  = 100,
                PosX  = rnd.Next(150, 300),
                PosY  = rnd.Next(150, 300)
            };

            playerstest.Add(pl1);
            playerstest.Add(pl2);
            playerstest.Add(pl3);

            PlayersList playersList = new PlayersList(playerstest.ToList());

            Form1.commandLogger.logMessage(AbstractLogger.TEST, "Iteravimas pirmyn \n");
            foreach (Player p in playersList)
            {
                Form1.commandLogger.logMessage(AbstractLogger.TEST, p.Name + "\n");
            }

            playersList.ReverseDirection();

            Form1.commandLogger.logMessage(AbstractLogger.TEST, "Iteravimas nuo galo \n");
            foreach (Player p in playersList)
            {
                Form1.commandLogger.logMessage(AbstractLogger.TEST, p.Name + "\n");
            }

            Form1.commandLogger.logMessage(AbstractLogger.TEST, "\n");
        }
Beispiel #4
0
        public void Connect(string name, string message, PlayersList pl)
        {
            IPEndPoint ipe = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8888);

            client = new TcpClient();
            client.Connect(ipe);
            netStream = client.GetStream();

            SendLogin(message);

            this.playersList   = pl;
            playersList.name   = name;
            playersList.stream = netStream;
            Thread receiveThread = new Thread(new ThreadStart(ReceiveData));

            receiveThread.Start();
        }
Beispiel #5
0
 public MainForm()
 {
     InitializeComponent();
     cm = new ClientManager();
     pl = new PlayersList();
 }
Beispiel #6
0
        private async void GameTimer_Tick(object sender, EventArgs e)
        {
            //GenerateScore();
            foreach (Monster mon in monsters)
            {
                mon.move();
                label1.Text = players.First().Life.ToString();
                label2.Text = players.Last().Life.ToString();

                label1.Text = mon.PosX.ToString();
                label2.Text = mon.PosY.ToString();

                if (mon.PosX >= 430 && mon.PosY == 30 && mon.owner.Name == "Player-1")
                {
                    mon.PosX = 45;
                    mon.PosY = 450;

                    AttackCommand ataka = new AttackCommand(mon, players.Where(u => u.Name == "Player-2").FirstOrDefault());

                    Player p2 = players.Where(u => u.Name == "Player-2").FirstOrDefault();

                    var updateStatusCode2 = await UpdatePlayerAsync(p2);

                    lastCommand = ataka;

                    if (players != null && currentPlayer != null)
                    {
                        Player p1 = players.Where(u => u.Name == currentPlayer.Name).FirstOrDefault();
                        p1.Score += 10;
                        var updateStatusCode = await UpdatePlayerAsync(p1);
                    }
                }
                if (mon.PosX <= 45 && mon.PosY == 450 && mon.owner.Name == "Player-2")
                {
                    mon.PosX = 430;
                    mon.PosY = 30;

                    AttackCommand ataka = new AttackCommand(mon, players.Where(u => u.Name == "Player-1").FirstOrDefault());

                    Player p1 = players.Where(u => u.Name == "Player-1").FirstOrDefault();

                    var updateStatusCode2 = await UpdatePlayerAsync(p1);

                    lastCommand = ataka;

                    if (players != null && currentPlayer != null)
                    {
                        Player p2 = players.Where(u => u.Name == currentPlayer.Name).FirstOrDefault();
                        p2.Score += 10;
                        var updateStatusCode = await UpdatePlayerAsync(p2);
                    }
                }
            }

            if (UpdateInterval >= 100)                                              //Kas 100 laikmačio tick'ų
            {
                players = await GetAllPlayerAsync(client.BaseAddress.PathAndQuery); //Atnaujinamas žaidėjų sąrašas

                PlayersList playersList = new PlayersList(players.ToList());

                // Naujas metodas su i iterator sablonu
                foreach (Player p in playersList)
                {
                    if (p.getObserverCount() == 0)
                    {
                        p.Attach(ScoreBoard);
                    }
                    p.Notify(players);   //Žaidėjai praneša observeriui (Taškų lentai), kad galimi pasikeitimai, ji irgi atsinaujina
                }

                //    foreach (Player p in players)
                //{
                //    if (p.getObserverCount() == 0)
                //        p.Attach(ScoreBoard);
                //    p.Notify(players);   //Žaidėjai praneša observeriui (Taškų lentai), kad galimi pasikeitimai, ji irgi atsinaujina
                //}

                UpdateInterval = 0;


                string text = ScoreBoard.getStatus();
                if (text != null)
                {
                    label6.Text = text; //Atnaujinamas žaidimo lentos tekstas
                }
                else
                {
                    label6.Text = "error";
                }

                checkWinners();
                label14.Text = gamestate.message;
            }
            else
            {
                UpdateInterval++;
            }

            label13.Text = time.ToString();
            time++;

            if (time <= gamestate.PreGameDuration && gamestate.message != "Game will begin soon")
            {
                gamestate.setState(new PreGameState(gamestate));
            }
            else if (time > gamestate.PreGameDuration && time <= gamestate.GameDuration + gamestate.PreGameDuration && gamestate.message != "Game in progress")
            {
                gamestate.NextState();
            }
            else if (time > gamestate.GameDuration + gamestate.PreGameDuration && time <= gamestate.GameDuration + gamestate.PreGameDuration + gamestate.EndingGameDuration && gamestate.message != "Game is ending soon")
            {
                gamestate.NextState();
            }
            else if (time > gamestate.GameDuration + gamestate.PreGameDuration + gamestate.EndingGameDuration && gamestate.message != "Game over")
            {
                gamestate.NextState();
                gameTimer.Stop();
                Player p1 = players.Where(u => u.Name == "Player-1").FirstOrDefault();
                Player p2 = players.Where(u => u.Name == "Player-2").FirstOrDefault();

                if (p1.Score > p2.Score)
                {
                    label12.Visible = true;
                    label12.Text    = "Žaidimas baigtas\nLaimėtojas: Player-1";
                }
                else
                {
                    label12.Visible = true;
                    label12.Text    = "Žaidimas baigtas\nLaimėtojas: Player-2";
                }
            }
            pictureBox1.Invalidate();
        }