Пример #1
0
        private static Ship GetPlayerShip(Player player, IPlayerInterface playerInterface)
        {
            Ship ship      = null;
            bool shipValid = false;
            int  tries     = 0;

            while (!shipValid)
            {
                if (tries++ > ConfigVariables.MaxInputAttempts)
                {
                    throw new Exception("GetPlayerShip Exceeded max attempts.");
                }

                ship = playerInterface.GetPlayerShip(player);

                if (!ship.Points.All(p => GameBoard.EnclosingRectangle.Contains(p)))
                {
                    playerInterface.DisplayError("Ship location out of bounds.  Try again.");
                    continue;
                }

                shipValid = true;
            }

            return(ship);
        }
Пример #2
0
        private static Point GetShotCoordinates(Player player, IPlayerInterface playerInterface)
        {
            bool  fireComplete = false;
            Point point        = new Point();
            int   tries        = 0;

            while (!fireComplete)
            {
                if (tries++ > ConfigVariables.MaxInputAttempts)
                {
                    throw new Exception("GetShotCoordinates Exceeded max attempts.");
                }

                // Get coord
                point = playerInterface.GetFiringCoordinate(player);

                // Check if coord legal on target (in rectangle)
                if (!GameBoard.EnclosingRectangle.Contains(point))
                {
                    playerInterface.DisplayError("Firing coordinate out of bounds.  Try again.");
                    continue;
                }

                if (player.CoordinateAlreadyTried(point))
                {
                    playerInterface.DisplayError("Cell has already been fired upon.  Try again.");
                    continue;
                }

                fireComplete = true;
            }

            return(point);
        }
Пример #3
0
 /// <summary>
 /// Create menu.
 /// </summary>
 /// <param name="rules">'Game of life' rules implementation</param>
 public Menu(IRules rules, IPlayerInterface playerInterface, ISaveManager saveManager)
 {
     _playerInterface = playerInterface;
     _saveManager     = saveManager;
     _gameRepo        = new GameRepository();
     _gameManager     = new (playerInterface, _gameRepo, rules);
 }
Пример #4
0
        private static void FireShot(Player shooter, Player target, IPlayerInterface playerInterface, IGameView view)
        {
            var coord = GetShotCoordinates(shooter, playerInterface);

            shooter.FireShot(coord);
            var shotResult = target.IncomingShot(coord);

            view.SetFireResult(target, coord, shotResult);
        }
Пример #5
0
 public ChannelState(IPlayerInterface play, int apu, int type, bool pal, int numN163Channels = 1)
 {
     player         = play;
     apuIdx         = apu;
     channelType    = type;
     palPlayback    = pal;
     maximumPeriod  = NesApu.GetPitchLimitForChannelType(channelType);
     noteTable      = NesApu.GetNoteTableForChannelType(channelType, pal, numN163Channels);
     note.Value     = Note.NoteStop;
     note.FinePitch = 0;
     Channel.GetShiftsForType(type, numN163Channels, out pitchShift, out slideShift);
 }
Пример #6
0
        protected ChannelState[] CreateChannelStates(IPlayerInterface player, Project project, int apuIdx, int expNumChannels, bool pal)
        {
            var channelCount = project.GetActiveChannelCount();
            var states       = new ChannelState[channelCount];

            int idx = 0;

            for (int i = 0; i < ChannelType.Count; i++)
            {
                if (project.IsChannelActive(i))
                {
                    var state = CreateChannelState(apuIdx, i, expNumChannels, pal);
                    states[idx++] = state;
                }
            }

            return(states);
        }
Пример #7
0
 public void setPlayerInterface(IPlayerInterface player, bool localPlayer)
 {
     this.player      = player;
     this.localPlayer = localPlayer;
 }
Пример #8
0
 public ChannelStateVrc6Saw(IPlayerInterface player, int apuIdx, int channelType) : base(player, apuIdx, channelType, false)
 {
 }
Пример #9
0
 public ChannelStateVrc6Square(IPlayerInterface player, int apuIdx, int channelType) : base(player, apuIdx, channelType, false)
 {
     regOffset = (channelType - ChannelType.Vrc6Square1) * 0x1000;
 }
Пример #10
0
 public ChannelStateFds(IPlayerInterface player, int apuIdx, int channelIdx) : base(player, apuIdx, channelIdx, false)
 {
 }
Пример #11
0
 public ChannelStateTriangle(IPlayerInterface player, int apuIdx, int channelType, bool pal) : base(player, apuIdx, channelType, pal)
 {
 }
Пример #12
0
 public ChannelStateSquare(IPlayerInterface player, int apuIdx, int channelType, bool pal) : base(player, apuIdx, channelType, pal)
 {
     regOffset = channelType * 4;
 }
Пример #13
0
 public ChannelStateN163(IPlayerInterface player, int apuIdx, int channelType, int numChannels, bool pal) : base(player, apuIdx, channelType, pal, numChannels)
 {
     regOffset   = 8 * -(channelType - ChannelType.N163Wave1);
     channelMask = (numChannels - 1) << 4;
 }
Пример #14
0
 public ChannelStateS5B(IPlayerInterface player, int apuIdx, int channelType, bool pal) : base(player, apuIdx, channelType, pal)
 {
     channelIdx = channelType - ChannelType.S5BSquare1;
 }
Пример #15
0
 public Core(IPlayerInterface Interface)
 {
     instance       = this;
     this.Interface = Interface;
     Members        = new List <Member>();
 }
Пример #16
0
 public ChannelStateMmc5Square(IPlayerInterface player, int apuIdx, int channelType) : base(player, apuIdx, channelType, false)
 {
     regOffset = (channelType - ChannelType.Mmc5Square1) * 4;
 }
Пример #17
0
 public Setup(IPlayerInterface playerInterface)
 {
     _playerInterface = playerInterface;
 }
Пример #18
0
 public Player(string name, IPlayerInterface commandProvider)
 {
     Name             = name;
     _playerInterface = commandProvider;
 }
Пример #19
0
        static void Main(string[] args)
        {
            var logger = Resolver.Resolve <ILogger>();

            logger.Info("Application Starting");

            try {
                // Resolve dependencies
                var              config          = Resolver.Resolve <IConfigurationProvider>().GetConfiguration();
                IGameView        view            = Resolver.Resolve <IGameView>();
                IPlayerInterface playerInterface = Resolver.Resolve <IPlayerInterface>();

                var player1 = new Player(config.Player1Name);
                var player2 = new Player(config.Player2Name);

                view.Initialize(player1, player2);
                view.Show();

                logger.Info(string.Format("Starting match between {0} and {1}", player1.Name, player2.Name));

                var ship1 = GetPlayerShip(player1, playerInterface);
                player1.SetShip(ship1);
                var ship2 = GetPlayerShip(player2, playerInterface);
                player2.SetShip(ship2);

                view.SetShip(player1, ship1.Points);
                view.SetShip(player2, ship2.Points);

                while (!player1.ShipSunk && !player2.ShipSunk)
                {
                    FireShot(player1, player2, playerInterface, view);
                    if (player2.ShipSunk)
                    {
                        break;
                    }

                    FireShot(player2, player1, playerInterface, view);
                    if (player1.ShipSunk)
                    {
                        break;
                    }
                }

                if (player1.ShipSunk)
                {
                    logger.Info(string.Format("{0} ship sunk", player1.Name));
                    view.SetSunk(player1);
                }
                else
                {
                    logger.Info(string.Format("{0} ship sunk", player2.Name));
                    view.SetSunk(player2);
                }
            }
            catch (Exception ex)
            {
                // Have a regular exception.
                logger.Error("Exception ocurred in Main :: ", ex);
            }
            Console.ReadLine();

            logger.Info("Application Exiting");
        }
Пример #20
0
 public ChannelStateNoise(IPlayerInterface player, int apuIdx, int channelIdx, bool pal) : base(player, apuIdx, channelIdx, pal)
 {
 }
Пример #21
0
 public ChannelStateVrc7(IPlayerInterface player, int apuIdx, int channelType) : base(player, apuIdx, channelType, false)
 {
     channelIdx    = channelType - ChannelType.Vrc7Fm1;
     customRelease = true;
 }