Thread: C Moving and TwoDimensional Array

  1. #1
    Registered User
    Join Date
    Dec 2017
    Posts
    1

    C Moving and TwoDimensional Array

    • Can someone tell me why the Ball isnt moving?

      Code:
      #include <stdio.h>
      Code:
    • #include <stdlib.h>
    • #include "console.h"
    • int main()
    • {
    • char laby[5][15] = {{2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
    • {0,0,0,0,0,0,0,0,0,0,0,0,0,0,2},
    • {0,0,0,1,1,0,0,0,0,0,0,0,0,0,2},
    • {0,0,0,1,1,0,0,0,0,0,0,0,0,0,2},
    • {0,0,0,0,0,0,0,0,0,0,0,0,0,0,2}};
    • int i, j;
    • int whilezahl = 1;
    • for(i = 0; i < 5; i++)
    • {
    • for(j = 0; j < 15; j++)
    • {
    • if(laby[i][j] == 1)
    • {
    • printf("o");
    • }
    • else if(laby[i][j] == 0)
    • {
    • printf(" ");
    • }
    • else if(laby[i][j] == 2)
    • {
    • printf("X");
    • }
    • }
    • printf("\n");
    • }
    • setCursorType(0);
    • while(whilezahl = 1)
    • {
    • char taste = getch();
    • switch(taste)
    • {
    • case 'd': {
    • for(i = 0; i < 5; i++)
    • {
    • for(j = 0; j < 15; j++)
    • {
    • if(laby[i + 1][j] == 2)
    • {
    • system("cls");
    • printf("TOT");
    • return;
    • }
    • else if(laby[i][j] == 1)
    • {
    • laby[i][j] = 0;
    • laby[i + 1][j] = 1;
    • }
    • }
    • }
    • break;
    • }
    • case 'a': {
    • for(i = 0; i < 5; i++)
    • {
    • for(j = 0; j < 15; j++)
    • {
    • if(laby[i + 1][j] == 2)
    • {
    • system("cls");
    • printf("TOT");
    • return;
    • }
    • else if(laby[i][j] == 1)
    • {
    • laby[i][j] = 0;
    • laby[i][j + 1] = 1;
    • }
    • }
    • }
    • break;
    • }
    • case 'w': {
    • for(i = 0; i < 5; i++)
    • {
    • for(j = 0; j < 15; j++)
    • {
    • if(laby[i][j - 1] == 2)
    • {
    • system("cls");
    • printf("TOT");
    • return;
    • }
    • else if(laby[i][j] == 1)
    • {
    • laby[i][j] = 0;
    • laby[i ][j - 1] = 1;
    • }
    • }
    • }
    • break;
    • }
    • case 's': {
    • for(i = 0; i < 5; i++)
    • {
    • for(j = 0; j < 15; j++)
    • {
    • if(laby[i - 1][j] == 2)
    • {
    • system("cls");
    • printf("TOT");
    • return;
    • }
    • else if(laby[i][j] == 1)
    • {
    • laby[i][j] = 0;
    • laby[i - 1][j] = 1;
    • }
    • }
    • }
    • break;
    • }
    • }
    • }
    • return 0;
    • }

  • #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Learn how to post your code.

    It means not including all manner of formatting from your IDE.

    I've seen better formatted dog food.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  • #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Wow, this mess managed to break the site's format... Impressive.

    We can't tell you because we can't test it, it's non-portable and it includes a header we know nothing about.

    By the way, it's my personal opinion that encasing each case inside its own block is superfluous if you don't declare any variables inside it.
    Devoted my life to programming...

  • Popular pages Recent additions subscribe to a feed

    Similar Threads

    1. Replies: 17
      Last Post: 03-01-2012, 05:39 AM
    2. Moving Average (from and into an array)
      By browser in forum C Programming
      Replies: 4
      Last Post: 01-24-2010, 03:36 PM
    3. moving from one array adress to another
      By jrb47 in forum C++ Programming
      Replies: 2
      Last Post: 11-10-2006, 05:32 PM
    4. Moving values in an array
      By venomgts550 in forum C++ Programming
      Replies: 1
      Last Post: 11-24-2001, 06:41 PM

    Tags for this Thread