Skip to content

Instantly share code, notes, and snippets.

@Koziolek
Created June 21, 2017 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Koziolek/ca6ad65e0db7ae8a95c8d5ad738feabe to your computer and use it in GitHub Desktop.
Save Koziolek/ca6ad65e0db7ae8a95c8d5ad738feabe to your computer and use it in GitHub Desktop.
package com.luxoft.tanks;
import java.util.Arrays;
/**
* Created by BKuczynski on 2017-06-21.
*/
public class Tanks {
final String[][] battleField = {
{"B", "B", "B", "B", "B", "B", "B", "B", "B"},
{" ", " ", " ", " ", " ", " ", " ", " ", "B"},
{"B", "B", "B", " ", "B", " ", "B", "B", "B"},
{"B", "B", "B", " ", " ", " ", "B", "B", "B"},
{"B", "B", "B", " ", "B", " ", "B", "B", "B"},
{"B", "B", " ", "B", "B", "B", " ", "B", "B"},
{"B", "B", " ", " ", " ", " ", " ", "B", "B"},
{"B", " ", " ", "B", "B", "B", " ", " ", "B"},
{"B", " ", " ", "B", "E", "B", " ", " ", "B"}
};
private int tankX = 8;
private int tankY = 2;
public static void main(String[] args) {
Tanks tanks = new Tanks();
tanks.setUp();
tanks.printCurrentBattleField();
//asdw q
}
private void setUp() {
battleField[tankX][tankY] = "T";
}
private void move(){
if(tankX == 0){
sleep(500);
return;
}
String up = battleField[tankX - 1][tankY];
if(!up.equals(" ")){
sleep(500);
return;
}
battleField[tankX][tankY] = " ";
tankX--;
battleField[tankX][tankY] = "T";
sleep(500);
}
private void sleep(int i) {
try {
Thread.sleep(i);
printCurrentBattleField();
} catch (InterruptedException e) {
}
}
private void printCurrentBattleField() {
System.out.println("--------------------------------");
for (String[] row : battleField) {
System.out.println(Arrays.toString(row));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment