Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
pokemon battle
  • Loading branch information
soikatesc committed May 10, 2017
commit f546e8ac081f9699c2f54e90a27eca2588f7dd0e
16 changes: 16 additions & 0 deletions md_rahaman/MEAN/fundamentals/pokemon_battle/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>Pokemon Battle</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>

<body>

<h1>Pokemon Battle</h1>
<script type="text/javascript" src="main.js">

</script>

</body>
</html>
50 changes: 50 additions & 0 deletions md_rahaman/MEAN/fundamentals/pokemon_battle/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@



var game = {
players: [],
addPlayer: function(player){
this.players.push(player);
},
playGame: function(){
//randomly select 2 players to battle
$('body').append(this.players[0].name)
console.log(this.players[0].name, " it is your turn!")
console.log('Your pokemon is ', this.players[0].hand[0].name)
console.log('your opponent', this.players[1].name)
console.log('Your pokemon is ', this.players[1].hand[0].name)
}

};



function playerConstructor(name){
player = {};
player.name = name;
player.hand = [];
player.addCard = function(card){
// console.log('upper scope', this)
var self = this;
rand = Math.floor((Math.random() * 811) + 1);
url = "http://pokeapi.co/api/v2/pokemon/"+rand+"/";
$.get(
url,
function(res){
self.hand.push(res);
},
'json'
)
};
game.addPlayer(player)
return player;
};

var json = playerConstructor("json")
var md = playerConstructor("Md")
// game.addPlayer(json)
// game.addPlayer(md)