Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to make game on python

import arcade

# Set constants for the screen size
SCREEN_WIDTH = 600
SCREEN_HEIGHT = 600

# Open the window. Set the window title and dimensions (width and height)
arcade.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, "Drawing Example")

# Set the background color to white.
# For a list of named colors see:
# http://arcade.academy/arcade.color.html
# Colors can also be specified in (red, green, blue) format and
# (red, green, blue, alpha) format.
arcade.set_background_color(arcade.color.WHITE)

# Start the render process. This must be done before any drawing commands.
arcade.start_render()

# Draw the face
x = 300
y = 300
radius = 200
arcade.draw_circle_filled(x, y, radius, arcade.color.YELLOW)

# Draw the right eye
x = 370
y = 350
radius = 20
arcade.draw_circle_filled(x, y, radius, arcade.color.BLACK)

# Draw the left eye
x = 230
y = 350
radius = 20
arcade.draw_circle_filled(x, y, radius, arcade.color.BLACK)

# Draw the smile
x = 300
y = 280
width = 120
height = 100
start_angle = 190
end_angle = 350
arcade.draw_arc_outline(x, y, width, height, arcade.color.BLACK, start_angle, end_angle, 10)

# Finish drawing and display the result
arcade.finish_render()

# Keep the window open until the user hits the 'close' button
arcade.run()
Comment

python game example


import random
import time

computerwins = 0
playerwins = 0
ties = 0
end = 0

while True:

    choices = ["rock",
               "paper",
               "scissors"]

    userChoice = raw_input("Rock, Paper, Scissors, or End")

    computerChoice = (random.choice(choices))
    print(computerChoice)

    if userChoice == computerChoice:
        time.sleep(0.5)
        print("Tie!
")
        ties += 1
        end += 1

    elif userChoice == "rock":
        if computerChoice == "paper":
            time.sleep(0.5)
            print("Computer Win!
")
            computerwins +=1
            end += 1

        else:
            time.sleep(0.5)
            print("Player win!
")
            playerwins += 1
            end += 1

    elif userChoice == "paper":
        if computerChoice == "rock":
            time.sleep(0.5)
            print("Player win!
")
            playerwins += 1
            end += 1

        else:
            time.sleep(0.5)
            print("Computer win!
")
            computerwins += 1
            end += 1

    elif userChoice == "scissors":
        if computerChoice == "rock":
            time.sleep(0.5)
            print("Computer win!
")
            computerwins += 1
            end += 1

        else:
            time.sleep(0.5)
            print("Player win!
")
            playerwins += 1
            end += 1

    elif userChoice == "end":
            choices.append("end")
            print("
Great game!
")
            print("Total score for computer: ", computerwins, "wins!")
            print("Total score for player: ", playerwins, "wins!")
            print("Total ties: ", ties, "ties!")
            time.sleep(2)
            break
Comment

how to make a game in python

#modules required - time and random
#Game 1
#Password game
import time
import random

Password = ['1', '2', 'a', 'G', '5', '89']

answer = input('Guess the password')
print(random.choice(Password)+' is the password')
Comment

PREVIOUS NEXT
Code Example
Python :: convert bytes to numpy array python 
Python :: convert number to binary python 
Python :: check if numpy arrays are equal 
Python :: Test Speed internet using Python 
Python :: drop columnd python 
Python :: neural network import 
Python :: Plotting keras model trainning history 
Python :: create jwt token python 
Python :: how to clear command prompt python 
Python :: pandas sort values group by 
Python :: one hot encoding python pandas 
Python :: python if else short version 
Python :: install python package from git colab 
Python :: get all files within multiple directories python 
Python :: normalize = true pandas 
Python :: delete index in df 
Python :: flask migrate install 
Python :: Qslider pyqt 
Python :: pyqt pylatex 
Python :: how to check if two columns match in pandas 
Python :: python search string for word 
Python :: flask post vs get 
Python :: how to construct simple timedelta in python 
Python :: value_counts to list 
Python :: plotly reverse y axis 
Python :: tkinter remove frame 
Python :: python nmap 
Python :: grassmann formula 
Python :: MySQLdb/_mysql.c:46:10: fatal error: Python.h: No such file or directory 
Python :: sys get current pythonpath 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =