Beispiel #1
0
        public ClientViewer(Render.IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer previousViewer, Gui gui)
            : base(renderView, audioInterface, previousViewer, gui, Type.Client)
        {
            Log.Verbose.Write(ErrorSystemType.Application, "Creating client viewer.");

            client = previousViewer.MainInterface.Client;
            client.Disconnected += Client_Disconnected;
        }
Beispiel #2
0
        internal Game Instantiate(Render.IRenderView renderView, Audio.IAudioInterface audioInterface)
        {
            var game = new Game(renderView, audioInterface);

            if (!game.Init(MapSize, RandomBase))
            {
                return(null);
            }

            uint playerIndex = 0u;

            // Initialize player and build initial castle
            foreach (var playerInfo in players)
            {
                if (playerInfo != null)
                {
                    var player = game.InsertPlayer(playerIndex, playerInfo.Intelligence,
                                                   playerInfo.Supplies, playerInfo.Reproduction);

                    if (!playerInfo.Face.IsHuman()) // not you or your partner
                    {
                        if (intro)
                        {
                            player.AI = new IntroAI(player, playerInfo);
                        }
                        else
                        {
                            player.AI = new AI(player, playerInfo);
                        }
                    }

                    player.InitView(playerInfo.Color, playerInfo.Face);

                    var castlePos = playerInfo.CastlePosition;

                    if (castlePos.Column > -1 && castlePos.Row > -1)
                    {
                        var position = game.Map.Position((MapPos)castlePos.Column, (MapPos)castlePos.Row);

                        game.BuildCastle(position, player);
                    }
                }

                ++playerIndex;

                if (playerIndex == Game.MAX_PLAYER_COUNT)
                {
                    break;
                }
            }

            game.InitKnights();

            return(game);
        }
Beispiel #3
0
        public ServerViewer(Render.IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer previousViewer, Gui gui)
            : base(renderView, previousViewer, gui, Type.Server)
        {
            // Note: It is ok if the only clients are spectators, but running a server without any connected client makes no sense.
            // Note: All clients must be setup at game start. Clients can not join during the game.
            // Note: There may be more than 3 clients because of spectators!
            server = Network.Network.DefaultServerFactory.CreateLocal(previousViewer.MainInterface.ServerGameName, previousViewer.MainInterface.ServerGameInfo);

            Init();
            MainInterface = new ServerInterface(renderView, audioInterface, this, server);
        }
Beispiel #4
0
        public ServerViewer(Render.IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer previousViewer, Gui gui)
            : base(renderView, previousViewer, gui, Type.Server)
        {
            Log.Verbose.Write(ErrorSystemType.Application, "Creating server viewer.");

            // Note: It is ok if the only clients are spectators, but running a server without any connected client makes no sense.
            // Note: All clients must be setup at game start. Clients can not join during the game.
            // Note: There may be more than 3 clients because of spectators!
            server = previousViewer.MainInterface.Server;
            server.NetworkDataReceiver = previousViewer.MainInterface.NetworkDataHandler.NetworkDataReceiver;

            Init();
            MainInterface = new ServerInterface(renderView, audioInterface, this, previousViewer.MainInterface);
        }
Beispiel #5
0
        public bool StartGame(GameInfo gameInfo, Render.IRenderView renderView, Audio.IAudioInterface audioInterface)
        {
            var newGame = gameInfo.Instantiate(renderView, audioInterface);

            if (newGame == null)
            {
                return(false);
            }

            lastSaveTime        = DateTime.MinValue;
            currentGameSaveFile = null;
            SetCurrentGame(newGame);

            return(true);
        }
Beispiel #6
0
        public Interface(IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer viewer)
            : base(renderView, audioInterface)
        {
            RenderView     = renderView;
            AudioInterface = audioInterface;
            Viewer         = viewer;

            TextRenderer = new TextRenderer(renderView);

            displayed = true;
            config    = UserConfig.Game.Options;

            mapCursorSprites[0] = new SpriteLocation {
                Sprite = 31
            };
            mapCursorSprites[1] = new SpriteLocation {
                Sprite = 32
            };
            mapCursorSprites[2] = new SpriteLocation {
                Sprite = 32
            };
            mapCursorSprites[3] = new SpriteLocation {
                Sprite = 32
            };
            mapCursorSprites[4] = new SpriteLocation {
                Sprite = 32
            };
            mapCursorSprites[5] = new SpriteLocation {
                Sprite = 32
            };
            mapCursorSprites[6] = new SpriteLocation {
                Sprite = 32
            };

            cursorSprite         = renderView.SpriteFactory.Create(16, 16, 0, 0, false, false, 255);
            cursorSprite.Layer   = renderView.GetLayer(Freeserf.Layer.Cursor);
            cursorSprite.Visible = true;

            SetSize(640, 480); // original size

            Viewport = null;

            PanelBar = new PanelBar(this);
            AddChild(PanelBar, 0, 0, false);
            Layout();
        }
Beispiel #7
0
        public Game Instantiate(Render.IRenderView renderView, Audio.IAudioInterface audioInterface)
        {
            var game = new Game(renderView, audioInterface);

            if (!game.Init(MapSize, RandomBase))
            {
                return(null);
            }

            // Initialize player and build initial castle
            foreach (var playerInfo in players)
            {
                var index = game.AddPlayer(playerInfo.Intelligence,
                                           playerInfo.Supplies,
                                           playerInfo.Reproduction);
                var player = game.GetPlayer(index);

                if (!playerInfo.Face.IsHuman()) // not you or your partner
                {
                    if (intro)
                    {
                        player.AI = new IntroAI(player, playerInfo);
                    }
                    else
                    {
                        player.AI = new AI(player, playerInfo);
                    }
                }

                player.InitView(playerInfo.Color, playerInfo.Face);

                var castlePos = playerInfo.CastlePosition;

                if (castlePos.Column > -1 && castlePos.Row > -1)
                {
                    var position = game.Map.Position((MapPos)castlePos.Column, (MapPos)castlePos.Row);

                    game.BuildCastle(position, player);
                }
            }

            return(game);
        }
Beispiel #8
0
        public bool LoadGame(string path, Render.IRenderView renderView, Audio.IAudioInterface audioInterface, ref Viewer viewer)
        {
            CloseGame();

            if (!GameStore.Instance.Load(path, () => new Game(renderView, audioInterface), out Game newGame))
            {
                return(false);
            }

            if (newGame.GetPlayer(0).IsAI)
            {
                viewer = viewer.ChangeTo(Viewer.Type.LocalSpectator);
            }

            lastSaveTime        = DateTime.Now;
            currentGameSaveFile = path;
            SetCurrentGame(newGame);
            newGame.TogglePause();

            return(true);
        }
Beispiel #9
0
        public LocalSpectatorViewer(Render.IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer previousViewer, Gui gui)
            : this(renderView, previousViewer, gui, Type.LocalSpectator)
        {
            if (previousViewer == null)
            {
                Init();
                MainInterface = new Interface(renderView, audioInterface, gui, this);
                MainInterface.OpenGameInit();
            }
            else
            {
                if (previousViewer.MainInterface.GetType() != typeof(Interface))
                {
                    MainInterface = new Interface(renderView, audioInterface, gui, this);
                }
                else
                {
                    MainInterface = previousViewer.MainInterface;
                }

                MainInterface.Viewer = this;
            }
        }
Beispiel #10
0
        public static Viewer Create(Type type, Render.IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer previousViewer, Gui gui)
        {
            switch (type)
            {
            default:
            case Type.LocalPlayer:
                return(CreateLocalPlayer(renderView, audioInterface, previousViewer, gui));

            case Type.LocalSpectator:
                return(CreateLocalSpectator(renderView, audioInterface, previousViewer, gui));

            case Type.Server:
                return(CreateServerPlayer(renderView, audioInterface, previousViewer, gui));

            case Type.Client:
                return(CreateClientPlayer(renderView, audioInterface, previousViewer, gui));

            case Type.RemoteSpectator:
                return(CreateRemoteSpectator(renderView, audioInterface, previousViewer, false, gui));

            case Type.RestrictedRemoteSpectator:
                return(CreateRemoteSpectator(renderView, audioInterface, previousViewer, true, gui));
            }
        }
Beispiel #11
0
 public RemoteInterface(IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer viewer)
     : base(renderView, audioInterface, viewer)
 {
 }
Beispiel #12
0
 public ClientViewer(Render.IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer previousViewer, Gui gui)
     : base(renderView, audioInterface, previousViewer, gui, Type.Client)
 {
 }
Beispiel #13
0
 public ServerInterface(IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer viewer, Network.ILocalServer server)
     : base(renderView, audioInterface, viewer)
 {
     this.server = server;
 }
Beispiel #14
0
        public Game PrepareMultiplayerGame(GameInfo gameInfo, Render.IRenderView renderView, Audio.IAudioInterface audioInterface)
        {
            var newGame = gameInfo.Instantiate(renderView, audioInterface);

            if (newGame == null)
            {
                return(null);
            }

            // Multiplayer games start paused.
            newGame.TogglePause();

            return(newGame);
        }
Beispiel #15
0
 // Client must also receive events from server (with the other clients player index)
 public static Viewer CreateClientPlayer(Render.IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer previousViewer, Gui gui)
 {
     throw new NotSupportedException("Not supported yet.");
 }
Beispiel #16
0
 public bool StartRandomGame(Render.IRenderView renderView, Audio.IAudioInterface audioInterface, bool aiPlayersOnly)
 {
     return(StartGame(new GameInfo(new Random(), aiPlayersOnly), renderView, audioInterface));
 }
 protected RemoteSpectatorViewer(Render.IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer previousViewer, Gui gui, Type type)
     : base(renderView, gui, type)
 {
     Init();
     MainInterface = new RemoteInterface(renderView, audioInterface, this, previousViewer.MainInterface);
 }
 public RemoteSpectatorViewer(Render.IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer previousViewer, Gui gui, bool restricted)
     : this(renderView, audioInterface, previousViewer, gui, restricted ? Type.RestrictedRemoteSpectator : Type.RemoteSpectator)
 {
 }
Beispiel #19
0
 // Client must also receive events from server (with the other clients player index)
 public static Viewer CreateClientPlayer(Render.IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer previousViewer, Gui gui)
 {
     return(new ClientViewer(renderView, audioInterface, previousViewer, gui));
 }
Beispiel #20
0
        public Game PrepareMultiplayerGame(GameInfo gameInfo, Render.IRenderView renderView, Audio.IAudioInterface audioInterface)
        {
            var newGame = gameInfo.Instantiate(renderView, audioInterface);

            if (newGame == null)
            {
                return(null);
            }

            return(newGame);
        }
Beispiel #21
0
 public static Viewer CreateRemoteSpectator(Render.IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer previousViewer, bool resticted, Gui gui)
 {
     throw new NotSupportedException("Not supported yet.");
 }
Beispiel #22
0
 public static Viewer CreateLocalSpectator(Render.IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer previousViewer, Gui gui)
 {
     return(new LocalSpectatorViewer(renderView, audioInterface, previousViewer, gui));
 }