Post

Game Project

My First Game Project

Hello everyone, I’m Aristo from Ciputra Makassar University. In this side I will show you my littel project that I made by my self. To make this littel project I’m use Python as my programer language. This project it’s a game that can play by two player. The objective of this game is to guess the other player word. If the player can guess the word, they will got a score to win the game and defeat the other player. Next I will show all of you the rest of the coding that I made.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import os
import time

class Permainan:
    def __init__(self):
        self.petunjuk1 = []
        self.score1 = 0
        self.petunjuk2 = []
        self.score2 = 0

    def bantuan(self, petunjuk_list):
        petunjuk = input("Pemberi kata masukkan petunjuk dari kata yang ingin ditebak: ")
        petunjuk_list.append(petunjuk)
        time.sleep(0.5)
        os.system('cls')
        for A in petunjuk_list:
            print(f"Petunjuk saat ini: {A}")
        return -5  

    def berhasil(self, kata, score, petunjuk_list):
        print(f"Berhasil menebak kata {kata}!")
        petunjuk_list.clear()
        return score + 20

    def menyerah(self, kata, score, petunjuk_list):
        print(f"Tidak berhasil menebak kata. Kata yang benar adalah '{kata}'")
        petunjuk_list.clear()
        return score - 20

game = Permainan()
os.system('cls')

jumlah_ronde = int(input("Masukkan jumlah ronde yang ingin dimainkan: "))
os.system('cls')

for ronde in range(1, jumlah_ronde + 1):
    print(f"--- Ronde {ronde} ---")
    time.sleep(1)

    kata1 = input("Pemain 1, masukkan kata yang ingin ditebak: ").lower()
    time.sleep(1)
    os.system('cls')
    kesempatan = 3

    while kesempatan > 0:
        tebak1 = input("Pemain 2, masukkan tebakan kata: ").lower()
        time.sleep(1)

        if tebak1 == kata1:
            game.score2 = game.berhasil(kata1, game.score2, game.petunjuk1)
            time.sleep(2)
            os.system('cls')
            break

        else:
            kesempatan -= 1
            print(f"Tebakan salah! Kesempatan tersisa: {kesempatan}")
            print("\n")

            if kesempatan > 0:
                print("Pilih opsi:")
                print("1. Minta Bantuan")
                print("2. Menebak Lagi")
                print("3. Menyerah")

                pilihan = input("Masukkan pilihan (1-3): ")
                time.sleep(1)
                os.system('cls')

                if pilihan == "1":
                    game.score2 += game.bantuan(game.petunjuk1)  
                elif pilihan == "3":
                    game.score2 = game.menyerah(kata1, game.score2, game.petunjuk1)
                    break

    kata2 = input("Pemain 2, masukkan kata yang ingin ditebak: ").lower()
    time.sleep(1)
    os.system('cls')
    kesempatan = 3

    while kesempatan > 0:
        tebak2 = input("Pemain 1, masukkan tebakan kata: ").lower()
        time.sleep(1)

        if tebak2 == kata2:
            game.score1 = game.berhasil(kata2, game.score1, game.petunjuk2)
            time.sleep(2)
            os.system('cls')
            break
        else:
            kesempatan -= 1
            print(f"Tebakan salah! Kesempatan tersisa: {kesempatan}")
            print("\n")
            if kesempatan > 0:
                print("Pilih opsi:")
                print("1. Minta Bantuan")
                print("2. Menebak Lagi")
                print("3. Menyerah")

                pilihan = input("Masukkan pilihan (1-3): ")
                time.sleep(1)
                os.system('cls')

                if pilihan == "1":
                    game.score1 += game.bantuan(game.petunjuk2) 
                elif pilihan == "3":
                    game.score1 = game.menyerah(kata2, game.score1, game.petunjuk2)
                    break

os.system('cls')
print("--- Skor Akhir ---")
print(f"Skor Pemain 1: {game.score1}")
print(f"Skor Pemain 2: {game.score2}")
print("\n")

if game.score1 > game.score2:
    print("Pemain 1 menang!")
elif game.score2 > game.score1:
    print("Pemain 2 menang!")
else:
    print("Permainan berakhir seri!")
This post is licensed under CC BY 4.0 by the author.