Compare commits

..
3 Commits
11 changed files with 237 additions and 200 deletions
+57
View File
@@ -0,0 +1,57 @@
import pygame
import random
import os
import sys
import time
pygame.init()
screen = pygame.display.set_mode((1920, 1080))
pygame.display.set_caption("Simple Pygame Example")
clock = pygame.time.Clock()
font = pygame.font.SysFont(None, 55)
WHITE = (255, 255, 255)
x = 20
y = 20
xbool = False
ybool = False
toWrite = "Drugs"
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
screen.fill((0, 0, 0))
text = font.render(toWrite, True, WHITE)
screen.blit(text, (x, y))
text_width, text_height = font.size(toWrite)
pygame.display.flip()
clock.tick(60)
if x > (screen.get_width() - text_width) or xbool:
x = x - 1
xbool = True
else:
x = x + 1
xbool = False
if y > (screen.get_height() - text_height) or ybool:
y = y - 1
ybool = True
else:
y = y + 1
ybool = False
if y < 0:
y = 0
ybool = False
if x < 0:
x = 0
xbool = False
print(x, y)
time.sleep(0.01)
+171
View File
@@ -0,0 +1,171 @@
import pygame
import random
import os
import sys
import time
pygame.init()
infoObject = pygame.display.Info()
ScreenResolution = (infoObject.current_w, infoObject.current_h)
screen = pygame.display.set_mode(ScreenResolution)
pygame.display.set_caption("pong")
clock = pygame.time.Clock()
font = pygame.font.SysFont(None, 55)
WHITE = (255, 255, 255)
pongSizeX, pongSizeY = font.size("pong")
x = screen.get_width() // 2
y = screen.get_height() // 2
pY = screen.get_height() // 2
pX = 1920 - 50
aiY = screen.get_height() // 2
playerPoints = 0
aiPoints = 0
if random.randint(0, 1) == 0:
xbool = True
else:
xbool = False
if random.randint(0, 1) == 0:
ybool = True
else:
ybool = False
rect_width = 10
rect_height = 10
menu = True
aiSpeed = 0.4
while menu:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
screen.fill((0, 0, 0))
text = font.render("Press SPACE to start or Press D to select Ai Diffclty", True, WHITE)
screen.blit(text, ((screen.get_width() // 2) - (text.get_width() // 2), (screen.get_height() // 2) - (text.get_height() // 2)))
pygame.display.flip()
if pygame.key.get_pressed()[pygame.K_SPACE]:
menu = False
elif pygame.key.get_pressed()[pygame.K_d]:
diffMenu = True
while diffMenu:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
screen.fill((0, 0, 0))
text = font.render("Press 1 for Easy, 2 for Medium, 3 for Hard", True, WHITE)
screen.blit(text, ((screen.get_width() // 2) - (text.get_width() // 2), (screen.get_height() // 2) - (text.get_height() // 2)))
pygame.display.flip()
if pygame.key.get_pressed()[pygame.K_1]:
aiSpeed = 0.3
diffMenu = False
elif pygame.key.get_pressed()[pygame.K_2]:
aiSpeed = 0.4
diffMenu = False
elif pygame.key.get_pressed()[pygame.K_3]:
aiSpeed = 0.7
diffMenu = False
clock.tick(60)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
screen.fill((0, 0, 0))
text = font.render("pong", True, WHITE)
pPointsText = font.render(str(playerPoints), True, WHITE)
aiPointsText = font.render(str(aiPoints), True, WHITE)
screen.blit(pPointsText, (screen.get_width() - pPointsText.get_width() - 20, 0))
screen.blit(aiPointsText, (20, 0))
screen.blit(text, ((screen.get_width() // 2) - pongSizeX, 0))
player_paddle = pygame.Rect(pX, pY, 20, 100)
ai_paddle = pygame.Rect(30, aiY, 20, 100)
ball = pygame.Rect(x, y, rect_width, rect_height)
pygame.draw.rect(screen, WHITE, ball)
pygame.draw.rect(screen, WHITE, player_paddle)
pygame.draw.rect(screen, WHITE, ai_paddle)
pygame.display.flip()
# Ball movement logic and player/AI paddle movement
if x > (screen.get_width() - rect_width) or ball.colliderect(player_paddle):
xbool = True
elif x < 0 or ball.colliderect(ai_paddle):
xbool = False
if xbool:
x = x - 0.5
else:
x = x + 0.5
if y > (screen.get_height() - rect_height) or ybool:
y = y - 0.5
ybool = True
else:
y = y + 0.5
ybool = False
if y < 0:
y = 0
ybool = False
if x < 0:
x = 0
xbool = False
if ai_paddle.centery < ball.centery:
aiY = aiY + aiSpeed
elif ai_paddle.centery > ball.centery:
aiY = aiY - aiSpeed
if pygame.key.get_pressed()[pygame.K_ESCAPE]:
pygame.quit()
sys.exit()
elif pygame.key.get_pressed()[pygame.K_DOWN] and pY + 100 < screen.get_height() - 10:
pY += 1
elif pygame.key.get_pressed()[pygame.K_UP] and pY - 10 > 0:
pY -= 1
# points logic
if x <= 0:
playerPoints += 1
x = screen.get_width() // 2
y = screen.get_height() // 2
if random.randint(0, 1) == 0:
xbool = True
else:
xbool = False
if random.randint(0, 1) == 0:
ybool = True
else:
ybool = False
elif x >= screen.get_width() - 30:
aiPoints += 1
x = screen.get_width() // 2
y = screen.get_height() // 2
if random.randint(0, 1) == 0:
xbool = True
else:
xbool = False
if random.randint(0, 1) == 0:
ybool = True
else:
ybool = False
+9 -20
View File
@@ -6,18 +6,8 @@ import webbrowser
BASE_URL = 'https://stock.minecartchris.cc'
log_file = "tradeLog.txt"
dayRun = 100
saveScore = False
asked = input("Do you want to save the score? (y/n): ")
if asked.lower() == 'y':
saveScore = True
else:
saveScore = False
# webbrowser.get('firefox').open(BASE_URL)
webbrowser.get('firefox').open(BASE_URL)
# Create a session object to maintain cookies/session across requests
session = requests.Session()
@@ -159,15 +149,14 @@ def main():
log(f"Starting balance: $1000")
log(f"Ending balance: ${data['balance']}")
log(f"Profit: ${data['balance'] - 1000}")
if saveScore == True:
response = session.post(f'{BASE_URL}/api/save-score',
json={
'name': "Chris's AutoTrader",
})
if response.status_code == 200:
log("Score saved successfully!")
else:
log(f"Error saving score: {response.status_code}")
response = session.post(f'{BASE_URL}/api/save-score',
json={
'name': 'AutoTrader',
})
if response.status_code == 200:
log("Score saved successfully!")
else:
log(f"Error saving score: {response.status_code}")
log_file.close()
-158
View File
@@ -1,158 +0,0 @@
import random
def printMenu(Balance, menu):
if menu == "main":
print("Balance: "+ str(Balance))
print("(1: Buy / 2: Sell) Buy/Sell menu: ")
print("3. See stock prices: ")
print("4. See remaining time: ")
print("5. check the index")
print("6. goto next day: ")
elif menu == "prices":
print("Kwik trip: " + str(kwiktripStockPrice))
print("Apple computers: " + str(appleStockPrice))
print("Microsoft: " + str(microsoftStockPrice))
print("Walmart Super Store: " + str(walmartStockPrice))
print("Car company: " + str(carStockPrice))
elif menu == "index":
print("The index as of day " + str(day) + " is " + str(indexPrice))
elif menu == "daysleft":
print("as of today you have " + str(daysleft) + " days left. have fun!")
"""
def newday():
kwiktripStockPrice = kwiktripStockPrice + random.randint(-100.99, 100.99)
appleStockPrice = appleStockPrice + random.randint(-100.99, 100.99)
microsoftStockPrice = microsoftStockPriice + random.randint(-100.99, 100.99)
walmartStockPrice = walmartStockPrice + random.randint(-100.99, 100.99)
carStockPrice = carStockPrice + random.randint(-100.99, 100.99)
"""
balance = 1000
kwiktripStockPrice = 100 + random.randint(-100, 100)
appleStockPrice = 100 + random.randint(-100, 100)
microsoftStockPrice = 100 + random.randint(-100, 100)
walmartStockPrice = 100 + random.randint(-100, 100)
carStockPrice = 100 + random.randint(-100, 100)
kwiktrip = 0
apple = 0
microsoft = 0
walmart = 0
car = 0
day = 1
indexPrice = (kwiktripStockPrice + appleStockPrice + microsoftStockPrice + walmartStockPrice + carStockPrice) / 5
daysleft = int(input("how many days do you wish to play?"))
while daysleft > -1:
printMenu(balance, "main")
stockcost = [kwiktripStockPrice, appleStockPrice, microsoftStockPrice, walmartStockPrice, carStockPrice]
usrinput = input()
if usrinput == "1":
print("1. Kwik trip: " + str(kwiktripStockPrice))
print("2. Apple computers: " + str(appleStockPrice))
print("3. Microsoft: " + str(microsoftStockPrice))
print("4. Walmart Super Store: " + str(walmartStockPrice))
print("5. Car company: " + str(carStockPrice))
stockinput = int(input("what stock do you want to buy?: "))
amountinput = int(input("how many stocks?: "))
amountcost = int(amountinput) * int(stockcost[int(stockinput)-1])
rusure = input("are you sure this will cost you " + str(amountcost) + " and you have $" + str(balance) + ": ")
if balance < amountcost:
print("you can not complete this purchace your poor")
else:
if rusure == "yes" or rusure == "y" or rusure == "Y" or rusure == "Yes":
balance = balance - amountcost
if stockinput == 1:
kwiktrip = kwiktrip + amountinput
elif stockinput == 2:
apple = apple + amountinput
elif stockinput == 3:
microsoft = microsoft + amountinput
elif stockinput == 4:
walmart = walmart + amountinput
elif stockinput == 5:
car = car + amountinput
print("\033c", end="")
elif usrinput == "2":
print("1. Kwik trip: " + str(kwiktripStockPrice) + " you own: " + str(kwiktrip))
print("2. Apple computers: " + str(appleStockPrice) + " you own: " + str(apple))
print("3. Microsoft: " + str(microsoftStockPrice) + " you own: " + str(microsoft))
print("4. Walmart Super Store: " + str(walmartStockPrice) + " you own: " + str(walmart))
print("5. Car company: " + str(carStockPrice) + " you own: " + str(car))
stockinput = int(input("what stock do you want to sell?: "))
amountinput = int(input("how many stocks?: "))
amountpayout = int(amountinput) * int(stockcost[int(stockinput)-1])
rusure = input("are you sure you will sell " + str(stockinput) + " and make " + str(amountpayout) + ": ")
if rusure == "yes" or rusure == "y" or rusure == "Y" or rusure == "Yes":
balance = balance + amountpayout
if stockinput == 1:
if kwiktrip >= amountinput:
kwiktrip = kwiktrip - amountinput
elif stockinput == 2:
if apple >= amountinput:
apple = apple - amountinput
elif stockinput == 3:
if microsoft >= amountinput:
microsoft = microsoft - amountinput
elif stockinput == 4:
if walmart >= amountinput:
walmart = walmart - amountinput
elif stockinput == 5:
if car >= amountinput:
car = car - amountinput
print("\033c", end="")
elif usrinput == "3":
printMenu(balance, "prices")
elif usrinput == "4":
printMenu(balance, "daysleft")
elif usrinput == "5":
printMenu(balance, "index")
elif usrinput == "6":
print("\033c", end="")
day = day + 1
daysleft = daysleft - 1
kwiktripStockPrice = abs(kwiktripStockPrice + random.randint(-100, 100))
appleStockPrice = abs(appleStockPrice + random.randint(-100, 100))
microsoftStockPrice = abs(microsoftStockPrice + random.randint(-100, 100))
walmartStockPrice = abs(walmartStockPrice + random.randint(-100, 100))
carStockPrice = abs(carStockPrice + random.randint(-100, 100))
marketCrash = random.randint(0, 1000)
if marketCrash == 555:
kwiktripStockPrice = -200
appleStockPrice = -200
microsoftStockPrice = -200
walmartStockPrice = -200
carStockPrice = -200
print("the market has crashed every stock is now -200 in value")
stockcost = [kwiktripStockPrice, appleStockPrice, microsoftStockPrice, walmartStockPrice, carStockPrice]
indexPrice = (kwiktripStockPrice + appleStockPrice + microsoftStockPrice + walmartStockPrice + carStockPrice) / 5
print("End game stats")
print("You started with 1000")
print("ending the game you have $" + str(balance))
print("total net worth is $" + str(balance + (kwiktrip * kwiktripStockPrice) + (apple * appleStockPrice) + (microsoft * microsoftStockPrice) + (walmart * walmartStockPrice) + (car * carStockPrice)))
print("you made " + str((balance - 1000)) + " dollars")
print("your stocks left over are")
print("kwik trip you have: " + str(kwiktrip))
print("apple you have: " + str(apple))
print("microsoft you have: " + str(microsoft))
print("walmart you have: " + str(walmart))
print("last you have " + str(car) + " in car company.")
-22
View File
@@ -1,22 +0,0 @@
# How to Run
There are two different interfaces available: CLI, and Web.
## Web
Run these commands to run the flask:
```sh
python3 mainweb.py
```
Or
```sh
flask run mainweb.py -p {port}
```
## CLI
Run main.py for the CLI interface:
```sh
python3 main.py
```