struct i funktion
hej eksperter.. jeg er igang med at lave et simpelt snake spil i dos.jeg har dog løbet ind i nogle problemer når jeg skal kalde både en struct + variable ind i en funktion:
////////////////////////////////////////////////////////////////////
#include <stdlib.h>
#include <iostream.h>
#include <conio.h>
#include <windows.h>
#include <vector.h>
#define NORTH 0
#define SOUTH 1
#define EAST 2
#define WEST 3
#define SCREEN_WIDTH 79
#define SCREEN_HEIGHT 25
#define ERASE 0
#define DRAW 1
struct Spiller
{
COORD Position;
int Direction;
};
void spilleplade();
void monster( int x, int y );
void Tjek_bane( Spiller Spiller );
void Move_spiller( Spiller & Spiller );
HANDLE hInput, hOutput;
///////////////////////////////////////////////////////////////////////////////
int main()
{
int monster_x, monster_y;
srand( time( NULL ) );
monster_x = ( rand() % 78 + 2 );
monster_y = ( rand() % 44 + 2 );
vector < int > x;
vector < int > y;
spilleplade();
monster( monster_x, monster_y );
Spiller Spiller;
hInput = GetStdHandle( STD_INPUT_HANDLE );
hOutput = GetStdHandle( STD_OUTPUT_HANDLE );
SetConsoleMode( hInput, ENABLE_PROCESSED_INPUT );
Spiller.Position.X = SCREEN_WIDTH / 2;
Spiller.Position.Y = SCREEN_HEIGHT / 2;
SetConsoleCursorPosition( hOutput, Spiller.Position );
////////////////////////////// G*A*M*E L*O*O*P ////////////////////////////////
while ( 1 )
{
INPUT_RECORD InputRecord; DWORD Events = 0;
ReadConsoleInput( hInput, & InputRecord, 1, & Events ); // bruges til at læse det man trykker på keyboard
int tempo = 50;
int dir; // direction, angiver hvilken vej man bevæger sig
if ( InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_RIGHT )
{
dir = 2;
Move_spiller(Spiller, dir, x, y); // HER LIGGER FEJLEN <----------
}
else if ( InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_LEFT )
{
dir = 4;
}
else if ( InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_UP )
{
dir = 1;
}
else if ( InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_DOWN )
{
dir = 3;
}
Sleep( tempo );
Tjek_bane( Spiller );
for ( double j = 0; j <= x.size(); j++ )
{
SetConsoleCursorPosition( hOutput, Spiller.Position );
char brik = 219;
gotoxy( x[j], y[j] );
cout << brik;
}
}
// FlushConsoleInputBuffer( hInput );
return 0;
}
////////////////////////////////////////////////////////////////////////////////
void spilleplade()
{
//starter øverste grænse
for ( int i = 1; i <= SCREEN_WIDTH; i++ )
{
gotoxy( i, 1 );
cout << "*";
}
//starter venstre grænse
for ( int j = 1; j <= SCREEN_HEIGHT; j++ )
{
gotoxy( 1, j );
cout << "*";
}
//starter højre grænse
for ( int h = 1; h <= SCREEN_HEIGHT; h++ )
{
gotoxy( 80, h );
cout << "*";
}
//starter nedre grænse
for ( int k = 1; k <= SCREEN_WIDTH; k++ )
{
gotoxy( k, SCREEN_HEIGHT );
cout << "*";
}
}
///////////////////////////////////////////////////////////////////////////////
void monster( int x, int y )
{
char monster = -219; // opretter en variabel med en asciiværdi
gotoxy( x, y );
cout << monster;
}
///////////////////////////////////////////////////////////////////////////////
void Tjek_bane( Spiller Spiller )
{
if ( Spiller.Position.X >= SCREEN_WIDTH )
{
gotoxy( 24, 65 );
cout << " DU ER DØD ";
}
else if ( Spiller.Position.X <= 0 )
{
gotoxy( 24, 65 );
cout << " DU ER DØD ";
}
else if ( Spiller.Position.Y >= SCREEN_HEIGHT - 1 )
{
gotoxy( 24, 65 );
cout << " DU ER DØD ";
}
else if ( Spiller.Position.Y <= 0 )
{
gotoxy( 24, 65 );
cout << " DU ER DØD ";
}
}
///////////////////////////////////////////////////////////////////////////////
void Move_spiller( int dir, vector<int>x, vector<int>y, Spiller & Spiller )
{
if ( dir == 2 ) // hvis retningen er op ad
{
Spiller.Position.Y--;
y.push_back( Spiller.Position.Y );
x.push_back( Spiller.Position.X );
}
else if ( dir == 2 ) // hvis retningen er til højre
{
Spiller.Position.X++;
y.push_back( Spiller.Position.Y );
x.push_back( Spiller.Position.X );
}
else if ( dir == 3 ) // hvis retningen er ned ad
{
Spiller.Position.Y++;
y.push_back( Spiller.Position.Y );
x.push_back( Spiller.Position.X );
}
else if ( dir == 2 ) // hvis retningen er til venstre
{
Spiller.Position.X--;
y.push_back( Spiller.Position.Y );
x.push_back( Spiller.Position.X );
}
}
///////////////////////////////////////////////////////////////
jeg får compiler fejl:
bcc32 -D_DEBUG -g100 -j25 -Od -r- -k -y -v -vi- -tWC -c -IC:\CBuilderX\include -o"C:\Documents and Settings\dannie\cbproject\snake\windows\Debug_Build\File2.obj" File2.cpp
Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland
File2.cpp:
"File2.cpp": E2227 Extra parameter in call to Move_spiller(Spiller &) in function main() at line 86
"File2.cpp": W8004 'dir' is assigned a value that is never used in function main() at line 135
"File2.cpp": W8066 Unreachable code in function main() at line 146
*** 1 errors in Compile ***
BCC32 exited with error code: 1
Build cancelled due to errors
hvad gør jeg galt???