Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <span id="display"></span><br />
<progress id="prog" value="0" max="100"><span>ABDEF</span></progress>
<p style="text-align: left">
  [BIT Downloader v0.1]<br />
  > It takes 2 bits to make a byte<br />
  > Every <span id="amt">100</span> a random bit is downloaded to the buffer<br />
  > Use your drive to store important bits<br />
</p>
<a href="" id="tgl">Show Drive</a><br />
<table id="tbl-buffer" cellpadding="9" style="margin-left: auto;margin-right: auto">
  <thead>
    <tr><td>BUFFER</td></tr>
    <tr style="background:#111">
      <td>Bytes</td>
      <td>Transfer</td>
      <td>Sell</td>
      <td>Drop</td>
    </tr>
  </thead>
  <tbody>
    <tr><td colspan="4"><progress id="buffer_prog" value="0" max="10"></progress></td></tr>
</table>
<table id="tbl-drive" cellpadding="9" style="margin-left: auto;margin-right: auto;display: none">
  <thead>
    <tr><td>DRIVE</td></tr>
    <tr style="background:#111">
      <td>Bytes</td>
      <td>Transfer</td>
      <td>Sell</td>
      <td>Drop</td>
    </tr>
  </thead>
  <tbody>
    <tr><td colspan="4"><progress id="drive_prog" value="0" max="10"></progress></td></tr>
</table>
              
            
!

CSS

              
                body {
  background: black;
  color: lightgreen;
  text-align: center;
  font-size: 22px;
  font-family: Courier;
}

a {
  color: lightgreen;
}

table {
  margin: 5px;
}


.btn {
  width: 250px;
  font-family: Courier;
  font-size: 15px;
  padding: 5px;
  margin: 5px;
  border: solid;
  background: black;
  color: lightgreen;
}

#prog {
  width: 95%;
}

#buffer_prog {
  width: 100%;
}

#drive_prog {
  width: 100%;
}

progress {
  height: 35px;
  border: lightgreen solid 1px;
  -webkit-appearance: none;
  background: black;
}

progress::-webkit-progress-bar {
	background: black;
  color: lightgreen;
	border-radius: 50px;
	padding: 1px;
}

progress::-webkit-progress-value {
  background: lightgreen;
}

#prog::-webkit-progress-value[50] {
  background: red;
}
              
            
!

JS

              
                //Player money
var money = 0;

//Player bits
var bits = 0;

//Incrimental counter
var i = 0;

//Game Time
var time = 0;

//Collect timer
var collect_timer = 0;

//Collect level
var collect_amt = 25;

//Player download buffer array
var buffer = [];

//Player save buffer array
var drive = [];

//Player buffer size
var buffer_size = 10;

//Player drive size
var drive_size = 6;

//Bit sell price
var bit_cost = 0.2;

//Game loop handle
var gl = null;

//PING or gametime(how many sec a TIME is)
var connspeed = 500;

//Drive display
var drive_display = 0;

function randomInt (low, high) {
    return Math.floor(Math.random() * (high - low) + low);
}

function collectRandomByte() {
  var r = randomInt(1,255);
  //var chr = String.fromCharCode(97 + r);
  //var chr = String.fromCharCode(r);
  var chr;
  //If its a single char hex value append a 0
  //So 0xF -> 0x0F
  if(r < 16) {
    chr = "0" + r.toString(16).toUpperCase();
  }
  else {
    chr = r.toString(16).toUpperCase();
  }
  buffer.push("0x"+chr);
  bits+=0.5;
  addTable("0x"+chr,0.02);
}

function addTableBuffer(byte,price) {
  var row = $("<tr></tr>");
  var byt = $("<td></td>").text(byte);
  var trans = $("<td></td>").html("<a href='#'>To Drive</a>");
  var pric = $("<td></td>").html("<a href='#'>Sell $"+price+"</a>");
  var drop = $("<td></td>").html("<a href='#'>Drop</a>");
  row.append(byt);
  row.append(trans);
  row.append(pric);
  row.append(drop);
  $("#tbl-buffer").append(row);
  
}

//Updates the Graphics
function updateUI() {
  display.text("Money: $" + Math.floor(money) + " | TIME: " + time + " | BITS: " + bits + " | BUFFER: " + buffer.length + "/" + buffer_size +"  | DRIVE: " + drive.length + "/" + drive_size + " | PING: " + connspeed);
  
  //stream.text(buildStr(buffer));
  $("#prog").attr("value",collect_timer);
  $("#buffer_prog").attr("value",buffer.length);
  $("#buffer_prog").attr("max",buffer_size);
  
  $("#drive_prog").attr("value",drive.length);
  $("#drive_prog").attr("max",drive_size);
  
  $("#amt").text(collect_amt);
  $("#prog").attr("max",collect_amt);
  
  if(drive_display) {
    $("#tbl-buffer").hide();
    $("#tbl-drive").show();
    $("#tgl").text("Show Buffer");
  }
  else {
    $("#tbl-buffer").show();
    $("#tbl-drive").hide();
    $("#tgl").text("Show Drive");
  }
  
}

$("#tgl").on("click",function(e){
  drive_display = !drive_display;
  e.preventDefault();
});

//Handles to html elements
var display = $("#display");
var stream = $("#str");
var btnSort = $("#sortBuffer");
var btnSell1 = $("#sellBuffer1");
var btnSell10 = $("#sellBuffer10");
var btnSell100 = $("#sellBuffer100");

//Sort Buffer button click
btnSort.on("click",function(e){
  buffer = buffer.sort();
  connspeed -= 10;
  updateUI();
});

btnSell1.on("click",function(){
  var i = buffer.pop();
  bits -= 0.5;
  money += bit_cost;
  
  updateUI();
});

function gameLoop() {
  i++;
  if(i > connspeed) {
    time++;  
    i=0;
    collect_timer++;
    if(collect_timer >= collect_amt) {
      if(buffer.length < buffer_size) {
        collectRandomByte();
        collect_timer = 0;
        updateUI();
      }
    }
  }
  updateUI();
}

gl = setInterval(gameLoop,10);
updateUI();
              
            
!
999px

Console