This is the Mexican Standoff prototype made by Francisco Martin and Andrew Smith. Please refer to the following link for instructions on hardware hookup: https://developer.mbed.org/users/fomartin/notebook/mexican-standoff-reaction-game/
Dependencies: SDFileSystem mbed-rtos mbed wave_player 4DGL-uLCD-SE PinDetect
CPU.cpp@2:3c1a5079243d, 2016-03-14 (annotated)
- Committer:
- fomartin
- Date:
- Mon Mar 14 19:14:23 2016 +0000
- Revision:
- 2:3c1a5079243d
- Parent:
- 0:75716bd37804
Fixed bug with player 2 pressing button during X prompt.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fomartin | 0:75716bd37804 | 1 | #include "States.h" |
fomartin | 0:75716bd37804 | 2 | #include <stdlib.h> |
fomartin | 0:75716bd37804 | 3 | #include <time.h> |
fomartin | 0:75716bd37804 | 4 | #include <float.h> |
fomartin | 0:75716bd37804 | 5 | |
fomartin | 0:75716bd37804 | 6 | |
fomartin | 0:75716bd37804 | 7 | |
fomartin | 0:75716bd37804 | 8 | CPU::CPU() |
fomartin | 0:75716bd37804 | 9 | { |
fomartin | 0:75716bd37804 | 10 | difficulty = 1; |
fomartin | 0:75716bd37804 | 11 | srand(time(NULL)); |
fomartin | 0:75716bd37804 | 12 | } |
fomartin | 0:75716bd37804 | 13 | |
fomartin | 0:75716bd37804 | 14 | CPU::CPU(int cpu_difficulty) |
fomartin | 0:75716bd37804 | 15 | { |
fomartin | 0:75716bd37804 | 16 | difficulty = cpu_difficulty; |
fomartin | 0:75716bd37804 | 17 | srand(time(NULL)); |
fomartin | 0:75716bd37804 | 18 | } |
fomartin | 0:75716bd37804 | 19 | |
fomartin | 0:75716bd37804 | 20 | float CPU::shootTime() |
fomartin | 0:75716bd37804 | 21 | { |
fomartin | 0:75716bd37804 | 22 | |
fomartin | 0:75716bd37804 | 23 | int randNumber = rand() % 10; |
fomartin | 0:75716bd37804 | 24 | |
fomartin | 0:75716bd37804 | 25 | float answer = (rand() % 10 + 1) / 10.0f; |
fomartin | 0:75716bd37804 | 26 | return answer / (float) difficulty; |
fomartin | 0:75716bd37804 | 27 | } |
fomartin | 0:75716bd37804 | 28 | |
fomartin | 0:75716bd37804 | 29 | bool CPU::shootAnswer(Prompt correctAnswer) |
fomartin | 0:75716bd37804 | 30 | { |
fomartin | 0:75716bd37804 | 31 | if(correctAnswer == Down || correctAnswer == Up) |
fomartin | 0:75716bd37804 | 32 | { |
fomartin | 0:75716bd37804 | 33 | int randNumber = rand() % 10; |
fomartin | 0:75716bd37804 | 34 | |
fomartin | 0:75716bd37804 | 35 | if(randNumber == 9) |
fomartin | 0:75716bd37804 | 36 | return false; |
fomartin | 0:75716bd37804 | 37 | } |
fomartin | 0:75716bd37804 | 38 | |
fomartin | 0:75716bd37804 | 39 | return true; |
fomartin | 0:75716bd37804 | 40 | } |