int main(int argc, char *argv[])
{
if (First_main_func_call == 1){
Set_k_default();
}
First_main_func_call = 0;
registershort keystroke;
Set_ground();
Set_walls();
while(1)
{
if (y <= 0)
{y++;}
if (y >= 59)
{y--;}
if (x <= 0)
{x++;}
if (x >= 24)
{x--;}
Set_Map(x, y, val);
Clear_Screen();
printf("TT Level editor 0.77 ALPHA(Linux port) \nEnter o key to save(l to load) Ctrl Z to exit\n");
printMap();
printf("xcord: %d\nycord: %d\nTile ID: %c", x, y, Set_Map(x, y, val));
printf("\nPress ESC for Menu\n");
keystroke = getchar();//getch wont work on linux
if( keystroke == 0 || keystroke == 224)
keystroke = getchar() + 255;//getch wont work on linux
if (keystroke == w)
{
x--;
}
elseif (keystroke == s)
{
x++;
}
elseif (keystroke == a)
{
y--;
}
elseif (keystroke == d)
{
y++;
}
if (keystroke == key_1)
{val = k1;}
if (keystroke == key_2)
{val = k2;}
if (keystroke == key_3)
{val = k3;}
if (keystroke == key_4)
{val = k4;}
if (keystroke == key_5)
{val = k5;}
if (keystroke == key_6)
{val = k6;}
if (keystroke == key_7)
{val = k7;}
if (keystroke == key_8)
{val = k8;}
if (keystroke == key_9)
{val = k9;}
if (keystroke == key_0)
{val = k0;}
if (keystroke == SPACE){val = 32;}
if (keystroke == ESC)//esc key
{menu();}
if (keystroke == o)
{save();}
if (keystroke == l)
{load(argv[1]);}//calling load function
}
return 0;
}
and headers if you want to know where the functions like SetMap() came from:
#include <stdio.h>
#include <stdlib.h>
#include "Text Engine.h"
#include "Functions.h"
#include "macros.h"
if anyone knows why this isnt working please reply!!
also i am running linux(xubuntu) with gcc as my compiler
thanks in advance!
A couple of other comments on your code:
load line 21: avoid the use of goto.
main line 3: It appears that you're calling main recursively. This is explicitly prohibited by the standard.
main line 7: Using the register keyword is unnecessary with today's optimizing compilers. If you're concerned about efficiency, you should use a switch statement for lines 27-70.
in reply to AbstractionAnon
thanks for the advice on the register keyword
but i have never understood why pepole dont use goto
i agree you should not use it often but for example
if you need to quickly escape from 4 layers of while and for loops
i think goto is a good idea
and also in simple functions i dont see why you should not use it
as long as it stays simple
Read Dijkstra's paper "Goto considered harmful". It is old, but still reasonable. For modern compilers main drawback is that goto can seriously hamper optimizations. Goto can be useful and descriptive as qoick jump in case of error (it should almost never be a part of normal execution): goto error; where error label is placed after last proper return.
if you need to quickly escape from 4 layers of while and for loops
Having 4 nested loops is already bad idea ( O(N4) complexity? ). Usually this is solved by refactoring your program and in most cases these loops are moved into separate function which you just return from.
>> Read Dijkstra's paper "Goto considered harmful". It is old, but still reasonable.
>> For modern compilers main drawback is that goto can seriously hamper optimizations.
Something contained in a separate file should have a more descriptive name. Also, macros are generally written in all capitals as a hint to the reader that they are macros.
I wish they would add a feature to the language that would let you put one or more optional keywords after the break command. The keywords would indicate what you want to break out of:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
for (...) {
while (...) {
switch(x) {
case 1:
break; // breaks out of switch
case 2:
breakswitchwhile; // breaks out of switch and while loop
case 3:
breakfor; // syntax error. First breakable statement isn't a for loop
case 4:
break; switchwhilefor // breaks out of all three
}
}
}