Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem mbed-rtos mbed wave_player 4DGL-uLCD-SE PinDetect
Diff: CPU.cpp
- Revision:
- 0:75716bd37804
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CPU.cpp Mon Mar 14 03:04:08 2016 +0000
@@ -0,0 +1,40 @@
+#include "States.h"
+#include <stdlib.h>
+#include <time.h>
+#include <float.h>
+
+
+
+CPU::CPU()
+{
+ difficulty = 1;
+ srand(time(NULL));
+}
+
+CPU::CPU(int cpu_difficulty)
+{
+ difficulty = cpu_difficulty;
+ srand(time(NULL));
+}
+
+float CPU::shootTime()
+{
+
+ int randNumber = rand() % 10;
+
+ float answer = (rand() % 10 + 1) / 10.0f;
+ return answer / (float) difficulty;
+}
+
+bool CPU::shootAnswer(Prompt correctAnswer)
+{
+ if(correctAnswer == Down || correctAnswer == Up)
+ {
+ int randNumber = rand() % 10;
+
+ if(randNumber == 9)
+ return false;
+ }
+
+ return true;
+}
\ No newline at end of file