Sunday, June 23, 2019

Conditionals Tiny Text Adventure

So my professor told us to pick someone else's English conditional statement, and turn it into code. I'm not sure if he wanted us to turn it into viable code, but I did. This code functions in Processing. In the discussion group, I picked the one that the student posted:
If today is Saturday and it is before 11 am and you woke up go back to sleep or if you are busy today wake up.
This scenario doesn't cover the case where it ISN'T a Saturday, so I just assumed that you'd go back to sleep regardless if it's not a Saturday and you're not busy.

I'm sure my code could be cleaned up, but here's what I got after toying around for a few hours, deciding whether or not boolean or integer values were better. I found using integer values made things easier even though the values were all boolean in nature.



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// From my assignment, I had to choose another student's conditional statement
// and turn it into code. I don't think I needed to make it viable, but
// I am an overachiever so I did so anyway. The student's English
// conditional statement was
// If today is Saturday and it is before 11 am and you woke up go back
// to sleep or if you are busy today wake up.

int IsItSat = 0;
int early = 0;
int circadian = 0;
int busy = -4;

int pressA = 0;
int pressB = 0;
int pressC = 0;
int pressD = 0;

void setup() {
  println("Is it Saturday? y/n for yes/no");
  println("Did you wake up? w/s for woke/slept");
  println("Are you busy? b/l for busy/lazy");
  println("Is it earlier than 11AM? e/f for earlier/after.");
}

void draw () {  

}

void keyTyped() {
  if (key == 'y') {
    IsItSat = 1;
    println("It is Saturday, you say.");
    pressA = 1;
  }
  if (key == 'n') {
    IsItSat = 0;
    println("It isn't Saturday, you say.");
    pressA = 1;
  }
  if (key == 'w') {
    circadian = 1;
    println("You woke up, you say.");
    pressB = 1;
  }
  if (key == 's') {
    circadian = 0;
    println("You are sleeping, you say.");
    pressB = 1;
  }
  if (key == 'b') {
    busy = -4;
    println("You are busy today, you say.");
    pressC = 1;
  }
  if (key == 'l') {
    busy = 0;
    println("You are not busy today, you say.");
    pressC = 1;
  }
  if (key == 'e'){
    early = 1;
    println("It's earlier than 11, you say.");
    pressD = 1;
  }
  if (key == 'f'){
    early = 0;
    println("It's later than 11, you say.");
    pressD = 1;
  }
  
int press = (pressA + pressB + pressC + pressD);
int day = (IsItSat + early + circadian + busy);
  
  if (press == 4){
    if ((day) >= 3){
      println("Go back to sleep. It's a Saturday and there's nothing to do.");
    }
    if ((day) < 0){
      println("Get out of bed. You have stuff to do.");
    }
    else if ((day >= 0) && (day < 3)) {
      println("Continue sleeping because you can.");
    }
  }
  if (press < 4) {
    println("Please answer all questions.");
  }

}

The video below demonstrates the code functioning in its various possible outcomes.



I mean, this assignment is worth 100 points so I wanted to be a little extra with this to make sure I get full pointage.

No comments:

Post a Comment