Hey everyone!
I have (for me) a big problem! I'm trying to repair it for few days and I have just run out of power and ideas what to do with it. My problem is that:
I have a pickled list, that already have some values inside.
Then I want to exchange those values with new ones by function and by adding things out of the function (the last one: it writes down the change when I print it, but... it doesn't save it in a file)
PLS HELP!
I have (for me) a big problem! I'm trying to repair it for few days and I have just run out of power and ideas what to do with it. My problem is that:
I have a pickled list, that already have some values inside.
Then I want to exchange those values with new ones by function and by adding things out of the function (the last one: it writes down the change when I print it, but... it doesn't save it in a file)
PLS HELP!
import pickle import random from tryb_walki import fight from wczytywanie_zapisków import loading from add_points import add_points print('1. Nowa gra') print('2. Wczytaj grę') print('3. Wyjdź z gry') menu_choice = 0 new_game=1 load_game=2 end_game=3 minimum_menu_choice=1 maximum_menu_choice=3 while not (menu_choice >= minimum_menu_choice and menu_choice <= maximum_menu_choice): try: menu_choice = int(input('Wpisz numer zadania które chciałbyś wykonać:')) except: print('Wpisz numere od 1 do 3') if menu_choice == new_game: print(''' #..#.###..####.#####.#####.####.###. #.#..#.#..##...#...#...#...#..#.#.#. ##...###..####.#####...#...#..#.###. #.#..#.#..#....#...#...#...#..#.#.#. #..#.#..#.####.#...#...#...####.#..# .................................... ###.####.####.#####.#####.####.#.... #.#.#..#.#......#...#...#.#....#.... ###.#..#.####...#...#####.#....#.... #...#..#....#...#...#...#.#....#.... #...####.####...#...#...#.####.#....''') min_choice_race=1 max_choice_race=4 save = open('game_save', 'wb') name = input('Wpisz swój nick') choice_race = 0 while not (choice_race >= min_choice_race and choice_race <= max_choice_race): while True: try: choice_race = int(input('''Wpisz jedną z 4 cyferek- każda oznacza inną rasę: 1-Wojownik 2-Łucznik 3-Mag 4-Ninja - Posiada tarcze (10% szans - atakuje z dystancu (3 - Może się leczyć (20% - Jest bardzo zwinny (20% na obronę przed atakiem) pierwsze ciosy w walce szans na przywrócenie na uniknięcie ciosu) są jego) punktów życia z zakresu - pierwszy cios jest 10 co atak) zawsze jego - 150 punktow życia - 80 punktów życia - 50 punktów życia - 120 punktów życia - zadaje obrażenia z zakresu - zadaje obrażenia z zakresu - Zadaje obrażenia z zakresu - Zadaje obrażenia z 8-10 12-15 15-20 zakresu 10-12 ''')) except: print("Wpisz liczbę z zakresu od 1 do 4, potwierdź enterem") break warrior=1 archer=2 wizard=3 if choice_race == warrior: race = [name, 'wojownik', 150, [8, 10], 10, 0, 0, 1]#nazwa,klasa, hp, obrażenia, szansa na unik, szansa na leczenie, leczone punkty, poziom elif choice_race == archer: race = [name, 'łucznik', 80, [12, 15], 0, 0, 0, 1] elif choice_race == wizard: race = [name, 'mag', 50, [15, 20], 0, 20, 10, 1] else: race = [name, 'ninja', 120, [10, 12], 20, 0, 0, 1] pickle.dump(race, save) save.close() save= open ('game_save', 'rb') all_saves = pickle.load(save) input('Wciśnij enter, jeżeli jesteś gotowy na pierwszą misję') elif menu_choice == load_game: save = open('game_save', 'rb') all_saves = pickle.load(save) print (loading(all_saves)) input('enter') if all_saves [7] == 1 : input ('Witaj na pierwszej misji, aby przejść dalej wciśnij (enter)') input('Pracujesz w służbie u króla, a ta misja ma za zadanie przeszkolić Cię do prawdziwej walki, (enter)') input ('Pierwsze wyzwanie: (enter)') input('Pokonaj trenera(enter)') trener=['Trener', 'wojownik', 20, [2,5],30, 0, 0] print(fight(all_saves, trener)) save.close() if trener[2]<=0: save = open('game_save', 'r+b') all_saves = pickle.load (save) all_saves[7]+=1 input('Okej- szkolenie zakończone') print('Otrzymujesz 5 punktów do rozdania do swoich umiejętności. Co chciałbyś ulepszyć?') print(add_points(5, all_saves)) print(all_saves) save.close() #add_points def add_points(amount_points,character): print('Otrzymujesz', amount_points ,'punktów do rozdania do swoich umiejętności. Co chciałbyś ulepszyć?') minimum_number=1 maximum_number=5 number=0 any_points=0 hp = int (character[2]) minimal_hit = int (character[3][0]) maximal_hit = int (character[3][1]) miss_chance = int (character[4]) heal_chance =int (character[5]) amount_heal = int (character[6]) while amount_points>any_points: print('masz', amount_points, 'punktów') print('Jak narazie twoje umiejętności wynoszą: ') print('1. Punkty życia:', hp) print('2. Zadawane obrażenia:', minimal_hit, '-', maximal_hit) print('3. Szansa na unik:', miss_chance) print('4. Szansa na uleczenie:', heal_chance) print('5. Leczone punkty życia:', amount_heal) while not (number>=minimum_number and number<=maximum_number): while True : try: number=int(input('Wybierz numer rzeczy którą chciałbyś wzmocnić:')) print(character [number+1]) break except IndexError: print ('wpisałeś złą liczbę') except ValueError: print('wpisz coś', 'albo przestań wpisywać tekst') except: print("znowu coś jest nie tak") while True: try: how_many=int(input('O ile?')) break except IndexError: print ('Wpisałeś złą liczbę') except ValueError: print('Wpisz coś', 'albo przestań wpisywać tekst') except: print("znowu coś jest nie tak") number_of_ability=number+1 if how_many<=amount_points: amount_points-=how_many if number_of_ability==2: hp+=how_many elif number_of_ability==3: minimal_hit+=how_many maximal_hit+=how_many elif number_of_ability==4: miss_chance+=how_many elif number_of_ability==5: heal_chance+=how_many elif number_of_ability==6: amount_heal+=how_many else: print ('masz za mało punktów') print ('nie masz już więcej punktów') print ('twoje umiejętności, to:') print('Punkty życia:', hp) print('Zadawane obrażenia:', minimal_hit, '-', maximal_hit) print('Szansa na unik:', miss_chance) print('Szansa na leczenie:', heal_chance) print('Leczone punkty życia:', amount_heal)