Skip to content

Instantly share code, notes, and snippets.

@bg451
Created September 24, 2013 06:31
Show Gist options
  • Save bg451/6681058 to your computer and use it in GitHub Desktop.
Save bg451/6681058 to your computer and use it in GitHub Desktop.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class ToDoList extends JApplet implements KeyListener
{
int loc = 1;
boolean laundryColor = false;
boolean groceryStore = false;
boolean kitchenTask = false ;
boolean roomTask = false;
public void init() {
setFocusable(true);
addKeyListener(this);
}
public void paint(Graphics g) {
g.clearRect(0, 0, 500, 500);
paintLocL(g);
paintLocG(g);
paintLocK(g);
paintLocR(g);
System.out.println("Swagger Dagger 1");
}
public void paintLocL(Graphics g) { // laundry room
g.setColor(Color.black);
g.drawLine(120, 60, 160, 60);
g.drawLine(60, 120, 60, 160);
if(loc == 1) {
System.out.println("Swagger dagger 2");
if (laundryColor == false) {
g.drawString("Do you want to do laundry? ", 300, 10);
g.drawString("1: yes, 2: no", 300, 30);
} else if (laundryColor == true) {
g.drawString("Which room do you want to go to? ", 300, 50);
g.drawString("g: grocery store, r: room", 300, 70);
}
g.setColor(Color.pink);
}
g.fillRect(20, 20, 100, 100);
}
public void paintLocG(Graphics g) { // grocery store
g.setColor(Color.black);
g.drawLine(20, 200, 160, 200);
g.drawLine(200, 120, 200, 160);
if(loc == 2) {
g.drawString("You are at the supermarket.", 300, 10);
if (groceryStore == false) {
g.drawString("Do you want to buy some eggs?", 300, 30);
g.drawString("1: yes, 2: no", 300, 50);
} else {
g.drawString("Which room do you want to go to? ", 300, 50);
g.drawString("k: kitchen, r: room", 300, 70);
}
g.setColor(Color.pink);
}
g.fillRect(20, 160, 100, 100);
}
public void paintLocK(Graphics g) { //kitchen
g.setColor(Color.black);
g.drawLine(120, 60, 160, 60);
if(loc == 3){
g.drawString("You are now in the kitchen.", 300, 10);
if (kitchenTask == false){
g.drawString("Do you want to do the dishes?", 300, 30);
g.drawString("1: yes, 2: no", 300, 50);
} else {
g.drawString("Which room do you want to go to?", 300, 50);
g.drawString("g: grocery store, r: room", 300, 70);
}
g.setColor(Color.pink);
}
g.fillRect(160, 20, 100, 100);
}
public void paintLocR(Graphics g) { //room
g.setColor(Color.black);
if(loc == 4){
g.drawString("You are now in your room.", 300, 20);
if (roomTask == false) {
g.drawString("Do you want to clean your room?", 300, 30);
g.drawString("1: yes, 2: no", 300, 50);
} else {
g.drawString("Which room do you want to go to?", 300, 50);
g.drawString("g: grocery store, l: laundry room", 300, 70);
}
g.setColor(Color.pink);
}
g.fillRect(160, 160, 100, 100);
}
public void keyPressed(KeyEvent e) {}
public void keyReleased(KeyEvent e) {}
public void keyTyped(KeyEvent e) {
System.out.println(loc + " key Pressed!" );
if(loc == 1) // laundry room
loc = (char) loc1(e.getKeyChar());
else if(loc == 2) // grocery store
loc = (char) loc2(e.getKeyChar());
else if(loc == 3) // kitchen
loc = (char) loc3(e.getKeyChar());
else if(loc == 4) // room
loc = (char) loc4(e.getKeyChar());
repaint();
}
public int loc1(char c) { // laundry room
if(c == 'g')
return 2;
if(c == 'k')
return 3;
if(c =='k')
loc = 3;
if (c == '1') {
laundryColor = true;
}
if (c == '2') {
laundryColor = false;
}
return 1;
}
public int loc2(char c) { // grocery store
if(c == 'r')
return 4;
if(c == 'l')
return 1;
if(c == '1') {
groceryStore = true;
}
if(c == '2') {
groceryStore = false;
System.out.println("Soemthing happened");
}
return 2;
}
public int loc3(char c) { //kitchen
if(c == 'l')
return 1;
if(c == 'r')
return 4;
if(c == '1')
kitchenTask = true;
if(c == '2')
kitchenTask = false;
return 3;
}
public int loc4(char c) { //room
if(c == 'g')
return 2;
if(c == 'k')
return 3;
if(c == '1')
roomTask = true;
if(c == '2')
roomTask = false;
return 4;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment