$
1
app/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
@ -3,11 +3,11 @@ plugins {
|
||||
}
|
||||
|
||||
android {
|
||||
namespace 'com.example.tamere'
|
||||
namespace 'com.example.jmastermind'
|
||||
compileSdk 33
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.example.tamere"
|
||||
applicationId "com.example.jmastermind"
|
||||
minSdk 19
|
||||
targetSdk 33
|
||||
versionCode 1
|
||||
@ -26,7 +26,7 @@ android {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
buildToolsVersion '33.0.1'
|
||||
buildToolsVersion '33.0.0'
|
||||
}
|
||||
|
||||
dependencies {
|
@ -1,4 +1,4 @@
|
||||
package com.example.tamere;
|
||||
package com.example.jmastermind;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
@ -21,6 +21,6 @@ public class ExampleInstrumentedTest {
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
assertEquals("com.example.tamere", appContext.getPackageName());
|
||||
assertEquals("com.example.jmastermind", appContext.getPackageName());
|
||||
}
|
||||
}
|
@ -1,30 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.Tamere"
|
||||
tools:targetApi="31">
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".GameRobot"
|
||||
android:exported="true">
|
||||
</activity>
|
||||
</application>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.JMastermind"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".Game.SoloGame"
|
||||
android:exported="true">
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
10
app/src/main/java/com/example/jmastermind/Deck/Deck.java
Normal file
@ -0,0 +1,10 @@
|
||||
package com.example.jmastermind.Deck;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Deck {
|
||||
public abstract List<Integer> getDeck();
|
||||
public abstract String displayComb();
|
||||
}
|
100
app/src/main/java/com/example/jmastermind/Deck/DeckCheck.java
Normal file
@ -0,0 +1,100 @@
|
||||
package com.example.jmastermind.Deck;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class DeckCheck implements Deck {
|
||||
private List<Integer> deck;
|
||||
private Deck lambda;
|
||||
private Deck winner;
|
||||
|
||||
public DeckCheck(Deck lambda, Deck winner) {
|
||||
this.deck = new LinkedList<>();
|
||||
this.lambda = lambda;
|
||||
this.winner = winner;
|
||||
}
|
||||
|
||||
public Deck doCheck() {
|
||||
this.deck = new LinkedList<>();
|
||||
List<Integer> winner = this.winner.getDeck();
|
||||
List<Integer> lambda = this.lambda.getDeck();
|
||||
|
||||
for(int i = 0; i <= winner.size()-1; i++) {
|
||||
Integer win = winner.get(i);
|
||||
Integer lam = lambda.get(i);
|
||||
|
||||
if(Objects.equals(win, lam)) {
|
||||
this.deck.add(Color.BLACK);
|
||||
} else {
|
||||
if(winner.contains(lam)) {
|
||||
this.deck.add(Color.WHITE);
|
||||
} else {
|
||||
this.deck.add(Color.GRAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Deck check = new DeckLambda(
|
||||
this.deck.get(0),
|
||||
this.deck.get(1),
|
||||
this.deck.get(2),
|
||||
this.deck.get(3)
|
||||
);
|
||||
|
||||
return check;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getDeck() {
|
||||
return this.deck;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String displayComb() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for(int i = 0; i <= this.deck.size()-1; i++) {
|
||||
switch(this.deck.get(i)) {
|
||||
case Color.BLACK: {
|
||||
sb.append("Noir").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.WHITE: {
|
||||
sb.append("Blanc").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.GRAY: {
|
||||
sb.append("Gris").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.GREEN: {
|
||||
sb.append("Vert").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.RED: {
|
||||
sb.append("Rouge").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.YELLOW: {
|
||||
sb.append("Jaune").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.BLUE: {
|
||||
sb.append("Bleu").append(", ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package com.example.jmastermind.Deck;
|
||||
|
||||
import android.graphics.Color;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeckLambda implements Deck{
|
||||
List<Integer> deck;
|
||||
|
||||
public DeckLambda(Integer c1, Integer c2, Integer c3, Integer c4) {
|
||||
this.deck = new LinkedList<>();
|
||||
this.deck.add(c1);
|
||||
this.deck.add(c2);
|
||||
this.deck.add(c3);
|
||||
this.deck.add(c4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getDeck() {
|
||||
return this.deck;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String displayComb() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for(int i = 0; i <= this.deck.size()-1; i++) {
|
||||
switch(this.deck.get(i)) {
|
||||
case Color.BLACK: {
|
||||
sb.append("Noir").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.WHITE: {
|
||||
sb.append("Blanc").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.GREEN: {
|
||||
sb.append("Vert").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.RED: {
|
||||
sb.append("Rouge").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.YELLOW: {
|
||||
sb.append("Jaune").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.BLUE: {
|
||||
sb.append("Bleu").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.GRAY: {
|
||||
sb.append("Gris").append(", ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.example.jmastermind.Deck;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class DeckWinner implements Deck{
|
||||
List<Integer> deck;
|
||||
|
||||
public DeckWinner(Integer c1, Integer c2, Integer c3, Integer c4) {
|
||||
this.deck = new LinkedList<>();
|
||||
this.deck.add(c1);
|
||||
this.deck.add(c2);
|
||||
this.deck.add(c3);
|
||||
this.deck.add(c4);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getDeck() {
|
||||
return this.deck;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String displayComb() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for(int i = 0; i <= this.deck.size()-1; i++) {
|
||||
switch(this.deck.get(i)) {
|
||||
case Color.BLACK: {
|
||||
sb.append("Noir").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.WHITE: {
|
||||
sb.append("Blanc").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.GREEN: {
|
||||
sb.append("Vert").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.RED: {
|
||||
sb.append("Rouge").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.YELLOW: {
|
||||
sb.append("Jaune").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.BLUE: {
|
||||
sb.append("Bleu").append(", ");
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.GRAY: {
|
||||
sb.append("Gris").append(", ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
package com.example.jmastermind.Events;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.example.jmastermind.Deck.Deck;
|
||||
import com.example.jmastermind.Deck.DeckCheck;
|
||||
import com.example.jmastermind.Deck.DeckLambda;
|
||||
import com.example.jmastermind.Game.Popup;
|
||||
import com.example.jmastermind.Geometrics.Circle;
|
||||
import com.example.jmastermind.R;
|
||||
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class ColorSelectorEvent extends View implements View.OnClickListener {
|
||||
private AppCompatActivity context;
|
||||
/**
|
||||
* [0] = x
|
||||
* [1] = y
|
||||
* */
|
||||
private int[] coords;
|
||||
private Deck winner;
|
||||
private int tentative;
|
||||
|
||||
public ColorSelectorEvent(AppCompatActivity context, Deck winner) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
this.winner = winner;
|
||||
this.coords = new int[]{1, 1};
|
||||
this.tentative = 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int idOfClickedColor = view.getId();
|
||||
Circle circleClicked = (Circle) this.context.findViewById(idOfClickedColor);
|
||||
int colorChoosed = circleClicked.getColor();
|
||||
|
||||
int id = this.context.getResources()
|
||||
.getIdentifier("normalCircle" + this.coords[0] + this.coords[1], "id", this.context.getPackageName());
|
||||
Circle c = this.context.findViewById(id);
|
||||
|
||||
switch(colorChoosed) {
|
||||
case Color.RED: {
|
||||
c.setColor(Color.RED);
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.GREEN: {
|
||||
c.setColor(Color.GREEN);
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.BLUE: {
|
||||
c.setColor(Color.BLUE);
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.YELLOW: {
|
||||
c.setColor(Color.YELLOW);
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.BLACK: {
|
||||
c.setColor(Color.BLACK);
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.WHITE: {
|
||||
c.setColor(Color.WHITE);
|
||||
break;
|
||||
}
|
||||
|
||||
case Color.GRAY: {
|
||||
c.setColor(Color.GRAY);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(this.coords[1] < 4) {
|
||||
this.coords[1]++;
|
||||
}
|
||||
}
|
||||
|
||||
public void goNext() {
|
||||
List<Integer> listOfColors = new LinkedList<>();
|
||||
|
||||
for(int i = 1; i <= 4; i++) {
|
||||
int id = this.context.getResources()
|
||||
.getIdentifier("normalCircle" + this.coords[0] + i, "id", this.context.getPackageName());
|
||||
Circle c = this.context.findViewById(id);
|
||||
|
||||
listOfColors.add(c.getColor());
|
||||
}
|
||||
|
||||
Deck lambda = new DeckLambda(
|
||||
listOfColors.get(0),
|
||||
listOfColors.get(1),
|
||||
listOfColors.get(2),
|
||||
listOfColors.get(3)
|
||||
);
|
||||
|
||||
DeckCheck checker = new DeckCheck(lambda, this.winner);
|
||||
Deck checkerPions = checker.doCheck();
|
||||
List<Integer> checkColors = checkerPions.getDeck();
|
||||
int countOfBlack = 0;
|
||||
|
||||
for(int i = 1; i <= 4; i++) {
|
||||
int id = this.context.getResources()
|
||||
.getIdentifier("checkCircle" + this.coords[0] + i, "id", this.context.getPackageName());
|
||||
Circle c = this.context.findViewById(id);
|
||||
|
||||
c.setColor(checkColors.get(i-1));
|
||||
|
||||
if(checkColors.get(i-1) == Color.BLACK) {
|
||||
countOfBlack++;
|
||||
}
|
||||
}
|
||||
|
||||
if(countOfBlack == 4) {
|
||||
String[] opts = new String[] {
|
||||
"Rejouer",
|
||||
"Voir votre jeu",
|
||||
"Retourner au menu"
|
||||
};
|
||||
|
||||
Popup popup = new Popup(this.context, opts, true, (10 - this.tentative + 1));
|
||||
popup.show();
|
||||
}
|
||||
|
||||
this.tentative--;
|
||||
|
||||
TextView tx = (TextView) this.context.findViewById(R.id.counter);
|
||||
tx.setText("Tentative rest. \n" + this.tentative);
|
||||
tx.invalidate();
|
||||
|
||||
this.coords[1] = 1;
|
||||
this.coords[0]++;
|
||||
}
|
||||
|
||||
public void resetCombi() {
|
||||
for(int i = 1; i <= this.coords[1]; i++) {
|
||||
int id = this.context.getResources()
|
||||
.getIdentifier("normalCircle" + this.coords[0] + i, "id", this.context.getPackageName());
|
||||
Circle c = this.context.findViewById(id);
|
||||
|
||||
c.setColor(Color.GRAY);
|
||||
}
|
||||
|
||||
this.coords[1] = 1;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.example.jmastermind.Events;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.example.jmastermind.Game.Controller;
|
||||
|
||||
public class ControlEvent extends View implements View.OnClickListener {
|
||||
private final AppCompatActivity context;
|
||||
private Controller controller;
|
||||
|
||||
public ControlEvent(AppCompatActivity context, Controller controller) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int idOfButton = view.getId();
|
||||
Button btnClicked = (Button) this.context.findViewById(idOfButton);
|
||||
CharSequence text = btnClicked.getText();
|
||||
|
||||
if ("Valider".equals(text)) {
|
||||
this.controller.viewValidate();
|
||||
} else if ("Effacer".equals(text)) {
|
||||
this.controller.viewReset();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +1,21 @@
|
||||
package com.example.tamere.Events;
|
||||
package com.example.jmastermind.Events;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import com.example.tamere.GameRobot;
|
||||
|
||||
public class MenuEvent implements View.OnClickListener {
|
||||
private Class option;
|
||||
private AppCompatActivity ac;
|
||||
|
||||
public MenuEvent(AppCompatActivity ac) {
|
||||
public MenuEvent(AppCompatActivity ac, Class option) {
|
||||
this.ac = ac;
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent i = new Intent(this.ac, GameRobot.class);
|
||||
Intent i = new Intent(this.ac, this.option);
|
||||
this.ac.startActivity(i);
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.example.jmastermind.Events;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.example.jmastermind.Game.Popup;
|
||||
import com.example.jmastermind.Game.SoloGame;
|
||||
import com.example.jmastermind.MainActivity;
|
||||
|
||||
public class PopupEvent implements DialogInterface.OnClickListener {
|
||||
private AppCompatActivity context;
|
||||
|
||||
public PopupEvent(AppCompatActivity context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
switch(i) {
|
||||
case 0: {
|
||||
Intent a = new Intent(this.context, SoloGame.class);
|
||||
this.context.startActivity(a);
|
||||
break;
|
||||
}
|
||||
|
||||
case 1: {
|
||||
dialogInterface.cancel();
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: {
|
||||
Intent c = new Intent(this.context, MainActivity.class);
|
||||
this.context.startActivity(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.example.jmastermind.Game;
|
||||
|
||||
import android.graphics.Color;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.example.jmastermind.Deck.Deck;
|
||||
import com.example.jmastermind.Deck.DeckWinner;
|
||||
import com.example.jmastermind.Events.ColorSelectorEvent;
|
||||
import com.example.jmastermind.Events.ControlEvent;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Controller {
|
||||
private Vuew vuew;
|
||||
private Model model;
|
||||
private AppCompatActivity context;
|
||||
private ColorSelectorEvent event;
|
||||
private ControlEvent controlEvent;
|
||||
|
||||
public Controller(AppCompatActivity context, int mode) {
|
||||
this.context = context;
|
||||
this.controlEvent = new ControlEvent(this.context, this);
|
||||
|
||||
this.model = new Model(this.context);
|
||||
this.model.init();
|
||||
|
||||
if(mode == 0) {
|
||||
this.model.genWinner();
|
||||
Deck winner = this.model.getWinner();
|
||||
System.out.println(winner.displayComb());
|
||||
this.event = new ColorSelectorEvent(this.context, winner);
|
||||
}
|
||||
|
||||
this.vuew = new Vuew(
|
||||
this.context,
|
||||
this.model.getListOfNormalCircle(),
|
||||
this.model.getListOfCheckCircle(),
|
||||
this.event,
|
||||
this.controlEvent
|
||||
);
|
||||
|
||||
this.vuew.init();
|
||||
}
|
||||
|
||||
public void viewValidate() {
|
||||
this.event.goNext();
|
||||
}
|
||||
|
||||
public void viewReset() {
|
||||
this.event.resetCombi();
|
||||
}
|
||||
}
|
116
app/src/main/java/com/example/jmastermind/Game/Model.java
Normal file
@ -0,0 +1,116 @@
|
||||
package com.example.jmastermind.Game;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.view.View;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import com.example.jmastermind.Deck.DeckWinner;
|
||||
import com.example.jmastermind.Geometrics.Circle;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class Model extends View {
|
||||
private List<Circle> listOfNormalCircle;
|
||||
private List<Circle> listOfCheckCircle;
|
||||
private DeckWinner winner;
|
||||
private AppCompatActivity context;
|
||||
|
||||
public Model(AppCompatActivity context) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
this.listOfNormalCircle = new LinkedList<>();
|
||||
this.listOfCheckCircle = new LinkedList<>();
|
||||
this.winner = null;
|
||||
}
|
||||
|
||||
public void genWinner() {
|
||||
Integer[] color = new Integer[]{0, 0, 0, 0};
|
||||
|
||||
for(int i = 0; i <= 3; i++) {
|
||||
Random rand = new Random();
|
||||
int ran = rand.nextInt(6) + 1;
|
||||
|
||||
switch(ran) {
|
||||
case 1: {
|
||||
color[i] = Color.RED;
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: {
|
||||
color[i] = Color.YELLOW;
|
||||
break;
|
||||
}
|
||||
|
||||
case 3: {
|
||||
color[i] = Color.BLUE;
|
||||
break;
|
||||
}
|
||||
|
||||
case 4: {
|
||||
color[i] = Color.GREEN;
|
||||
break;
|
||||
}
|
||||
|
||||
case 5: {
|
||||
color[i] = Color.WHITE;
|
||||
break;
|
||||
}
|
||||
|
||||
case 6: {
|
||||
color[i] = Color.BLACK;
|
||||
break;
|
||||
}
|
||||
|
||||
case 7: {
|
||||
color[i] = Color.GRAY;
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.winner = new DeckWinner(color[1], color[0], color[2], color[3]);
|
||||
}
|
||||
|
||||
public DeckWinner getWinner() {
|
||||
return this.winner;
|
||||
}
|
||||
|
||||
public Boolean init() {
|
||||
try {
|
||||
for(int i = 1; i <= 10; i++) {
|
||||
for(int j = 1; j <= 4; j++) {
|
||||
int normalId = this.context.getResources().
|
||||
getIdentifier("normalCircle" + i + j, "id", this.context.getPackageName());
|
||||
Circle normal = this.context.findViewById(normalId);
|
||||
|
||||
int checkId = this.context.getResources()
|
||||
.getIdentifier("checkCircle" + i + j, "id", this.context.getPackageName());
|
||||
Circle check = this.context.findViewById(checkId);
|
||||
|
||||
this.listOfNormalCircle.add(normal);
|
||||
this.listOfCheckCircle.add(check);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch(ArrayIndexOutOfBoundsException e) {
|
||||
System.out.println("[!] Probleme lors de l'initiliation du model (ArrayIndexOutOfBoundsException).");
|
||||
return false;
|
||||
} catch(NullPointerException e) {
|
||||
System.out.println("[!] Probleme lors de l'initiliation du model (NullPointerException).");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Circle> getListOfNormalCircle() {
|
||||
return this.listOfNormalCircle;
|
||||
}
|
||||
|
||||
public List<Circle> getListOfCheckCircle() {
|
||||
return this.listOfCheckCircle;
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package com.example.jmastermind.Game;
|
||||
|
||||
public class MultiGame {
|
||||
}
|
23
app/src/main/java/com/example/jmastermind/Game/Popup.java
Normal file
@ -0,0 +1,23 @@
|
||||
package com.example.jmastermind.Game;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import com.example.jmastermind.Events.PopupEvent;
|
||||
|
||||
public class Popup extends AlertDialog.Builder {
|
||||
private AppCompatActivity context;
|
||||
|
||||
public Popup(AppCompatActivity context, String[] options, Boolean isWinner, int tentative) {
|
||||
super(context);
|
||||
|
||||
this.context = context;
|
||||
|
||||
if(isWinner) {
|
||||
this.setTitle("Félicitation ! Vous avez gagner en : " + tentative + " coup(s).");
|
||||
} else {
|
||||
this.setTitle("Perdu !");
|
||||
}
|
||||
|
||||
this.setItems(options, new PopupEvent(this.context));
|
||||
}
|
||||
}
|
17
app/src/main/java/com/example/jmastermind/Game/SoloGame.java
Normal file
@ -0,0 +1,17 @@
|
||||
package com.example.jmastermind.Game;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import com.example.jmastermind.R;
|
||||
|
||||
public class SoloGame extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.game);
|
||||
|
||||
Controller controller = new Controller(this, 0);
|
||||
}
|
||||
}
|
75
app/src/main/java/com/example/jmastermind/Game/Vuew.java
Normal file
@ -0,0 +1,75 @@
|
||||
package com.example.jmastermind.Game;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.widget.Button;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.example.jmastermind.Events.ColorSelectorEvent;
|
||||
import com.example.jmastermind.Events.ControlEvent;
|
||||
import com.example.jmastermind.Geometrics.Circle;
|
||||
import com.example.jmastermind.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Vuew {
|
||||
private ColorSelectorEvent event;
|
||||
private List<Circle> normalCircle;
|
||||
private List<Circle> checkedCircle;
|
||||
private AppCompatActivity context;
|
||||
private ControlEvent controlEvent;
|
||||
|
||||
public Vuew(AppCompatActivity context, List<Circle> normalCircle, List<Circle> checkCircle, ColorSelectorEvent event, ControlEvent controlEvent) {
|
||||
this.context = context;
|
||||
this.normalCircle = normalCircle;
|
||||
this.checkedCircle = checkCircle;
|
||||
this.event = event;
|
||||
this.controlEvent = controlEvent;
|
||||
}
|
||||
|
||||
public Boolean init() {
|
||||
try {
|
||||
Circle yellow = (Circle) this.context.findViewById(R.id.yellow);
|
||||
yellow.setColor(Color.YELLOW);
|
||||
yellow.setOnClickListener(this.event);
|
||||
|
||||
Circle red = (Circle) this.context.findViewById(R.id.red);
|
||||
red.setColor(Color.RED);
|
||||
red.setOnClickListener(this.event);
|
||||
|
||||
Circle green = (Circle) this.context.findViewById(R.id.green);
|
||||
green.setColor(Color.GREEN);
|
||||
green.setOnClickListener(this.event);
|
||||
|
||||
Circle blue = (Circle) this.context.findViewById(R.id.blue);
|
||||
blue.setColor(Color.BLUE);
|
||||
blue.setOnClickListener(this.event);
|
||||
|
||||
Circle gray = (Circle) this.context.findViewById(R.id.gray);
|
||||
gray.setColor(Color.GRAY);
|
||||
gray.setOnClickListener(this.event);
|
||||
|
||||
Circle white = (Circle) this.context.findViewById(R.id.white);
|
||||
white.setColor(Color.WHITE);
|
||||
white.setOnClickListener(this.event);
|
||||
|
||||
Circle black = (Circle) this.context.findViewById(R.id.black);
|
||||
black.setColor(Color.BLACK);
|
||||
black.setOnClickListener(this.event);
|
||||
|
||||
Button validate = (Button) this.context.findViewById(R.id.validate);
|
||||
validate.setOnClickListener(this.controlEvent);
|
||||
|
||||
Button reset = (Button) this.context.findViewById(R.id.reset);
|
||||
reset.setOnClickListener(this.controlEvent);
|
||||
|
||||
return true;
|
||||
} catch(NullPointerException e) {
|
||||
System.out.println("[!] Probleme lors de l'initiliation de la vue (NullPointerException).");
|
||||
return false;
|
||||
} catch(ArrayIndexOutOfBoundsException e) {
|
||||
System.out.println("[!] Probleme lors de l'initiliation de la vue (ArrayIndexOutOfBoundsException).");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,41 +1,42 @@
|
||||
package com.example.tamere.Geometrics;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.view.View;
|
||||
|
||||
public class Circle extends View {
|
||||
private Paint picasso;
|
||||
private int color;
|
||||
private Boolean canModify;
|
||||
|
||||
public Circle(Context context, int color, Boolean canModify) {
|
||||
super(context);
|
||||
this.color = color;
|
||||
this.canModify = canModify;
|
||||
this.picasso = new Paint();
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public void setColor(int c) {
|
||||
if(this.canModify) {
|
||||
this.color = c;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
int centerX = getWidth() / 2;
|
||||
int centerY = getHeight() / 2;
|
||||
int radius = Math.min(centerX, centerY);
|
||||
|
||||
this.picasso.setColor(this.color);
|
||||
canvas.drawCircle(centerX, centerY, radius, this.picasso);
|
||||
}
|
||||
}
|
||||
package com.example.jmastermind.Geometrics;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class Circle extends View {
|
||||
private Paint picasso;
|
||||
private int color;
|
||||
|
||||
public Circle(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
this.color = Color.GRAY;
|
||||
this.picasso = new Paint();
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public void setColor(int c) {
|
||||
this.color = c;
|
||||
this.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
int centerX = getWidth() / 2;
|
||||
int centerY = getHeight() / 2;
|
||||
int radius = Math.min(centerX, centerY);
|
||||
|
||||
this.picasso.setColor(this.color);
|
||||
canvas.drawCircle(centerX, centerY, radius, this.picasso);
|
||||
}
|
||||
}
|
22
app/src/main/java/com/example/jmastermind/MainActivity.java
Normal file
@ -0,0 +1,22 @@
|
||||
package com.example.jmastermind;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Button;
|
||||
import com.example.jmastermind.Events.MenuEvent;
|
||||
import com.example.jmastermind.Game.*;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.menu);
|
||||
|
||||
Button btnSoloGame = (Button) findViewById(R.id.robotselect);
|
||||
btnSoloGame.setOnClickListener(new MenuEvent(this, SoloGame.class));
|
||||
|
||||
Button btnMultiGame = (Button) findViewById(R.id.jcjselect);
|
||||
btnMultiGame.setOnClickListener(new MenuEvent(this, MultiGame.class));
|
||||
}
|
||||
}
|
869
app/src/main/res/layout/game.xml
Normal file
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 982 B After Width: | Height: | Size: 982 B |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 7.6 KiB |
@ -1,6 +1,6 @@
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.Tamere" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<style name="Theme.JMastermind" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<!-- Primary brand color. -->
|
||||
<item name="colorPrimary">@color/purple_200</item>
|
||||
<item name="colorPrimaryVariant">@color/purple_700</item>
|
@ -7,5 +7,4 @@
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
<color name="violetfonce">#C71585</color>
|
||||
</resources>
|
3
app/src/main/res/values/strings.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">JMastermind</string>
|
||||
</resources>
|
@ -1,6 +1,6 @@
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.Tamere" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<style name="Theme.JMastermind" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<!-- Primary brand color. -->
|
||||
<item name="colorPrimary">@color/purple_500</item>
|
||||
<item name="colorPrimaryVariant">@color/purple_700</item>
|
@ -1,4 +1,4 @@
|
||||
package com.example.tamere;
|
||||
package com.example.jmastermind;
|
||||
|
||||
import org.junit.Test;
|
||||
|
Before Width: | Height: | Size: 21 KiB |
@ -1,155 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--Created with JFLAP 7.1.--><structure>
|
||||
<type>fa</type>
|
||||
<automaton>
|
||||
<!--The list of states.-->
|
||||
<state id="0" name="0">
|
||||
<x>75.0</x>
|
||||
<y>123.0</y>
|
||||
<initial/>
|
||||
</state>
|
||||
<state id="1" name="1">
|
||||
<x>280.0</x>
|
||||
<y>120.0</y>
|
||||
</state>
|
||||
<state id="2" name="3">
|
||||
<x>515.0</x>
|
||||
<y>386.0</y>
|
||||
</state>
|
||||
<state id="3" name="2">
|
||||
<x>426.0</x>
|
||||
<y>224.0</y>
|
||||
</state>
|
||||
<state id="4" name="q4">
|
||||
<x>255.0</x>
|
||||
<y>399.0</y>
|
||||
<label>P</label>
|
||||
</state>
|
||||
<state id="5" name="4">
|
||||
<x>632.0</x>
|
||||
<y>246.0</y>
|
||||
<label>V</label>
|
||||
<final/>
|
||||
</state>
|
||||
<!--The list of transitions.-->
|
||||
<transition>
|
||||
<from>0</from>
|
||||
<to>4</to>
|
||||
<read>r</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>2</from>
|
||||
<to>4</to>
|
||||
<read>r</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>1</from>
|
||||
<to>4</to>
|
||||
<read>n</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>0</from>
|
||||
<to>4</to>
|
||||
<read>v</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>3</from>
|
||||
<to>4</to>
|
||||
<read>b</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>1</from>
|
||||
<to>4</to>
|
||||
<read>j</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>1</from>
|
||||
<to>4</to>
|
||||
<read>bl</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>3</from>
|
||||
<to>4</to>
|
||||
<read>n</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>2</from>
|
||||
<to>4</to>
|
||||
<read>y</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>3</from>
|
||||
<to>4</to>
|
||||
<read>j</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>1</from>
|
||||
<to>4</to>
|
||||
<read>b</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>3</from>
|
||||
<to>4</to>
|
||||
<read>v</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>2</from>
|
||||
<to>4</to>
|
||||
<read>b</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>3</from>
|
||||
<to>4</to>
|
||||
<read>r</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>0</from>
|
||||
<to>4</to>
|
||||
<read>bl</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>0</from>
|
||||
<to>4</to>
|
||||
<read>j</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>1</from>
|
||||
<to>3</to>
|
||||
<read>r</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>2</from>
|
||||
<to>4</to>
|
||||
<read>bl</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>1</from>
|
||||
<to>4</to>
|
||||
<read>v</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>0</from>
|
||||
<to>4</to>
|
||||
<read>n</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>0</from>
|
||||
<to>1</to>
|
||||
<read>b</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>2</from>
|
||||
<to>5</to>
|
||||
<read>v</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>2</from>
|
||||
<to>4</to>
|
||||
<read>n</read>
|
||||
</transition>
|
||||
<transition>
|
||||
<from>3</from>
|
||||
<to>2</to>
|
||||
<read>bl</read>
|
||||
</transition>
|
||||
</automaton>
|
||||
</structure>
|
BIN
assets/jeu.PNG
Before Width: | Height: | Size: 47 KiB |