id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
ed416f89-ef0f-4d2e-b429-a299f16581a0 | public void setFiring (boolean fire) {firing = fire;} |
991f489b-a24b-4303-b364-f11e8a90207f | public void setScore (int sc) {score += sc;} |
2ac9d3e3-b9be-40e8-9e8c-cb4ba04f23b2 | public boolean isDead () {return lives <= 0;} |
61a029b9-c404-4378-874e-675beba9e84f | public boolean isRecovering () {return recovering;} |
60bd7093-007c-4267-b1d7-ff02ffe70c95 | public int getLives () {return lives;} |
c324a5f4-08e4-4121-a360-be3f85636fcf | public int getPower () {return power;} |
a3495022-47c1-4ec4-884d-552ed28743e0 | public int getPowerLevel () {return powerLevel;} |
d2950a10-53f5-4935-8d6d-82f36081d721 | public int getR () {return r;} |
267664af-8134-4f7a-ab3f-a9b127d79cf1 | public int getRequiredPower () {return requiredPower[powerLevel];} |
3a4968e3-0058-46a9-92f6-9598dc669db8 | public int getScore () {return score;} |
04615a5a-0d9a-4381-becd-e1c29d37eda2 | public int getX () {return x;} |
5f07bd4d-9df7-49eb-bbdb-7200f25a4017 | public int getY () {return y;} |
ce0c9133-01c6-4585-86fe-1076173f947b | public void loseLife () {
lives--;
recovering = true;
recoveryTimer = System.nanoTime();
} |
08905ef7-7510-431a-832c-0ed911240428 | public void increasePower (int pwr) {
if (power < 6) {
power += pwr;
if (power >= requiredPower[powerLevel]) {
power -= requiredPower[powerLevel];
powerLevel++;
}
}
} |
c23ae9f3-58ed-424e-8adc-cac859dad8df | public PowerUp (int type, double x, double y) {
this.type = type;
this.x = x;
this.y = y;
if (type == 1) {
if (imgLife == null) imgLife = new Generals().loadImg("/img/features/life.png");
r = 3;
}
if (type == 2) {
color = Color.WHITE;
r = 4;
}
if (type == 3) {
if (imgPower2 == null) imgP... |
d796ff22-19d1-42e7-a7bd-05ec076d8e48 | public double getX () {return x;} |
0b32f278-631b-45be-8abd-109b09ce6933 | public double getY () {return y;} |
f7dcd321-9958-4e33-b388-8a66b88c1f44 | public double getR () {return r;} |
06d00721-7b6e-4682-a475-14786d617a0c | public int getType () {return type;} |
5c849813-009e-42ab-aaa0-2f59d51a4b00 | public boolean update () {
y += 2;
if (y > SpacePanel.height + r) return true;
return false;
} |
85018e2a-e7d1-4867-a453-f488e8addcdb | public void draw (Graphics2D g) {
if (type == 1) {
g.drawImage(imgLife, (int) (x - r), (int) (y - r), null);
} else
if (type == 3) {
g.drawImage(imgPower2, (int) (x - r), (int) (y - r), null);
} else {
g.setColor(color);
g.fillRect((int) (x - r), (int) (y - r), 2 * r, 2 * r);
g.setStroke(new Ba... |
851adb12-095a-43ea-9f82-6567945b30a3 | public BufferedImage loadImg (String urlName) {
try {
URL url = getClass().getResource(urlName);
BufferedImage img = ImageIO.read(url);
return img;
} catch (Exception e) {
System.out.println("Error " + e.getMessage());
return null;
}
} |
16853b04-a156-4c85-8f28-a8f907b6d137 | public SpacePanel () {
super();
setPreferredSize(new Dimension(width, height));
setFocusable(true);
requestFocus();
} |
a206fb18-39fd-4e31-8a3f-4ef4eafb8422 | public void addNotify () {
super.addNotify();
// Thread to start our game
if (thread == null) {
thread = new Thread(this);
thread.start();
}
addKeyListener(this);
} |
3033886e-a6aa-4c0c-a135-b14ee54decff | public void run () {
running = true;
if (imgPlayer == null) imgPlayer = new Generals().loadImg("/img/hero/hero-up-transp.png");
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
g = (Graphics2D) image.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE... |
058c6b09-c3a2-486d-9d2c-37f9825623d3 | private void createNewEnemies () {
enemies.clear();
Enemy e;
if (waveNumber >= 1 && waveNumber <= 4) {
for (int i = 0; i < waveNumber; i++)
enemies.add(new Enemy(1, 1));
for (int i = 0; i < 3; i++)
enemies.add(new Enemy(1, waveNumber));
}
if (waveNumber >= 5 && waveNumber <= 8) {
for (int ... |
800bc7b7-9ad9-47f9-9b0b-c76a78c1cb10 | private void gameUpdate() {
if (waveStartTimer == 0 && enemies.size() == 0) {
waveNumber++;
waveStart = false;
waveStartTimer = System.nanoTime();
} else {
waveStartTimerDiff = (System.nanoTime() - waveStartTimer) / 1000000;
if (waveStartTimerDiff > waveDelay) {
waveStart = true;
waveStartTim... |
03e62cf3-20b9-44ae-a386-eb55c0b49eeb | private void gameRender() {
// Drawing da background of our game
g.drawImage(image, 0, 0, null);
if (waveNumber >= 1 && waveNumber <= 4)
bk = background1;
if (waveNumber >= 5 && waveNumber <= 8)
bk = background2;
if (waveNumber >= 9 && waveNumber <= 12)
bk = background3;
if (waveNumber >= 13... |
d835f9cb-9ee3-4e9f-9206-cb8b9249634c | private void gameDraw() {
Graphics g2 = this.getGraphics();
g2.drawImage(image, 0, 0, null);
g2.dispose();
} |
531c32c4-84bd-44de-b5dc-cb74c6d5e537 | public void keyPressed (KeyEvent e) {
int keyCode = e.getKeyCode();
// When R|r key is pressed I need to restart the application, not yet
// Ctrl key value = 17 R|r key value = 82
if (keyCode == 17)
keyControl = true;
else
if (keyControl && keyCode == 82)
keyControl = false;
// When R|r key... |
d3b27300-731c-46e7-b3cb-5839b05a64a8 | public void keyReleased (KeyEvent e) {
int keyCode = e.getKeyCode();
if (keyCode == 27) System.exit(0);
if (keyCode == KeyEvent.VK_LEFT) player.setLeft(false);
if (keyCode == KeyEvent.VK_RIGHT) player.setRigth(false);
if (keyCode == KeyEvent.VK_UP) player.setUp(false);
if (keyCode == KeyEvent.VK_DOWN) play... |
7cd7a94a-236f-4627-b453-42058d4c3641 | public void keyTyped (KeyEvent e) {} |
082b0203-78f0-4c20-89a3-19f0d4c07fb6 | private String readScoreFile (String srcFile) {
String line = null;
try {
flFile = new File(srcFile);
frRead = new FileReader(flFile);
brRead = new BufferedReader(frRead);
line = brRead.readLine();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (null != frRead) {
... |
8fc13122-8b2d-4aef-a123-2c69deb6e3f8 | public void writeFile (String srcFile, String content) {
try {
outputFile = new PrintWriter(new FileWriter(srcFile), true);
outputFile.print(content);
outputFile.close();
} catch (IOException er) {
System.err.println("Issue");
}
} |
4e94645a-0586-47a7-97b9-b5d876a11fb2 | public Enemy (int type, int rank) {
this.type = type;
this.rank = rank;
// BadAss types and ranks
if (type == 1) {
if (bd1 == null) bd1 = new Generals().loadImg("/img/badass/badAss_1.png");
if (rank == 1) {
speed = 3;
r = 15;
health = 1;
}
if (rank == 2) {
speed = 3;
r = 20;
... |
5c85209a-ffd3-4c02-a5c2-b2f38a2e582a | public double getX () {return x;} |
6a4db79f-c133-4e40-b158-691dd3dcb397 | public double getY () {return y;} |
1551f746-d6e1-4d52-9778-eb856e1e3bf0 | public int getR () {return r;} |
709dd3d0-946e-4064-9e53-8a696dc853c5 | public boolean isDead () {return dead;} |
4ed0cc4f-9ba8-4d69-a104-d7a63ed759fb | public int getType () {return type;} |
165e3436-a643-44e8-8bc1-474c227975df | public int getRank () {return rank;} |
1d404684-d8cc-41a7-ac46-9134d9c7a271 | public void explode () {
if (rank > 1) {
int amount = 0;
if (type == 1) amount = 2;
if (type == 2) amount = 3;
if (type == 3) amount = 4;
if (type == 4) amount = 5;
if (type == 5) amount = 6;
if (type == 6) amount = 8;
if (type == 7) amount = 6;
if (type == 8) amount = 5;
if (type == 9) ... |
c3437332-33bf-48db-b0c2-c0f3338d0543 | public void hit () {
health--;
if (health <= 0) dead = true;
hit = true;
hitTimer = System.nanoTime();
} |
0f37045e-cdd4-43c1-9a4d-c9d3ad734e26 | public void update () {
x += dx;
y += dy;
if (!ready)
if (x > r && x < SpacePanel.width - r && y > r && y < SpacePanel.height - r)
ready = true;
// Bounce
if (x < r && dx < 0) dx = -dx;
if (y < r && dy < 0) dy = -dy;
if (x > SpacePanel.width - r && dx > 0) dx = -dx;
if (y > SpacePanel.height... |
bdede2a0-238a-422c-a581-23b656aaa3e9 | public void draw (Graphics2D g) {
g.drawImage(image, (int) (x - r), (int) (y - r), (int) (r * 2), (int) (r * 1.7), null);
} |
5416a4db-2ffe-4743-b347-a79f69e71afd | public Explosion (double x, double y, int r, int max) {
if (ex == null) ex = new Generals().loadImg("/img/badass/explosion/explosionBoom.png");
this.x = x;
this.y = y;
this.r = r;
this.maxRadius = max;
} |
05b322da-6531-45ae-9ce4-1867cdb0cfe7 | public boolean update () {
r += 2;
if (r >= maxRadius) return true;
return false;
} |
e9047df8-8e35-41c5-8718-2ba579ffa1fd | public void draw (Graphics2D g) {
g.drawImage(ex, (int) (x - r), (int) (y - r), 75, 75, null);
} |
bb314e43-bbe5-4195-a07d-69047b1e8578 | public Bullet (double angle, int x, int y) {
this.x = x;
this.y = y;
r = 5;
rad = Math.toRadians(angle);
speed = 10;
dx = Math.cos(rad) * speed;
dy = Math.sin(rad) * speed;
color = Color.YELLOW;
} |
39978bbc-94f7-4bf6-bb0e-54056a9bcc0d | public boolean update () {
x += dx;
y += dy;
// Validating if let frame
if (x < -r || x > SpacePanel.width + r || y > SpacePanel.height + r)
return true;
return false;
} |
ad1b9f14-496c-4e64-90f5-4b238fe2bb86 | public void draw (Graphics2D g) {
g.setColor(color);
g.fillOval((int) (x - r) - 10, (int) (y - r) - 15, 2 * r, 2 * r);
} |
d836a62a-9779-4965-86dd-2a5415c7f0be | public double getX () {return x;} |
9ac35777-78b2-4436-ad04-de6a639dfbfc | public double getY () {return y;} |
7adfb862-d828-4e38-a8ac-645beb487418 | public double getR () {return r;} |
e7f536c7-11b0-4b9d-b947-7ade0fcf26ee | public void setInput(int [] givenIP){
this.inputArray= new int[givenIP.length];
for(int i=0; i<givenIP.length;i++)
{ inputArray[i] = givenIP[i];}
} |
8a666813-24d8-46ca-a4d3-3ce2ed32b9df | public int[] getInput(){
return this.inputArray;
} |
dd60bca2-52b4-4a9e-90e3-599f85fb0396 | public boolean isValidArr(int[] givenArr){
if(givenArr==null)
{return false;}
if(givenArr.length < 1)
{return false;}
return true;
} |
988fb882-129f-4f3f-9385-870fcd7c743b | public static void main(String[] args){
// TODO Auto-generated method stub
CodesTest o_tc = new CodesTest();
int [] arr = {1,-2,-3,-4,-5,2,3,4,5};
// Count Distinct Absolute Value
if(new CodesTest().isValidArr(arr))
{System.out.println("Distint Abs Value in arr is " + new CountDistinctABSValue().getOu... |
784ebb06-420d-4f7c-b9bb-6cf3041483d5 | public int findEquilibrium( int[] arr, int n)
{
if (n==0)
{return -1;}
long sum = 0;
int i;
for(i=0;i<n;i++) sum+=(long ) arr[i];
long sum_left = 0;
for(i=0;i<n;i++) {
long sum_right = sum - sum_left - (long ) arr[i];
if (sum_left == sum_right)... |
713e8950-8021-4e84-8e1e-7b8a1d2e1df2 | public int getNumOfEvenPairs(int[] givenArr)
{
if (givenArr == null || givenArr.length < 2) {
return 0;
}
int evenNumbersCount = 0;
int oddNumberCount = 0;
for (int nelement : givenArr) {
if (nelement % 2 == 0) {
evenNumbersCount++;
} else {
oddNumberCount++;
}
... |
69bb7c94-5083-4664-a7d9-ad93831df7b3 | public int getBinaryGap(int number)
{
int previous = 0;
int current = 0;
int longest = 0;
if(number<0)
{System.out.println("Please Enter a positive number."); return 0;}
do{
previous= number & 1;
number = number>>1;
if(previous==0)
{current++;}
... |
9cd9f983-f31c-4161-b95f-6995296ae3ff | public int getDominator(int[] givenInput){
if(givenInput == null)
{System.out.println("The object is null"); return -1;}
if(givenInput.length<1)
{System.out.println("Invalid Data"); return -1;}
if(givenInput.length==1)
{return 1;}
... |
12120e8f-8f22-4de6-931f-bfc6194da720 | public CountDistinctABSValue() {
// TODO Auto-generated constructor stub
count = 0;
} |
51cef3f0-9a9c-42d8-9c7b-208ea7109231 | public int getOutput(int [] givenInput)
{
if(givenInput == null)
{System.out.println("Please Enter some variables Sir."); return -1;}
if(givenInput.length<1)
{System.out.println("Please Enter some variables Sir."); return -1; }
if(givenInput.length < 2)
{count+=1; return count;}
HashSet<Integer>... |
c2f3b7bc-e2d6-42c5-9dd2-27e285fb44e8 | @Before
public void init() {
data = new double[SIZE];
theSort = new InsertionSort(data);
} |
38914747-020e-444f-bf16-e703a9c21b1a | @Before
public void init() {
double[] data = { 3, 2, 7, 5, 11, 1, 6 };
theSort = new HeapSort(data);
} |
15ec26c6-5a5b-4f36-be0e-c29428ab383d | @Test
public void actuallySortedTest() {
swapList = theSort.sort();
ArrayList<Double> theSortedData = theSort.getData();
Collections.sort(theSortedData);
LinkedList<Swap> trueSwaps = new LinkedList<Swap>();
trueSwaps.add(new Swap(1, 4));
trueSwaps.add(new Swap(0, 1));
trueSwaps.add(new Swap(1, 3))... |
9b667ba5-10a4-4d2d-b49b-db8bca900da0 | private Swap sw(int start, int end) {
return new Swap(start, end);
} |
131c4f84-3cc9-44d6-a466-a1df3ef643ab | private <T extends Collection<Swap>> void checkCollection(String message, T set, Swap ... swaps) {
System.out.println(message);
assertEquals("Collection had wrong length, got " + set, swaps.length, set.size());
for (Swap s: swaps) {
assertTrue("Expected " + s + " in collection, got " + set, set.contains(s));... |
24eea1d8-f47a-4ee4-9f36-1061d8e555e4 | @Test
public void testBubbleSortSwap() {
BubbleSort bs = new BubbleSort(8, 6, 7, 3);
checkCollection("checking bubblesort...", bs.sort(), sw(0, 1), sw(1, 2), sw(2, 3), sw(1, 2), sw(0, 1));
} |
ea159322-ed3c-4109-9646-aa34199745d0 | @Test
public void testSwapEquals(){
assertEquals(sw(0, 1), sw(0, 1));
assertEquals(sw(0, 1), sw(1, 0));
} |
b895b346-ec55-4e83-8c55-7dbe598296c2 | @Test
public void testInsertionSortSwap() {
InsertionSort is = new InsertionSort(8, 6, 7, 3);
checkCollection("checking Insertionsort...", is.sort(), sw(0, 1), sw(1, 2), sw(2, 3), sw(1, 2), sw(0, 1));
} |
4a80d880-c8fd-455c-a5f3-56cbc7526d73 | @Test
public void testZeroSwapBubbleSort() {
BubbleSort bs = new BubbleSort();
checkCollection("bubblesort zero...", bs.sort());
} |
55fe7dba-5d32-495d-932e-a90512d47a10 | @Test
public void testZeroSwapInsertionSort() {
InsertionSort is = new InsertionSort();
checkCollection("Insertionsort zero...", is.sort());
} |
b81a9489-972f-4739-8dda-9689d21fbe17 | @Test
public void testOneSwapBubbleSort() {
BubbleSort bs = new BubbleSort(1);
checkCollection("bubblesort zero...", bs.sort());
} |
4fe4c3b7-55d1-49c4-a7ce-eb97dc88e6d2 | @Test
public void testOneSwapInsertionSort() {
InsertionSort is = new InsertionSort(1);
checkCollection("Insertionsort zero...", is.sort());
} |
1194f497-dc04-4fa6-b065-7679b1571940 | public abstract LinkedList<Swap> sort(); |
8753bd68-bca5-4f25-a244-2b14f6085831 | public abstract String getName(); |
c11b1926-0e7b-4943-97e9-121bbe5b0b80 | public Sorter(double ... data){
this.data = new ArrayList<Double>();
for (double i: data) this.data.add(i);
scrambledData= (ArrayList<Double>)this.data.clone();
this.swapList = new LinkedList<Swap>();
} |
fe6ac450-f821-451a-9ec1-a70b0e801faf | @Override
public abstract Object clone(); |
97ad76d5-b24d-4b8b-8084-0a2b2d202f13 | public void setData(ArrayList<Double> data) {
this.data.clear();
this.data = data;
scrambledData= (ArrayList<Double>)data.clone();
} |
c84a4069-2dfe-4350-b141-a65f9d3aa4cf | public Sorter(ArrayList<Double> data){
this.data = data;
this.swapList = new LinkedList<Swap>();
} |
e614ce32-b56b-409d-84bf-94293150f65b | protected void doSwap(int loc1, int loc2) {
swapList.add(new Swap(loc1, loc2));
Collections.swap(data, loc1, loc2);
} |
8de51a8e-c8c3-466f-8d79-c9eea77c2bdf | public ArrayList<Double> getData() {
return new ArrayList<Double>(data);
} |
9f1acbf6-e956-4c22-a07d-d81cb5a3f864 | public void draw(int leftX, int upperY, int height, int width, Graphics g){
int widthRect = (int) (width)/scrambledData.size();
for(int i = 0; i<scrambledData.size(); i++){
double curPoint = (double)scrambledData.get(i);
if(curSwap != null && (curSwap.getStart() == i || curSwap.getEnd() == i)){
g.setColor... |
126810f3-508d-4791-863f-aad60bc82988 | public boolean nextStep(){
if(!swapList.isEmpty()){
curSwap = swapList.pop();
Collections.swap(scrambledData, curSwap.getStart(), curSwap.getEnd());
return true;
}else{
curSwap=null;
return false;
}
} |
e7247667-d278-4286-b806-d189c713c624 | public QuickSort(double ... data){
super(data);
} |
25e27834-ac56-4f55-ad40-75a0c6d63f58 | public QuickSort(ArrayList<Double> data){
super(data);
} |
a0918fd5-2cd6-4e43-82f7-dae96b1c57ac | @Override
public LinkedList<Swap> sort() {
sort(0, data.size()-1);
return swapList;
} |
3654cc5d-3640-4db9-8b18-4da5c0dcd697 | private int partition(int less, int greater, int pivot) {
Double pivotValue = data.get(pivot);
int newPivot;
doSwap(pivot, greater);
int curIndex = less;
for(int i = less; i < greater; i++){
if(data.get(i) < pivotValue) {
doSwap(i, curIndex);
curIndex++;
}
}
doSwap(curIndex, greater);
retu... |
2e3ac1f2-4595-4540-adaf-9593d4cc2226 | public void sort(int less, int greater) {
int pivot;
if(less < greater) {
pivot = less;
int newPivot = partition(less, greater, pivot);
sort(less, newPivot - 1);
sort(newPivot + 1, greater);
}
} |
83edbb2a-6279-490e-bdaf-e991f8b6178c | @Override
public String getName() {
return "Quick Sort";
} |
dc42076e-8e8f-42f9-a580-9a70f34a9823 | @Override
public Object clone() {
Sorter out = new QuickSort((ArrayList<Double>)getData().clone());
out.swapList = (LinkedList<Swap>) swapList.clone();
out.scrambledData = (ArrayList<Double>) scrambledData.clone();
return out;
} |
7aad5041-cfec-42ac-b2e7-fe1e29f052a9 | public String getName() {
return "Insertion Sort";
} |
f424ba80-0305-4bc6-8d86-aa43c194d06a | public InsertionSort(double ... data){
super(data);
} |
46cdb0ad-5308-415f-b89c-d7ee833e9627 | public InsertionSort(ArrayList<Double> data){
super(data);
} |
28324c44-9fc5-4fea-8e06-f86614300992 | public LinkedList<Swap> sort(){
for(int i = 1; i < data.size(); i++){
for(int j = i; j > 0; j--){
if(data.get(j) > data.get(j-1)){
break;
}
doSwap(j, j-1);
}
}
return swapList;
} |
da80fd19-d8fe-4475-a49c-d570d53ad499 | @Override
public Object clone() {
Sorter out = new InsertionSort((ArrayList<Double>)getData().clone());
out.swapList = (LinkedList<Swap>) swapList.clone();
out.scrambledData = (ArrayList<Double>) scrambledData.clone();
return out;
} |
b4d71f8b-0f0d-4a86-aa95-1e4d2263c412 | public Swap(int start, int end) {
super();
this.start = start;
this.end = end;
} |
e2607314-0aa7-43d8-bd1f-071c4fa3e9a7 | public int getStart() {
return start;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.