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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"/>

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<div class="background">
  <div class="r row r8">
   <div class="col-md-2 center border c1"></div>
    <div class="col-md-2 center border c2"></div>
    <div class="col-md-2 center border c3">
</div>
    <div class="col-md-2 center border c4">
</div>
    <div class="col-md-2 center border c5">
</div>
    <div class="col-md-2 center border c6">
</div>
  </div>
  
  <div class="r row r7">
   <div class="col-md-2 center border c1"></div>
    <div class="col-md-2 center border c2"></div>
    <div class="col-md-2 center border c3">
</div>
    <div class="col-md-2 center border c4">
</div>
    <div class="col-md-2 center border c5">
</div>
    <div class="col-md-2 center border c6">
</div>
  </div>
  
  <div class="r row r6">
   <div class="col-md-2 center border c1"></div>
    <div class="col-md-2 center border c2"></div>
    <div class="col-md-2 center border c3">
</div>
    <div class="col-md-2 center border c4">
</div>
    <div class="col-md-2 center border c5">
</div>
    <div class="col-md-2 center border c6">
</div>
  </div>
  
  <div class="r row r5">
   <div class="col-md-2 center border c1"></div>
    <div class="col-md-2 center border c2"></div>
    <div class="col-md-2 center border c3">
</div>
    <div class="col-md-2 center border c4">
</div>
    <div class="col-md-2 center border c5">
</div>
    <div class="col-md-2 center border c6">
</div>
  </div>
  
  <div class="r row r4">
   <div class="col-md-2 center border c1"></div>
    <div class="col-md-2 center border c2"></div>
    <div class="col-md-2 center border c3">
</div>
    <div class="col-md-2 center border c4">
</div>
    <div class="col-md-2 center border c5">
</div>
    <div class="col-md-2 center border c6">
</div>
  </div>
  
  <div class="r row r3">
   <div class="col-md-2 center border c1"></div>
    <div class="col-md-2 center border c2"></div>
    <div class="col-md-2 center border c3">
</div>
    <div class="col-md-2 center border c4">
</div>
    <div class="col-md-2 center border c5">
</div>
    <div class="col-md-2 center border c6">
</div>
  </div>
  
  <div class="r row r2">
   <div class="col-md-2 center border c1"></div>
    <div class="col-md-2 center border c2"></div>
    <div class="col-md-2 center border c3">
</div>
    <div class="col-md-2 center border c4">
</div>
    <div class="col-md-2 center border c5">
</div>
    <div class="col-md-2 center border c6">
</div>
  </div>
  
  <div class="r row r1">
   <div class="col-md-2 center border c1"></div>
    <div class="col-md-2 center border c2"></div>
    <div class="col-md-2 center border c3">
</div>
    <div class="col-md-2 center border c4">
</div>
    <div class="col-md-2 center border c5">
</div>
    <div class="col-md-2 center border c6">
</div>
  </div>
  <div class="base row top-border">
   <div class="col-md-2 center c1" id="one">
     <button class="btn btn-primary btn-md " >Move here!</button>
   </div>
    <div class="col-md-2 center c2" id="two">
      <button class="btn btn-primary btn-md ">Move here!</button>
    </div>
    <div class="col-md-2 center c3" id="three">
      <button class="btn btn-primary btn-md " id="b3">Move here!</button>
</div>
    <div class="col-md-2 center c4" id="four">
      <button class="btn btn-primary btn-md " id="b4">Move here!</button>
</div>
    <div class="col-md-2 center c5" id="five">
      <button class="btn btn-primary btn-md " id="b5">Move here!</button>
</div>
    <div class="col-md-2 center c6" id="six">
      <button class="btn btn-primary btn-md " id="b6">Move here!</button>
</div>
  </div>
  <div class="base row">
    <h4 class="text-center green status"><strong>Click a "Move here" button to start!</strong></h4>
  </div>
  <i id="chara"></i>
  <i id="laser"></i>
  <i id="enemy"></i>
</div>
              
            
!

CSS

              
                .background{
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
}
.border{
  border: 2px solid;
  border-color: black;
}
.r, .base{
  width: 101.025%;
  height: 10%;
  position: relative;
  margin-left: 30px;
}
.top-border{
  border-top: 2px solid;
  border-color: black;
}
.r{
  background-color: black;
}
.base{
  background-color: gray;
}
.square{
  width: 100px;
  height: 20px;
  background-color: gray;
}
.center{
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
}
.green{
  color: #32cd32;
}
.r1 {
  background-color: red;
}
.red{
  color: #e94b3cff;
}
              
            
!

JS

              
                
var towerHealth = 300;
var interval;
var interval2;
var interval3;
var seconds = 0;
var minutes = 0;
// time survived
function counter() {
  seconds++;
  if (seconds === 60) {
    minutes++;
    seconds = 0;
  }
}
//enemy programming
function enemy() {
  var clone2 = $("#enemy").clone();
  $(clone2).addClass("fab fa-android fa-3x red remove-later");
  var row = ".r8 ";
  var randomC = ".c" + Math.ceil(Math.random() * 5).toString();
  $(clone2).appendTo(row + randomC);
  var attk = setInterval(enemyFunc, 500);
  function enemyFunc() {
    if (row[2] === "2" && typeof towerHealth === "number") {
      clearInterval(attk);
      towerHealth -= 50;
      $(".status").html("<strong>Base health: " + towerHealth + "</strong>");
     
      
      if (towerHealth === 0) {
        towerHealth = "";
        clearInterval(interval3);
        setTimeout(function() {
            alert("Game over! Your time survived is " + minutes + " minutes " + seconds + " seconds. Reload to play again.");
            $(".remove-later").remove();
            clearInterval(interval);
            clearInterval(interval2);
        }, 500);
      }
      $(clone2).remove();
    } else {
      var current = row;
      var num = parseInt(row[2]) - 1;
      var numBefore = num  + 2;
      var split2 = row.split("");
      split2[2] = numBefore;
      var before = split2.join("");
      var split = row.split("");
      split[2] = num.toString();
      row = split.join("");
      if ($(row + randomC).children().length > 0) {
        $(clone2).remove();
        clearInterval(attk);
      } else if ($(clone2).siblings().length > 0){
        $(clone2).remove();
        clearInterval(attk);
      } else if ($(before + randomC).children().length > 0){
        $(clone2).remove();
        clearInterval(attk);
      } else {
        $(clone2).appendTo(row + randomC);
      }
    }
  }
}
// shooting programming
function shoot() {
  var clone = $("#laser").clone();
  $(clone).addClass("fab fa-android fa-3x green remove-later");
  var row = ".r1 ";
  var rColumn = "." + $("#chara").parent().attr("class").split(" ")[2];
  $(clone).appendTo(row + rColumn);
  var deploy = setInterval(bulletFunc, 500);
  function bulletFunc() {
    if (row[2] === "8") {
      $(clone).remove();
      clearInterval(deploy);
    }
    var num = parseInt(row[2]) + 1;
    var split = row.split("");
    split[2] = num.toString();
    row = split.join("");
    $(clone).appendTo(row + rColumn);
  }
}
// button programming
var previous;
var parent;
var id;
function click() {
  if (previous === undefined) {
    $("#chara").addClass("fab fa-android fa-3x green");
    $(".status").html("<strong> Base health: " + towerHealth + "</strong>");
    interval = setInterval(shoot, 1000);
    interval2 = setInterval(enemy, 1500);
    interval3 = setInterval(counter, 1000);
  }
  if (previous != undefined && parent != undefined) {
    var clone = $(previous).clone();
    $(clone).appendTo(parent);
    $(clone).on("click", click)
  }
  parent = "#" + $(this).parent().attr("id");
  previous = this;
  $(this).remove();
  $("#chara").appendTo(parent);
}
$("button").on("click", click);


              
            
!
999px

Console