Octopuses now change direction
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Mon, 20 Jun 2011 16:07:33 +0000 (19:07 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Mon, 20 Jun 2011 16:07:33 +0000 (19:07 +0300)
...when crossing borders or hitting something.

mainwindow.cpp
timercontrolledtursas.cpp

index 3996d73..7907344 100644 (file)
@@ -79,7 +79,7 @@ void MainWindow::initializeBoundaries()
 
 void MainWindow::restartLevel()
 {
-    pScene_->setupMap(5,10,0);
+    pScene_->setupMap(5,10,5);
 }
 
 void MainWindow::about()
index 317bab9..1b89939 100644 (file)
@@ -103,7 +103,47 @@ void TimerControlledTursas::move()
 
 void TimerControlledTursas::changeDirection()
 {
-   // direction_ = rand()/8;
+    qDebug () << "Supposed to change direction";
+
+    int direction = (qrand()%8);
+    qDebug()  << direction;
+
+    switch (direction)
+    {
+        case 0:
+            direction_ = S;
+            break;
+
+        case 1:
+            direction_ = SW;
+            break;
+
+       case 2:
+            direction_ = W;
+            break;
+
+       case 3:
+            direction_ = NW;
+            break;
+
+       case 4:
+            direction_ = N;
+            break;
+
+       case 5:
+            direction_ = NE;
+            break;
+
+       case 6:
+            direction_ = E;
+            break;
+
+      case 7:
+            direction_ = SE;
+            break;
+
+
+    }
 
 }