{"id":4148,"date":"2023-03-08T18:14:41","date_gmt":"2023-03-08T18:14:41","guid":{"rendered":"https:\/\/studiotechx.com\/projects\/?p=4148"},"modified":"2023-03-08T18:16:49","modified_gmt":"2023-03-08T18:16:49","slug":"car-game-c-program","status":"publish","type":"post","link":"https:\/\/studiotechx.com\/projects\/car-game-c-program\/","title":{"rendered":"Car Game in C Program"},"content":{"rendered":"\n<p>Text Based Car Racing Game<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;stdio.h>\n#include &lt;stdlib.h>\n#include &lt;time.h>\n\n#define TRACK_LENGTH 20\n\nvoid print_track(int player_position, int opponent_position);\nint get_move();\n\nint main() {\n    srand(time(NULL));\n    int player_position = 0;\n    int opponent_position = 0;\n    printf(\"Welcome to the Text-based Car Racing Game!\\n\");\n    printf(\"Your car: &#91;P]\\nOpponent car: &#91;O]\\n\");\n    while (1) {\n        print_track(player_position, opponent_position);\n        int move = get_move();\n        player_position += move;\n        opponent_position += rand() % 3 + 1; \/\/ opponent moves randomly\n        if (player_position >= TRACK_LENGTH) {\n            printf(\"You win!\\n\");\n            break;\n        }\n        else if (opponent_position >= TRACK_LENGTH) {\n            printf(\"You lose!\\n\");\n            break;\n        }\n    }\n    return 0;\n}\n\nvoid print_track(int player_position, int opponent_position) {\n    printf(\"\\n\");\n    for (int i = 0; i &lt; TRACK_LENGTH; i++) {\n        if (i == player_position) {\n            printf(\"&#91;P]\");\n        }\n        else if (i == opponent_position) {\n            printf(\"&#91;O]\");\n        }\n        else {\n            printf(\"&#91; ]\");\n        }\n    }\n    printf(\"\\n\");\n}\n\nint get_move() {\n    int move;\n    while (1) {\n        printf(\"Enter a move (1-3): \");\n        scanf(\"%d\", &amp;move);\n        if (move >= 1 &amp;&amp; move &lt;= 3) {\n            break;\n        }\n        printf(\"Invalid move. Please enter a move between 1 and 3.\\n\");\n    }\n    return move;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"Text Based Car Racing Game\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":"","csco_singular_sidebar":"","csco_page_header_type":"","csco_appearance_grid":"","csco_page_load_nextpost":"","csco_post_video_location":[],"csco_post_video_location_hash":"","csco_post_video_url":"","csco_post_video_bg_start_time":0,"csco_post_video_bg_end_time":0},"categories":[19],"tags":[],"aioseo_notices":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/posts\/4148"}],"collection":[{"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/comments?post=4148"}],"version-history":[{"count":2,"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/posts\/4148\/revisions"}],"predecessor-version":[{"id":4152,"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/posts\/4148\/revisions\/4152"}],"wp:attachment":[{"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/media?parent=4148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/categories?post=4148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studiotechx.com\/projects\/wp-json\/wp\/v2\/tags?post=4148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}