Esempio n. 1
0
// Prints the instructions that the user should follow when
// testing the verifySequence state machine.
// Takes an argument that specifies the length of the sequence so that
// the instructions are tailored for the length of the sequence.
// This assumes a simple incrementing pattern so that it is simple to
// instruct the user.
void verifySequence_printInstructions(uint8_t length, bool startingOver) {
  display_fillScreen(DISPLAY_BLACK);	    // Clear the screen.
  display_setTextSize(MESSAGE_TEXT_SIZE);   // Make it readable.
  display_setCursor(MESSAGE_X, MESSAGE_Y);  // Rough center.
  if (startingOver) {	                    // Print a message if you start over.
    display_fillScreen(DISPLAY_BLACK);	    // Clear the screen if starting over.
    display_setTextColor(DISPLAY_WHITE);    // Print whit text.
    display_println("Starting Over. ");
  }
  display_println("Tap: ");
  display_println();
  switch (length) {
  case 1:
    display_println("red");
    break;
  case 2:
    display_println("red, yellow ");
    break;
  case 3:
    display_println("red, yellow, blue ");
    break;
  case 4:
    display_println("red, yellow, blue, green ");
    break;
  default:
    break;
  }
  display_println("in that order.");
  display_println();
  display_println("hold BTN0 to quit.");
}
Esempio n. 2
0
// Draw the game-over screen.
void wamDisplay_drawGameOverScreen()
{
    wamDisplay_freeMemory(currentBoardsize); //deallocate the memory

    display_fillScreen(DISPLAY_BLACK); //clear screen
    //center and move down the Game Over message
    display_setCursor(WAM_D_MESSAGE_OFFSET*DISPLAY_CHAR_WIDTH * WAM_D_BIG_TEXT,
            WAM_D_MESSAGE_OFFSET*DISPLAY_CHAR_HEIGHT*WAM_D_BIG_TEXT);
    display_setTextSize(WAM_D_BIG_TEXT); //set size of text
    display_println(WAM_D_GAME_OVER_MESSAGE1); //print GAME OVER
    display_setTextSize(WAM_D_NORMAL_TEXT); //lower text size
    sprintf(gameOverStatString, WAM_D_GAME_OVER_MESSAGE2_FORMAT, oldHits, oldMisses, currentLevel);
    display_println(gameOverStatString); //display
    wamDisplay_resetAllScoresAndLevel(); //after printing, reset it all.
}
Esempio n. 3
0
// Sets the miss value in the score window.
void wamDisplay_setMissScore(uint16_t misses)
{
    //move cursors to correct spot
    //14 chars over (hit:%   Miss:) and 1 char up
    display_setCursor(DISPLAY_CHAR_WIDTH*MISS_SCORE_OFFSET*WAM_D_NORMAL_TEXT, DISPLAY_HEIGHT-(DISPLAY_CHAR_HEIGHT*WAM_D_NORMAL_TEXT));
    //cover up current score in black
    display_setTextColor(DISPLAY_BLACK);
    display_println(oldMisses);
    //redraw with new score in white
    display_setTextColor(DISPLAY_WHITE);
    //move cursor back
    display_setCursor(DISPLAY_CHAR_WIDTH*MISS_SCORE_OFFSET*WAM_D_NORMAL_TEXT, DISPLAY_HEIGHT-(DISPLAY_CHAR_HEIGHT*WAM_D_NORMAL_TEXT));
    display_println(misses);
    oldMisses = misses; //set old to newHits.
}
Esempio n. 4
0
// I used a busy-wait delay (utils_msDelay) that uses a for-loop and just blocks until the time has passed.
// When you implement the game, you CANNOT use this function as we discussed in class. Implement the delay
// using the non-blocking state-machine approach discussed in class.
void simonDisplay_runTest(uint16_t touchCount) {
  display_init();  // Always initialize the display.
  char str[MAX_STR];   // Enough for some simple printing.
  uint8_t regionNumber;
  uint16_t touches = 0;
  // Write an informational message and wait for the user to touch the LCD.
  display_fillScreen(DISPLAY_BLACK);        // clear the screen.
  display_setCursor(0, display_height()/2); //
  display_setTextSize(TEXT_SIZE);
  display_setTextColor(DISPLAY_RED, DISPLAY_BLACK);
  sprintf(str, "Touch and release to start the Simon demo.");
  display_println(str);
  display_println();
  sprintf(str, "Demo will terminate after %d touches.", touchCount);
  display_println(str);
  while (!display_isTouched());       // Wait here until the screen is touched.
  while (display_isTouched());        // Now wait until the touch is released.
  display_fillScreen(DISPLAY_BLACK);  // Clear the screen.
  simonDisplay_drawAllButtons();      // Draw all of the buttons.
  bool touched = false;  	      // Keep track of when the pad is touched.
  int16_t x, y;  		      // Use these to keep track of coordinates.
  uint8_t z;      		      // This is the relative touch pressure.
  while (touches < touchCount) {  // Run the loop according to the number of touches passed in.
    if (!display_isTouched() && touched) {         // user has stopped touching the pad.
      simonDisplay_drawSquare(regionNumber, true); // Erase the square.
      simonDisplay_drawButton(regionNumber);	   // DISPLAY_REDraw the button.
      touched = false;															// Released the touch, set touched to false.
    } else if (display_isTouched() && !touched) {   // User started touching the pad.
      touched = true;                               // Just touched the pad, set touched = true.
      touches++;  																	// Keep track of the number of touches.
      display_clearOldTouchData();  // Get rid of data from previous touches.
      // Must wait this many milliseconds for the chip to do analog processing.
      utils_msDelay(TOUCH_PANEL_ANALOG_PROCESSING_DELAY_IN_MS);
      display_getTouchedPoint(&x, &y, &z);                  // After the wait, get the touched point.
      regionNumber = simonDisplay_computeRegionNumber(x, y);// Compute the region number.
      simonDisplay_drawSquare(regionNumber, false);	    // Draw the square (erase = false).
    }
  }
  // Done with the demo, write an informational message to the user.
  display_fillScreen(DISPLAY_BLACK);        // clear the screen.
  display_setCursor(0, display_height()/2); // Place the cursor in the middle of the screen.
  display_setTextSize(2);                   // Make it readable.
  display_setTextColor(DISPLAY_RED, DISPLAY_BLACK);  // red is foreground color, black is background color.
  sprintf(str, "Simon demo terminated");    // Format a string using sprintf.
  display_println(str);                     // Print it to the LCD.
  sprintf(str, "after %d touches.", touchCount);  // Format the rest of the string.
  display_println(str);  // Print it to the LCD.
}
Esempio n. 5
0
void ticTacToeDisplay_runTest()
{
    while(1) //until button 1 is pressed
    {
        while(buttons_read() != (TICTACTOEDISPLAY_BTN0_ON))//until button 0 is pressed
        {
            if(buttons_read() == (TICTACTOEDISPLAY_BTN1_ON))//button has been pressed
            {
                display_setTextSize(TICTACTOEDISPLAY_TEXT_SIZE);  // this sets the text size
                display_setCursor(TICTACTOEDISPLAY_HALF_WIDTH-TICTACTOEDISPLAY_ONE_THIRD_WIDTH, //position x coordinate of cursor
                        TICTACTOEDISPLAY_HALF_HEIGHT - TICTACTOEDISPLAY_ONE_SIXTH_HEIGHT);//position y coordinate of cursor
                display_println("Game Over!");//print to the lcd
                return;//return out of both loops immediately
            }

            if(display_isTouched())
            {
                display_clearOldTouchData(); // Throws away all previous touch data.
                uint8_t row, column;
                ticTacToeDisplay_touchScreenComputeBoardRowColumn(&row, &column);//compute location of square
                if(switches_read() == TICTACTOEDISPLAY_SWITCH0_ON)//SW0 is up
                {
                    ticTacToeDisplay_drawO(row, column);//draw O character
                }
                if(switches_read() == TICTACTOEDISPLAY_SWITCH0_OFF)//SW0 is down
                {
                    ticTacToeDisplay_drawX(row, column);//draw X character
                }
            }
        }
        ticTacToeDisplay_init();//clear the screen
    }
}
Esempio n. 6
0
void TicTacToeDisplay_complete()
{
	display_fillScreen(DISPLAY_BLACK);
	display_setTextColor(DISPLAY_RED);
	display_setTextSize(4);
	display_println("TEST COMPLETE" );

}
Esempio n. 7
0
//pass currentHits in as hits
// Sets the hit value in the score window.
void wamDisplay_setHitScore(uint16_t hits)
{
    //move cursor to correct spot
    //4 chars over (Hit:) and bottom - 1 char height
    display_setCursor(DISPLAY_CHAR_WIDTH*WAM_D_MESSAGE_OFFSET*WAM_D_NORMAL_TEXT,
            DISPLAY_HEIGHT-(DISPLAY_CHAR_HEIGHT*WAM_D_NORMAL_TEXT));
    //cover up current score in black
    display_setTextColor(DISPLAY_BLACK);
    display_println(oldHits);
    //redraw with new score in white
    display_setTextColor(DISPLAY_WHITE);
    //move cursor back
    display_setCursor(DISPLAY_CHAR_WIDTH*WAM_D_MESSAGE_OFFSET*WAM_D_NORMAL_TEXT,
            DISPLAY_HEIGHT-(DISPLAY_CHAR_HEIGHT*WAM_D_NORMAL_TEXT));
    display_println(hits);
    oldHits = hits; //set old to newHits.
}
Esempio n. 8
0
// Completely draws the score screen.
void wamDisplay_drawScoreScreen()
{
    //the score screen is the number strip at the bottom of the screen
    //set the cursor to bottom row of screen
    display_setTextSize(WAM_D_NORMAL_TEXT);
    display_setTextColor(DISPLAY_WHITE);
    display_setCursor(0, DISPLAY_HEIGHT-(DISPLAY_CHAR_HEIGHT*WAM_D_NORMAL_TEXT));
    display_println(WAM_SCORE_SCREEN);
}
Esempio n. 9
0
// Sets the level value on the score board.
void wamDisplay_incrementLevel()
{
    //also increment max actives here
    if ( wamControl_getMaxActiveMoles() < currentBoardsize) ///cant have more active moles than holes
        wamControl_setMaxActiveMoles(wamControl_getMaxActiveMoles() + 1);

    //move cursors to correct spot
    //14 chars over (hit:%   Miss:%   Level:) and 1 char up
    display_setCursor(DISPLAY_CHAR_WIDTH*LEVEL_SCORE_OFFSET*WAM_D_NORMAL_TEXT, DISPLAY_HEIGHT-(DISPLAY_CHAR_HEIGHT*WAM_D_NORMAL_TEXT));
    //cover up current score in black
    display_setTextColor(DISPLAY_BLACK);
    display_println(currentLevel);
    currentLevel++; //inclevel
    //redraw with new score in white
    display_setTextColor(DISPLAY_WHITE);
    //move cursor back
    display_setCursor(DISPLAY_CHAR_WIDTH*LEVEL_SCORE_OFFSET*WAM_D_NORMAL_TEXT, DISPLAY_HEIGHT-(DISPLAY_CHAR_HEIGHT*WAM_D_NORMAL_TEXT));
    display_println(currentLevel);
}
Esempio n. 10
0
// Draw the initial splash (instruction) screen.
void wamDisplay_drawSplashScreen()
{
    display_setTextSize(WAM_D_NORMAL_TEXT);
    display_fillScreen(DISPLAY_BLACK); //clear screen
    //position in center ish
    display_setCursor(WAM_D_MESSAGE_OFFSET*DISPLAY_CHAR_WIDTH * WAM_D_NORMAL_TEXT,
            WAM_D_NORMAL_TEXT*DISPLAY_CHAR_HEIGHT);
    //print
    display_println(WAM_INSTRUCTIONS);
}
void ticTacToeDisplay_gameOver() {
	display_init();  // Must init all of the software and underlying hardware for LCD.
	display_fillScreen(DISPLAY_BLACK);  // Blank the screen.
	display_setRotation(true);
	ticTacToeDisplay_drawX(TICTACTOE_DISP_ROW_0,TICTACTOE_DISP_COLUMN_0);
	ticTacToeDisplay_drawX(TICTACTOE_DISP_ROW_0,TICTACTOE_DISP_COLUMN_2);
	display_drawFastHLine(display_width()/3, display_height()/2, display_width()/3, DISPLAY_CYAN);

	display_setCursor(TICTACTOE_DISP_COLUMN_1_PT,TICTACTOE_DISP_ROW_2_PT);
	display_println("Game Over");

}
Esempio n. 12
0
void buttons_runTest() {
  buttons_init();  // Initialize buttons
  display_init();  // Initialize display, which sets Rotation = 1 by default
  display_fillScreen(DISPLAY_BLACK); // blank the screen
  display_setTextColor(DISPLAY_BLACK);  // Change text color to black
  display_setTextSize(BUTTONS_TEXT_SIZE); // Make text larger

  // Set the values of the global variables
  x_max = display_width();
  y_max = display_height();

  // Set the values of screen positions
  x_fourth = FOURTH(x_max);
  x_half = HALF(x_max);
  x_three_fourths = THREE_FOURTHS(x_max);
  y_fourth = FOURTH(y_max);
  y_half = HALF(y_max);
  y_three_fourths = THREE_FOURTHS(y_max);

  // Do an initial read of button values
  int32_t buttonValues = buttons_read();

  // Until all 4 BTNS are pressed simultaneously, write info to the LCD
  while (buttonValues != BUTTONS_ALL_BTNS_ON) {

    // Draw the Rects/Text on the LCD corresponding to current buttons
    buttons_write_LCD(buttonValues);

    // Poll new value of buttons
    buttonValues = buttons_read();
  }

  // After all buttons are pushed simultaneously, finish test.
  display_fillScreen(DISPLAY_BLACK);  // blank screen
  display_setTextColor(DISPLAY_CYAN); // change text color
  display_setCursor(0,0);  // reset cursor to origin
  display_println("Button Test Finished!");  // print that the test is complete
}
Esempio n. 13
0
void buttons_runTest() {
    buttons_init();
    // Initialize the display for writing.
    display_init();
    // Clear the screen; make the whole thing black.
    display_fillScreen(DISPLAY_BLACK);
    // Set up a var for storing the current value of the buttons.
    // This will be updated every time our while loop cycles.
    uint32_t newVal = 0;
    // Set up a var for storing the previous value of the buttons.
    // This will be updated every time our while loop cycles.
    uint32_t lastVal = 0;
    // Set the text size to a value of 2.
    display_setTextSize(BUTTONS_TEXT_SIZE);

    // As long as all four buttons are not all pressed at once, do this:
    while(newVal ^ BUTTONS_ARE_ALL_PRESSED) {
        // Copy newVal into lastVal because we're going to update newVal.
        lastVal = newVal;
        // Read the state of the buttons into newVal.
        newVal = buttons_read();
        // We need to check whether BUTTONS_BUTTON1's corresponding square has
        // already been drawn. We don't want to draw it again if it's
        // already there.
        if(!(lastVal & BUTTONS_BUTTON1) && (newVal & BUTTONS_BUTTON1)) {
            // Fill the far right square with yellow.
            display_fillRect(BUTTONS_BUTTON1_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_YELLOW);
            // Set our text cursor to a good place in the center of the square.
            display_setCursor(BUTTONS_BUTTON1_CURSOR_X_CORD, BUTTONS_ALL_BUTTONS_CURSOR_Y_CORD);
            // Make the text color black.
            display_setTextColor(DISPLAY_BLACK);
            // Write BTN0 in the center of the square.
            display_println(BUTTONS_BUTTON1_TEXT);
        }
        // If the square is drawn, and button 1 is no longer pressed:
        else if((lastVal & BUTTONS_BUTTON1) && !(newVal & BUTTONS_BUTTON1)) {
            // Write a black square on top of the yellow square.
            display_fillRect(BUTTONS_BUTTON1_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLACK);
        }
        // Repeat the process for BUTTONS_BUTTON1 for all other buttons:
        if(!(lastVal & BUTTONS_BUTTON2) && (newVal & BUTTONS_BUTTON2)) {
            // Draw a green square
            display_fillRect(BUTTONS_BUTTON2_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_GREEN);
            // Set the cursor
            display_setCursor(BUTTONS_BUTTON2_CURSOR_X_CORD, BUTTONS_ALL_BUTTONS_CURSOR_Y_CORD);
            // Set text color to black
            display_setTextColor(DISPLAY_BLACK);
            // Write BTN1
            display_println(BUTTONS_BUTTON2_TEXT);
        }
        // If the BUTTONS_BUTTON2 square is there and BUTTONS_BUTTON2 is no longer pressed:
        else if((lastVal & BUTTONS_BUTTON2) && !(newVal & BUTTONS_BUTTON2)) {
            // Draw a black square over the top of the green one
            display_fillRect(BUTTONS_BUTTON2_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLACK);
        }
        // If BUTTONS_BUTTON3 is pressed and the square is not already drawn:
        if(!(lastVal & BUTTONS_BUTTON3) && (newVal & BUTTONS_BUTTON3)) {
            // Draw a red rectangle
            display_fillRect(BUTTONS_BUTTON3_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_RED);
            // Set the cursor
            display_setCursor(BUTTONS_BUTTON3_CURSOR_X_CORD, BUTTONS_ALL_BUTTONS_CURSOR_Y_CORD);
            // Set the text color to white
            display_setTextColor(DISPLAY_WHITE);
            // Write BTN2 to the screen
            display_println(BUTTONS_BUTTON3_TEXT);
        }
        // If BUTTONS_BUTTON3 is no longer pressed and the square is on the screen:
        else if((lastVal & BUTTONS_BUTTON3) && !(newVal & BUTTONS_BUTTON3)) {
            // Draw a black rectangle over the top of the red one
            display_fillRect(BUTTONS_BUTTON3_X_CORD, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLACK);
        }
        // If BUTTONS_BUTTON4 is pressed and the square isn't on the screen:
        if(!(lastVal & BUTTONS_BUTTON4) && (newVal & BUTTONS_BUTTON4)) {
            // Draw a blue rectangle
            display_fillRect(0, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLUE);
            // Set the cursor
            display_setCursor(BUTTONS_BUTTON4_CURSOR_X_CORD, BUTTONS_ALL_BUTTONS_CURSOR_Y_CORD);
            // Set the text to be white
            display_setTextColor(DISPLAY_WHITE);
            // Write BTN3 to the screen
            display_println(BUTTONS_BUTTON4_TEXT);
        }
        // If BUTTONS_BUTTON4 is no longer pressed and the square is on the screen:
        else if((lastVal & BUTTONS_BUTTON4) && !(newVal & BUTTONS_BUTTON4)) {
            // Draw a black square over the blue one
            display_fillRect(0, 0, BUTTONS_ALL_BUTTONS_X_LENGTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLACK);
        }
    }
    // Once all 4 buttons are pressed simultaneously,
    // Draw a black square over the top part of the screen
    // To reset it.
    display_fillRect(0, 0, BUTTONS_SCREEN_WIDTH, BUTTONS_ALL_BUTTONS_Y_LENGTH, DISPLAY_BLACK);
}
Esempio n. 14
0
//*********************************************************************************************
// verifySequence_eraseInfroMessage(verifySequence_infoMessage_t messageType)
// @param: verifySequence_infoMessage_t messageType
// Erases informational messages based upon a message type (see above).
//*********************************************************************************************
void verifySequence_eraseInfoMessage(verifySequence_infoMessage_t messageType)
{
    display_setTextColor(DISPLAY_BLACK);
    display_setCursor(MESSAGE_X, MESSAGE_Y);
  
    switch(messageType)
    {
        case user_time_out_e:  // Tell the user that they typed too slowly.
            display_println("Error:");
            display_println();
            display_println("  User tapped sequence");
            display_println("  too slowly.");
            break;
            
        case user_wrong_sequence_e:  // Tell the user that they tapped the wrong color.
            display_println("Error: ");
            display_println();
            display_println("  User tapped the");
            display_println("  wrong sequence.");
            break;
            
        case user_correct_sequence_e:  // Tell the user that they were correct.
            display_println("User tapped");
            display_println("the correct sequence.");
            break;
            
        case user_quit_e:             // Acknowledge that you are quitting the test.
            display_println("quitting runTest().");
            break;
            
        default:
            break;
  }
}
Esempio n. 15
0
    void simonControl_tick()
    {
        SC_debugStatePrint();


        /// //ACTIONS***********************************************************************
        switch(SC_State)
        {
        case SC_init_st:
            //do nothing
            break;
        case SC_instructions_st:
            display_setTextColor(DISPLAY_WHITE);
            display_setCursor(SC_INSTRUCTION_CURSORX,SC_INSTRUCTION_CURSORY);
            display_setTextSize(SC_INSTRUCTION_TEXTSIZE);
            display_println(SC_INSTRUCTIONS);
            break;
        case SC_wait_first_touch_st:
            // do nothing
            break;
        case SC_get_sequence_st:
            SC_currentScore = 0; //reset
            SC_setSequence();
            break;
        case SC_flash_sequence_st:
            //do nothing
            break;
        case SC_verify_sequence_st:
            //do nothing
            break;
        case SC_error_st:
            errorTimer++;
            if (verifySequence_isTimeOutError()) // user didn't press
            {
                display_setTextSize(SC_TEXTSIZE);
                display_println(ERROR_MESSAGE_TIMEOUT);
            }
            else if (verifySequence_isUserInputError()) //pressed wrong input
            {
                display_setTextSize(SC_TEXTSIZE);
                display_println(ERROR_MESSAGE_INPUT);
            }
            verifySequence_disable(); //set this here so we can read these flags. disable resets the error flags
            break;
        case SC_print_score_st:
            sprintf(maxScoreString, SC_HIGHSCORE_MESSAGE, SC_maxScore);
            display_setTextSize(SC_TEXTSIZE); //decrease text size
            display_println(maxScoreString);
            //reset scores, index, and sequence
            SC_currentIndex = 1; //reset to 1. since this is sequence length, when we setSequence, don't put to zero
            SC_maxScore = 0; //reset
            errorTimer = 0; //reset timer
            lvlMessageTimer = 0;
            break;
        case SC_level_complete_st:
            lvlMessageTimer++;
            if(printFlag) //set a flag so it doesn't keep being printed
            {
                display_println(SC_LVL_MESSAGE);
                printFlag = false; //switch flag
            }
            break;
        default:
            printf(SC_ERROR_MESSAGE); //invalid state
            break;
        }


        //TRANSITIONS***********************************************************************
        switch(SC_State)
        {
        case SC_init_st:
            SC_State = SC_instructions_st; //just go to instructions
            break;
        case SC_instructions_st:
            SC_State = SC_wait_first_touch_st; //go wait after drawing.
            break;
        case SC_wait_first_touch_st:
            if (display_isTouched()) //if touched, move ahead
            {
                SC_State = SC_get_sequence_st;
                display_fillScreen(DISPLAY_BLACK); //clear screen of instructions
            }
            break;
        case SC_get_sequence_st:
            SC_State = SC_flash_sequence_st;
            flashSequence_enable();
            break;
        case SC_flash_sequence_st:
            if (flashSequence_completed())
            {
                SC_State = SC_verify_sequence_st; //go to verify
                flashSequence_disable(); //disable flash machine
                simonDisplay_drawAllButtons(); //draw the buttons upon exit
                verifySequence_enable();
            }
            break;
        case SC_verify_sequence_st:
            if (verifySequence_isComplete()) //done verifying
            {
                //if there a time out error or wrong input error
                if (verifySequence_isTimeOutError() || verifySequence_isUserInputError()) //no errors
                {
                    SC_State = SC_error_st;
                    display_fillScreen(DISPLAY_BLACK); //clear buttons off screen
                }
                //level complete
                else if (globals_getSequenceIterationLength() == SC_sequence_length)
                {
                    SC_sequence_length++;
                    SC_State = SC_level_complete_st;
                    verifySequence_disable();
                    display_fillScreen(DISPLAY_BLACK); //clear buttons off screen
                    SC_currentIndex = 1; //reset
                    SC_maxScore = SC_currentScore;
                }
                else
                {
                    SC_State = SC_flash_sequence_st;
                    flashSequence_enable();
                    SC_currentIndex++; //how many to flash?
                    globals_setSequenceIterationLength(SC_currentIndex); //udate how many to falsh
                    verifySequence_disable();
                    display_fillScreen(DISPLAY_BLACK); //clear buttons off screen
                    SC_currentScore++;
                    if (SC_currentScore > SC_maxScore) //before first level is complete, maxScore doesn't get set
                    {
                        SC_maxScore = SC_currentScore; //this mostly before first level is complete
                    }
                }
            }
            break;
        case SC_error_st:
            if (errorTimer >= SC_ERROR_EXPIRE)
            {
                SC_State = SC_print_score_st; //print highest score
                display_fillScreen(DISPLAY_BLACK);
            }

            break;
        case SC_print_score_st:
            SC_State = SC_instructions_st;
            SC_maxScore = 0; //reset the maxScore!
            sequenceSeed++; //change the seed
            break;
        case SC_level_complete_st:
            if (lvlMessageTimer > SC_LVL_MESSAGE_EXPIRE) //timed out
            {
                SC_State = SC_print_score_st;
            }
            else if (display_isTouched())
            {
                SC_State = SC_instructions_st;
                display_fillScreen(DISPLAY_BLACK); // clear screen
                sequenceSeed++; //change the seed
                printFlag = true; //rest print flag
            }
            break;
        default:
            printf(SC_ERROR_MESSAGE);
            break;
        }

    }
Esempio n. 16
0
void ticTacToeControl_tick() //actions and transitions of state machine
{
    debugStatePrint(); //print state for debugging

    switch (TTT_State) //state machine actions
    {
    case TTT_init_st: //inital entry state
        readTimer = 0; //initialize read timer
        firstTouchTimer = 0; //set to zero
        adTimer = 0; //set to zerio
        break;
    case TTT_draw_instructions_st:
        //draw print the instructions
        display_setTextSize(TEXT_SIZE); //how big
        display_setTextColor(DISPLAY_WHITE);//set the color
        display_setCursor(INSTRUCTIONS_LOCATION_X, INSTRUCTIONS_LOCATION_Y);
        display_println(INSTRUCTIONS);//print instructions
        break;
    case TTT_let_user_read_st:
        readTimer++; //increase read timer
        break;
    case TTT_wait_first_touch_st:
        firstTouchTimer++; //increment first touch wait timer
        break;
    case TTT_wait_for_settle_st:
        adTimer++; //increment timer for settling
        break;
    case TTT_computer_play_st:
        if (playerX) //computer is O
        {
            minimax_computeNextMove(&currentBoard, false, &controlTouchRow, &controlTouchColumn); //its always computing computers move, so just set the bool to false
            ticTacToeDisplay_drawO(controlTouchRow, controlTouchColumn);
            //mark that board space
            currentBoard.squares[controlTouchRow][controlTouchColumn] = MINIMAX_OPPONENT_SQUARE;
        }

        else //computer went first, is X
        {
            minimax_computeNextMove(&currentBoard, false, &controlTouchRow, &controlTouchColumn); //its always computing computers move, so just set the bool to false
            ticTacToeDisplay_drawX(controlTouchRow, controlTouchColumn);
            //mark that board space
            currentBoard.squares[controlTouchRow][controlTouchColumn] = MINIMAX_OPPONENT_SQUARE;
        }

        break;
    case TTT_user_play_st:
        //read button value here, and check in transitions
        newBTNValue = buttons_read();

        invalidMoveFlag = false; // reset the flag

        //reset wait for settle timer
        adTimer = 0;

        if (playerX) //player went first, is X
        {
            ticTacToeDisplay_touchScreenComputeBoardRowColumn(&controlTouchRow, &controlTouchColumn);
            if(currentBoard.squares[controlTouchRow][controlTouchColumn] == MINIMAX_EMPTY_SQUARE) //check square is empty
            {
                ticTacToeDisplay_drawX(controlTouchRow, controlTouchColumn); //draw the x
                //mark that board space
                currentBoard.squares[controlTouchRow][controlTouchColumn] = MINIMAX_PLAYER_SQUARE; //mark move in board
            }
            else
                invalidMoveFlag = true; //player tried to go in occupied square
        }

        else //player is O
        {
            ticTacToeDisplay_touchScreenComputeBoardRowColumn(&controlTouchRow, &controlTouchColumn);
            if(currentBoard.squares[controlTouchRow][controlTouchColumn] == MINIMAX_EMPTY_SQUARE) //check square is empty
            {
                ticTacToeDisplay_drawO(controlTouchRow, controlTouchColumn); //draw the O
                //mark that board space
                currentBoard.squares[controlTouchRow][controlTouchColumn] = MINIMAX_PLAYER_SQUARE; //mark move in board
            }
            else
                invalidMoveFlag = true; //player tried to go in occupied square
        }
        break;
    case TTT_wait_touch_st:
    //just wait
    case TTT_end_st:
        //read button value here, and check in transitions
        //only reset at end game
        newBTNValue = buttons_read();

    default:
        break;
    }



    //////////////////////////////////////////////////////////////////////////////////////////////////



    switch (TTT_State) //state machine transitions
    {
    case TTT_init_st: //inital entry state
        TTT_State = TTT_draw_instructions_st; //move to instructions state
        break;
    case TTT_draw_instructions_st:
        TTT_State = TTT_let_user_read_st; //go straight to reading after instructions are drawn
        break;
    case TTT_let_user_read_st:
        if (readTimer == TTT_READ_EXPIRED)
        {
            TTT_State = TTT_wait_first_touch_st; //wait for touching
            ticTacToeDisplay_reset();//draw empty board. mealey action
        }
        break;
    case TTT_wait_first_touch_st:
    {
        if (firstTouchTimer == TTT_FIRST_TOUCH_EXPIRED) //if the wait is expired
        {
            //computer goes first. computer is X
            TTT_State = TTT_computer_play_st;
            playerX = false;
        }
        else if (display_isTouched()) //human touched a spot
        {
            //human goes first. is X
            TTT_State = TTT_wait_for_settle_st;
            playerX = true;
        }
    }
    break;
    case TTT_wait_for_settle_st:
        if (adTimer == ADTIMER_EXPIRE) //gave touch screen time to settle
        {
            TTT_State = TTT_user_play_st; //go to user play
        }
        break;
    case TTT_computer_play_st:
        // if board full, go to end game
        if (ticTacToeControl_checkEndGame(&currentBoard, false)) //pass in the board, does matter what the bool is, just need an endgame score
            TTT_State = TTT_end_st;
        else
            TTT_State = TTT_wait_touch_st; //go to place to wait for player to touch
        break;
    case TTT_user_play_st:
        if (ticTacToeControl_checkEndGame(&currentBoard, true)) //pass in the board, does matter what the bool is, just need an endgame score
            TTT_State = TTT_end_st;

        else if(invalidMoveFlag) //player tried to go in occupied space
        {
            TTT_State = TTT_wait_touch_st; //wait for another touch
        }

        else
            TTT_State = TTT_computer_play_st; //go to computer move


        break;
    case TTT_wait_touch_st:
        if (ticTacToeControl_checkEndGame(&currentBoard, playerX)) //pass in the board, does matter what the bool is, just need an endgame score
            TTT_State = TTT_end_st;
        else if (display_isTouched()) //done waiting
        {
            TTT_State = TTT_wait_for_settle_st; //go settle state
        }
        break;
    case TTT_end_st:
        ticTacToeControl_checkResetBTN(); //check if button has been pressed,
        break;
    default:
        printf("ERROR: missed transition\n\r");
        break;
    }
}
Esempio n. 17
0
// Helper function to write data to the LCD based on what button is pressed,
// blanks the screen otherwise.
void buttons_write_LCD(int32_t buttons) {

  // If BTN 0 is pressed
  if (buttons & BUTTONS_BTN0_MASK) {
    // check if btn0 is set so image is only drawn once
    if (btn0_status == BUTTONS_NOT_SET) {
      // Draw the background colored rectangle
      display_fillRect(x_three_fourths, 0, x_fourth, y_max, DISPLAY_CYAN);

      // Print BTN text in the middle of the rectangle
      display_setCursor(x_three_fourths, y_half); // position cursor
      display_println(" BTN 0");

      // Mark the button as SET so that there is no flickering of the image
      btn0_status = BUTTONS_SET;
    }
  }
  else {
    // Blank the used portion of the screen
    display_fillRect(x_three_fourths, 0, x_fourth, y_max, DISPLAY_BLACK);
    btn0_status = BUTTONS_NOT_SET; // mark btn0 as not set
  }

  // If BTN 1 is pressed
  if (buttons & BUTTONS_BTN1_MASK) {
    // Only draw image once
    if (btn1_status == BUTTONS_NOT_SET) {
      // Draw the background colored rectangle
      display_fillRect(x_half, 0, x_fourth, y_max, DISPLAY_YELLOW);

      // Print BTN text in the middle of the rectangle
      display_setCursor(x_half, y_half);  // position the cursor
      display_println(" BTN 1");

      // Mark the button as SET to eliminate flickering
      btn1_status = BUTTONS_SET;
    }
  }
  else {
    // Blank the used portion of the screen
    display_fillRect(x_half, 0, x_fourth, y_max, DISPLAY_BLACK);
    btn1_status = BUTTONS_NOT_SET;
  }

  // If BTN 2 is pressed
  if (buttons & BUTTONS_BTN2_MASK) {
    // Only draw image once
    if (btn2_status == BUTTONS_NOT_SET) {
      // Draw the background colored rectangle
      display_fillRect(x_fourth, 0, x_fourth, y_max, DISPLAY_GREEN);

      // Print BTN text in the middle of the rectangle
      display_setCursor(x_fourth, y_half);  // Position the cursor
      display_println(" BTN 2");

      // Mark the button as SET to eliminate flickering
      btn2_status = BUTTONS_SET;
    }
  }
  else {
    // Blank the used portion of the screen
    display_fillRect(x_fourth, 0, x_fourth, y_max, DISPLAY_BLACK);
    btn2_status = BUTTONS_NOT_SET;
  }

  // If BTN 3 is pressed
  if (buttons & BUTTONS_BTN3_MASK) {
    // Only draw image once
    if (btn3_status == BUTTONS_NOT_SET) {
      // Draw the background colored rectangle
      display_fillRect(0, 0, x_fourth, y_max, DISPLAY_RED);

      // Print BTN text in the middle of the rectangle
      display_setCursor(0, y_half); // set cursor to middle of rect
      display_println(" BTN 3");

      // Mark the button as SET to eliminate flickering
      btn3_status = BUTTONS_SET; // mark btn3 as set
    }
  }
  else {
    // Blank the used portion of the screen
    display_fillRect(0, 0, x_fourth, y_max, DISPLAY_BLACK);
    btn3_status = BUTTONS_NOT_SET;
  }
}