codecombat中国游戏网址:
http://www.codecombat.cn/
所有代码为javascript代码分享
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37、Deadly Discs
//要有足够的钱买新英雄,大约是4800左右
// If the ogre takes damage, she‘ll wake up and smash the peasant.
// You‘ve got these razor-discs you can throw(). Maybe that‘ll help?
// Looks like you‘ll need three discs to kill the ogre.
// Make all three hit the ogre simultaneously!
// Hint: razor discs bounce off of obstacles!
var targets = [];
targets.push({ x: this.pos.x, y: this.pos.y - 5 });
// Figure out where to throw the other two discs.
targets.push({ x: this.pos.x, y: this.pos.y + 5 });
targets.push({ x: this.pos.x - 5, y: this.pos.y });
while(targets.length > 0) {
if(this.isReady("throw")) {
// shift() removes and returns the first element of an array
var target = targets.shift();
this.throwPos(target);
} else {
this.wait(0.01);
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38、Summit‘s Gate
//未通过
// Fight your way into the Inner Sanctum of the ogre chieftain, and kill her.
this.flags = function(){
var flagg = this.findFlag("green");
var flagb = this.findFlag("black");
if (flagg) {
this.pickUpFlag(flagg);
}
if (flagb) {
this.jumpTo(flagb.pos);
this.pickUpFlag(flagb);
}
};
this.attacks = function(){
var enemy = this.findNearest(this.findEnemies());
if (enemy && this.distanceTo(enemy) < 15) {
this.attack(enemy);
}
if (enemy) {
if (this.isReady("mana-blast") && this.distanceTo(this.findNearest(this.findEnemies())) < 10) {
this.manaBlast();
}
}
};
this.builds = function(){
if (this.gold > this.costOf("griffin-rider")) {
this.summon("griffin-rider");
}
if (this.isReady("summon-fangrider")) {
this.cast("summon-fangrider");
}
if (this.isReady("reset-cooldown")) {
this.resetCooldown("summon-fangrider");
}
};
this.comm = function(friend){
if (friend) {
var enemy = friend.findNearestEnemy();
if (enemy && enemy.health > 1) {
this.command(friend, "attack", enemy);
}
}
};
this.commandFriends = function() {
// Command your friends.
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
var friend = friends[i];
if(friend.type == "griffin-rider") {
this.comm(friend);
} else if(friend.type == "paladin") {
this.comm(friend);
}
else if (friend.type == "archer") {
this.comm(friend);
}
else if (friend.type == "solider") {
this.comm(friend);
}
}
};
loop {
this.flags();
this.builds();
this.attacks();
this.commandFriends();
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39、Cloudrip Siege
// Your goal is to keep at least one flower alive for 60 seconds.
// This is an optional challenge level, intended to be difficult. Be creative with your code!
// It gets harder (and more lucrative) each time you succeed. If you fail, you must wait a day to resubmit.
var summonTypes = ["soldier","soldier","archer","griffin-rider"];
this.builds = function() {
var type = summonTypes[this.built.length % summonTypes.length];
if(this.gold >= this.costOf(type)) {
this.summon(type);
}
};
this.coll = function(){
var item = this.findNearest(this.findItems());
if (item) {
this.move(item.pos);
}
};
this.comm = function(friend){
if (friend) {
var enemy = friend.findNearestEnemy();
if (enemy) {
this.command(friend, "attack", enemy);
}
}
};
this.commandFriends = function() {
// Command your friends.
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
var friend = friends[i];
if(friend.type == "griffin-rider") {
this.comm(friend);
}
else if (friend.type == "archer") {
this.comm(friend);
}
else if (friend.type == "soldier") {
this.comm(friend);
}
}
};
this.speedUp = function(){
if (this.canCast("shrink")) {
this.cast("shrink", this);
}
};
loop {
this.builds();
this.speedUp();
this.coll();
this.commandFriends();
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40、Cloudrip Treasure
// Your goal is to collect coins / gems.
// This level is repeatable. If you win, the difficulty and rewards will increase.
// If you fail, you have to wait a day to resubmit.
// This level is an optional challenge level. You don‘t need to beat it to continue the campaign!
var summonTypes = ["soldier","soldier","archer","archer"];
this.builds = function() {
var type = summonTypes[this.built.length % summonTypes.length];
if(this.gold >= this.costOf(type)) {
this.summon(type);
}
};
this.coll = function(){
var friends = this.findByType("peasant");
for(var i = 0; i< friends.length; i++){
var friend = friends[i];
if (friend) {
var item = friend.findNearestItem();
if (item) {
this.command(friend, "move", item.pos);
}
}
}
};
this.comm = function(friend){
if (friend) {
var enemy = friend.findNearestEnemy();
if (enemy) {
this.command(friend, "attack", enemy);
}
}
};
this.commandFriends = function() {
// Command your friends.
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
var friend = friends[i];
if(friend.type == "griffin-rider") {
this.comm(friend);
}
else if (friend.type == "archer") {
this.comm(friend);
}
else if (friend.type == "soldier") {
this.comm(friend);
}
}
};
this.attacks = function(){
var enemy = this.findNearest(this.findEnemies());
if (enemy) {
if (this.distanceTo(enemy) < 10) {
if (this.isReady("mana-blast")) {
this.manaBlast();
}
}
else {
this.attack(enemy);
}
}
};
loop {
this.builds();
this.coll();
this.commandFriends();
this.attacks();
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41、Cloudrip Brawl
// Stay alive for one minute.
// If you win, the next time you play will be more difficult and more rewarding!
// If you lose, you must wait a day before submitting again.
var summonTypes = ["soldier","soldier","archer","griffin-rider"];
this.builds = function() {
var type = summonTypes[this.built.length % summonTypes.length];
if(this.gold >= this.costOf(type)) {
this.summon(type);
}
};
this.coll = function(){
var item = this.findNearest(this.findItems());
if (item) {
this.move(item.pos);
}
};
this.comm = function(friend){
if (friend) {
var enemy = friend.findNearestEnemy();
if (enemy) {
this.command(friend, "attack", enemy);
}
}
};
this.commandFriends = function() {
// Command your friends.
var friends = this.findFriends();
for(var i=0; i < friends.length; i++) {
var friend = friends[i];
if(friend.type == "griffin-rider") {
this.comm(friend);
}
else if (friend.type == "archer") {
this.comm(friend);
}
else if (friend.type == "soldier") {
this.comm(friend);
}
}
};
this.speedUp = function(){
if (this.canCast("shrink")) {
this.cast("shrink", this);
}
};
loop {
this.builds();
this.speedUp();
this.coll();
this.commandFriends();
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
番外篇:地牢42关-Kithgard Apprentice
//需要一身好装备和好操作
// Your goal is to survive.
// Also have fun. Maybe win in the leaderboards!
// Good thing you never stumbled into this room the first time you were here, amirite?
this.summons = function(){
while (this.gold > this.costOf("soldier")) {
this.summon("soldier");
}
};
this.flag = function(){
var flagg = this.findFlag("green");
var flagb = this.findFlag("black");
if (flagg) {
this.pickUpFlag(flagg);
}
if (flagb) {
this.jumpTo(flagb.pos);
this.pickUpFlag(flagb);
}
};
this.attacks = function(){
var enemy = this.findNearest(this.findEnemies());
if (enemy) {
this.attack(enemy);
if (this.isReady("bash")) {
this.bash(enemy);
}
}
};
this.commands = function(){
var friends = this.findFriends();
if (friends) {
for(var i = 0; i < friends.length; i++){
var friend = friends[i];
var enemy = friend.findNearestEnemy();
if (enemy) {
this.command(friend, "attack", enemy);
}
}
}
};
loop {
this.flag();
this.summons();
this.commands();
this.attacks();
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~