Example #1
0
        public void notifyAllPlayers()
        {
            List <string> clientsUrl = new List <string>();

            for (int i = 0; i < maxPlayersServer; i++)
            {
                clientsUrl.Add(players[i].getUrl());
            }
            for (int i = 0; i < maxPlayersServer; i++)
            {
                try
                {
                    Console.WriteLine(players[i].getUrl());
                    ClientInterface c = (ClientInterface)Activator.GetObject(typeof(ClientInterface), players[i].getUrl());
                    c.notifyGameStart();
                    // c.updatePlayersOnClient(clientsUrl);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    failureDetector.getKnownProcessById(i.ToString()).addFail(new Fail());
                    //make thread to try again with this client
                    players[i].setAlive(false);
                }
            }
            Console.WriteLine("All players notified");
        }
Example #2
0
        public void startGame(List <Player> playerList)
        {
            Console.WriteLine("GAME STARTING");
            gameRunning = true;
            players     = playerList;

            //initiate list of pacmans
            for (int i = 0; i < players.Count; i++)
            {
                pacmans.Add(new List <int> {
                    players[i].getId(), players[i].getLeft(), players[i].getTop(), players[i].getScore()
                });
            }

            //initiate list of walls
            for (int i = 0; i < walls.Count; i++)
            {
                wallsRemote.Add(new List <int> {
                    walls[i].getLeft(), walls[i].getTop(), walls[i].getWidth(), walls[i].getHeight()
                });
            }

            //initiate list of walls
            for (int i = 0; i < coins.Count; i++)
            {
                coinsRemote.Add(new List <int> {
                    coins[i].getLeft(), coins[i].getTop(), coins[i].getWidth(), coins[i].getHeight()
                });
            }

            ghostsRemote.Add(new List <int> {
                redGhost.getLeft(), redGhost.getTop(), redGhost.getWidth(), redGhost.getHeight()
            });
            ghostsRemote.Add(new List <int> {
                yellowGhost.getLeft(), yellowGhost.getTop(), yellowGhost.getWidth(), yellowGhost.getHeight()
            });
            ghostsRemote.Add(new List <int> {
                pinkGhost.getLeft(), pinkGhost.getTop(), pinkGhost.getWidth(), pinkGhost.getHeight()
            });


            for (int i = 0; i < players.Count; i++)
            {
                try
                {
                    ClientInterface c = (ClientInterface)Activator.GetObject(typeof(ClientInterface), players[i].getUrl());
                    c.definePacmans(i, pacmans);
                    c.defineWalls(wallsRemote);
                    c.defineGhosts(ghostsRemote);
                    c.defineCoins(coinsRemote);
                }
                catch (Exception e)
                {
                    Console.WriteLine("ERRO2");
                    failureDetector.getKnownProcessById(i.ToString()).addFail(new Fail());
                    players[i].setAlive(false);
                }
            }

            game();
        }