codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
class Field; class Food; // Forward-declaration struct Controls { int u, d, l, r; void loadFromFile(); void saveToFile(); }; class Snake { public: void setControls(Controls &ctr) { ctrl = ctrl; } Snake() { } ~Snake() { } private: Controls ctrl; }; class Tile { public: Tile() {} virtual bool canPass() { return true; } private: }; class Food : public Tile { public: Food(int color) { this->color = color; } bool canPass() { return false; } private: int color; }; class Field { public: Field(Snake &s) : sn(s) {} void spawnFood(const Food &food) { // SnakeBoundaries = s.getBoundaries(); // Generate random place // See if everything is right // Spawn it to the field field[9][9] = food; } bool isDeadly() { // See where snake is with his segments // you can control each tile nicely if(field[2][2].canPass() != true) return true; // GAME OVER } private: Snake &sn; Tile field[10][10]; }; class Graphics { public: Graphics(Snake &s, Field &f) : snake(s), field(f) {} void drawGraphics() { // You have access to snake and field here } private: Snake &snake; Field &field; }; int main() { Snake a; Field field(a); field.spawnFood(Food(10)); // Maybe use RGB etc.. Graphics gfx(a, field); gfx.drawGraphics(); }
Private
[
?
]
Run code
Submit