public static void Init(BattleParams param)
        {
            _init = true;
            _shouldSendActions = false;

            _elapsedSinceLastLogicUpdate = Fix64.Zero;
            _framesPerKeyFrame           = param.framesPerKeyFrame;
            _frameRate    = param.frameRate;
            _nextKeyFrame = _framesPerKeyFrame;

            cBattle = new CBattle(param);
            lBattle = new Battle(param);

            _logicThread = new Thread(LogicWorker);
            _logicThread.IsBackground = true;
            _logicThread.Start();

            if (Env.useNetwork)
            {
                NetModule.instance.AddACMDListener(Module.BATTLE, Command.ACMD_BATTLE_START, HandleBattleStart);
                NetModule.instance.AddACMDListener(Module.BATTLE, Command.ACMD_FRAME, HandleFrame);
                NetModule.instance.AddACMDListener(Module.BATTLE, Command.ACMD_BATTLE_END, HandleBattleEnd);
                NetModule.instance.Send(ProtocolManager.PACKET_BATTLE_QCMD_BATTLE_CREATED());
            }
        }
Beispiel #2
0
        private void SendIsAlive()
        {
            while (this.isReading == true)
            {
                this.Send(ProtocolManager.IsAlive());

                Thread.Sleep(2000);
            }
        }
 public static void SendActions(int frameId)
 {
     NetModule.instance.Send(ProtocolManager.PACKET_BATTLE_QCMD_ACTION(ACTIONS.ToArray(), frameId));
     ACTIONS.Clear();
 }
Beispiel #4
0
        public void CreateGame()
        {
            int amountOfPlayers = 2;

            while (true)
            {
                Menu.DisplayGameHeader();

                Console.WriteLine();

                Console.ForegroundColor = ConsoleColor.White;

                Console.WriteLine("Please set the number of players with the UP ARROW and DOWN ARROW!");
                Console.WriteLine("Press ENTER to confirm and create a new game!");
                Console.WriteLine();
                Console.Write("Players: ");

                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write(amountOfPlayers);

                ConsoleKeyInfo cki = Console.ReadKey(true);

                if (cki.Key == ConsoleKey.UpArrow)
                {
                    if (amountOfPlayers + 1 > 4)
                    {
                        amountOfPlayers = 2;
                    }
                    else
                    {
                        amountOfPlayers++;
                    }
                }
                else if (cki.Key == ConsoleKey.DownArrow)
                {
                    if (amountOfPlayers - 1 < 2)
                    {
                        amountOfPlayers = 4;
                    }
                    else
                    {
                        amountOfPlayers--;
                    }
                }
                else if (cki.Key == ConsoleKey.Enter)
                {
                    Console.Clear();

                    this.networkManager.Start();

                    if (this.networkManager.Connected == true)
                    {
                        this.networkManager.Send(ProtocolManager.CreateGame(amountOfPlayers.ToString()));

                        this.WaitForServerResponse();

                        if (validAction == true)
                        {
                            this.DisplayWaitingScreen();
                            this.Start();
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.WriteLine();
                            Console.WriteLine("The game couldn't be created!");
                            Console.WriteLine("Press any key to return to the main menu...");

                            Console.ReadKey(true);
                        }
                    }

                    break;
                }

                Console.Clear();
            }

            Console.Clear();

            Menu.DisplayMainMenu();
        }
Beispiel #5
0
        private void SetCard()
        {
            int position      = 0;
            int positionStart = 0;
            int positionEnd;
            int unoYesOrNo = 0;

            if (this.Deck.Count > 5)
            {
                positionEnd = 5;
            }
            else
            {
                positionEnd = this.Deck.Count;
            }

            while (this.gameOver == false)
            {
                DisplayCards(positionStart, positionEnd, position);

                if (Console.KeyAvailable == false)
                {
                    continue;
                }

                ConsoleKeyInfo cki = Console.ReadKey(true);

                if (cki.Key == ConsoleKey.RightArrow)
                {
                    if (position + 1 == this.Deck.Count)
                    {
                    }
                    else if (position + 1 > positionEnd - 1)
                    {
                        position++;
                        positionStart++;
                        positionEnd++;
                    }
                    else
                    {
                        position++;
                    }
                }
                else if (cki.Key == ConsoleKey.LeftArrow)
                {
                    if (position - 1 < 0)
                    {
                    }
                    else if (position - 1 < positionStart)
                    {
                        position--;
                        positionStart--;
                        positionEnd--;
                    }
                    else
                    {
                        position--;
                    }
                }
                else if (cki.Key == ConsoleKey.U)
                {
                    unoYesOrNo = 1;
                }
                else if (cki.Key == ConsoleKey.Enter)
                {
                    if ((this.Deck[position].Color == Color.White))
                    {
                        this.Deck[position] = this.ChooseColor(this.Deck[position]);
                    }

                    this.networkManager.Send(ProtocolManager.SetCard(this.lobbyID.ToString(), this.playerID.ToString(), ((char)this.Deck[position].Color).ToString(), ((char)this.Deck[position].Value).ToString(), unoYesOrNo.ToString()));

                    this.WaitForServerResponse();

                    if (this.validAction == true)
                    {
                        break;
                    }
                    else if (this.validAction == false)
                    {
                        // When the client receives invalid from server he's still on turn
                        // Set Card continues
                    }
                }
            }
        }
Beispiel #6
0
        public void JoinGame()
        {
            this.networkManager.Start();

            if (this.networkManager.Connected == true)
            {
                string[] roomArray = null;
                this.networkManager.Send(ProtocolManager.RequestRooms());

                this.WaitForServerResponse();

                int position = 0;

                while (true)
                {
                    Menu.DisplayGameHeader();
                    Console.WriteLine();
                    Console.ForegroundColor = ConsoleColor.White;

                    Console.WriteLine("[UP/DOWN ARROW] Navigate [R] Refresh room list [E] Go back to main menu");
                    Console.WriteLine();

                    if (this.roomList == null || this.roomList == string.Empty)
                    {
                        Console.WriteLine("There aren't any rooms open to join!");
                        Console.WriteLine("Please create a new game...");
                    }
                    else
                    {
                        roomArray = this.roomList.Split('-');

                        for (int i = 0; i < roomArray.Length; i += 3)
                        {
                            if (i == position * 3)
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                            }

                            Console.WriteLine("Room ID: {0}", roomArray[i]);
                            Console.WriteLine("Players: {0}/{1}", roomArray[i + 1], roomArray[i + 2]);
                            Console.WriteLine();

                            Console.ForegroundColor = ConsoleColor.White;
                        }
                    }

                    ConsoleKeyInfo cki = Console.ReadKey(true);

                    if (cki.Key == ConsoleKey.R)
                    {
                        this.networkManager.Send(ProtocolManager.RequestRooms());

                        this.WaitForServerResponse();
                    }
                    else if (cki.Key == ConsoleKey.E)
                    {
                        break;
                    }
                    else if (cki.Key == ConsoleKey.UpArrow)
                    {
                        if (roomArray != null)
                        {
                            if (position - 1 < 0)
                            {
                                position = (roomArray.Length / 3) - 1;
                            }
                            else
                            {
                                position--;
                            }
                        }
                    }
                    else if (cki.Key == ConsoleKey.DownArrow)
                    {
                        if (roomArray != null)
                        {
                            if (position + 1 > (roomArray.Length / 3) - 1)
                            {
                                position = 0;
                            }
                            else
                            {
                                position++;
                            }
                        }
                    }
                    else if (cki.Key == ConsoleKey.Enter)
                    {
                        if (roomArray != null)
                        {
                            this.networkManager.Send(ProtocolManager.JoinGame(roomArray[position * 3]));

                            this.WaitForServerResponse();

                            Console.Clear();

                            if (this.validAction == true)
                            {
                                DisplayWaitingScreen();
                                this.Start();
                            }
                            else if (this.validAction == false)
                            {
                                Menu.DisplayGameHeader();
                                Console.WriteLine();
                                Console.ForegroundColor = ConsoleColor.White;

                                Console.WriteLine("The room you tried to join isn't open or already full!");
                                Console.WriteLine("Press any key to continue!");

                                Console.ReadKey(true);

                                this.networkManager.Send(ProtocolManager.RequestRooms());

                                this.WaitForServerResponse();

                                roomArray = this.roomList.Split('-');
                            }
                        }

                        break;
                    }

                    Console.Clear();
                }

                this.networkManager.Stop();

                Console.Clear();

                Menu.DisplayMainMenu();
            }
        }