Racers-API - a game where you have to go around racing with your car, earning money

Overview

Racers-API

About

Racers API is a game where you have to go around racing with your car, earning money. With that money you can buy cars and progress through the game! You have to combine your coding skills and knowledge to start and finish. Making HTTP requests to the API and getting a response is what you need to learn. You can play Racers API with any language that supports HTTP requests. Learn more in the Documentation section

Documentation

Python

Checking the status of the server:

import requests

#Checking the status of the server
statusURL = "https://racersapi.billybob456.repl.co/status"
status = requests.get(statusURL)
status = status.content.decode("utf-8")
print(status)
if status == "Racers API is ready to play!":
	pass
else:
	print("Racers API is unavailable to play at the moment")
	exit()

If it outputs "Racers API is ready to play!" then the server is available. Otherwise, you might get an error. If that happens and all you code is correct, it means the server is likely down.

Getting a key and starting off:

import requests
import json

#Checking the status of the server
statusURL = "https://racersapi.billybob456.repl.co/status"
status = requests.get(statusURL)
status = status.content.decode("utf-8")
print(status)
if status == "Racers API is ready to play!":
	pass
else:
	print("Racers API is unavailable to play at the moment")
	exit()

#Getting an API key
username = "hello"
startURL = "https://racersapi.billybob456.repl.co/start/" + username

x = requests.get(startURL)
x = x.content
x = json.loads(x)
key = x["key"]
print(x["message"])

Getting your account information:

import requests
import json

#Checking the status of the server
statusURL = "https://racersapi.billybob456.repl.co/status"
status = requests.get(statusURL)
status = status.content.decode("utf-8")
print(status)
if status == "Racers API is ready to play!":
	pass
else:
	print("Racers API is unavailable to play at the moment")
	exit()

#Getting an API key
username = "hello"
startURL = "https://racersapi.billybob456.repl.co/start/" + username

x = requests.get(startURL)
x = x.content
x = json.loads(x)
key = x["key"]
print(x["message"])

account = requests.get("https://racersapi.billybob456.repl.co/account/" + key).content.decode("utf-8")
print(account)

Getting your current car:

import requests
import json
import ast

#Checking the status of the server
statusURL = "https://racersapi.billybob456.repl.co/status"
status = requests.get(statusURL)
status = status.content.decode("utf-8")
print(status)
if status == "Racers API is ready to play!":
	pass
else:
	print("Racers API is unavailable to play at the moment")
	exit()

#Getting an API key
username = "hello"
startURL = "https://racersapi.billybob456.repl.co/start/" + username

x = requests.get(startURL)
x = x.content
x = json.loads(x)
key = x["key"]
print(x["message"])

account = ast.literal_eval(requests.get("https://racersapi.billybob456.repl.co/account/" + key).content.decode("utf-8"))
print(account)

currentCar = account["car"]
print(currentCar)

Getting the available races:

...
availableRaces = requests.get("https://racersapi.billybob456.repl.co/available-races/" + key).content.decode("utf-8")
print(availableRaces)

Selecting the race with best difficult:payout ratio:

...
#Selecting the best race with difficulty:payout ratio
litEvalList = ast.literal_eval(availableRaces)
length = len(litEvalList)
for race in litEvalList:
	avgSpeed = race["average top speed"]
	if avgSpeed == currentCar["top speed"]:
		raceNum = litEvalList.index(race)
raceKey = json.loads(availableRaces)[raceNum]["key"]

Racing the selected race:

...
#Racing the selected race
raceURL = "https://racersapi.billybob456.repl.co/race/" + key + "/" + raceKey
raceResults = requests.get(raceURL).content.decode('utf-8')
raceKey = ""
raceResults = ast.literal_eval(raceResults)
key = raceResults["key"] #new key
print(raceResults["message"])

Full script:

import requests
import json
import ast

#Checking the status of the server
statusURL = "https://racersapi.billybob456.repl.co/status"
status = requests.get(statusURL)
status = status.content.decode("utf-8")
print(status)
if status == "Racers API is ready to play!":
	pass
else:
	print("Racers API is unavailable to play at the moment")
	exit()

#Getting an API key
username = "hello"
startURL = "https://racersapi.billybob456.repl.co/start/" + username

x = requests.get(startURL)
x = x.content
x = json.loads(x)
key = x["key"]
print(x["message"])

#Getting account information
account = ast.literal_eval(requests.get("https://racersapi.billybob456.repl.co/account/" + key).content.decode("utf-8"))
print(account)

#Getting you current car
currentCar = account["car"]
print(currentCar)

#Getting available races
availableRaces = requests.get("https://racersapi.billybob456.repl.co/available-races/" + key).content.decode("utf-8")
print(availableRaces)

#Selecting the best race with difficulty:payout ratio
litEvalList = ast.literal_eval(availableRaces)
length = len(litEvalList)
for race in litEvalList:
	avgSpeed = race["average top speed"]
	if avgSpeed == currentCar["top speed"]:
		raceNum = litEvalList.index(race)
raceKey = json.loads(availableRaces)[raceNum]["key"]

#Racing the selected race
raceURL = "https://racersapi.billybob456.repl.co/race/" + key + "/" + raceKey
raceResults = requests.get(raceURL).content.decode('utf-8')
raceKey = ""
raceResults = ast.literal_eval(raceResults)
key = raceResults["key"]
print(raceResults["message"])

Well done! You've successfully gone through the basics of Racers API and completed your first race! Below are your next steps.

After getting you new key, you want to save it somewhere! Here's a modified script of the full script that will allow you to continue your game with the new key:

import requests
import json
import ast

#Checking the status of the server
statusURL = "https://racersapi.billybob456.repl.co/status"
status = requests.get(statusURL)
status = status.content.decode("utf-8")
print(status)
if status == "Racers API is ready to play!":
	pass
else:
	print("Racers API is unavailable to play at the moment")
	exit()

key = "YOUR KEY HERE!" #put your key in there!

#Getting account information
account = ast.literal_eval(requests.get("https://racersapi.billybob456.repl.co/account/" + key).content.decode("utf-8"))
print(account)

#Getting you current car
currentCar = account["car"]
print(currentCar)

#Getting available races
availableRaces = requests.get("https://racersapi.billybob456.repl.co/available-races/" + key).content.decode("utf-8")
print(availableRaces)

#Selecting the best race with difficulty:payout ratio
litEvalList = ast.literal_eval(availableRaces)
length = len(litEvalList)
for race in litEvalList:
	avgSpeed = race["average top speed"]
	if avgSpeed == currentCar["top speed"]:
		raceNum = litEvalList.index(race)
raceKey = json.loads(availableRaces)[raceNum]["key"]

#Racing the selected race
raceURL = "https://racersapi.billybob456.repl.co/race/" + key + "/" + raceKey
raceResults = requests.get(raceURL).content.decode('utf-8')
raceKey = ""
raceResults = ast.literal_eval(raceResults)
key = raceResults["key"]
print(raceResults["message"])

More documentation coming out soon including how to buy new cars and mod the game to add your own cars!

You might also like...
Parkour game made in Python with Ursina Game Engine along with ano0002, Greeny127 and Someone-github Snake game mixed with Conway's Game of Life
Snake game mixed with Conway's Game of Life

SnakeOfLife Snake game mixed with Conway's Game of Life The rules are the same than a normal snake game but you have to avoid cells created by Conway'

Lint game data metafiles against GTA5.xsd for Rockstar's game engine (RAGE)
Lint game data metafiles against GTA5.xsd for Rockstar's game engine (RAGE)

rage-lint Lint RAGE (only GTA5 at the moment) meta/XML files for validity based off of the GTA5.xsd generated from game code. This script accepts a se

A near-exact clone of google chrome's no internet game, or the "google dinosaur game", with some additions and extras.

dinoGame A near-exact clone of google chrome's no internet game, or the "google dinosaur game", with some additions and extras. Installation Download

Quantum version of the classical Nim game. An automatic opponent allows to game to not be as easy as it seems.

Nim game Running the game To run the program just launch : python3 game.py Rules This game is inspiring from the Nim game. You are 2 players face to f

Average Clicker Game (AVG) is a Python made game using tkinter

Average-Clicker-Game Average Clicker Game (AVG) is a Python clicker game not made with pygame but with tkinter, it has worker, worker upgrades, times

Ice-Walker-Game - This repository is about the Ice Walker game made in Python.

Ice-Walker-Game Ce dépot contient le jeu Ice Walker programmé en Python. Les différentes grilles du jeu sont contenues dans le sous-dossier datas. Vou

Deal Or No Deal was a very popular game show. Even now, for a family party, it's a fun game to pass time

Deal Or No Deal was a very popular game show. Even now, for a family party, it's a fun game to pass time. I made a code to play the game right in your terminal/console. This isn't made to be a game which can be installed by everyone and played, I just made it as a fun project as I just started out with python. So if you have python installed and wanna have some fun, or just curious to see how I did this, feel free to check the code out!

Mastermind-Game - A game to test programming and logical skills

Bem vindo ao jogo Mastermind! O jogo consiste em adivinhar uma senha que será ge

Simple car game written in PyGame

Welcome to CarGame ?? Car Game written in PyGame! NOTE: This is still new and there may be stuff broken... ?? Homepage Install install pygame by typin

John 1 Oct 29, 2021
AutoPilot is a game where the player controls a car and tries to get the highest score he can while not dying under falling cement blocks.

AutoPilot AutoPilot is a game where the player controls a car and tries to get the highest score he can while not dying under falling cement blocks. C

Enoc Mena 1 Nov 17, 2021
A Pygame Hangman Game coded in Python 3. Run Hangman.py in a terminal if you have Python 3

Hangman A Pygame Hangman Game coded in Python 3. Run python3 Hangman.py in a terminal if you have Python 3.

null 1 Dec 24, 2022
Blender Game Engine Game Type Templates Logic Bricks (and Python script) based Game Templates for Blender

Blender-Game-Engine-Templates Blender Game Engine Game Type Templates Logic Bric

null 3 Oct 25, 2022
Tic Tac Toe game developed in python; have 2 difficulty levels

Tic Tac Toe Game This is a code for Tic Tac Toe game in python. Game has 2 difficulty levels. Easy Hard To play the game, use this command in a LINUX

Akshat Mittal 1 Jun 25, 2022
Wordle is a web-based word game. Players have six attempts to guess a five-letter word;

Wordle is a web-based word game. Players have six attempts to guess a five-letter word; feedback is given for each guess, in the form of colored tiles, indicating when letters match or occupy the correct position. This program helps solving wordle problems.

Abhishek 2 May 21, 2022
HTTP API for FGO game data. Transform the raw game data into something a bit more manageable.

FGO game data API HTTP API for FGO game data. Transform the raw game data into something a bit more manageable. View the API documentation here: https

Atlas Academy 51 Dec 26, 2022
A car learns to drive in a small 2D environment using the NEAT-Algorithm with Pygame

Self-driving-car-with-Pygame A car learns to drive in a small 2D environment using the NEAT-Algorithm with Pygame Description A car has 5 sensors ("ey

Henri 3 Feb 1, 2022
Simple game where you try to survive as long as you can on screen.

Survival Game Simple game where you try to survive as long as you can on screen. Play To run, download the code and run the survival_game.py file. Fro

Logan Morris 1 Feb 10, 2022
This a Chess PGN saver which allows you to save your game pgns, in a .pgn file

PGN Saver This a Chess PGN saver which allows you to save your game pgns, in a .pgn file This can be a very useful tool for the people using chessbase

null 3 Jan 6, 2022