예제 #1
0
        static void Main(string[] args)
        {
            /*
             * This implementation of chain of responsibility demonstrates the
             * method chaining approach. This approach is the most basic form in which
             * you apply various modifiers and responsibilities to the original object's
             * operations.
             */
            var ba = new BankAccount("John Doe", 1000M);
            var t  = new Transaction(ba);

            t.AddTransaction(new SafeWithdrawTransaction(ba, 750));
            t.AddTransaction(new SafeWithdrawTransaction(ba, 500));
            t.AddTransaction(new SafeDepositTransaction(ba, 300));
            t.AddTransaction(new SafeWithdrawTransaction(ba, 250));
            t.Handle();

            /*
             * Below exercise demonstrates the chain of responsibility pattern
             * with a Mediator pattern approach. This can be called broker chain
             * instead of method chain since there is a broker in between the calls
             * and we avoid mutating the original object's properties.
             */

            var carGame = new CarGame();
            var car     = new Car(carGame);

            WriteLine(car);
            using (new DoubleSpeedModifier(carGame, car))
            {
                WriteLine(car);
            }
            WriteLine(car);

            /*
             * Below is the course exercise in which we simulate a card game.
             * Goblins have default A/D points 1/1 and GoblinKing has 3/3.
             * A Goblin gets +1 defense point for every other Goblin on the board (king is a goblin)
             * All Goblins get +1 attack point when a GoblinKing is on the board.
             */

            var game = new Game();
            var c1   = new Goblin(game);
            var c2   = new Goblin(game);
            var c3   = new Goblin(game);
            var king = new GoblinKing(game);

            game.Creatures.Add(c1);
            game.Creatures.Add(c2);
            game.Creatures.Add(c3);
            game.Creatures.Add(king);

            WriteLine(c1);
            WriteLine(c2);
            WriteLine(c3);
            WriteLine(king);
        }
예제 #2
0
파일: Program.cs 프로젝트: Calyd/autonomous
        private static void RunGui(GameOptions options)
        {
            Random r       = new Random();
            var    length  = (float)r.NextDouble() * (options.MaxLength - options.MinLength) + options.MinLength;
            var    traffic = (float)r.NextDouble() * (options.MaxTraffic - options.MinTraffic) + options.MinTraffic;

            using (var game = new CarGame(length, traffic, options.PlayerCollision, options.PlaySounds))
            {
                game.Run();
            }
        }
예제 #3
0
        private static void RunTournament(GameOptions options)
        {
            Random r = new Random();

            for (int i = 0; i < options.Rounds; i++)
            {
                var length  = (float)r.NextDouble() * (options.MaxLength - options.MinLength) + options.MinLength;
                var traffic = (float)r.NextDouble() * (options.MaxTraffic - options.MinTraffic) + options.MinTraffic;
                using (var game = new CarGame(length, traffic, options.PlayerCollision, options.PlaySounds, options.TimeAcceleration))
                {
                    game.Run();
                }
            }
        }
        public void DeleteUser()
        {
            // not working with these two
            //ApplicationUser LoggedUser2 = User.GetLoggedInUserInDB();
            //var id = LoggedUser2.Id;

            string          userId     = User.Identity.GetUserId();
            ApplicationUser LoggedUser = db.Users.Find(userId);

            db.Users.Remove(LoggedUser);

            CarGame     carGame     = db.CarGame.Find(userId);
            PackManGame packManGame = db.PackManGame.Find(userId);

            db.CarGame.Remove(carGame);
            db.PackManGame.Remove(packManGame);

            db.SaveChanges();
        }
예제 #5
0
파일: Program.cs 프로젝트: Calyd/autonomous
        private static void RunInSilentMode(GameOptions options)
        {
            Random r       = new Random();
            var    length  = (float)r.NextDouble() * (options.MaxLength - options.MinLength) + options.MinLength;
            var    traffic = (float)r.NextDouble() * (options.MaxTraffic - options.MinTraffic) + options.MinTraffic;

            using (var game = new CarGame(length, traffic, options.PlayerCollision, false))
            {
                game.InitializeModel();
                var sw       = Stopwatch.StartNew();
                int lastTick = (int)(sw.Elapsed.TotalMilliseconds * options.TimeAcceleration);
                while (!game.Stopped)
                {
                    int frameStart = (int)(sw.Elapsed.TotalMilliseconds * options.TimeAcceleration);
                    var elapsed    = frameStart - lastTick;
                    lastTick = frameStart;
                    game.UpdateModel(new GameTime(TimeSpan.FromMilliseconds(frameStart), TimeSpan.FromMilliseconds(elapsed)));
                }
            }
        }
예제 #6
0
 public Car(CarGame game)
 {
     _game = game;
 }