Skip to content

Commit

Permalink
trying to fix blue
Browse files Browse the repository at this point in the history
eferreyr committed Aug 2, 2020
1 parent 532d441 commit 9cbc15b
Showing 5 changed files with 35 additions and 25 deletions.
14 changes: 8 additions & 6 deletions source/GamePlayDelegate.mc
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ using Toybox.WatchUi as Ui;
using Toybox.System;

//Emilia
class GamePlayDelegate extends Ui.MenuInputDelegate {
class GamePlayDelegate extends Ui.BehaviorDelegate {

function initialize() {
MenuInputDelegate.initialize();
@@ -12,26 +12,28 @@ class GamePlayDelegate extends Ui.MenuInputDelegate {
var keys = [ Ui.KEY_UP, Ui.KEY_ENTER, Ui.KEY_DOWN, Ui.KEY_ESC];

function onKey(k) {
System.println("GamePlayDelegate onKey step:" + step + "seq[step]:" + seq[step]);

keyPressed = true;

//user hit a key so the timer stops,
//then we check if it's the right key or not
sequenceTimer.stop();

//if the user hits the button that the sequence expected,
//display color, increment step, and create a new GamePlayView
if (k.getKey() == keys[seq[step]]){
System.println("Correct Key Press");
gamePlayColorIndex = seq[step];
WatchUi.requestUpdate();
Ui.requestUpdate();
step++;

//when step reaches the end of the list,
//reset step to zero and stop timer, then transition to gameplay
//reset step to zero, then transition to PlaySequence
if (step >= seq.size()) {
step = 0;
Ui.pushView(new PlaySequenceView(), new PlaySequenceDelegate(), Ui.SLIDE_IMMEDIATE);
}
else {
Ui.pushView(new GamePlayView(), new GamePlayDelegate(), Ui.SLIDE_IMMEDIATE);
}


}
33 changes: 18 additions & 15 deletions source/GamePlayView.mc
Original file line number Diff line number Diff line change
@@ -6,31 +6,35 @@ using Toybox.Math;
using Toybox.System;

var gamePlayColorIndex;
var keyPressed;

//Emilia
class GamePlayView extends Ui.View {
var deeCee;


function initialize() {
View.initialize();
}

// Load your resources here
function onLayout(dc) {
System.println("GamePlayView onLayout");
gamePlayColorIndex = -1; //black
keyPressed = false;

sequenceTimer.start(method(:endGamecallback), 3000, false);
//start sequenceTimer which gives player 3 seconds to press the correct button
//if no button is pressed within this time, player loses and endGameCallback is called
sequenceTimer.start(method(:endGameCallback), 3000, false);
}

//end game and return to start screen
function endGamecallback() {
sequenceTimer.stop();
Ui.pushView(new SimonGameView(), new SimonGameDelegate(), Ui.SLIDE_IMMEDIATE);
function endGameCallback() {
Ui.pushView(new SimonGameView(), new SimonGameDelegate(), Ui.SLIDE_IMMEDIATE); //go to start screen
}

function resetColorCallback() {

showColor(deeCee, gamePlayColorIndex);
//can't pass dc into this function which is needed to show color
//so do nothing here and show color in onUpdate after
}

// Called when this View is brought to the foreground. Restore
@@ -41,16 +45,15 @@ class GamePlayView extends Ui.View {

// Update the view
function onUpdate(dc) {
play(seq[step]);
//play(seq[step]); //play sound

showColor(dc, gamePlayColorIndex);

gamePlayColorIndex = -1;
deeCee = dc;

clearingTimer.start(method(:resetColorCallback), 500, false);

showColor(dc, gamePlayColorIndex); //show color


if(keyPressed) {
keyPressed = false;
sequenceTimer.start(method(:endGameCallback), 3000, false);
}
}

// Called when this View is removed from the screen. Save the
9 changes: 7 additions & 2 deletions source/PlaySequenceView.mc
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ function showColor(dc, colorIndex) {
//keep background black and draw a circle in corresponding corner
dc.setColor( colorIndex < 0 ? Graphics.COLOR_BLACK : colors[colorIndex] , Graphics.COLOR_BLACK);
dc.fillCircle(getX(colorIndex), getY(colorIndex), screenWidth * .75);
//use local variables
}

//Button 0 has coordinates (0,0), Button 1 has corrdinates (0,1), and so on
@@ -83,7 +84,8 @@ class PlaySequenceView extends Ui.View {

// Update the view
function onUpdate(dc) {

System.println("PlaySequenceView onUpdate step:" + step + "currentColorIndex:" + currentColorIndex);

//when step reaches the end of the list,
//reset step to zero and stop timer, then transition to gameplay
if (step >= seq.size()) {
@@ -93,7 +95,7 @@ class PlaySequenceView extends Ui.View {
}

//play tone at index given by value in seq[step]
play(seq[step]);
//play(seq[step]);

//draw color
showColor(dc, currentColorIndex);
@@ -104,6 +106,8 @@ class PlaySequenceView extends Ui.View {
//are, in fact, two different elements in the sequence
clearingTimer.start(method(:clearColorCallback), waitTime() * BLINK_FACTOR, false);

System.println("X");

}

// Called when this View is removed from the screen. Save the
@@ -122,6 +126,7 @@ class PlaySequenceView extends Ui.View {
}

function drawColorCallback() {
clearingTimer.stop();
step++; //increment step

//while there is another element in seq, set currentColorIndex to next value in seq
2 changes: 1 addition & 1 deletion source/SimonGameApp.mc
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ var step;
var iteration;
var wait;
var interval;
var maxStep;
var maxStep;
var screenHeight;
var screenWidth;
var endGame;
2 changes: 1 addition & 1 deletion source/SimonGameView.mc
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ class SimonGameView extends WatchUi.View {
clearingTimer = new Timer.Timer();
sequenceTimer = new Timer.Timer();
iteration = 0;
step = 0;
step = 0;
seq = [];
}

0 comments on commit 9cbc15b

Please sign in to comment.