#include #include "outputManager.h" #include "inputManager.h" #include "loopTimer.h" //#include "cGameManager.h"; #include using std::deque; using namespace std; int newxsnake = 20; int newysnake = 20; deque xsnake; deque ysnake; COORD snakeDirection; CInputManager InputManager; COutputManager OutputManager; CLoopTimer LoopTimer(5); enum gameStatus{ down, up }; unsigned long score = 0; void opp(){ newxsnake = xsnake[0]; newysnake = ysnake[0]- 1; } void ned(){ newxsnake = xsnake[0]; newysnake = ysnake[0]+1; } void left(){ newxsnake = xsnake[0]-1; newysnake = ysnake[0]; } void right(){ newxsnake = xsnake[0]+1; newysnake = ysnake[0]; } void scorekeeping(){ OutputManager.SetColor(TEXT_WHITE, BACK_WHITE); OutputManager.PrintAt(" tomlinje " ,0, 40); OutputManager.SetColor(TEXT_WHITE, BACK_BLACK); OutputManager.PrintAt("Use arrow keys to control snake.", 5, 42); OutputManager.PrintAt("Score:", 65,42); OutputManager.PrintAt(score, 72, 42); OutputManager.PrintAt("[q] to quit to Main Menu", 5, 43); } void start(){ OutputManager.Initialize("Snake Window", 80, 50, TEXT_RED_BRIGHT, BACK_BLACK); OutputManager.PrintAt("Welcome to CCSnake. What do you want to do?", 10, 10); OutputManager.PrintAt("[P]lay Game", 22, 12); OutputManager.PrintAt ("[Q]uit Game", 22, 14); int eGameStatus = ' '; InputManager.GetNextKeyWait(eGameStatus); if(eGameStatus == 'p'){ LoopTimer.Start(); OutputManager.ClearScreen(); bool run = true; for(int i = 0; i < 4; i++) { xsnake.push_front(newxsnake); ysnake.push_front(newysnake); OutputManager.PrintAt('0', xsnake.front(), ysnake.front()); newxsnake++; } OutputManager.PrintAt('@', xsnake.front(), ysnake.front()); //TORE -- det er noe galt her en plass, hvis jeg setter løkken inn i while(run) kjører den uten stopp //men den dobler seg hele tiden. //slik som koden står nå, starter den med 4 element, før den blir til 1, den kjører heller ikke selv... int keyPressed = ' '; snakeDirection.X = 1; snakeDirection.Y = 0; while(run){ //scorekeeping(); LoopTimer.SleepUntilUpdate(); //OutputManager.PrintAt('0', xsnake.front(), ysnake.front()); if(InputManager.AnyKeyPressed()) { InputManager.GetNextKey(keyPressed); if(keyPressed == -11){ opp(); snakeDirection.X = 0; snakeDirection.Y = -1; }else if(keyPressed == -12){ ned(); snakeDirection.X = 0; snakeDirection.Y = 1; }else if(keyPressed == -13){ left(); snakeDirection.X = -1; snakeDirection.Y = 0; }else if(keyPressed == -14){ right(); snakeDirection.X = 1; snakeDirection.Y = 0; } } // end anykeypressed newxsnake = xsnake[0] + snakeDirection.X; newysnake = ysnake[0] + snakeDirection.Y; OutputManager.PrintAt(' ', xsnake.back(), ysnake.back()); xsnake.pop_back(); ysnake.pop_back(); OutputManager.PrintAt('O', xsnake.front(), ysnake.front()); xsnake.push_front(newxsnake); ysnake.push_front(newysnake); OutputManager.PrintAt('@', xsnake.front(), ysnake.front()); } // end while }else if(eGameStatus == 'q'){ OutputManager.ClearScreen(); } // end else if } // end start int main(){ start(); //system("pause"); return 0; }