Skip to content

Commit

Permalink
Adding twitter interface to public repo
Browse files Browse the repository at this point in the history
  • Loading branch information
mitrisdev committed Apr 10, 2014
1 parent b518e12 commit e917ee7
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/edu/mit/d54/TwitterClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package edu.mit.d54;

public class TwitterClient {

private static boolean enableTwitter = false;
private static TwitterClient instance;

public static boolean enableTwitter()
{
enableTwitter = getInstance().doEnableTwitter();
return enableTwitter;
}

public static void disableTwitter()
{
enableTwitter = false;
}

public static boolean isEnabled()
{
return enableTwitter;
}

public static void setInstance(TwitterClient instance)
{
enableTwitter = false;
TwitterClient.instance = instance;
}

protected static TwitterClient getInstance()
{
if (instance == null)
instance = new TwitterClient();
return instance;
}

public static void tweet(String tweet)
{
getInstance().doTweet(tweet);
}

public TwitterClient()
{
}

protected boolean doEnableTwitter()
{
return true;
}

protected void doTweet(String tweet) {
if (enableTwitter)
{
System.out.printf("(SIM) Tweeted: %s\n", tweet);
}
else
{
System.out.printf("(SIM - Twitter not enabled) Would have tweeted: %s\n", tweet);
}
}
}
11 changes: 11 additions & 0 deletions src/edu/mit/d54/plugins/mitris/MITrisPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import edu.mit.d54.ArcadeListener;
import edu.mit.d54.Display2D;
import edu.mit.d54.DisplayPlugin;
import edu.mit.d54.TwitterClient;

/**
* This is a plugin implementing the MITris game. User input is received over the TCP socket on port 12345.
Expand Down Expand Up @@ -78,6 +79,7 @@ public MITrisPlugin(Display2D display, double framerate) throws IOException {
controller = ArcadeController.getInstance();

System.out.println("Game paused until client connect");
TwitterClient.tweet("Tetris is now being played on the MIT Green Building! #mittetris");

gameState=State.IDLE;
}
Expand Down Expand Up @@ -170,6 +172,15 @@ protected void loop() {
gameState=State.GAME_END_1;
gameOverBoard=mitrisGame.getDisplayBoard();
animTime=0;
String extra="";
if (gameOverBoard.getLevel()>=5)
extra=" Great job!";
if (gameOverBoard.getLevel()>=8)
extra=" Amazing!!";
TwitterClient.tweet(String.format("Someone just played Tetris on the MIT Green Building! "+
"They cleared %d lines and lasted %1.1f seconds!%s #mittetris",
gameOverBoard.getNumCleared(),mitrisGame.getTime(),extra));

}
break;
case GAME_END_1:
Expand Down

0 comments on commit e917ee7

Please sign in to comment.