Python 2.7.13 Minispiele

Elperdano

Spieler
8 Mai 2015
47
Hallo liebe Leute,
da ich in meiner (mittlerweile leider sehr knapp bemessenen) Freizeit gerne ein bisschen mit Python (Version: 2.7.13) rumprogrammiere und ein, zwei kleine Ideen für Minispiele habe, wollte ich euch da einfach mal dran teilhaben lassen.

Ich werde dieses Thema regelmäßig (1 Mal die Woche) aktualisieren und euch an meinen Fortschritten teilhaben lassen!

Wenn ihr Anregungen für weitere Minispiele habt schreibt sie hier gerne oder mir persönlich, sollten irgendwelche fragen zu dem Code aufkommen so fragt einfach ;D

Meine Ideen:
Galgenraten (Hangman)
4 Gewinnt

Meine Scripte bis jetzt:
Asciiarts | Status: wird mit jedem Programm aktualisiert | Code: 1
Galgenraten (Hangman) | Status: Fertig | Code: 2
4 Gewinnt | Status: in Arbeit, ca. 3% fertiggestellt| Code 3

Was haltet ihr davon?

Ich freue mich auf eure Reaktionen!

MFG Hannes
 
Zuletzt bearbeitet:
Code 1
Asciiarts


Das ist die meine asciiart Datei wo ich alle asciiarts für die Programme speicher.

WICHTIG: Man beachte das dieses Script im selben Verzeichnis abgelegt werden muss, wie die Programme die darauf zugreifen!

Code:
# -*- coding: utf-8 -*
#/usr/bin/python

def lifespic8():
    print " "
    print " " 
    print " "
    print " "
    print " "
    print " "
    print "    _________ "
    print "   /         \ "
    print "__/           \__ "

def lifespic7():
    print ""
    print "        |"
    print "        |   "
    print "        |    "
    print "        |     "
    print "        |    "
    print "    ____|____ "
    print "   /         \ "
    print "__/           \__ "
    
def lifespic6():
    print "         _____ "
    print "        |"
    print "        |   "
    print "        |    "
    print "        |     "
    print "        |     "
    print "    ____|____ "
    print "   /         \ "
    print "__/           \__ "
    
def lifespic5():
    print "         _____ "
    print "        |/    "
    print "        |    "
    print "        |    "
    print "        |"
    print "        |     "
    print "    ____|____ "
    print "   /         \ "
    print "__/           \__ "

def lifespic4():
    print "         _____ "
    print "        |/    | "
    print "        |    "
    print "        |     "
    print "        |     "
    print "        |     "
    print "    ____|____ "
    print "   /         \ "
    print "__/           \__ "

def lifespic3():
    print "         _____ "
    print "        |/    | "
    print "        |   (x.x) "
    print "        |"
    print "        |      "
    print "        |     "
    print "    ____|____ "
    print "   /         \ "
    print "__/           \__ "

def lifespic2():
    print "         _____ "
    print "        |/    | "
    print "        |   (x.x) "
    print "        |     | "
    print "        |     | "
    print "        |      "
    print "    ____|____ "
    print "   /         \ "
    print "__/           \__ "

def lifespic1():
    print "         _____ "
    print "        |/    | "
    print "        |   (x.x) "
    print "        |    \|/ "
    print "        |     | "
    print "        |    "
    print "    ____|____ "
    print "   /         \ "
    print "__/           \__ "

def lifespic0():
    print "         _____ "
    print "        |/    | "
    print "        |   (x.x) "
    print "        |    \|/ "
    print "        |     | "
    print "        |    / \ "
    print "    ____|____ "
    print "   /         \ "
    print "__/           \__ "
    
def winup():
    print "         _____ "
    print "        |/    | "
    print "        |    "
    print "        |     "
    print "        |     "
    print "        |         (^.^)"
    print "    ____|____      \|/ "
    print "   /         \      | "
    print "__/           \__  / \ "

def windown():
    print "         _____ "
    print "        |/    | "
    print "        |    "
    print "        |     "
    print "        |     "
    print "        |         (^.^)"
    print "    ____|____      /|\ "
    print "   /         \      | "
    print "__/           \__  / \ "

def gameover():
    print '''  .----------------.  .----------------.  .----------------.  .----------------.  '''
    print ''' | .--------------. || .--------------. || .--------------. || .--------------. | '''
    print ''' | |    ______    | || |      __      | || | ____    ____ | || |  _________   | | '''
    print ''' | |  .' ___  |   | || |     /  \     | || ||_   \  /   _|| || | |_   ___  |  | | '''
    print ''' | | / .'   \_|   | || |    / /\ \    | || |  |   \/   |  | || |   | |_  \_|  | | '''
    print ''' | | | |    ____  | || |   / ____ \   | || |  | |\  /| |  | || |   |  _|  _   | | '''
    print ''' | | \ `.___]  _| | || | _/ /    \ \_ | || | _| |_\/_| |_ | || |  _| |___/ |  | | '''
    print ''' | |  `._____.'   | || ||____|  |____|| || ||_____||_____|| || | |_________|  | | '''
    print ''' | |              | || |              | || |              | || |              | | '''
    print ''' | '--------------' || '--------------' || '--------------' || '--------------' | '''
    print ''' '----------------'  '----------------'  '----------------'  '----------------'   ''' .....

def frame():
    print "|                |"
    print "|                |"
    print "|                |"
    print "|                |"
    print "|                |"
    print "|                |"
    print "|________________|"

def framex():
    print "|                |"
    print "|   \         /  |"
    print "|     \     /    |"
    print "|        x       |"
    print "|     /     \    |"
    print "|   /         \  |"
    print "|________________|"

def frameo():
    print "|    ________    |"
    print "|   /        \   |"
    print "|  /          \  |"
    print "| |            | |"
    print "|  \          /  |"
    print "|   \________/   |"
    print "|________________|"

Das ist jetzt zwar nicht zu erkennen, sollte aber im Programm richtig funktionieren.
 
Zuletzt bearbeitet von einem Moderator:
Code 2
Galgenraten (Hangman)

Das ist das fertige Script für Galgenraten, man beachte bitte das in dem selben Verzeichnis wie das Script eine .txt Datei mit dem Namen "Text" abgelegt werden muss, mit einer Liste aller zu verwendenen Wörter. Diese Wörter dürfen maximal 3 Mal den selben Buchstaben enthalten, das Programm ersetzt Zeichensetzung automatisch und ä, ü, ö mit ae, ue, oe welche jedoch als einzelne Buchstaben gehandhabt werden.

Code:
# -*- coding: utf-8 -*
#/usr/bin/python

import asciiarts
import time
import os

from random import randint

os.system('color F0')

clear = lambda: os.system('cls')
a = 1
b = 0
c = 1
d = 0
e = 0
i = 1
m = 0
p = 1
q = 0
lifes = 0
lifesmax = 0
victime = 0

wordaray = []
letterpositions = []
wrongletters = []

with open("Text.txt") as text:
    text1 = text.readlines()
text2 = text1[0]
text3 = text2.replace('.', '')
text4 = text3.replace(',', '')
text5 = text4.replace('\x96', '')
text6 = text5.replace('(', '')
text7 = text6.replace(')', '')
text8 = text7.replace('"', '')
text9 = text8.replace('!', '')
text10 = text9.replace('?', '')
text11 = text10.replace('„', '')
text12 = text11.replace('[', '')
text13 = text12.replace(']', '')
text14 = text13.replace('1', '')
text15 = text14.replace('\xe4', 'ae')
text16 = text15.replace('\xfc', 'ue')
text17 = text16.replace('\xf6', 'oe')
text18 = text17.replace('\x84', '')
text19 = text18.replace('\x93', '')
text20 = text19.lower()

text1 = 0
text2 = 0
text3 = 0
text4 = 0
text5 = 0
text6 = 0
text7 = 0
text8 = 0
text9 = 0
text10 = 0
text11 = 0
text12 = 0
text13 = 0
text14 = 0
text15 = 0
text16 = 0
text17 = 0
text18 = 0
text19 = 0

words = text20.split()
#print words
    
count = (len(words)-1)
#print "Count: %s" % (count)
#print "\n"

wordnumber = randint(0, count)
#print  "Wordnumber: %s" % (wordnumber)
#print "\n"

word = words[wordnumber]
#print "Word: %s" % (word)
#print "\n"

spellword = list(word)
viccomp = list(word)
#print spellword

letters = len(spellword)
#print letters

while i <= letters:
    wordaray.append ("_")
    i = i+1

print wordaray
while a == 1:
    lifes = int(input("\nLifes = "))
    lifesmax = lifes
    print lifes
    b = raw_input("\nok?\nYes[y] No[n]\n")
    if b == 'y':
        break
    elif b == 'n':
        print "Restart"
    else:
        print "ERROR"
clear()
print "\n"
print "Wrong letters: %s" %(wrongletters)
print wordaray
        
#print letters*"_ "

while c == 1:
    lifespic = ((lifes - 0) * (9 - 0) / (lifesmax - 0) + 0)
    if lifespic == 8:
        asciiarts.lifespic8()
    if lifespic == 7:
        asciiarts.lifespic7()
    if lifespic == 6:
        asciiarts.lifespic6()
    if lifespic == 5:
        asciiarts.lifespic5()
    if lifespic == 4:
        asciiarts.lifespic4()
    if lifespic == 3:
        asciiarts.lifespic3()
    if lifespic == 2:
        asciiarts.lifespic2()
    if lifespic == 1:
        asciiarts.lifespic1()
    if lifespic == 0:
        asciiarts.lifespic0()
        time.sleep(2)
        clear()
        os.system('color 04')
        print "The correct word was: %s" % (viccomp)
        asciiarts.gameover()
        e = 1
        while e == 1:
            os.system('color 04')
            time.sleep(.2)
            os.system('color 0C')
            time.sleep(.2)

    letter = raw_input("Type your letter: ")
    d = letter in spellword
    #print d
    if d == True:
        clear()
        print "In Word"
        print "Remaining Lifes: %s" %(lifes)

        letterposition = (spellword.index(letter)+1)
        #print letterposition
        wordaray [letterposition-1] = letter
        #print wordaray
        spellword [letterposition-1] = "."
        d = letter in spellword
        if d == True:
            letterposition = (spellword.index(letter)+1)
            #print letterposition
            wordaray [letterposition-1] = letter
            #print wordaray
            spellword [letterposition-1] = "-"
            d = letter in spellword
        print wordaray
        print "Wrong letters: %s" %(wrongletters)
    else:
        clear()
        print "Not in word"
        lifes = lifes-1
        print "Remaining lifes: %s" % (lifes)
        print wordaray
        wrongletters.append(letter)
        print "Wrong letters: %s" %(wrongletters)

    vic = viccomp == wordaray
    if vic == True:
        clear()
        print wordaray
        print "You got the Word. CONGRATULATIONS!"
        victime = 1
        while victime == 1:
            rcolor = randint(0, 9)
            #print rcolor
            time.sleep(.2)
            clear()
            print wordaray
            print "You got the Word. CONGRATULATIONS!"
            print "         _____ "
            print "        |/    | "
            print "        |    "
            print "        |     "
            print "        |     "
            print "        |         (^.^)"
            print "    ____|____      /|\ "
            print "   /         \      | "
            print "__/           \__  / \ "
            os.system('color 0C')
            time.sleep(.2)
            clear()
            print wordaray
            print "You got the Word. CONGRATULATIONS!"
            print "         _____ "
            print "        |/    | "
            print "        |    "
            print "        |     "
            print "        |     "
            print "        |         (^.^)"
            print "    ____|____      \|/ "
            print "   /         \      | "
            print "__/           \__  / \ "
            os.system('color 01')
            time.sleep(.2)
            clear()
            print wordaray
            print "You got the Word. CONGRATULATIONS!"
            print "         _____ "
            print "        |/    | "
            print "        |    "
            print "        |     "
            print "        |     "
            print "        |         (^.^)"
            print "    ____|____      /|\ "
            print "   /         \      | "
            print "__/           \__  / \ "
            os.system('color 02')
            time.sleep(.2)
            clear()
            print wordaray
            print "You got the Word. CONGRATULATIONS!"
            print "         _____ "
            print "        |/    | "
            print "        |    "
            print "        |     "
            print "        |     "
            print "        |         (^.^)"
            print "    ____|____      \|/ "
            print "   /         \      | "
            print "__/           \__  / \ "
            os.system('color 03')
            time.sleep(.2)
            clear()
            print wordaray
            print "You got the Word. CONGRATULATIONS!"
            print "         _____ "
            print "        |/    | "
            print "        |    "
            print "        |     "
            print "        |     "
            print "        |         (^.^)"
            print "    ____|____      /|\ "
            print "   /         \      | "
            print "__/           \__  / \ "
            os.system('color 04')
            time.sleep(.2)
            clear()
            print wordaray
            print "You got the Word. CONGRATULATIONS!"
            print "         _____ "
            print "        |/    | "
            print "        |    "
            print "        |     "
            print "        |     "
            print "        |         (^.^)"
            print "    ____|____      \|/ "
            print "   /         \      | "
            print "__/           \__  / \ "
            os.system('color 05')
            time.sleep(.2)
            clear()
            print wordaray
            print "You got the Word. CONGRATULATIONS!"
            print "         _____ "
            print "        |/    | "
            print "        |    "
            print "        |     "
            print "        |     "
            print "        |         (^.^)"
            print "    ____|____      /|\ "
            print "   /         \      | "
            print "__/           \__  / \ "
            os.system('color 06')
            time.sleep(.2)
            clear()
            print wordaray
            print "You got the Word. CONGRATULATIONS!"
            print "         _____ "
            print "        |/    | "
            print "        |    "
            print "        |     "
            print "        |     "
            print "        |         (^.^)"
            print "    ____|____      \|/ "
            print "   /         \      | "
            print "__/           \__  / \ "
            os.system('color 07')
            time.sleep(.2)
            clear()
            print wordaray
            print "You got the Word. CONGRATULATIONS!"
            print "         _____ "
            print "        |/    | "
            print "        |    "
            print "        |     "
            print "        |     "
            print "        |         (^.^)"
            print "    ____|____      /|\ "
            print "   /         \      | "
            print "__/           \__  / \ "
            os.system('color 08')
            time.sleep(.2)
            clear()
            print wordaray
            print "You got the Word. CONGRATULATIONS!"
            print "         _____ "
            print "        |/    | "
            print "        |    "
            print "        |     "
            print "        |     "
            print "        |         (^.^)"
            print "    ____|____      \|/ "
            print "   /         \      | "
            print "__/           \__  / \ "
            os.system('color 09')
 
Code 3
4 Gewinnt

An diesem Script arbeite ich im Moment hauptsächlich, es ist gleichzeitig das erste wo ich versuche eine GUI hinzubekommen.

Code:
# -*- coding: utf-8 -*
#/usr/bin/python

#---Import Module---#
import asciiarts as a
import time
import os

from random import randint
from Tkinter import *

#---Standartbefehle---#
clear = lambda: os.system('cls')

class modi:
    def __init__(self, master):
        frame = Frame(master)
        frame.pack()
        self.slogan = Button(frame, text="Multiplayer", fg="black", command=self.write_slogan_m)
        self.slogan.pack(side=RIGHT)
        self.slogan = Button(frame, text="Singelplayer", fg="black", command=root.destroy)
        self.slogan.pack(side=LEFT)
    def write_slogan_s(self):
        print "Singleplayer"
    def write_slogan_m(self):
        print "Multiplayer"
        framew()
        

def framew():
    def __init__(self, master):
        frame = Frame(master)
        frame.pack()
        self.slogan = Button(frame, text=a.frame(), fg="black", command=self.framew)
        self.slogan.pack(side=RIGHT)
    

root = Tk()
modi = modi(root)

        
#---Variablen---#
loop1 = 0
loop2 = 0
sws = 0
sw = 0
sp = 1
mp = 2

#---gui initzialisierung---#


#---Spielmoduswahl---#
loop1 = 0
while loop1 == 1:
    clear()
    sw = int(input("Sibgleplayer [1]   Multiplayer [2] \nChoose the mode: "))
    if sw == sp:
        print "Singleplayer"
        print "Not available"
#        loop1 = 0
    elif sw == mp:
        print "Multiplayer"
        loop1 = 0
        loop2 = 1
    else:
        print "Error"
        print "Please try again"

#---Main script Multiplayer---#
root.mainloop()
 

Benutzer, die dieses Thema gerade lesen

ONLINE 14 Spieler