From 2351f97350e617128bd2035dda99a305bb74b45e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Heli=20Hyv=C3=A4ttinen?= Date: Mon, 20 Jun 2011 19:07:33 +0300 Subject: [PATCH] Octopuses now change direction ...when crossing borders or hitting something. --- mainwindow.cpp | 2 +- timercontrolledtursas.cpp | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 3996d73..7907344 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -79,7 +79,7 @@ void MainWindow::initializeBoundaries() void MainWindow::restartLevel() { - pScene_->setupMap(5,10,0); + pScene_->setupMap(5,10,5); } void MainWindow::about() diff --git a/timercontrolledtursas.cpp b/timercontrolledtursas.cpp index 317bab9..1b89939 100644 --- a/timercontrolledtursas.cpp +++ b/timercontrolledtursas.cpp @@ -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; + + + } } -- 1.7.9.5