Thursday, 2 May 2013

Source Code Output











Snake and Ladder's Source Code


#include<stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include <string.h>
void layout (void);
void display (void);
void kotak (void);
int dice(void);
int snake(void);
int ladder(void);
void greetx(void);
void greety(void);
void actionx(void);
void actiony(void);


int p1=0, p2=0,y, m,x,j;   // mm=throw dice P1 // m=throw dice P2
int dadu, rands;      // randg=dice     //rands=snake/ladder
int level[25]={0,2,0,1,2,2,1,2,0,1,2,2,1,2,0,1,2,2,1,1,0,0,0,1,2};  
char P1name[100], P2name[100], mm;   //y=titik2
int main()
{
    system("TITLE SNAKE N LADDER");
    layout();
   
   
    fflush (stdin);
    printf("\n\nWe need to have your name\n");
    printf("\n\nEnter Player 1 name:");
    scanf("%s", &P1name);
    printf("\n\nEnter Player 2 name:");
    scanf("%s", &P2name);
    system("cls");
 
 
       
    do      // do-while function
    {
            kotak ();
     
          system("color F9");
          printf("\n\n------------------------\nNow is %s's turn(P1). Throw your dice by enter any number between 1-9 .\n", strupr(P1name));
         
         
          x=dice();                  //function call 2
          p1+=x;
         
          do{
          scanf(" %c", &mm);   //dummies
          }while(isdigit(mm)==0);
         
         
               
          for(y=0;y<20;y++)
          {
              printf(".");
              sleep(100);
          }
          printf("\nyour dice number is %d\n", x);
          greetx();           //function call 3
          actionx();          //function call 5
          p1+=rands;  
          greetx();
   
          printf("\n\n------------------------\nNow is %s's turn(P2). Throw your dice by enter any number between 1-9 .\n", strupr(P2name));
   
          j=dice();
          p2+=j;
          scanf("%d", &m);
                 //dummies
          for(y=0;y<20;y++)
          {
              printf(".");
              sleep(100);
          }
          printf("\nyour dice number is %d\n", j);
          greety();            //function call 4
          actiony();           //function call 6
          p2+=rands;
          greety();
         
        sleep(3000);
        system("cls");  

    }while(p1<=25 && p2<=25);
   
    printf ("THANK YOU FOR PLAYING ! LOVE YA !");
   
    system("pause");
    return 0;
}                   //end of function main

 layout ()
{
     
    sleep(1000);
    printf("\n\t\t\t\tHOLLA GUYS\n\n\n\n\n");
    sleep(1000);
    printf ("\a");
    printf("\tCaution: this is a 2 players game. You need a partner to play with !\n\n\n\n\n\n");
    sleep(2000);
   
    printf ("   ");
    for(y=0;y<20;y++)
    {printf(".");
    sleep(100);
     }
     printf("T");
     sleep(100);
     printf ("H");
     sleep(100);
     printf ("E");
     sleep(100);
     printf (" ");
     sleep(100);
     printf ("D");
     sleep(100);
      printf("O");
      sleep(100);
      printf("N");
      sleep(100);
      printf("U");
      sleep(100);
      printf("T");
      sleep(100);
       printf("");
       sleep(100);
      printf("I");
      sleep(100);
      printf("I");
      sleep(100);
      printf("U");
      sleep(100);
      printf("M");
      sleep(100);
       printf(" ");
       sleep(100);
      printf("C");
      sleep(100);
      printf("O");
      sleep(100);
      printf("M");
      sleep(100);
      printf("P");
      sleep(100);
      printf("A");
      sleep(100);
      printf("N");
      sleep(100);
      printf("Y");
      sleep(100);
       printf(" ");
       sleep(100);
      printf("P");
      sleep(100);
      printf("R");
      sleep(100);
      printf("E");
      sleep(100);
      printf("S");
      sleep(100);
      printf("E");
      sleep(100);
      printf("N");
      sleep(100);
      printf("T");
      sleep(100);
      printf("S");
    for(y=0;y<20;y++)
    {printf(".");
    sleep(100);
     }
     sleep(1000);
    system("cls");
   
     for (x=0;x<4;x++)
    {
        if(x==1)
        {system("color 05");
         sleep(200);
         system("cls");}
        else if(x==2)
        {system("color 09");
         sleep(200); system("cls");}
        else if(x==3)
        {system("color 03");
         sleep(200); system("cls");}
       
       
    printf ("                               A NEW VERSION OF \n\n\n");
    printf("\n\n");
    printf("                OOOOOOO    OOO   OO      OOO      OO  OO  OOOOOOO          \n");
    printf("               OOO     OO  OOOO  OO     OO OO     OO OO   OO               \n");  
    printf("                 OOOOO     OO OO OO    OO   OO    OOOO    OOOOO         \n");
    printf("              OO     OOO   OO  OOOO   OOOOOOOOO   OO 00   OO              \n");
    printf("                OOOOOOO    OO   OOO  OO       00  00  00  OOOOOOO          \n\n");
   
    printf("                             OO   OOO   OO  00                                  \n");
    printf("                                  OOOO  OO                                     \n");  
    printf("                                  OO OO OO                                      \n");
    printf("                                  OO  OOOO                                      \n");
    printf("                                  OO   OOO                                     \n\n");


    printf("           OO           OOO      OOOOOO    OOOOOO   OOOOOO  OOOOOO      \n");  
    printf("           OO          OO OO     OO   OO   OO   OO  OO      OO   OO     \n");  
    printf("           OO         OO   OO    OO    OO  OO    OO OOOO    OOOOOO      \n");
    printf("           OO        OOOOOOOOO   OO   OO   OO   OO  OO      OO  OO      \n");
    printf("           OOOOOOO  OO       OO  OOOOOO    OOOOOO   OOOOOO  OO   OO     \n");
   
    }
    display();
    system("cls");  
}
display()
{
   
     int num;
   
     system("color 0B");
   
     printf("\n\t\t\t\t1. Instruction\n");
     printf("\t\t\t\t2. Help\n");
     printf("\t\t\t     Press any Key to Start\n");
     scanf("%d", &num);
     system("cls");
     switch (num)
     {
         
     case 1 : system("color 0E");
     printf("1. Enter your name to play.\n2. Roll the dice to move on.\n3. Press any number on keyboard and program will randomly choose the number for you.\n4. You need to answer the questions provided when you have stepped on ladder or snake.\n5. If you answer correctly, you'll be rewarded. If not, you'll be punished.\n6. The first player who can make it to the level 20 will be the winner.\n7. Consonant S indicates snake while consonant L indicates ladder on board game but they are randomly distributed and not exactly seen on the board game.\n\n");
     sleep(23000);
     system("cls");break;
     case 2 : system("color 0B");
     printf("Any enquires, please contact any of these programmers :\n1. Abdul Muhaimin \n2. Afiq Zahin\n3. Abdul Halim\n4. Abdul Rahim\n4. Abdul Hakim\n");
     sleep(5000);
     system("cls");break;
     default : printf ("you may start\n");
   
     }
}

kotak ()
{
    printf  ("\n.------.------.------.------.------.\n");
    printf    ("|      |      |      |      |      |\n");
    printf    ("|  25  |  24  |  23  |  22  |  21  |\n");
    printf    ("|      |      |      |      |      |\n");
    printf    ("|------|------|------|------|------|\n");
    printf    ("|      |      |      |      |      |\n");
    printf    ("|  16  |  17  |  18  |  19  |  20  |\n");
    printf    ("|      |      |      |      |      |\n");
    printf    ("|------|------|------|------|------|\n");
    printf    ("|      |      |      |      |      |\n");
    printf    ("|  11  |  12  |  13  |  14  |  15  |\n");
    printf    ("|      |      |      |      |      |\n");
    printf    ("|------|------|------|------|------|\n");
    printf    ("|      |      |      |      |      |\n");
    printf    ("|  10  |  9   |  8   |  7   |  6   |\n");
    printf    ("|      |      |      |      |      |\n");
    printf    ("|------|------|------|------|------|\n");
    printf    ("|      |      |      |      |      |\n");
    printf    ("|  1   |  2   |  3   |  4   |  5   |\n");
    printf    ("|      |      |      |      |      |\n");
    printf    ("'------'------'------'------'------'\n");
}

int dice()            //function 2
{
       
      srand(time(NULL));
      dadu =1+ rand() %6;
     
      return dadu;
}

void greetx()           //function 3
{
        if(p1<25)
       printf("you are now level %d\n", p1);
       else
       printf("yay! menang! CONGRATS ! ");
}

void greety()        //function 4
{
        if(p2<25)
        printf("you are now level %d\n", p2);
        else
        printf("yay! menang! CONGRATS !");
}

void actionx(void)          //function 5
{
        switch( level[p1])  
        {
        case 0: printf("this level doesnt have any snake or ladder\n"); break;
        case 1: printf("this level have snake! \n");snake(); break;        //function call 7
        case 2: printf("this level have ladder! good for you!\n");ladder(); break;      //function call 8
        }
}

void actiony(void)            //function 6
{
        switch( level[p2])  
        {
        case 0: printf("this level doesnt have any snake or ladder\n"); break;
        case 1: printf("this level have snake! \n");snake(); break;               //function call 7
        case 2: printf("this level have ladder! good for you!\n");ladder(); break;    //function call 8
        }
}

       

int snake(void)              //function 7     //questions (salah undur)
{

       int ss, ans;
     
       srand(time(NULL));
      rands = -3+ rand() %3;
      printf("You may slip by %d if u can't answer this quetion.\n", rands);
     
      srand(time(NULL));
      ss = 1+ rand() %12;
      switch(ss)
      {
                case 1 : printf("who is capable to be prime minister after GE13?\n 1. tun mahathir \n 2. hisyamuddin hussin\n 3. muhyiddin hussin\n 4. muhkriz mahathir\n");
                scanf("%d", &ans);
                if(ans!=4)
                printf("Your answer is wrong!");
                else
                {
                    printf("Your answer is correct!");
                    rands=0;
                }
                ; break;
                case 2 : printf("what is fastest smartphone OS?\n 1. android 4.2\n 2. ios6 \n 3. bada\n 4. windows\n");
                scanf("%d", &ans);
                if(ans!=2)
                printf("Your answer is wrong!");
                else
                {
                    printf("Your answer is correct!");
                    rands=0;
                }
                ; break;
                case 3 : printf("what is the slimmest ultrabook?\n 1. asus zenbook\n 2. acer s5\n 3. samsung s7\n 4. apple macbook air\n");
                scanf("%d", &ans);
                if(ans!=2)
                printf("Your answer is wrong!");
                else
                {
                    printf("Your answer is correct!");
                    rands=0;
                }
                ; break;
                case 4 : printf("what is the largest ocean in this world?\n 1.pacific \n 2. indian\n 3. atlantic s7\n 4. english channel\n");
                scanf("%d", &ans);
                if(ans!=1)
                printf("Your answer is wrong!");
                else
                {
                    printf("Your answer is correct!");
                    rands=0;
                }
                ; break;
                case 5 : printf("What is the largest state in Malaysia\n 1. Perlis \n 2.Sabah  \n 3. Pahang \n 4. Sarawak \n");
                scanf("%d", &ans);
                if(ans!=4)
                printf("Your answer is wrong!");
                else
                {
                    printf("Your answer is correct!");
                    rands=0;
                }
                ; break;
                case 6 : printf("which one of them is the english actress?\n 1. Katie Holmes \n 2. Taylor Swift \n 3. Emma Watson \n 4. Katy Perry \n");
                scanf("%d", &ans);
                if(ans!=3)
                printf("Your answer is wrong!");
                else
                {
                    printf("Your answer is correct!");
                    rands=0;
                }
                ; break;
                case 7 : printf("which coutry have largest population?\n 1. Russia \n 2. USA \n 3. Brazil \n 4. Papua New Guinea\n");
                scanf("%d", &ans);
                if(ans!=3)
                printf("Your answer is wrong!");
                else
                {
                    printf("Your answer is correct!");
                    rands=0;
                }
                ; break;
                case 8 : printf("Frog belong to which animal group?\n 1. mammals \n 2. amphibians \n 3. reptiles \n 4. intervebtares \n");
                scanf("%d", &ans);
                if(ans!=2)
                printf("Your answer is wrong!");
                else
                {
                    printf("Your answer is correct!");
                    rands=0;
                }
                ; break;
                case 9 : printf("which is not  William Shakespear poem?\n 1. The Sonnet \n 2. As you Like It \n 3. Life Brief Candles\n 4. Five Ways To Kill A Man\n");
                scanf("%d", &ans);
                if(ans!=4)
                printf("Your answer is wrong!");
                else
                {
                    printf("Your answer is correct!");
                    rands=0;
                }
                ; break;
                case 10 : printf("which is thriller drama series?\n 1.Arrow \n 2.Friends \n 3.Malcomn In The Middle\n 4. Sabrina The Teenage Witch \n");
                scanf("%d", &ans);
                if(ans!=1)
                printf("Your answer is wrong!");
                else
                {
                    printf("Your answer is correct!");
                    rands=0;
                }
                ; break;
                case 11 : printf("Gabriel Bastistuta was once footballers for which coutry?\n 1.Malaysia \n 2. Brazil\n 3. Argentina\n 4. Spain\n");
                scanf("%d", &ans);
                if(ans!=3)
                printf("Your answer is wrong!");
                else
                {
                    printf("Your answer is correct!");
                    rands=0;
                }
                ; break;
                case 12 : printf(" which one of them not related to Avengers heroes?\n 1.The Flash \n 2. Thor\n 3. Hawkeye\n 4. Hulk\n");
                scanf("%d", &ans);
                if(ans!=1)
                printf("Your answer is wrong!");
                else
                {
                    printf("Your answer is correct!");
                    rands=0;
                }
                ; break;
               
               
               
      }
      return rands;
}

int ladder(void)                   //function 8     //questions (if betul dapat skip)
{
      int ss, ans;
      srand(time(NULL));
      rands = 1+ rand() %3;
      printf("You may skip by %d if u can answer this question.\n", rands);
     
      ss = 1+ rand() %6;
      switch(ss)
      {
                case 1 : printf("10x20=?\n 1. 20\n 2. 400\n 3. 200\n 4. 2000\n");
                scanf("%d", &ans);
                if(ans==3)
                printf("Your answer is correct!");
                else
                {
                    printf("Your answer is wrong!");
                    rands=0;
                }
                ; break;
                case 2 : printf("5+5=??\n 1. 10\n 2. 20\n 3. 30\n 4. 40\n");
                scanf("%d", &ans);
                if(ans==1)
                printf("Your answer is correct!");
                else
                {
                    printf("Your answer is wrong!");
                    rands=0;
                }
                ; break;
                case 3 : printf("5x3=?\n 1. 0\n 2. 5\n 3. 10\n 4. 15\n");
                scanf("%d", &ans);
                if(ans==4)
                printf("Your answer is correct!");
                else
                {
                    printf("Your answer is wrong!");
                    rands=0;
                }
                ; break;
                case 4 : printf("5+3x4=?\n 1. 18\n 2. 17\n 3. 32\n 4. 60\n");
                scanf("%d", &ans);
                if(ans==2)
                printf("Your answer is correct!");
                else
                {
                    printf("Your answer is wrong!");
                    rands=0;
                }
                ; break;
                case 5 : printf("9/3x5=?\n 1. 9\n 2. 3.5\n 3. 8\n 4. 15\n");
                scanf("%d", &ans);
                if(ans==4)
                printf("Your answer is correct!");
                else
                {
                    printf("Your answer is wrong!");
                    rands=0;
                }
                ; break;
                case 6 : printf("1+1=?\n 1. 4\n 2. 3\n 3. 2\n 4. 1\n");
                scanf("%d", &ans);
                if(ans==3)
                printf("Your answer is correct!");
                else
                {
                    printf("Your answer is wrong!");
                    rands=0;
                }
                ; break;
               
               
      }
      return rands;
}

FLOW CHART

Click links to download flow charts .

flow chart #1

flow chart #2

flow chart #3


Work Distribution

In order to complete this project , we were divided each group members with their own assignment . Our work include publication, idea and creativity, and management.  As a result , we can manage the project systemically and if we have a problem we gather and solve the problem together . Stated below is the program development life cycle (PDLC) of this project .

Requirements

As everyone agreed, we decided to make a program of snake and ladder game . We collected the requirements needed in this game to ensure the users will use this program with full of pleasure . 

Design

We then, distribute the responsibility to design our game to few members that have high taste in art art design . They also need to design the header in order to make this game nice to see and attractive. At this level we met a lot to ensure all members are all updated to the latest development of this project.

Implementation

At this point, we started to build the source code with few functions used . The suorce code then need to be reviewed for quit some time.

Verification

We run the source code a lot to enable us to detect the errors in the source code . As the error detected, we'll fix it and run it again until everything run perfectly .

Maintenance

The program that has been completed will undergo maintenance to add some features up to enhance the functionality of the program . Colors, questions chosen are some maintenance done in this program .




Functions

As discussed with other members, we find that few functions should be used in this program .

SNAKE ( ) ---->  will have 3 questions . The question will be randomly choose using srand as the player reaches this specific level . If the player fails to answer the question the level of the player will be reduced accordingly .

LADDER ( ) -----> will have 3 questions . The question will be randomly choose using srand as the player reaches this specific level . If the player fails to answer the question the level of the player will be remained accordingly . Else, the level will be increased .

DICE ( ) ------>Player will literally roll the dice by enter any number . We use srand function to randomly choose number from 1 to 6 for the player by using formula : randNo = 1 + rand( ) % (6-1+1) . The random number is actually the level of the player and will be sum up on the next dice roll .

ACTIONX( ) -----> This function is to indicate whether there's snake or ladder at particular level for player 1 .


ACTIONY( ) -----> This function is to indicate whether there's snake or ladder at particular level for player 2 .

GREETX ( ) -------> This function will calculate the current level of player 1 as dice rolled .

GREETY ( ) -------> This function will calculate the current level of player 2 as dice rolled .

LAYOUT ( ) -------> To display the layout of the snake and ladder board.








Tuesday, 23 April 2013

About This Game

This game should be played by 2 players at one time . The layout of the board should be like this :
The snake and ladder board

However, in our program, everything is in text form . 

At the beginning, the players will enter their names to indicate which one is the first player and the second player . Both players will start at level 0 . The first player will literally roll the dice by inserting any number and a number between 1 to 6 will be chosen randomly by program . This 1 to 6 number show the current level of the player . As turn changes, the level of the previous one and the new result of the dice rolled, will be sum up to show which level the player would be next . 

Snake
For some levels, we had put snakes from one specific level to one other level . As the player reaches the level which have the head of the snake (refer figure above), a question will be given randomly . As the player fails to answer correctly, program will reduces the level according (as in figure, at the tail of the snake) .  However, succeed to answer correctly, the level be remained there . 

Ladder
Just like the snake, ladder also exist at some levels . As the player reaches this level, a question will be given and the player should answer correctly to enable the player literally climbs the ladder to skip few levels accordingly . Fails to answer question correctly, the level will be remained there .

The winner is the first one who reaches level 25 . The End ! Stay tuned !