Exemple #1
0
        public void StartGame()
        {
            int width  = 20;
            int height = 20;
            // init game
            GameScreen myGame = new GameScreen(width, height);

            // fill game with game data.
            myGame.SetHero(new Hero(width / 2, height - 2, "HERO", width));

            Random rnd = new Random();


            // render loop
            bool needToRender = true;

            Console.CursorVisible = false;

            int frameCount = 0;

            do
            {
                // isvalom ekrana
                Console.Clear();
                frameCount++;

                while (Console.KeyAvailable)
                {
                    ConsoleKeyInfo pressedChar = Console.ReadKey(true);

                    switch (pressedChar.Key)
                    {
                    case ConsoleKey.Escape:
                        needToRender = false;
                        break;

                    case ConsoleKey.RightArrow:
                        myGame.GetHero().MoveRight();
                        break;

                    case ConsoleKey.LeftArrow:
                        myGame.GetHero().MoveLeft();
                        break;
                    }
                }

                if (frameCount % 7 == 0)
                {
                    myGame.MoveAllEnemiesDown();
                }
                if (frameCount % 15 == 0)
                {
                    myGame.AddEnemy();
                }
                myGame.Render();


                System.Threading.Thread.Sleep(100);
            } while (needToRender);
        }
Exemple #2
0
        public void StartGame(GuiController guiController)
        {
            // init game
            GameScreen myGame = new GameScreen(30, 20);

            // fill game with game data.
            myGame.SetHero(new Hero(5, 5, "HERO"));

            Random rnd        = new Random();
            int    enemyCount = 0;

            for (int i = 0; i < 10; i++)
            {
                myGame.AddEnemy(new Enemy(enemyCount, rnd.Next(0, 10), rnd.Next(0, 10), "enemy" + enemyCount));
                enemyCount++;
            }

            // render loop
            bool needToRender = true;

            do
            {
                // isvalom ekrana
                Console.Clear();
                myGame.Render();

                while (Console.KeyAvailable)
                {
                    ConsoleKeyInfo pressedChar = Console.ReadKey(true);
                    int            hashCode    = pressedChar.Key.GetHashCode();

                    switch (hashCode)
                    {
                    case 27:     //ConsoleKey.Escape:
                        needToRender = false;
                        Console.Clear();
                        guiController.ShowMenu();
                        break;

                    case 39:     // ConsoleKey.RightArrow:
                        myGame.GetHero().MoveRight();
                        Console.Clear();
                        myGame.Render();
                        break;

                    case 37:     // ConsoleKey.LeftArrow:
                        myGame.GetHero().MoveLeft();
                        Console.Clear();
                        myGame.Render();
                        break;
                    }
                }


                System.Threading.Thread.Sleep(250);
            } while (needToRender);
        }
        public void InitGame()
        {
            myGame.SetHero(new Hero(5, 9, "BatMan"));
            Random rnd     = new Random();
            int    enemyNr = 0;

            for (int i = 0; i < 10; i++)
            {
                myGame.AddEnemy(new Enemy(enemyNr, rnd.Next(0, 10), rnd.Next(0, 10), "enemy" + enemyNr));
                enemyNr++;
            }
        }
Exemple #4
0
        void StartGame()
        {
            bool       needToRender = true;
            GameScreen myGame       = new GameScreen(30, 20);

            myGame.SetHero(new Hero("HERO", 5, 5));

            Random rnd        = new Random();
            int    enemyCount = 0;

            for (int i = 0; i < 10; i++)
            {
                myGame.AddEnemy(new Enemy("enemy" + enemyCount, rnd.Next(0, 10), rnd.Next(0, 10), enemyCount));
                enemyCount++;
            }

            myGame.Render();

            myGame.GetHero().MoveLeft();
            myGame.MoveAllEnemiesDown();
            Enemy secondEnemy = myGame.getEnemyById(1);

            if (secondEnemy != null)
            {
                secondEnemy.MoveDown();
            }
            do
            {
                Console.Clear();

                while (Console.KeyAvailable)
                {
                    ConsoleKeyInfo pressedChar = Console.ReadKey(true);
                    switch (pressedChar.Key)
                    {
                    case ConsoleKey.Escape:
                        break;

                    case ConsoleKey.RightArrow:
                        myGame.GetHero().MoveRight();
                        break;

                    case ConsoleKey.LeftArrow:
                        myGame.GetHero().MoveLeft();
                        break;
                    }
                }

                myGame.Render();

                System.Threading.Thread.Sleep(250);
            } while (needToRender);
        }
        public void InitGame()
        {
            myGame = new GameScreen(30, 20);
            myGame.SetHero(new Hero(5, 5, "Mantas"));

            Random rnd = new Random();

            for (int i = 0; i < 10; i++)
            {
                myGame.AddEnemy(new Enemy(rnd.Next(0, 10), rnd.Next(0, 10), "Enemy" + i, i));
            }
        }
Exemple #6
0
        public void InitGame()
        {
            int gameWidth  = 120;
            int gameHeight = 30;

            myGame = new GameScreen(gameWidth, gameHeight);

            myGame.SetHero(new Hero(gameWidth / 2, gameHeight - 5, "Herojus"));

            Random rnd        = new Random();
            int    enemyCount = 0;

            for (int i = 0; i < 10; i++)
            {
                myGame.AddEnemy(new Enemy(enemyCount, rnd.Next(0, gameWidth), rnd.Next(0, 5), "enemy" + enemyCount));
                enemyCount++;
            }
        }
Exemple #7
0
        static void Main()
        {
            GameScreen myGame = new GameScreen(30, 20);

            myGame.SetHero(new Hero(5, 5, "HERO"));

            // create

            Random rnd        = new Random();
            int    enemyCount = 0;

            for (int i = 0; i < 10; i++)
            {
                myGame.AddEnemy(new Enemy(enemyCount, rnd.Next(0, 10), rnd.Next(0, 10), "enemy" + enemyCount));
                enemyCount++;
            }

            // print

            myGame.Render();

            // move

            myGame.MoveHeroLeft();
            myGame.MoveAllEnemiesDown();

            // print

            Enemy secondEnemy = myGame.GetEnemyById(1);

            if (secondEnemy != null)
            {
                secondEnemy.MoveDown();
            }

            myGame.Render();

            Console.ReadKey();
        }
Exemple #8
0
        public int Check()
        {
            NetIncomingMessage message;
            OpenedPacket       packet = new OpenedPacket();

            if (client.ConnectionStatus == NetConnectionStatus.Connected && connecting == true)
            {
                connecting = false;
            }
            if (connecting == false)
            {
                if (client.ConnectionStatus == NetConnectionStatus.Disconnected)
                {
                    game.SetScreen(new MenuScreen(game));
                }
            }
            while ((message = client.ReadMessage()) != null)
            {
                switch (message.MessageType)
                {
                case NetIncomingMessageType.Data:
                    int type = message.ReadByte();
                    if (type == ServerPackets.PLAYERINFORMATION)
                    {
                        bool   mine        = false;
                        string name        = message.ReadString();
                        int    x           = message.ReadInt32();
                        int    y           = message.ReadInt32();
                        int    id          = message.ReadInt32();
                        string playerClass = message.ReadString();
                        int    playerRole  = message.ReadInt32();

                        PlayerPacket pPacket = new PlayerPacket(ServerPackets.PLAYERINFORMATION, x, y, name, id, playerClass, playerRole);
                        if (pPacket.name == userName)
                        {
                            mine = true;
                        }
                        else
                        {
                            Console.WriteLine(String.Format("{0} joined the world!", name));
                        }

                        if (playerClass == CharacterSelections.NONE)
                        {
                            if (mine)
                            {
                                return(CheckConstants.CHARACTERSELECT);
                            }
                        }
                        else
                        {
                            gameScreen.AddPlayer(new Player(pPacket.id, pPacket.name, pPacket.x, pPacket.y, mine, this, pPacket.playerClass, pPacket.playerRole, gameScreen));
                        }
                    }
                    else if (type == ServerPackets.POSITION)
                    {
                        int            id      = message.ReadInt32();
                        int            x       = message.ReadInt32();
                        int            y       = message.ReadInt32();
                        PositionPacket pPacket = new PositionPacket(ServerPackets.POSITION, id, x, y);

                        Player posPlayer = gameScreen.GetPlayerByID(pPacket.playerID);
                        if (posPlayer != null)
                        {
                            posPlayer.SetPosition(new Vector2(pPacket.x, pPacket.y));
                        }
                    }
                    else if (type == ServerPackets.LEAVINGPLAYER)
                    {
                        int id = message.ReadInt32();
                        gameScreen.RemovePlayerByID(id);
                    }
                    else if (type == ServerPackets.CHATPACKET)
                    {
                        int    id     = message.ReadInt32();
                        string text   = message.ReadString();
                        Player player = gameScreen.GetPlayerByID(id);
                        gameScreen.AddChat(new ChatHolder(player, text));
                    }
                    else if (type == ServerPackets.ENEMYSPAWN)
                    {
                        int   enemyType       = message.ReadInt32();
                        int   enemyX          = message.ReadInt32();
                        int   enemyY          = message.ReadInt32();
                        bool  enemyAggressive = message.ReadBoolean();
                        int   netID           = message.ReadInt32();
                        Enemy enemy           = new Enemy(new Vector2(enemyX, enemyY), enemyType, enemyAggressive, netID, gameScreen);
                        gameScreen.AddEntity(enemy);
                        gameScreen.AddEnemy(enemy);
                    }
                    else if (type == ServerPackets.ENEMYMOVE)
                    {
                        int   x  = message.ReadInt32();
                        int   y  = message.ReadInt32();
                        int   id = message.ReadInt32();
                        Enemy e  = gameScreen.GetEnemyByID(id);
                        if (e != null)
                        {
                            e.Move(x, y);
                        }
                    }
                    else if (type == ServerPackets.ENEMYDESTINATION)
                    {
                        int   destX = message.ReadInt32();
                        int   destY = message.ReadInt32();
                        int   id    = message.ReadInt32();
                        Enemy e     = gameScreen.GetEnemyByID(id);
                        if (e != null)
                        {
                            e.SetDestination(destX, destY);
                        }
                    }
                    else if (type == ServerPackets.ENEMYSTOP)
                    {
                        int   id = message.ReadInt32();
                        Enemy e  = gameScreen.GetEnemyByID(id);
                        if (e != null)
                        {
                            e.ClearDestination();
                        }
                    }

                    break;

                case NetIncomingMessageType.StatusChanged:
                    //SortConnections(message);
                    break;

                case NetIncomingMessageType.DebugMessage:
                    try
                    {
                        if (ServerInfo.DEBUG)
                        {
                            Console.WriteLine(message.ReadString());
                        }
                    } catch (Exception e) { Console.Write(e); }
                    break;

                case NetIncomingMessageType.ErrorMessage:
                    try
                    {
                        if (ServerInfo.DEBUG)
                        {
                            Console.WriteLine(message.ReadString());
                        }
                    } catch (Exception e) { Console.Write(e); }
                    break;

                default:
                    break;
                }
            }
            if (packet.PacketType >= 0)
            {
                Use(packet);
            }
            return(CheckConstants.FULFILLED);
        }