Skip to content
This repository has been archived by the owner on Sep 15, 2020. It is now read-only.

Commit

Permalink
Cambiado flujo del programa
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandoAndrade committed Jul 10, 2019
1 parent da41321 commit 53a8f0a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
18 changes: 5 additions & 13 deletions UILayer/src/main/java/Serial/PortReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,28 @@ public void serialEvent(SerialPortEvent serialPortEvent)
}
}

private void repeatMessage(boolean repeat, String message)
{
if(repeat)
{
SerialManager.sentMessage(message);
}
}

public void filter(String s)
{
System.out.println(s);
if(s.substring(0,12).equals("$$pedirtruco"))//12 pedir truco
{
repeatMessage(SerialManager.trick(s.substring(12,14)),s);
SerialManager.trick(s.substring(12,14), s);
}
else if(s.substring(0,11).equals("$$resptruco"))//11 responder truco
{
repeatMessage(SerialManager.trickResponse(s.substring(11,14)),s);
SerialManager.trickResponse(s.substring(11,14), s);
}
else if(s.substring(0,9).equals("$$jugar##"))//9 poner carta en juego
{
repeatMessage(SerialManager.playCard(s.substring(9,14)),s);
SerialManager.playCard(s.substring(9,14), s);
}
else if(s.substring(0,9).equals("$$setvira"))//9 poner vira
{
repeatMessage(SerialManager.setVira(s.substring(9,14)),s);
SerialManager.setVira(s.substring(9,14), s);
}
else if(s.substring(0,3).equals("$$r"))//Repartir cartas a jugadores
{
repeatMessage(SerialManager.giveCards(s.substring(3,14)),s);
SerialManager.giveCards(s.substring(3,14), s);
}
else if(s.substring(0,12).equals("$$hand#shake"))
{
Expand Down
15 changes: 10 additions & 5 deletions UILayer/src/main/java/Serial/SerialManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ private static int translateLetters(char c)
return 0;
}

public static boolean giveCards(String cards)
public static boolean giveCards(String cards, String message)
{
int sender = translateLetters(cards.charAt(0));
if(sender != GameManager.getPLAYER())
{
sentMessage(message);
int receiver = translateLetters(cards.charAt(1));
GameManager.setPlayersCards(new CardFactory().createFromTrama(cards.substring(2)),receiver);
return true;
Expand All @@ -136,11 +137,12 @@ public static void playCard(PlayCard card, int player)
sentMessage(message);
}

public static boolean playCard(String card)
public static boolean playCard(String card, String message)
{
int sender = translateLetters(card.charAt(0));
if(sender!=GameManager.getPLAYER())
{
sentMessage(message);
int number = Integer.parseInt(card.substring(2, 4));
PlayCard car = new Card(number, deParser().get(card.substring(4)));
GameManager.playCard(sender, car);
Expand Down Expand Up @@ -170,11 +172,12 @@ public static void setVira(PlayCard card)
sentMessage(message);
}

public static boolean setVira(String message)
public static boolean setVira(String message, String s)
{
int sender = translateLetters(message.charAt(0));
if(sender != GameManager.getPLAYER())
{
sentMessage(s);
int number = Integer.parseInt(message.substring(2, 4));
String type = deParser().get(message.substring(4));
PlayCard card = new Card(number, type);
Expand All @@ -190,11 +193,12 @@ public static void trick(int player)
sentMessage(message);
}

public static boolean trick(String s)
public static boolean trick(String s, String message)
{
int sender=translateLetters(s.charAt(0));
if(sender!=GameManager.getPLAYER())
{
SerialManager.sentMessage(message);
int receiver=translateLetters(s.charAt(1));
GameManager.trick(sender, receiver);
return true;
Expand All @@ -208,11 +212,12 @@ public static void trickResponse(int player, boolean ans)
sentMessage(message);
}

public static boolean trickResponse(String s)
public static boolean trickResponse(String s, String message)
{
int sender=translateLetters(s.charAt(0));
if(sender!=GameManager.getPLAYER())
{
sentMessage(message);
boolean accept = s.charAt(2) == 'S';
GameManager.trickResponse(sender, accept);
return true;
Expand Down

0 comments on commit 53a8f0a

Please sign in to comment.