Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@

public class FizzBuzz {

public String fizzBuzz(int i) {
public static void main(String[] args) {

System.out.println("Stage 1: ");

for(int i = 1; i <= 100; i++) {
System.out.print(fizzBuzz(i)+", ");
}

System.out.println("\nStage 2: ");

for(int i = 1; i <= 100; i++) {
System.out.print(fizzBuzz2(i)+", ");
}
}

public static String fizzBuzz(int i) {
String s = "";

NumberWordCorrelation[] correlations = {
Expand All @@ -24,7 +39,7 @@ public String fizzBuzz(int i) {
return s;
}

public String fizzBuzz2(int i) {
public static String fizzBuzz2(int i) {
String s = "";

NumberWordCorrelation[] correlations = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
package code._2_challenge._2_foobarqix;

public class FooBarQix {
public String compute(int i) {

public static void main(String[] args) {

System.out.println("Stage 1: ");

for(int i = 1; i <= 100; i++) {
System.out.println(i+" => "+compute(i));
}

System.out.println("\nStage 2: ");

for(int i = 1; i <= 100; i++) {
System.out.println(i+" => "+compute(i));
}
}

public static String compute(int i) {
String s = "";
if (i % 3 == 0) s += "Foo";
if (i % 5 == 0) s += "Bar";
Expand All @@ -22,7 +38,7 @@ public String compute(int i) {
return s;
}

public String compute2(int i) {
public static String compute2(int i) {
String s = "";

boolean isDivisible = false;
Expand Down
2 changes: 1 addition & 1 deletion _1_basics/src/main/java/code/_3_in_class/HelloWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public class HelloWorld {

public static void main(String[] args) {
System.out.println("hello world 2");
System.out.println("hello world test github");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,24 @@ public ChessBoard() {
}

public void Add(Pawn pawn, int xCoordinate, int yCoordinate, PieceColor pieceColor) {
throw new UnsupportedOperationException("Need to implement ChessBoard.add()");
try {
pawn.setPieceColor(pieceColor);
} catch (UnsupportedOperationException e) {System.out.println("Color invalid");}

try {
pawn.setChessBoard(this);
pawn.setYCoordinate(yCoordinate);
pawn.setXCoordinate(xCoordinate);

pieces[xCoordinate][yCoordinate] = pawn;

} catch(ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) {
pawn.setYCoordinate(-1);
pawn.setXCoordinate(-1);
}
}

public boolean IsLegalBoardPosition(int xCoordinate, int yCoordinate) {
throw new UnsupportedOperationException("Need to implement ChessBoard.IsLegalBoardPosition()");
return xCoordinate <= 7 && yCoordinate <= 7 && xCoordinate >= 0 && yCoordinate >= 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ public PieceColor getPieceColor() {
return this.pieceColor;
}

private void setPieceColor(PieceColor value) {
public void setPieceColor(PieceColor value) {
pieceColor = value;
}

public void Move(MovementType movementType, int newX, int newY) {
throw new UnsupportedOperationException("Need to implement Pawn.Move()");
if(movementType == MovementType.MOVE){
if(newY == getYCoordinate()+1 && newX == getXCoordinate() ){
setYCoordinate(newY);
} else if(newY == getYCoordinate()-1 && newX == getXCoordinate() ){
setYCoordinate(newY);
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void testIsLegalBoardPosition_True_X_equals_5_Y_equals_5() {
@Test
public void testIsLegalBoardPosition_False_X_equals_11_Y_equals_5() {
boolean isValidPosition = testSubject.IsLegalBoardPosition(11, 5);
assertTrue(isValidPosition);
assertFalse(isValidPosition);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package clean.code.design_patterns.requirements;

public class Bow implements Weapon {
@Override
public void shoot() {
GameScore gameScore = GameScore.getInstance();
gameScore.AddScore(5);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package clean.code.design_patterns.requirements;

public class GameScore {
private int score = 0;
private static final GameScore instance = new GameScore();

private GameScore() {
this.score = 0;
}

public static GameScore getInstance() {
return instance;
}

public int getScore() {
return score;
}

public void AddScore(int valueToAdd) {
this.score += valueToAdd;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package clean.code.design_patterns.requirements;

public class Gun implements Weapon {
@Override
public void shoot() {
GameScore gameScore = GameScore.getInstance();
gameScore.AddScore(15);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,52 @@
package clean.code.design_patterns.requirements;
import java.util.Scanner;
//Singleton Design Pattern pentru GameScore
//Composite Pattern pentru Weapon, Bow, Pistol, Gun si Shooting

//Clasele se pot aplica in anumite jocuri indie cu un singur player care are un singur scor/joc (singleton) si in
//functie de arma aleasa pentru a efectua o actiune scorul este modificat corespunzator

public class Main {

public static void main(String[] args) {
//TODO implement your design patterns in this package
Scanner console = new Scanner(System.in);

Weapon bow = new Bow();
Weapon pistol = new Pistol();
Weapon gun = new Gun();

Shooting shooting = new Shooting();

GameScore gameScore = GameScore.getInstance();
System.out.println("Your initial score is: " + gameScore.getScore());

String chooseWeapon;


label:
while(true) {
System.out.println("Choose your weapon by writing 'bow', 'pistol', 'gun' or something else if you want to finish");
chooseWeapon = console.nextLine();

switch (chooseWeapon) {
case "bow":
shooting.add(bow);
break;
case "pistol":
shooting.add(pistol);
break;
case "gun":
shooting.add(gun);
break;
default:
break label;
}

}

shooting.shoot();
System.out.println("Your score is: " + gameScore.getScore());

}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package clean.code.design_patterns.requirements;

public class Pistol implements Weapon {
@Override
public void shoot() {
GameScore gameScore = GameScore.getInstance();
gameScore.AddScore(10);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package clean.code.design_patterns.requirements;

import java.util.ArrayList;
import java.util.List;

public class Shooting implements Weapon {
private List<Weapon> weapons = new ArrayList<>();

public void add(Weapon w) {
this.weapons.add(w);
}

@Override
public void shoot() {
for (Weapon wp : weapons) {
wp.shoot();
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package clean.code.design_patterns.requirements;

public interface Weapon {
void shoot();
}