个人游戏创作拒绝工作(C编程)

时间:2016-06-25 01:18:04

标签: c

我已经调试了我的Fallout Lockpick模拟器几天了,没有任何进展。每次我加载这个游戏并输入一个程度来移动发夹时,它说我赢了。相反,游戏应该循环,直到 win 设置为1,然后说我赢了。什么阻止我的程序完成这个?完整代码如下。谢谢!

// Fallout Lockpick Sim
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <ctype.h>

void command(int *newWin, int key);

main()
{
    time_t t;
    char stillPlay;
    int win;
    int key;

    do {
            system("cls");
            win = 0;
            srand(time(&t));
            key = (rand() % 359);
            lockface();
            command(&win, key);
            printf("You Won!!!\n");
            printf("Do you want to play again?");
            scanf(" %c", &stillPlay);
    } while (toupper(stillPlay) == 'Y');

    return;
}

lockface()
{
    printf("      ___ \n");
    printf("    /     \\ \n");
    printf("  /         \\ \n");
    printf(" |           | \n");
    printf(" |           | \n");
    printf("  \\         / \n");
    printf("    \\ ___ / \n");
}

void command(int *newWin, int key)
{
    int cmd;

    do {
    printf("Angle:");
    scanf(" %d", &cmd);
    if ((cmd >= 0 && cmd <= 21) || (cmd >= 338 && cmd <= 359))
    {
        system("cls");
        face0();
        if (fabs(key - cmd) <= 10)
        {
            *newWin = 0;
        }
    }
    else if (cmd >= 22 && cmd <= 67)
    {
        system("cls");
        face45();
        if (fabs(key - cmd) <= 10)
        {
            *newWin = 0;
        }
    }
    else if (cmd >= 68 && cmd <= 112)
    {
        system("cls");
        face90();
        if (fabs(key - cmd) <= 10)
        {
            *newWin = 0;
        }
    }
    else if (cmd >= 113 && cmd <= 157)
    {
        system("cls");
        face135();
        if (fabs(key - cmd) <= 10)
        {
            *newWin = 0;
        }
    }
    else if (cmd >= 158 && cmd <= 202)
    {
        system("cls");
        face180();
        if (fabs(key - cmd) <= 10)
        {
            *newWin = 0;
        }
    }
    else if (cmd >= 203 && cmd <= 247)
    {
        system("cls");
        face225();
        if (fabs(key - cmd) <= 10)
        {
            *newWin = 0;
        }
    }
    else if (cmd >= 248 && cmd <= 292)
    {
        system("cls");
        face270();
        if (fabs(key - cmd) <= 10)
        {
            *newWin = 0;
        }
    }
    else if (cmd >= 293 && cmd <= 337)
    {
        system("cls");
        face315();
        if (fabs(key - cmd) <= 10)
        {
            *newWin = 0;
        }
    }
    else
    {
        printf("Not valid command!");
        exit(1);
    }
    } while (*newWin != 1);
}

face0()
{
    printf("      ___ \n");
    printf("    /  |  \\ \n");
    printf("  /    |    \\ \n");
    printf(" |     |     | \n");
    printf(" |           | \n");
    printf("  \\         / \n");
    printf("    \\ ___ / \n");
}

face45()
{
    printf("      ___ \n");
    printf("    /     \\ \n");
    printf("  /      /  \\ \n");
    printf(" |     /     | \n");
    printf(" |           | \n");
    printf("  \\         / \n");
    printf("    \\ ___ / \n");
}

face90()
{
    printf("      ___ \n");
    printf("    /     \\ \n");
    printf("  /         \\ \n");
    printf(" |      _____| \n");
    printf(" |           | \n");
    printf("  \\         / \n");
    printf("    \\ ___ / \n");
}

face135()
{
    printf("      ___ \n");
    printf("    /     \\ \n");
    printf("  /         \\ \n");
    printf(" |           | \n");
    printf(" |      \\    | \n");
    printf("  \\      \\  / \n");
    printf("    \\ ___ / \n");
}

face180()
{
    printf("      ___ \n");
    printf("    /     \\ \n");
    printf("  /         \\ \n");
    printf(" |           | \n");
    printf(" |      |    | \n");
    printf("  \\    |    / \n");
    printf("    \\ _|_ / \n");
}

face225()
{
    printf("      ___ \n");
    printf("    /     \\ \n");
    printf("  /         \\ \n");
    printf(" |           | \n");
    printf(" |     /     | \n");
    printf("  \\ /       / \n");
    printf("    \\ ___ / \n");
}

face270()
{
    printf("      ___ \n");
    printf("    /     \\ \n");
    printf("  /         \\ \n");
    printf(" |______     | \n");
    printf(" |           | \n");
    printf("  \\         / \n");
    printf("    \\ ___ / \n");
}

face315()
{
    printf("      ___ \n");
    printf("    /     \\ \n");
    printf("  /  \\      \\ \n");
    printf(" |     \\     | \n");
    printf(" |           | \n");
    printf("  \\         / \n");
    printf("    \\ ___ / \n");
}

1 个答案:

答案 0 :(得分:0)

我尝试了你的代码并且它有效。我使用的是Ubuntu Linux,因此我无法使用system来电,我在330处添加了一个休息时间,以便程序会在您输入330或大致时通知您获胜那。

// Fallout Lockpick Sim
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <ctype.h>

void command(int *newWin, int key);

face0() {
    printf("      ___ \n");
    printf("    /  |  \\ \n");
    printf("  /    |    \\ \n");
    printf(" |     |     | \n");
    printf(" |           | \n");
    printf("  \\         / \n");
    printf("    \\ ___ / \n");
}

face45() {
    printf("      ___ \n");
    printf("    /     \\ \n");
    printf("  /      /  \\ \n");
    printf(" |     /     | \n");
    printf(" |           | \n");
    printf("  \\         / \n");
    printf("    \\ ___ / \n");
}

face90() {
    printf("      ___ \n");
    printf("    /     \\ \n");
    printf("  /         \\ \n");
    printf(" |      _____| \n");
    printf(" |           | \n");
    printf("  \\         / \n");
    printf("    \\ ___ / \n");
}

face135() {
    printf("      ___ \n");
    printf("    /     \\ \n");
    printf("  /         \\ \n");
    printf(" |           | \n");
    printf(" |      \\    | \n");
    printf("  \\      \\  / \n");
    printf("    \\ ___ / \n");
}

face180() {
    printf("      ___ \n");
    printf("    /     \\ \n");
    printf("  /         \\ \n");
    printf(" |           | \n");
    printf(" |      |    | \n");
    printf("  \\    |    / \n");
    printf("    \\ _|_ / \n");
}

face225() {
    printf("      ___ \n");
    printf("    /     \\ \n");
    printf("  /         \\ \n");
    printf(" |           | \n");
    printf(" |     /     | \n");
    printf("  \\ /       / \n");
    printf("    \\ ___ / \n");
}

face270() {
    printf("      ___ \n");
    printf("    /     \\ \n");
    printf("  /         \\ \n");
    printf(" |______     | \n");
    printf(" |           | \n");
    printf("  \\         / \n");
    printf("    \\ ___ / \n");
}

face315() {
    printf("      ___ \n");
    printf("    /     \\ \n");
    printf("  /  \\      \\ \n");
    printf(" |     \\     | \n");
    printf(" |           | \n");
    printf("  \\         / \n");
    printf("    \\ ___ / \n");
}

lockface() {
    printf("      ___ \n");
    printf("    /     \\ \n");
    printf("  /         \\ \n");
    printf(" |           | \n");
    printf(" |           | \n");
    printf("  \\         / \n");
    printf("    \\ ___ / \n");
}

int main(void) {
    time_t t;
    char stillPlay;
    int win;
    int key;

    do {
        //system("cls");
        win = 0;
        srand((unsigned) time(&t));
        key = (rand() % 359);
        lockface();
        command(&win, key);
        printf("You Won!!!\n");
        printf("Do you want to play again?");
        scanf(" %c", &stillPlay);
    } while (toupper(stillPlay) == 'Y');

    return 0;
}


void command(int *newWin, int key) {
    int cmd;

    do {
        printf("Angle:");
        scanf(" %d", &cmd);
        if ((cmd >= 0 && cmd <= 21) || (cmd >= 338 && cmd <= 359)) {

            face0();
            if (fabs(key - cmd) <= 10) {
                *newWin = 0;
            }
        }
        else if (cmd >= 22 && cmd <= 67) {

            face45();
            if (fabs(key - cmd) <= 10) {
                *newWin = 0;
            }
        }
        else if (cmd >= 68 && cmd <= 112) {

            face90();
            if (fabs(key - cmd) <= 10) {
                *newWin = 0;
            }
        }
        else if (cmd >= 113 && cmd <= 157) {

            face135();
            if (fabs(key - cmd) <= 10) {
                *newWin = 0;
            }
        }
        else if (cmd >= 158 && cmd <= 202) {

            face180();
            if (fabs(key - cmd) <= 10) {
                *newWin = 0;
            }
        }
        else if (cmd >= 203 && cmd <= 247) {

            face225();
            if (fabs(key - cmd) <= 10) {
                *newWin = 0;
            }
        }
        else if (cmd >= 248 && cmd <= 292) {

            face270();
            if (fabs(key - cmd) <= 10) {
                *newWin = 0;
            }
        }
        else if (cmd >= 293 && cmd <= 337) {

            face315();
            //if (fabs(key - cmd) <= 10) {
            *newWin = 1;
            //}
        }
        else {
            printf("Not valid command!");
            exit(1);
        }
    } while (*newWin != 1);
}

输出

      ___ 
    /     \ 
  /         \ 
 |           | 
 |           | 
  \         / 
    \ ___ / 
Angle:90
      ___ 
    /     \ 
  /         \ 
 |      _____| 
 |           | 
  \         / 
    \ ___ / 
Angle:290
      ___ 
    /     \ 
  /         \ 
 |______     | 
 |           | 
  \         / 
    \ ___ / 
Angle:330
      ___ 
    /     \ 
  /  \      \ 
 |     \     | 
 |           | 
  \         / 
    \ ___ / 
You Won!!!
Do you want to play again?

在代码块和Windows 10中,它们是相同的:

enter image description here