Skip to content

Commit

Permalink
Feature/visualize base range (jmattheis#138)
Browse files Browse the repository at this point in the history
* make Base grow with more range
  • Loading branch information
Nicolas Ries committed Apr 20, 2016
1 parent 9ed0fa0 commit b0e28ba
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
7 changes: 5 additions & 2 deletions AntWars/AI/AIBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using AntWars.Board.Ants;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace AntWars.AI {
/// <summary>
Expand Down Expand Up @@ -107,8 +108,10 @@ protected bool buyWarrior(int attackPower, int viewRange, int inventory, int mov
/// </summary>
/// <returns>false wenn man zuwenig Geld hat oder das Upgrade schon die höhste Stufe hat</returns>
public bool upgradeRange() {
if (payUpgrade(getBase().RangeLevel)) {
getBase().RangeLevel++;
Base pbase = getBase();
if (payUpgrade(pbase.RangeLevel)) {
pbase.RangeLevel++;
pbase.RangeCoords = new ReadOnlyCollection<Coordinates>(pbase.Coords.getAdjacentCoordinates(pbase.RangeLevel));
return true;
}
return false;
Expand Down
9 changes: 8 additions & 1 deletion AntWars/Board/Base.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace AntWars.Board {
using System.Collections.ObjectModel;

namespace AntWars.Board {

/// <summary>
/// Die Base hier "spawnen" die Ameisen, wird generell am Rand des Spielfeldes generiert.
Expand All @@ -12,6 +14,11 @@ public class Base : BoardObject {
/// </summary>
public int RangeLevel { get; internal set; }

/// <summary>
/// Alle Coordinates innerhalb des RangeLevel
/// </summary>
public ReadOnlyCollection<Coordinates> RangeCoords { get; internal set; }

/// <summary>
/// Das Level der Erholungrate gibt an um wieviel % sich die Ameise erholen kann. Rechnung: (level/10)%
/// </summary>
Expand Down
22 changes: 14 additions & 8 deletions AntWars/GamePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,29 @@ private void print(BoardObject[] boardObjects) {

private void setColor(BoardObject obj, Bitmap bitmap) {
if (obj.isCarry()) {
setColor(bitmap, obj, COLOR_PLAYER1_CARRY, COLOR_PLAYER2_CARRY, (obj as Ant).Owner);
setColor(bitmap, obj.Coords, COLOR_PLAYER1_CARRY, COLOR_PLAYER2_CARRY, (obj as Ant).Owner);
} else if (obj.isScout()) {
setColor(bitmap, obj, COLOR_PLAYER1_SCOUT, COLOR_PLAYER2_SCOUT, (obj as Ant).Owner);
setColor(bitmap, obj.Coords, COLOR_PLAYER1_SCOUT, COLOR_PLAYER2_SCOUT, (obj as Ant).Owner);
} else if (obj.isWarrior()) {
setColor(bitmap, obj, COLOR_PLAYER1_WARRIOR, COLOR_PLAYER2_WARRIOR, (obj as Ant).Owner);
setColor(bitmap, obj.Coords, COLOR_PLAYER1_WARRIOR, COLOR_PLAYER2_WARRIOR, (obj as Ant).Owner);
} else if (obj.isBase()) {
setColor(bitmap, obj, COLOR_PLAYER1_BASE, COLOR_PLAYER2_BASE, (obj as Base).Player);
Base playerbase = obj as Base;
if (playerbase.RangeLevel > 0) {
for (int i = 0;i < playerbase.RangeCoords.Count;i++) {
setColor(bitmap, playerbase.RangeCoords[i], COLOR_PLAYER1_BASE, COLOR_PLAYER2_BASE, playerbase.Player);
}
}
setColor(bitmap, obj.Coords, COLOR_PLAYER1_BASE, COLOR_PLAYER2_BASE, (obj as Base).Player);
} else if (obj.isSugar()) {
setColor(bitmap, obj, COLOR_GAME_SUGAR, Color.Transparent, null);
setColor(bitmap, obj.Coords, COLOR_GAME_SUGAR, Color.Transparent, null);
}
}

private void setColor(Bitmap bitmap, BoardObject obj, Color player1Color, Color player2Color, Player player1) {
private void setColor(Bitmap bitmap, Coordinates coords, Color player1Color, Color player2Color, Player player1) {
if (player1 == null || player1 == game.Player1) {
bitmap.SetPixel(obj.Coords.X, obj.Coords.Y, player1Color);
bitmap.SetPixel(coords.X, coords.Y, player1Color);
} else {
bitmap.SetPixel(obj.Coords.X, obj.Coords.Y, player2Color);
bitmap.SetPixel(coords.X, coords.Y, player2Color);
}
}

Expand Down
5 changes: 4 additions & 1 deletion Player1AI/AI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ public override string Playername {
get { return "Random"; }
}
public override void nextTick() {
buyWarrior(1, 10, 1, 3, 10);
buyWarrior(1, 1, 1, 1, 1);
buyScout(1, 1, 1, 1);
buyCarrier(1, 1, 1, 1);
upgradeRange();
}
}

Expand Down

0 comments on commit b0e28ba

Please sign in to comment.