diff --git a/angular-playground.sln b/angular-playground.sln new file mode 100644 index 0000000..f3c421b --- /dev/null +++ b/angular-playground.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "angular-playground", ".", "{1C264CEB-6514-436C-8705-3789D954C442}" + ProjectSection(WebsiteProperties) = preProject + TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.0" + Debug.AspNetCompiler.VirtualPath = "/localhost_52606" + Debug.AspNetCompiler.PhysicalPath = "..\..\..\..\..\..\source\angular-playground\" + Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_52606\" + Debug.AspNetCompiler.Updateable = "true" + Debug.AspNetCompiler.ForceOverwrite = "true" + Debug.AspNetCompiler.FixedNames = "false" + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.VirtualPath = "/localhost_52606" + Release.AspNetCompiler.PhysicalPath = "..\..\..\..\..\..\source\angular-playground\" + Release.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_52606\" + Release.AspNetCompiler.Updateable = "true" + Release.AspNetCompiler.ForceOverwrite = "true" + Release.AspNetCompiler.FixedNames = "false" + Release.AspNetCompiler.Debug = "False" + VWDPort = "52606" + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1C264CEB-6514-436C-8705-3789D954C442}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1C264CEB-6514-436C-8705-3789D954C442}.Debug|Any CPU.Build.0 = Debug|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/app/components/bindings/BindingsController.js b/app/components/bindings/BindingsController.js index 281242d..87d65a6 100644 --- a/app/components/bindings/BindingsController.js +++ b/app/components/bindings/BindingsController.js @@ -5,5 +5,6 @@ app.controller('BindingsController', BindingsController); function BindingsController(){ this.bindingsStatus = 'Working'; - this.name= "Please enter your Name"; + this.name = "Please enter your Name"; + this.somethingOfYourChoice = "Something of your choice"; } \ No newline at end of file diff --git a/app/components/bindings/bindings.html b/app/components/bindings/bindings.html index c6bb99f..2887c17 100644 --- a/app/components/bindings/bindings.html +++ b/app/components/bindings/bindings.html @@ -36,10 +36,10 @@

Exercises

diff --git a/app/components/controllers/ControllersController.js b/app/components/controllers/ControllersController.js index 6a3d65f..aecba63 100644 --- a/app/components/controllers/ControllersController.js +++ b/app/components/controllers/ControllersController.js @@ -4,5 +4,12 @@ app.controller('ControllersController', ControllersController); function ControllersController(){ - this.controllersStatus = 'Working'; -} \ No newline at end of file + this.controllersStatus = 'Working'; + this.friends = ['Joey', 'Chandler', 'Monica', 'Phebes', 'Ross & Rachel']; + this.addFriend = function () { + if (this.newFriend) { + this.friends.push(this.newFriend); + this.newFriend = null; + } + } +} diff --git a/app/components/controllers/controllers.html b/app/components/controllers/controllers.html index 4c6da3a..f04e7c6 100644 --- a/app/components/controllers/controllers.html +++ b/app/components/controllers/controllers.html @@ -32,12 +32,18 @@

Exercises

create a property in the constructor called friends which will be an array of strings ['Joey', 'Chandler', 'Monica', 'Phebes', 'Ross & Rachel']; -
- -
- +

+
+
  • Write a function called addFriend that will take the input from ng-model="controller.newFriend" If done correctly you should see your new friend pop up on the list above once you click submit
    @@ -50,4 +56,5 @@

    Exercises

  • - \ No newline at end of file + + diff --git a/app/components/expressions/ExpressionsController.js b/app/components/expressions/ExpressionsController.js index f90acbf..e2ee29d 100644 --- a/app/components/expressions/ExpressionsController.js +++ b/app/components/expressions/ExpressionsController.js @@ -5,5 +5,5 @@ app.controller('ExpressionsController', ExpressionsController); function ExpressionsController(){ this.expressionsStatus = 'Working'; - this.test = 'Angular is really neat! Look how easy it was for you to connect this string to your view'; + this.test = 'Angular is really neat! Look how easy it was for you to connect this string to your view'; } \ No newline at end of file diff --git a/app/components/expressions/expressions.html b/app/components/expressions/expressions.html index ca65403..f53d197 100644 --- a/app/components/expressions/expressions.html +++ b/app/components/expressions/expressions.html @@ -69,19 +69,19 @@

    Exercises

  • Write a math equation that Angular can evaluate
    - {{}} + {{8 + 8}}
  • Using string concatination get the customary Hello, World! to display on the screen. Don't forget your quotes
    - {{}} + {{'Hello, ' + 'World!'}}
  • We have a controller driving this view. The controller is nothing more than an object with properties. One of the properties on the controller object is called test. Render the test property to the screen
    - {{}} + {{controller.test}}
  • diff --git a/app/components/repeat/RepeatController.js b/app/components/repeat/RepeatController.js index cf9c4e7..bc33593 100644 --- a/app/components/repeat/RepeatController.js +++ b/app/components/repeat/RepeatController.js @@ -1,60 +1,87 @@ -var app = angular.module('angularPlayground'); +var app = angular.module('angularPlayground'); app.controller('RepeatController', RepeatController); -function RepeatController(){ - this.repeatStatus = 'Working'; - //The cart is an array of items that we are adding from our view - this.cart = []; - //The store is what we are using to populate our page with - this.store = { - items: StoreData - }; - //*** No Need to edit anything above this line **** - - this.name = "My BɼokƏn Cart!"; - - this.getCartCount = function(){ - //return the length of our cart - }; - - /* - * Write a calculateCartTotal function - * make it assesible to our view - * this function should return the total cost - * of each item that is in our cart - */ - - - this.removeItemFromCart = function(item){ - //Item gets passed in from our view when the user clicks the x button +function RepeatController() { + this.repeatStatus = 'Working'; + //The cart is an array of items that we are adding from our view + this.cart = []; + //The store is what we are using to populate our page with + this.store = { + items: StoreData + }; + //*** No Need to edit anything above this line **** + + this.name = "My BɼokƏn Cart!"; + + this.getCount = function () { + //return the length of our cart + return this.cart.length; + }; + /* - * This function should be able to remove the passed in item - * from our cart. You will have to first identify where the passed - * in item is in the array. Then you will need to use the correct - * Array.method to remove 1 item hint method(i, 1); + * Write a calculateCartTotal function + * make it assesible to our view + * this function should return the total cost + * of each item that is in our cart */ - }; - - this.addItemToCart = function(item){ - //item gets passed in to this function from the view - - /* - Our cart demands that items being added to it must have the following properties - var newItem = { - name:'', - color:'', - size: '', - quantity: 1, - price:'', - } - console.log the item being passed in from the view - to figure out which properties from item need to be - remaped to the newItem object. - After building the newItem add it to the cart - */ - - } - + + this.calculateCartTotal = function () { + var total = 0; + for (var i = 0; i < this.cart.length; i++) { + total += this.cart[i].price * this.cart[i].quantity; + //console.log(i + " Item:"+this.cart[i].name+" Price:"+this.cart[i].price+" Quantity:"+this.cart[i].quantity + " RunningTotal:"+ total); + } + return total; + }; + + this.removeItemFromCart = function (item) { + //Item gets passed in from our view when the user clicks the x button + for (var i = 0; i < this.cart.length; i++) { + if (item.name === this.cart[i].name && + item.color === this.cart[i].color && + item.size === this.cart[i].size && + item.quantity === this.cart[i].quantity && + item.price === this.cart[i].price) { + //console.log("Delete " + i + " which is " + item.name + ":" + item.size + ":" + item.color); + this.cart.splice(i, 1); + break; + } + } + /* + * This function should be able to remove the passed in item + * from our cart. You will have to first identify where the passed + * in item is in the array. Then you will need to use the correct + * Array.method to remove 1 item hint method(i, 1); + */ + }; + + this.addItemToCart = function (item) { + //item gets passed in to this function from the view + //console.log(item); + var newItem = { + name: item.name, + color: item.selectedColor, + size: item.selectedSize, + quantity: 1, + price: item.price, + } + //console.log(newItem); + this.cart.push(newItem); + /* + Our cart demands that items being added to it must have the following properties + var newItem = { + name:'', + color:'', + size: '', + quantity: 1, + price:'', + } + console.log the item being passed in from the view + to figure out which properties from item need to be + remaped to the newItem object. + After building the newItem add it to the cart + */ + } } \ No newline at end of file diff --git a/app/components/repeat/repeating.html b/app/components/repeat/repeating.html index 3717987..448a9c2 100644 --- a/app/components/repeat/repeating.html +++ b/app/components/repeat/repeating.html @@ -1,90 +1,89 @@ -RepeatController Status: {{controller.repeatStatus}} +RepeatController Status: {{controller.repeatStatus}}
    -

    Help Fix this Cart

    -

    What we have here is a broken website. There are a few challenges we need to solve to get it working

    -

    using the comments in the html and in the controller file as guides you should be able to get this cart back in top notch condition.

    - -

    First things first lets start with the HTML.

    - +

    Help Fix this Cart

    +

    What we have here is a broken website. There are a few challenges we need to solve to get it working

    +

    using the comments in the html and in the controller file as guides you should be able to get this cart back in top notch condition.

    + +

    First things first lets start with the HTML.

    +

    -

    {{controller.name}}

    -

    Items added to your Cart ({{controller.getCount() || 0}})

    -
    -

    - You have no items in your cart... Buy something! -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    ItemColorSizeQuantityPrice
    {{item.name}}{{item.color}}{{item.size}} - - {{item.price * item.quantity}} - -
    Total:{{controller.calculateCartTotal()}}
    -
    -
    -
    - -
    -
    - -

    {{item.price}}

    -

    - {{item.name}}

    - -

    - - -

    - +

    {{controller.name}}

    +

    Items added to your Cart ({{controller.getCount() | number:0}})

    +
    +

    + You have no items in your cart... Buy something! +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ItemColorSizeQuantityPrice
    {{item.name}}{{item.color}}{{item.size}} + + {{item.price * item.quantity | currency}} + +
    Total:{{controller.calculateCartTotal() | currency}}
    +
    +
    +
    + +
    +
    + +

    {{item.price | currency}}

    +

    {{item.name}}

    + +

    + + +

    + +
    +
    -
    -
    -
    \ No newline at end of file +
    diff --git a/assets/css/site.css b/assets/css/site.css index 483c07b..d3840f1 100644 --- a/assets/css/site.css +++ b/assets/css/site.css @@ -45,4 +45,11 @@ color:yellow; font-size:16px; font-weight:bold; +} + +.box1-custom { + width:300px; + background-color:lightgrey; + border-color:black; + border-width:2px; } \ No newline at end of file diff --git a/img/BullFrog.gif b/img/BullFrog.gif new file mode 100644 index 0000000..9794bb4 Binary files /dev/null and b/img/BullFrog.gif differ diff --git a/racingFrogs-app.css b/racingFrogs-app.css new file mode 100644 index 0000000..6304efc --- /dev/null +++ b/racingFrogs-app.css @@ -0,0 +1,38 @@ +body { + background-color: lightblue; +} +.button-custom { + background-color:lightgreen; + display:inline-block; +} +.button-custom-top { + background-color:lightgreen; + display:inline-block; + color:darkblue; +} +.float-left { + display:inline-block; + float:left; +} +.float-right { + display:inline-block; + float:right; +} +.winner-found { + font-size:large; + color:red; +} +.under-button { + font-size:small; +} +.bet-history { + display:inline-block; + float:right; +} +#bet-box { + width:135px; + height:200px; + display:inline-block; + background-color:paleturquoise; + padding:5px; +} diff --git a/racingFrogs-app.js b/racingFrogs-app.js new file mode 100644 index 0000000..94a6c63 --- /dev/null +++ b/racingFrogs-app.js @@ -0,0 +1,221 @@ +var app = angular.module('racingFrogs', []); +app.controller('MainController', MainController); +//No need to change anything above this line. + +function MainController(BettingService, $timeout) { + var vm = this; //instead of using this when referring to the controller, let's use vm. It will make things easier. + vm.working = "Yes"; + + vm.frogSet = [ + { lane: 1, name: "Frank", posX: 0, picUrl: "img/BullFrog.gif", color: "red" }, + { lane: 2, name: "Harry", posX: 0, picUrl: "img/BullFrog.gif", color: "green" }, + { lane: 3, name: "Eddie", posX: 0, picUrl: "img/BullFrog.gif", color: "maroon" }, + { lane: 4, name: "Duane", posX: 0, picUrl: "img/BullFrog.gif", color: "blue" }, + { lane: 5, name: "Hank", posX: 0, picUrl: "img/BullFrog.gif", color: "orange" }, + { lane: 6, name: "Drake", posX: 0, picUrl: "img/BullFrog.gif", color: "indigo" }, + { lane: 7, name: "Gerik", posX: 0, picUrl: "img/BullFrog.gif", color: "brown" }, + { lane: 8, name: "Monte", posX: 0, picUrl: "img/BullFrog.gif", color: "purple" }, + { lane: 9, name: "Abel", posX: 0, picUrl: "img/BullFrog.gif", color: "orangered" } + ]; + + // initial load of 6 frogs and no winner yet + vm.frogs = []; + for (var i = 0; i < 6; i++) { + vm.frogs.push(vm.frogSet[i]); + } + vm.winner = "You have " + vm.frogs.length + " frogs ready to RACE ! "; + var raceReady = false; + + for (var i = 0; i < 9; i++) { + vm.raceId = BettingService.registerRace(); + } + vm.races = BettingService.getAllRace(); + + vm.setFrogposX = function () { + for (var i = 0; i < vm.frogs.length; i++) { + vm.frogs[i].posX = 0; + document.getElementById('frog' + (i + 1)).style.left = vm.frogs[i].posX + "px"; + vm.winner = "You have " + vm.frogs.length + " frogs ready to RACE ! "; + } + } + + vm.addFrog = function () { + var a = vm.frogs.length + 1; + if (a > 9) { a = 9 }; + vm.frogs = []; + for (var i = 0; i < a; i++) { + vm.frogs.push(vm.frogSet[i]); + } + vm.setFrogposX(); + } + + vm.removeFrog = function () { + var a = vm.frogs.length - 1; + if (a < 2) { a = 2 }; + vm.frogs = []; + for (var i = 0; i < a; i++) { + vm.frogs.push(vm.frogSet[i]); + } + vm.setFrogposX(); + } + + vm.getTrackWidth = function () { + var raceTrackWidth = document.getElementById('raceTrack').offsetWidth - 50 ; + //console.log("Track width is : " + raceTrackWidth); in px + return raceTrackWidth; + }; + + vm.practiceHeat = function () { + if (!raceReady) { + vm.winner = ""; + vm.setFrogposX(); + raceReady = true; + vm.startRace(); + } + } + + vm.newRace = function () { + vm.winner = ""; + vm.races = BettingService.getAllRace(); + raceReady = true; + for (var i = 0; i < vm.frogs.length; i++) { + vm.frogs[i].posX = 0; + document.getElementById('frog' + (i + 1)).style.left = vm.frogs[i].posX + "px"; + vm.winner = "You have " + vm.frogs.length + " frogs ready to RACE ! "; + } + } + + vm.startRace = function () { + if (raceReady) { + vm.winner = "And they're off ! "; + var itsDone = false; + var winning = 0; + var raceTrackWidth = document.getElementById('raceTrack').offsetWidth - 50; + if (!itsDone) { + for (var i = 0; i < vm.frogs.length; i++) { + var posX = vm.frogs[i].posX + Math.floor(Math.random() * 20); + vm.frogs[i].posX = posX; + document.getElementById('frog' + (i + 1)).style.left = posX + "px"; + if (winning < posX) { winning = posX; }; + if (winning >= raceTrackWidth) { + vm.winner = " Winner: " + vm.frogs[i].name + " wearing " + vm.frogs[i].color + " in lane " + vm.frogs[i].lane + " "; + itsDone = true; + break; + } + } + } + if (!itsDone) { + $timeout(vm.startRace, 70); + } else { + raceReady = false; + } + } + } + + + // Fun with Joe and Bob panel ------------------------------------------------------------ + vm.joe = new Guy("Joe", 100); + vm.bob = new Guy("Bob", 150); + vm.bank = 200; + + function Guy(name, startingCash) { + this.name = name; + this.cash = startingCash; + this.giveCash = function (amount) { + if (amount <= this.cash && amount > 0) { + this.cash = this.cash - amount; + return amount; + } else { + console.log("I don't have enough cash to give you " + amount + ". " + this.name + " says..."); + return 0; + } + }; + this.receiveCash = function (amount) { + if (amount > 0) { + this.cash = this.cash + amount; + return amount; + } else { + console.log(amount + " isn't an amount I'll take " + this.name + " says..."); + return 0; + } + } + } + + vm.giveMoneyToJoe = function () { + if (vm.bank >= 10) { + vm.bank -= vm.joe.receiveCash(10); + } else { + alert("The bank is out of money."); + } + } + + vm.receiveMoneyFromBob = function () { + vm.bank += vm.bob.giveCash(5); + } + +} + +// Betting Service is separate from Main Controller ================================= +app.service('BettingService', BettingService); + +function BettingService() { + var _races = {}; + var _raceId = 0; + this.registerRace = function () { + var race = new Race(); + return race.id; + } + this.getAllRace = function () { + return _races; + } + this.getRace = function (raceId) { + return _races[raceId]; + } + this.addContestant = function (raceId, contestant) { + //Adds a frog to the race object remember to get the race first + //Also dont let frogs be added after the race has started. + } + this.getContestants = function (raceId) { + //just returns the contestants for a specified race + } + //Number raceId, String bettingOn, Boolean outcome, Number wager + this.placeBet = function (raceId, bettingOn, wager) { + console.log("BettingService.placeBet has been called") + /*this function is the one that gets called from your controller. + build the appropriate bet object fro the arguments and add it to the race. + consider ensuring that the raceId is an actual race object + validate the bettingOn contestant + pool the wages from the race + */ + } + this.closeRace = function (raceId) { + //No more bets please the race has started + } + this.setWinners = function (raceId, winners) { + //make sure winners can only be set once + } + function isValidBet(race, bet) { + var valid; + for (var i = 0; i < race.contestants.length; i++) { + //make sure the frog selected is actually in the race system Prevents Cheating + } + return valid; + } + function generateTicket(race, bet) { + //responsible for adding a bet to the specified race by its ticketNumber + //Don't forget to increase the ticketing count system + race.tickets++; + } + var Race = function () { + this.id = _raceId; + this.tickets = 1300; + this.contestants = []; + this.open = true; + this.bets = {}; + this.winner = {}; + _races[this.id] = this; + _raceId++; + } + + } +// end of Betting Service ===================================================== diff --git a/racingFrogs-index.html b/racingFrogs-index.html new file mode 100644 index 0000000..e880b2d --- /dev/null +++ b/racingFrogs-index.html @@ -0,0 +1,137 @@ + + + + + Racing Frogs + + + + + + {{1 + 1}} +
    +
    +
    +
    +

    Welcome to The Frog Races

    + + + Add Frog
    (up to 9)
    +
    + + + Remove Frog
    (down to 2)
    +
    + Practice
    Heat
    +



    +
    +
    + + + + + + + + + + + + + + + +
    | Frog + | START + FINISH | +
    {{frog.lane | number:0}} + - {{frog.name}} + +
    + +
    +
    +
    + +
    + +
    +
    +
    +

    Betting on the Races (under development)


    +
    +
    +
    +
    + +

    Placing Your Bets
    Race must be open

    +

    Race:

    +

    Frog:

    +

    Wager:

    +
    +

    Place Bet

    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + +
    RaceOpenTicketsBetsWinnerContestants
    {{race.id + 1 | number:0}} {{race.open}}{{race.tickets | number:0}} {{race.bets}} {{race.winner}} {{race.contestants}}
    +
    + +
    + +
    + +
    +
    + Fun with Joe and Bob +
    +
    +

    + Joe has {{ vm.joe.cash | currency }} +

    +

    + Bob has {{ vm.bob.cash | currency }} +

    +

    + The bank has {{ vm.bank | currency }} +

    +
    + +
    +
    +
    + Angular Working? {{vm.working}} + + + + +