**WARNING: THIS CONTAINS SPOILERS OF THE HOMEWORK, DO NOT READ FURTHER THEN THIS IF YOU DIDN't FINISH YOUR HOMEWORK.**

okay. big enough warning?

So... here is my Game.cpp ( I think I don't need to do Game.h also, because its the same like everyone i think)

Code: Select all

```
#include "Game.h"
Game::Game( HWND hWnd,const KeyboardServer& kServer )
: gfx ( hWnd ),
kbd( kServer ),
x( 400 ),
y( 300 )
{}
void Game::Go()
{
gfx.BeginFrame();
ComposeFrame();
gfx.EndFrame();
}
void Game::ComposeFrame()
{
int gb;
int speed;
gb = 255;
speed = 3;
if( kbd.EnterIsPressed() )
{
speed = 8;
}
if( kbd.SpaceIsPressed() )
{
speed = 1;
}
if( kbd.LeftIsPressed() )
{
x = x - speed;
}
if( kbd.RightIsPressed() )
{
x = x + speed;
}
if ( kbd.UpIsPressed() )
{
y = y - speed;
}
if( kbd.DownIsPressed() )
{
y = y + speed;
}
if( x < 5 )
{
x = 5;
}
if( x > 794 )
{
x = 794;
}
if( y < 5 )
{
y = 5;
}
if( y > 594 )
{
y = 594;
}
if( x < 300 )
{
gb = 5;
}
if( x > 500 )
{
gb = 5;
}
if( y < 300 )
{
gb = 5;
}
if( y > 500 )
{
gb = 5;
}
gfx.PutPixel( x, y,255,gb,gb );
gfx.PutPixel( -5 + x, y,255,gb,gb );
gfx.PutPixel( -4 + x, y,255,gb,gb );
gfx.PutPixel( -3 + x, y,255,gb,gb );
gfx.PutPixel( 3 + x, y,255,gb,gb );
gfx.PutPixel( 4 + x, y,255,gb,gb );
gfx.PutPixel( 5 + x, y,255,gb,gb ); <--- this might look messed up, but it aint in the file.
gfx.PutPixel( + x,-5 + y,255,gb,gb );
gfx.PutPixel( + x,-4 + y,255,gb,gb );
gfx.PutPixel( + x,-3 + y,255,gb,gb );
gfx.PutPixel( + x, 3 + y,255,gb,gb );
gfx.PutPixel( + x, 4 + y,255,gb,gb );
gfx.PutPixel( + x, 5 + y,255,gb,gb );
}
```

Code: Select all

```
#include "Game.h"
Game::Game( HWND hWnd,const KeyboardServer& kServer )
: gfx ( hWnd ),
kbd( kServer ),
x( 400 ),
y( 300 )
{}
void Game::Go()
{
gfx.BeginFrame();
ComposeFrame();
gfx.EndFrame();
}
void Game::ComposeFrame()
{
int r;
int b;
int g;
int speed;
r = 0;
b = 255;
g = 255;
speed = 3;
if( kbd.EnterIsPressed() )
{
speed = 8;
}
if( kbd.SpaceIsPressed() )
{
speed = 1;
}
if( kbd.LeftIsPressed() )
{
x = x - speed;
}
if( kbd.RightIsPressed() )
{
x = x + speed;
}
if ( kbd.UpIsPressed() )
{
y = y - speed;
}
if( kbd.DownIsPressed() )
{
y = y + speed;
}
if( x < 5 )
{
x = 5;
}
if( x > 794 )
{
x = 794;
}
if( y < 5 )
{
y = 5;
}
if( y > 594 )
{
y = 594;
}
if( x < 300 )
{
r = 255;
}
if( x > 500 )
{
r = 255;
}
if( y < 200 )
{
r = 255;
}
if( y > 400 )
{
r = 255;
}
gfx.PutPixel( x, y,r,g,b );
gfx.PutPixel( -5 + x, y,r,g,b );
gfx.PutPixel( -4 + x, y,r,g,b );
gfx.PutPixel( -3 + x, y,r,g,b );
gfx.PutPixel( 3 + x, y,r,g,b );
gfx.PutPixel( 4 + x, y,r,g,b );
gfx.PutPixel( 5 + x, y,r,g,b );
gfx.PutPixel( + x,-5 + y,r,g,b );
gfx.PutPixel( + x,-4 + y,r,g,b );
gfx.PutPixel( + x,-3 + y,r,g,b );
gfx.PutPixel( + x, 3 + y,r,g,b );
gfx.PutPixel( + x, 4 + y,r,g,b );
gfx.PutPixel( + x, 5 + y,r,g,b );
}
```