Skip to content
Snippets Groups Projects
Commit 9edd3303 authored by mva021's avatar mva021
Browse files

Code after lecture 16

parent dc77d3fa
Branches master
No related tags found
No related merge requests found
Pipeline #122877 failed
package lecture16;
public class Feilmeldinger {
public static void main(String[] args) {
//nullPointer();
//indexOutOfBounds();
printReverse("Martin");
printReverse("");
}
private static void printReverse(String string) {
if(string.length()==1)
System.out.print(string);
else {
printReverse(string.substring(1));
System.out.print(string.charAt(0));
}
}
private static void indexOutOfBounds() {
int[] tall = new int[]{1,2,3,4};
for(int i=1; i<=4; i++) {
System.out.println(tall[i]);
}
}
private static void nullPointer() {
String name = null;
int tall = 42;
if(tall>42) {
name = "Martin";
}
for(int i=0; i<name.length(); i++)
System.out.println(name.charAt(i));
}
}
package lecture16;
public interface Game {
boolean isOver();
Player getCurrentPlayer();
boolean isValid(Move move);
void makeMove(Move move);
}
package lecture16;
public class GameLoop {
public void run(Game game){
while(!game.isOver()) {
Player player = game.getCurrentPlayer();
Move move = player.getMove(game);
if(game.isValid(move)) {
game.makeMove(move);
}
else
System.out.println("InvalidMove");
}
}
}
package lecture16;
public class Move {
}
package lecture16;
public interface Player {
public Move getMove(Game game);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment