diff options
author | Joursoir <chat@joursoir.net> | 2021-03-08 23:28:31 +0000 |
---|---|---|
committer | Joursoir <chat@joursoir.net> | 2021-03-08 23:28:31 +0000 |
commit | d987781b24c6f505a61a01794b6bc76b07c9b25d (patch) | |
tree | 7f6e5a971d9b3cb19746c79780deff364b5dcde9 | |
parent | ac3ab1206a7bddec5312bf974479853429426dfa (diff) | |
download | ascii-road-d987781b24c6f505a61a01794b6bc76b07c9b25d.tar.gz ascii-road-d987781b24c6f505a61a01794b6bc76b07c9b25d.tar.bz2 ascii-road-d987781b24c6f505a61a01794b6bc76b07c9b25d.zip |
add infinity vehicle ride
-rw-r--r-- | Vehicle.cpp | 5 | ||||
-rw-r--r-- | Vehicle.hpp | 10 | ||||
-rw-r--r-- | main.cpp | 48 |
3 files changed, 47 insertions, 16 deletions
diff --git a/Vehicle.cpp b/Vehicle.cpp index 3e71db4..9a5153c 100644 --- a/Vehicle.cpp +++ b/Vehicle.cpp @@ -23,3 +23,8 @@ bool Vehicle::Draw(int bound_x) return ret; } + +int Vehicle::GetLength() +{ + return veh_info[type].length; +}
\ No newline at end of file diff --git a/Vehicle.hpp b/Vehicle.hpp index 418a532..4e5e854 100644 --- a/Vehicle.hpp +++ b/Vehicle.hpp @@ -9,8 +9,18 @@ public: : type(a_type), pos_y(a_y), pos_x(a_x) { } ~Vehicle() { } + int GetLength(); + void MoveRight() { pos_x++; } bool Draw(int bound_x); /* return false if not draw anything */ }; +struct ll_vehicle { + Vehicle *data; + struct ll_vehicle *next; + + ll_vehicle(Vehicle *a_data, struct ll_vehicle *a_ptr) + : data(a_data), next(a_ptr) { } +}; + #endif /* ASCIIROAD_VEHICLE_H */ @@ -39,15 +39,6 @@ void draw_background() mvprintw(total_rows-3, 40, " | |"); mvprintw(total_rows-2, 40, " | |"); mvprintw(total_rows-1, 40, "______// \\\\"); - - refresh(); -} - -Vehicle *get_random_vehicle(int y, int x) -{ - Vehicle *car; - car = new Vehicle(rand() % veh_types_max, y, x); - return car; } int main(int argc, char *argv[]) @@ -63,24 +54,49 @@ int main(int argc, char *argv[]) getmaxyx(stdscr, total_rows, total_cols); Vehicle *car = 0; + struct ll_vehicle *ptr_first = new struct ll_vehicle(0, 0); + struct ll_vehicle *ptr; + int wait_move = 0; for(;;) { clear(); draw_background(); - if(!car) - car = get_random_vehicle(total_rows, -1); + ptr = ptr_first; + while(ptr) + { + car = ptr->data; + if(!car) { + if(wait_move > 0) + break; - car->MoveRight(); - if(!(car->Draw(total_cols))) { - delete car; - car = 0; + ptr->data = new Vehicle( + rand() % veh_types_max, total_rows, -1); + car = ptr->data; + wait_move = car->GetLength() + 3 + rand() % 10; + + ptr->next = new struct ll_vehicle(0, 0); + } + + car->MoveRight(); + if(!car->Draw(total_cols)) { + ptr = ptr->next; + delete car; + delete ptr_first; + ptr_first = ptr; + continue; + } + + ptr = ptr->next; } + if(wait_move > 0) + wait_move--; + refresh(); nanosleep(&my_timer, NULL); } - + endwin(); return 0; } |