The key function returns an integer value from a key input. Which then i input into the d function to move the snake around using the snakex and snakey variables. If you look at the d function it has 3 parameters. Everything seems like it should be a okay, but im getting these errors.
Line 64 is what needs to work.
1 2 3 4 5 6 7
||=== Build file: "no target" in "no project" (compiler: unknown) ===|
D:\Eclipse Workspace\MyfirstGame\src\MyfirstGame.cpp||In function 'int main()':|
D:\Eclipse Workspace\MyfirstGame\src\MyfirstGame.cpp|71|error: invalid conversion from 'int (*)()' to 'int' [-fpermissive]|
D:\Eclipse Workspace\MyfirstGame\src\MyfirstGame.cpp|16|note: initializing argument 1 of 'long int d(int, int&, int&)'|
D:\Eclipse Workspace\MyfirstGame\src\MyfirstGame.cpp||In function 'long int d(int, int&, int&)':|
D:\Eclipse Workspace\MyfirstGame\src\MyfirstGame.cpp|122|warning: no return statement in function returning non-void [-Wreturn-type]|
||=== Build failed: 1 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <windows.h>
#include <unistd.h>
#include <conio.h>
int key();
long d(int x, int &t, int &c);
int snakex=9;
int snakey=9;
bool running=true;
char map[20][20]={};
void Map_r() {
int i=0;
int j=0;
start:
do{
map[i][j]=('i');
char x=map[i][j];
++j;
std::cout<<x<<" ";
}while(j<20);
std::cout<<std::endl;
j=0;
++i;
if(i<20){
goto start;
}
}
void Map_p() {
int i=0;
int j=0;
startf:
do{
char x=map[i][j];
++j;
std::cout<<x<<" ";
}while(j<20);
std::cout<<std::endl;
j=0;
++i;
if(i<20){
goto startf;
}
}
void snake(int &o, int&p)
{
map[o][p]=('0');
}
int main(){
int rows=20;
snake(snakex,snakey);
while(running)
{
Map_r();
system("CLS");
//THIS isnt workingvvvvvvvvvvvvvv
d(key,snakex,snakey);
//This isnt working^^^^^^^^^
Map_p();
sleep(10);
system("CLS");
}
}
int i;
int key()
{
while(1)
{
for(i = 8; i <= 190; i++)
{
if (GetAsyncKeyState(i) & 0x8000)
{
return (i);
}}
return 0;
}
}
long d(int x, int &t, int &c)
{
switch (x)
{
case 38:{
c+=1;
map[t][c]={0};
break;
}
case 40:
{
//down
break;
}
case 37:
{
//left
break;
}
case 39:
{
//right
break;
default:
map[t][c]=0;
}
}
map[t][c]=0;
}
Im having problems with the d function. The key() function is supposed to input in the the d() function along with the snakex, and snake y variables through reference. Line 64 should work in theory, but it doesn't.