Ejemplo n.º 1
0
        private void DrawWater(IWater water)
        {
            var notHit = ViewSettings.WaterNotHitSymbol;
            var hit    = ViewSettings.HitSymbol;

            foreach (var element in water.Elements)
            {
                var elementPosition = CalculateDrawingPosition(element.Position);

                Console.SetCursorPosition(elementPosition.Col, elementPosition.Row);

                char symbol;

                if (element.IsHit)
                {
                    this.SetConsole(ConsoleSettings.WaterHit);
                    symbol = hit;
                }
                else
                {
                    this.SetConsole(ConsoleSettings.WaterNotHit);
                    symbol = notHit;
                }

                Console.Write(symbol);
            }
        }
Ejemplo n.º 2
0
        public Player(string name, IWater water, IBattlefield battlefield)
        {
            this.Name  = name;
            this.ships = new List <IShip>();
            SetHealth();
            this.IsAlive = true;

            Guard.WhenArgument(water, "Water").IsNull().Throw();
            this.water = water;

            Guard.WhenArgument(battlefield, "Battlefield").IsNull().Throw();
            this.battlefield = battlefield;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Floods pipe with water.
        /// </summary>
        /// <param name="water">Water instance.</param>
        /// <returns>True if flooded successfully, otherwise false.</returns>
        public bool Flood(IWater water)
        {
            /* note on this method:
             * commands to and from ui are always being dispatched asynchronously.
             * game engine has a separate thread and presentation ui has a separate thread as well.
             * to get smooth flooding and also enable both game and ui threads to respond, we need
             * another thread which is responsible of flooding pipes (see waterflow).
             *
             * now that we know that this method is being called from whatever thread, we
             * somehow have to synchronize the asynchronous commands in order to get sequential
             * behaviour for this method.
             *
             * i chose one of the simplest mechanism here. after ui is being signalled to flood,
             * this method loops for a specified (flood duration) amount of time. if, within that time,
             * ui responds that pipe has been flooded, method returns success, otherwise not.
             * */

            bool done = false;

            /* able to flood? */
            if (this.IsFloodable && this.CanWaterFlow(water))
            {
                /* yep, we're flooding now */
                this.isFlooding = true;

                /* signal ui to flood */
                this.ExecuteCommand(PresentationCommands.Pipe.Flood, new PresentPipeFloodParameter(this.Id, this.Type, water.Direction, water.Duration));
                this.LetWaterFlow(water);

                /* millis waited so far for UI to complete */
                int waitingMilliseconds = 0;

                /* millis to wait for UI until we timeout */
                int timeoutMilliseconds = (int)Math.Ceiling(water.Duration.TotalMilliseconds * 2);

                /* wait until presentation has finished flooding */
                while ((waitingMilliseconds < timeoutMilliseconds) && this.isFlooding && (!this.isFloodAborted))
                {
                    /* suspend thread - gives chance for others as well */
                    Thread.Sleep(FLOOD_WAIT_FREQUENCY);
                    waitingMilliseconds += FLOOD_WAIT_FREQUENCY;
                }

                /* if flooded, then done, if aborted than undone. */
                done = !this.isFlooding;

                this.isFlooding = false;
            }

            return done;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks whether water can flow through pipe.
        /// </summary>
        /// <param name="water">Water instance.</param>
        /// <returns>True if water can flow, otherwise false.</returns>
        protected override bool CanWaterFlow(IWater water)
        {
            bool can = false;

            if (this.orientation == StraightPipeOrientation.Horizontal)
            {
                can = water.Direction == Direction.Left || water.Direction == Direction.Right;
            }
            else if (this.orientation == StraightPipeOrientation.Vertical)
            {
                can = water.Direction == Direction.Up || water.Direction == Direction.Down;
            }

            return can;
        }
Ejemplo n.º 5
0
 public string Interact(IWater water)
 {
     return("CocaCola");
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Lets water flow through pipe and changes water flow direction if required.
 /// </summary>
 /// <param name="water">Water instance.</param>
 protected override void LetWaterFlow(IWater water)
 {
     this.IsFloodable = false;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Checks whether water can flow through pipe.
 /// </summary>
 /// <param name="water">Water instance.</param>
 /// <returns>True if water can flow, otherwise false.</returns>
 protected override bool CanWaterFlow(IWater water)
 {
     return this.IsFloodable;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Checks whether water can flow through pipe.
        /// </summary>
        /// <param name="water">Water instance.</param>
        /// <returns>True if water can flow, otherwise false.</returns>
        protected override bool CanWaterFlow(IWater water)
        {
            bool can = false;

            if (this.orientation == EdgePipeOrientation.DownLeft) /* from downside to leftside */
            {
                /* water can flow up to left or right to down */
                can = water.Direction == Direction.Up || water.Direction == Direction.Right;
            }
            else if (this.orientation == EdgePipeOrientation.DownRight) /* from downside to leftside */
            {
                /* water can flow up to right or left to down */
                can = water.Direction == Direction.Up || water.Direction == Direction.Left;
            }
            else if (this.orientation == EdgePipeOrientation.UpLeft) /* from upside to leftside */
            {
                /* water can flow down to left or right to up */
                can = water.Direction == Direction.Down || water.Direction == Direction.Right;
            }
            else if (this.orientation == EdgePipeOrientation.UpRight) /* from upside to rightside */
            {
                /* water can flow down to right or left to up */
                can = water.Direction == Direction.Down || water.Direction == Direction.Left;
            }

            return can;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Lets water flow through pipe and changes water flow direction if required.
        /// </summary>
        /// <param name="water">Water instance.</param>
        protected override void LetWaterFlow(IWater water)
        {
            this.IsFloodable = false;

            if (this.orientation == EdgePipeOrientation.DownLeft) /* from downside to leftside */
            {
                if (water.Direction == Direction.Up) water.Direction = Direction.Left;
                if (water.Direction == Direction.Right) water.Direction = Direction.Down;
            }
            else if (this.orientation == EdgePipeOrientation.DownRight) /* from downside to rightside */
            {
                if (water.Direction == Direction.Up) water.Direction = Direction.Right;
                if (water.Direction == Direction.Left) water.Direction = Direction.Down;
            }
            else if (this.orientation == EdgePipeOrientation.UpLeft) /* from upside to leftside */
            {
                if (water.Direction == Direction.Down) water.Direction = Direction.Left;
                if (water.Direction == Direction.Right) water.Direction = Direction.Up;
            }
            else if (this.orientation == EdgePipeOrientation.UpRight) /* from upside to rightside */
            {
                if (water.Direction == Direction.Down) water.Direction = Direction.Right;
                if (water.Direction == Direction.Left) water.Direction = Direction.Up;
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Lets water flow through pipe and changes water flow direction if required.
 /// </summary>
 /// <param name="water">Water instance.</param>
 protected abstract void LetWaterFlow(IWater water);
Ejemplo n.º 11
0
 /// <summary>
 /// Checks whether water can flow through pipe.
 /// </summary>
 /// <param name="water">Water instance.</param>
 /// <returns>True if water can flow, otherwise false.</returns>
 protected abstract bool CanWaterFlow(IWater water);
Ejemplo n.º 12
0
 public Water(IWater ws)
 {
     State = ws;
 }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            var gameWindow = new GameWindow(WindowWidth, WindowHeight, new GraphicsMode(32, 24, 0, 8), "Ocean sim (Grestner waves) and terrain", GameWindowFlags.Default, DisplayDevice.AvailableDisplays.Last());

            gameWindow.MakeCurrent();
            gameWindow.Context.LoadAll();

            Utils.Utils.GLRenderProperties(WindowWidth, WindowHeight);

            _camera = Factory <Camera.Camera> .Create(_cameraPosition0, LookAt0, new Vector3(0, 1, 0));


            _light = LightFactory.Create(new Vector3(-350.0f, 300.0f, 0.0f), new Color4(255, 255, 255, 1), new Color4(255, 255, 255, 1), new Color4(252, 252, 252, 1), LightName.Light0);
            _light.Load();



            _terrain = Terrainfactory.Create(Utils.Utils.GetImageResource <ITerrain>("Landscape.Terrains.TOPOMAP1.GIF"),
                                             Utils.Utils.GetImageResource <ITerrain>("Landscape.Terrains.Dirt.jpg"),
                                             Utils.Utils.GetImageResource <ITerrain>("Landscape.Terrains.sand.jpg"),
                                             Utils.Utils.GetImageResource <ITerrain>("Landscape.Terrains.Grass.png"),
                                             Utils.Utils.GetImageResource <ITerrain>("Landscape.Terrains.Rock.png"));
            _terrain.Load();


            _cubeMap = CubeMapFactory.Create(2500, false, new Vector3(256, 0, 256),
                                             Utils.Utils.GetImageResource <ICubeMap>("EnvironmentMap.Textures.Desert.Desert_front.jpg"),
                                             Utils.Utils.GetImageResource <ICubeMap>("EnvironmentMap.Textures.Desert.Desert_back.jpg"),
                                             Utils.Utils.GetImageResource <ICubeMap>("EnvironmentMap.Textures.Desert.Desert_front.jpg"),
                                             Utils.Utils.GetImageResource <ICubeMap>("EnvironmentMap.Textures.Desert.Desert_top.jpg"),
                                             Utils.Utils.GetImageResource <ICubeMap>("EnvironmentMap.Textures.Desert.Desert_left.jpg"),
                                             Utils.Utils.GetImageResource <ICubeMap>("EnvironmentMap.Textures.Desert.Desert_right.jpg")
                                             );
            _cubeMap.Load();

            _woodenChest = CubeMapFactory.Create(100, true, new Vector3(256, 150, 256), Utils.Utils.GetImageResource <ICubeMap>("EnvironmentMap.Textures.plank.jpg"));
            _woodenChest.Load();

            _water = new Water(WaterWidth, WaterHeight);
            _water.Load();

            _seaBed = PlaneFactory.Create(true, new Vbo()
            {
                Position = new Vector3(0, -70, 0), Normal = new Vector3(0, 1, 0), TexCoord = new Vector2(0, 0)
            },
                                          new Vbo()
            {
                Position = new Vector3(0, -70, WaterHeight), Normal = new Vector3(0, 1, 0), TexCoord = new Vector2(0, 1)
            },
                                          new Vbo()
            {
                Position = new Vector3(WaterWidth, -70, WaterHeight), Normal = new Vector3(0, 1, 0), TexCoord = new Vector2(1, 1)
            },
                                          new Vbo()
            {
                Position = new Vector3(WaterWidth, -70, 0), Normal = new Vector3(0, 1, 0), TexCoord = new Vector2(1, 0)
            },
                                          Utils.Utils.GetImageResource <ITerrain>("Landscape.Terrains.seabed.jpg"), TextureWrapMode.ClampToEdge);
            _seaBed.Load();

            _birdTexture = FramBufferOBjectFactory.Create(512, 512);
            _birdTexture.Load();

            gameWindow.RenderFrame += gameWindow_RenderFrame;
            gameWindow.UpdateFrame += gameWindow_UpdateFrame;

            gameWindow.Keyboard.KeyDown += Keyboard_KeyDown;
            gameWindow.Run(60.0, 30.0);
        }
Ejemplo n.º 14
0
 public string Interact(IWater water)
 {
     return("Pepsi");
 }
Ejemplo n.º 15
0
 public Client(IFactory factory)
 {
     _water  = factory.CreateWater();
     _bottle = factory.CreateBottle();
 }
 public IPlayer CreatePlayer(string name, IWater water, IBattlefield battlefield)
 {
     return(new Player(name, water, battlefield));
 }
Ejemplo n.º 17
0
 public void WaterVehicle(IWater watervehicle)
 {
     watervehicle.Drive();
 }
Ejemplo n.º 18
0
 private void OnWaterBoiled(IWater water, ICup cup)
 {
     _portaFilter.Push(water);
     _portaFilter.Receive(cup);
 }