Ejemplo n.º 1
0
        private static void MultiplayerMode()
        {
            string[] Settings  = { "Host Game", "Connect to a Hosted Game(Enter IP and Port)", "Connect to a Locally Hosted Game" };
            string   Question  = "Multyplayer Main Menu";
            int      CursorPos = 0;

            while (true)
            {
                switch (Interface.AnswerInterface(Question, Settings, CursorPos))
                {
                case 0:
                    HostGame();
                    break;

                case 1:
                    CursorPos = 1;
                    string[] NetworkData;
                    if (!Interface.GetIPAndPort(Settings, 1, out NetworkData))
                    {
                        break;
                    }
                    ConnectToGame(NetworkData[0], int.Parse(NetworkData[1]));
                    break;

                case 2:
                    ConnectToGame();
                    break;
                }
            }
        }
Ejemplo n.º 2
0
 private void WinningCheck(Player player, AI oldAI)
 {
     if (MaxPts != 0 && (player.Points >= MaxPts || oldAI.Points >= MaxPts))
     {
         Paused    = true;
         ai.Paused = true;
         if (player.Points >= MaxPts)
         {
             string   WinningTextPlayer = "The Player has won the game. Glory to the Sinful One!";
             string[] Options           = { "Get boiled alive by the Satan." };
             if (Interface.AnswerInterface(WinningTextPlayer, Options) == 0)
             {
                 System.Environment.Exit(0);                                                             //Yes, that's brutal!
             }
         }
         else
         {
             string   WinningTextAI = "The AI has won the game. Glory to the Machine!";
             string[] Options       = { "Get sacrificed to the AI." };
             if (Interface.AnswerInterface(WinningTextAI, Options) == 0)
             {
                 System.Environment.Exit(0);                                                         //Yes, even more brutal!
             }
         }
     }
     else
     {
         return;
     }
 }
Ejemplo n.º 3
0
        private static void HostGame()
        {
            Map map = MapFiller();

            string[] Settings = { "Host", "Host Locally(Adress - 127.0.0.1:8005)", "Change Map", "Change the Number of Players" };
            string   Question;
            int      CursorPos    = 0;
            int      NumOfPlayers = 2;

            while (true)
            {
                Question = $"Current map is:{map.Name}||Number of Players:{NumOfPlayers}";
                switch (Interface.AnswerInterface(Question, Settings, CursorPos))
                {
                case 0:
                    string[] NetworkData;
                    if (!Interface.GetIPAndPort(Settings, 0, out NetworkData))
                    {
                        break;
                    }
                    Server server = new Server(NetworkData[0], int.Parse(NetworkData[1]));
                    Console.Clear();
                    server.Start(NumOfPlayers, map);
                    break;

                case 1:
                    Server LocalServer = new Server("127.0.0.1", 8005);
                    Console.Clear();
                    LocalServer.Start(NumOfPlayers, map);
                    break;

                case 2:
                    CursorPos = 2;
                    if (map.Number == 6)
                    {
                        map = MapFiller(1);                      //Yes, you have to manually change number of maps, when ones are added...Sorry, I guess...
                    }
                    else
                    {
                        map = MapFiller(map.Number + 1);
                    }
                    break;

                case 3:
                    CursorPos = 3;
                    if (NumOfPlayers == 5)
                    {
                        NumOfPlayers = 2;
                    }
                    else
                    {
                        NumOfPlayers++;
                    }
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        public void Start(int NumOfPlayers, Program.Map Map)
        {
            IPEndPoint ipPoint      = new IPEndPoint(IPAddress.Parse(HostIP), Port);
            Socket     ListenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            string Title = $"Waiting for Players to connect - {NumOfPlayers - 1 - ConnectedPlayers.Count}";

            string[] NullArray = new string[0];
            Interface.AnswerInterface(Title, NullArray);
            Console.CursorTop += 2;
            int OrigTop = Console.CursorTop;

            ListenSocket.Bind(ipPoint);
            ListenSocket.Listen(NumOfPlayers - 1);
            while (ConnectedPlayers.Count < NumOfPlayers - 1)
            {
                Socket newPlayer = ListenSocket.Accept();
                ConnectedPlayers.Add(newPlayer, ReceiveData(newPlayer) as Player);

                SendLobbyInfo(NumOfPlayers, Map);

                Title = $"Waiting for Players to connect - {NumOfPlayers - 1 - ConnectedPlayers.Count}";
                Interface.AnswerInterfaceTitleChange(Title);

                Console.SetCursorPosition(6, OrigTop + 2 * ConnectedPlayers.Count - 1);
                Console.Write("\x4 {0} - {1} is connected.", (char)ConnectedPlayers.Count, ConnectedPlayers.Last().Key.AddressFamily.ToString());
            }
            Console.Clear();
            PlayerInitializing();

            List <Player> Players = ConnectedPlayers.Values.ToList();

            Players.Add(HostPlayer);

            Game         = new Multiplayer.MultiplayerGame();
            Game.Map     = Map;
            Game.Players = Players;

            Game.StartAsync();
            while (Game.State == false)
            {
            }
            while (true)
            {
                SendGameInfo();
                HostPlayer.MovementAsync(Map);//Host player movement
                for (int i = 0; i < ConnectedPlayers.Count; i++)
                {
                    PlayerMovement(ConnectedPlayers.Keys.ToArray()[i]);
                }
                Players = ConnectedPlayers.Values.ToList();
                Players.Add(HostPlayer);
                Game.Players = Players;
            }
        }
Ejemplo n.º 5
0
        public void Connect()
        {
            IPEndPoint ipPoint = new IPEndPoint(IPAddress.Parse(serverIP), serverPort);

            Socket ClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            ClientPlayer = new Player();

            ClientSocket.Connect(ipPoint);
            SendPlayerPos(ClientSocket);

            Server.LobbyInfo LobbyInfo = ReceiveGameInfo(ClientSocket, false) as Server.LobbyInfo; //Creating Lobby

            string[] NullArray = new string[0];
            string   Title     = $"Waiting for Players to connect - {LobbyInfo.NumberOfPlayers - 1 - LobbyInfo.ConnectedPlayers.Count}";

            Interface.AnswerInterface(Title, NullArray);//Lobby Initialization
            Console.CursorTop += 2;
            int OrigTop = Console.CursorTop;

            for (int i = 0; i < LobbyInfo.ConnectedPlayers.Count; i++)
            {
                Console.SetCursorPosition(6, OrigTop + 2 * i);
                Console.Write("\x4 {0} - is connected.", (char)(i + 1));
            }

            int NumOfPlayersToConnect = LobbyInfo.NumberOfPlayers - 1 - LobbyInfo.ConnectedPlayers.Count;

            for (int i = 0; i < NumOfPlayersToConnect; i++)
            {
                LobbyInfo = ReceiveGameInfo(ClientSocket, false) as Server.LobbyInfo;
                Title     = $"Waiting for Players to connect - {NumOfPlayersToConnect - i}";
                Interface.AnswerInterfaceTitleChange(Title);
                Console.SetCursorPosition(6, OrigTop + 2 * LobbyInfo.ConnectedPlayers.Count - 1);
                Console.Write("\x4 {0} - is connected.", (char)LobbyInfo.ConnectedPlayers.Count);
            }
            Console.Clear();                                                                         //End of Lobby stage

            ClientPlayer = ReceiveGameInfo(ClientSocket, false) as Player;                           //Player registration

            GameInfo = ReceiveGameInfo(ClientSocket, false) as Multiplayer.MultiplayerGame.GameInfo; //Game registration
            while (true)
            {
                GameInfo = ReceiveGameInfo(ClientSocket) as Multiplayer.MultiplayerGame.GameInfo;

                ClientPlayer.MovementAsync(GameInfo.Map);
                SendPlayerPos(ClientSocket);

                Interface.MultiplayerMapDraw(GameInfo.Map, GameInfo.Players, GameInfo.Food);
                Interface.MultiplayerShowPoints(GameInfo.Map, GameInfo.Players);
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            string[] Answers  = { "Single-Player", "Multiplayer", "Exit" };
            string   Question = "Main Menu";

            switch (Interface.AnswerInterface(Question, Answers))
            {
            case 0:
                SinglePlayerMode();
                break;

            case 1:
                MultiplayerMode();
                break;

            case 2:
                break;
            }
        }
Ejemplo n.º 7
0
        private static void SinglePlayerMode()
        {
            Map    map    = MapFiller();
            Player player = new Player();

            string[] Settings = { "Start", "Change Map", "Change AI's Difficulty", "Change Points Goal" };
            string   Question;
            int      CursorPos    = 0;
            int      AIDifficulty = 3;
            int      PointsGoal   = 0;

            while (true)
            {
                Question = $"Current map is:{map.Name}";
                switch (AIDifficulty)
                {
                case 1:
                    Question += "||AI Difficulty - Hard";
                    break;

                case 2:
                    Question += "||AI Difficulty - Medium";
                    break;

                case 3:
                    Question += "||AI Difficulty - Easy";
                    break;
                }
                switch (PointsGoal)
                {
                case 0:
                    Question += "|Pts:Infinite";
                    break;

                default:
                    Question += $"|Pts:{PointsGoal}";
                    break;
                }


                switch (Interface.AnswerInterface(Question, Settings, CursorPos))
                {
                case 0:
                    Game NewGame = new Game(map, player, PointsGoal);
                    NewGame.Start(AIDifficulty);
                    break;

                case 1:
                    CursorPos = 1;
                    if (map.Number == 6)
                    {
                        map = MapFiller(1);                      //Yes, you have to manually change number of maps, when ones are added...Sorry, I guess...
                    }
                    else
                    {
                        map = MapFiller(map.Number + 1);
                    }
                    break;

                case 2:
                    CursorPos = 2;
                    if (AIDifficulty == 1)
                    {
                        AIDifficulty = 3;
                    }
                    else
                    {
                        AIDifficulty--;
                    }
                    break;

                case 3:
                    CursorPos = 3;
                    if (PointsGoal == 1000)
                    {
                        PointsGoal = 0;
                    }
                    else
                    {
                        PointsGoal += 200;
                    }
                    break;
                }
            }
        }