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
164 changes: 164 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,168 @@ tests/out
.idea
.DS_Store
.*
# Created by https://www.toptal.com/developers/gitignore/api/intellij,maven,java
# Edit at https://www.toptal.com/developers/gitignore?templates=intellij,maven,java

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/

# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml

# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/

# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/$CACHE_FILE$

# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml

# Azure Toolkit for IntelliJ plugin
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
.idea/**/azureSettings.xml

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar

# Eclipse m2e generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath

*/target/*
# End of https://www.toptal.com/developers/gitignore/api/intellij,maven,java

!.gitignore
16 changes: 16 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.machinecoding</groupId>
<artifactId>machineCoding-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
<module>snakeAndLadder</module>
<module>splitWise</module>
</modules>
</project>
34 changes: 34 additions & 0 deletions snakeAndLadder/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.machinecoding</groupId>
<artifactId>machineCoding-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>snakeAndLadder</artifactId>

<properties>
<maven.compiler.source>23</maven.compiler.source>
<maven.compiler.target>23</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.0.0</version> <!-- Use the latest stable version -->
<scope>test</scope>
</dependency>
</dependencies>
</project>
41 changes: 41 additions & 0 deletions snakeAndLadder/src/main/java/org/machinecoding/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.machinecoding;

import org.machinecoding.models.Board;
import org.machinecoding.services.GameController;
import org.machinecoding.models.Dice;
import org.machinecoding.models.Player;
import org.machinecoding.models.teleports.Ladder;
import org.machinecoding.models.teleports.Snake;
import org.machinecoding.models.teleports.TeleporterEntity;

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

public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int targetCell = 100;

int numSnakes = scan.nextInt();
List<TeleporterEntity> teleporterList = new ArrayList<>();
for (int i = 0; i < numSnakes; i++)
teleporterList.add(new Snake(scan.nextInt(), scan.nextInt()));

int numLadder = scan.nextInt();
for (int i = 0; i < numLadder; i++)
teleporterList.add(new Ladder(scan.nextInt(), scan.nextInt()));

int numPlayers = scan.nextInt();
List<Player> playerList = new ArrayList<>();
for (int i = 0; i < numPlayers; i++)
playerList.add(new Player(scan.next(), 0, targetCell));

List<Dice> diceList = new ArrayList<>();
diceList.add(new Dice());

GameController gameController = new GameController(new Board(targetCell),
teleporterList, playerList, diceList);
gameController.start();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.machinecoding.models;

public class Board {
private int cells;

public Board(int cells) { this.cells = cells; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.machinecoding.models;

public class Dice {
public int roll() {
return (int) (Math.random() * 6) + 1;
}
}
29 changes: 29 additions & 0 deletions snakeAndLadder/src/main/java/org/machinecoding/models/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.machinecoding.models;

public class Player {
private final String name;
private int position;
private final int targetPosition;

public Player(String name, int startPosition, int targetPosition){
this.name = name;
this.position = startPosition;
this.targetPosition = targetPosition;
}

public void move(int newPosition){
this.position = (newPosition > targetPosition) ? position : newPosition;
}

public boolean isWinner(){
return (position == targetPosition);
}

public int getPosition(){
return position;
}

public String getName(){
return name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.machinecoding.models.teleports;

public class Ladder extends TeleporterEntity {
public Ladder(int startCell, int endCell) {
super(startCell, endCell);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.machinecoding.models.teleports;

public class Snake extends TeleporterEntity {
public Snake(int startCell, int endCell) {
super(startCell, endCell);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.machinecoding.models.teleports;

public interface Teleporter {
boolean canBeUsed(int currentPosition);
int teleport();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.machinecoding.models.teleports;

public class TeleporterEntity implements Teleporter {
private final int startCell;
private final int endCell;

public TeleporterEntity(int startCell, int endCell){
this.startCell = startCell;
this.endCell = endCell;
}

@Override
public boolean canBeUsed(int currentPosition) {
return (startCell == currentPosition);
}

@Override
public int teleport() {
return endCell;
}

public int getStartCell() {
return startCell;
}

public int getEndCell() {
return endCell;
}
}
Loading