Initial commit with card generation
This commit is contained in:
		
						commit
						5ccdcef1d6
					
				
					 3 changed files with 88 additions and 0 deletions
				
			
		
							
								
								
									
										57
									
								
								cards.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								cards.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,57 @@
 | 
			
		|||
var cardColors = [
 | 
			
		||||
  'red',
 | 
			
		||||
  'blue',
 | 
			
		||||
  'yellow',
 | 
			
		||||
  'black',
 | 
			
		||||
  'white',
 | 
			
		||||
];
 | 
			
		||||
var cardShapes = [
 | 
			
		||||
  'triangle',
 | 
			
		||||
  'square',
 | 
			
		||||
  'pentagon',
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
var maxValue = 10;
 | 
			
		||||
 | 
			
		||||
function createCard(id, rareChance) {
 | 
			
		||||
  id = typeof id !== 'undefined' ? id : generateId();
 | 
			
		||||
  rarechance = typeof rareChance !== 'undefined' ? rareChance : 0.25;
 | 
			
		||||
  var color = cardColors[Math.floor(Math.random() * (cardColors.length - (Math.random() < rareChance ? 0 : 2)))];
 | 
			
		||||
  var shape = cardShapes[Math.floor(Math.random() * (cardShapes.length - (Math.random() < rareChance ? 0 : 1)))];
 | 
			
		||||
  var value1 = Math.floor(Math.random() * maxValue) + 1;
 | 
			
		||||
  var value2 = Math.floor(Math.random() * maxValue) + 1;
 | 
			
		||||
 | 
			
		||||
  return {
 | 
			
		||||
    id: id,
 | 
			
		||||
    color: color,
 | 
			
		||||
    shape: shape,
 | 
			
		||||
    value1: value1,
 | 
			
		||||
    value2: value2,
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function generateId() {
 | 
			
		||||
  var id = '';
 | 
			
		||||
  for (var i = 0; i < 5; i++) {
 | 
			
		||||
    id += Math.floor(Math.random() * 10).toString();
 | 
			
		||||
  }
 | 
			
		||||
  return parseInt(id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function createPack() {
 | 
			
		||||
  var cards = [];
 | 
			
		||||
  for (var i = 0; i < 5; i++) {
 | 
			
		||||
    cards.push(createCard(undefined, i > 2 ? 0.5 : undefined));
 | 
			
		||||
  }
 | 
			
		||||
  return cards;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function generateDatabase() {
 | 
			
		||||
  var db = [];
 | 
			
		||||
  for (var i = 0; i < 99999; i++) {
 | 
			
		||||
    db.push(createCard(i + 1, 0.5));
 | 
			
		||||
  }
 | 
			
		||||
  console.log(db);
 | 
			
		||||
  var uriContent = "data:application/octet-stream," + encodeURIComponent(JSON.stringify(db));
 | 
			
		||||
  var newWindow = window.open(uriContent, 'cardDb.json');
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										15
									
								
								index.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								index.html
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,15 @@
 | 
			
		|||
<!DOCTYPE html>
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
  <title>カードス! (Kaadosu!)</title>
 | 
			
		||||
  <script src="cards.js"></script>
 | 
			
		||||
  <script src="player.js"></script>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
<script>
 | 
			
		||||
window.onload = function () {
 | 
			
		||||
  generateDatabase();
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
							
								
								
									
										16
									
								
								player.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								player.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,16 @@
 | 
			
		|||
function Player () {
 | 
			
		||||
  this.collection = []; // Cards
 | 
			
		||||
  this.decks = [
 | 
			
		||||
    // {
 | 
			
		||||
    //   name: 'Deck Name',
 | 
			
		||||
    //   cards: [], // Card ids
 | 
			
		||||
    // }
 | 
			
		||||
  ];
 | 
			
		||||
}
 | 
			
		||||
Player.prototype.checkCurrency = function (type) {
 | 
			
		||||
  if (typeof type !== 'undefined') {
 | 
			
		||||
    for (var i = 0; i < this.collection.length; i++) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue