termios - Cursor moving erratically (C) -
i'm having trouble doing nim game program. far have program show pyramid of pipes. looks "start position" pyramid on picture.
http://www.mathsisfun.com/puzzles/images/b-nim.gif
anyways, i'm having trouble moving around this, whenever try moving around, cursor move in erratic ways. thid make game totally unplayable. i'm not sure if problem counting variables or smaller thing i'm totally missing, anyways here's have:
#include <stdlib.h> int nim() { char *tab; if ((tab = malloc(sizeof(char) * 20 + 4)) == null) return (-1); tab = " | \n ||| \n ||||| \n |||||||\n"; /* indeed nasty way :p */ putstr(tab); } int move_normally() { char bffr[10]; int x; int y; x = 0; y = 0; while (42 && x <= 6 && y <= 3) { read(0, bffr, 10); putstr(tgoto(tgetstr("cm", null), x, y); if (bffr[2] == 66 && y <= 3 && x <= 6) y++ else if (bffr[2] == 65 && x <= 6 && y <= 3 && (y - 1) >= 0) y = y - 1; else if (bffr[2] == 67 && x <= 6 && y <= 3) x++ else if (bffr[2] == 68 && x <= 6 && y <= 3 && (x - 1) >= 0) x++ } }
so, there i'm missing here? else works , can't hands on why giving trouble. also, there other ways this? i'm open alternative way.
Comments
Post a Comment