repl.it
@ArjunSS1/

KeyBoard Spammy

Python

No description

fork
loading
Files
  • main.py
main.py
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import curses, time, os,random
#----------------------------
#Work on a method for this to increase difficulty
def timer():
  return random.random()

global hack1,hack2,hack3
hack1,hack2,hack3 = 0,0,0
#--------------------------------------h
def input_char(message):
    try:
        win = curses.initscr()
        win.addstr(0, 0, message)
        while True: 
            ch = win.getch()
            if ch in range(32, 127): break
            time.sleep(0.01)
    except: raise
    finally:
        curses.endwin()
    return chr(ch)
#--------------------------------------
def switch(char):
  keyboard = {
    "q":0,
    "w":0,
    "e":0,
    "r":0,
    "t":1,
    "y":1,
    "u":1,
    "i":2,
    "o":2,
    "p":2,
    "[":2,
    "a":0,
    "s":0,
    "d":0,
    "f":0,
    "g":1,
    "h":1,
    "j":2,
    "k":2,
    "l":2,
    ";":2,
    "z":0,
    "x":0,
    "c":0,
    "v":0,
    "b":1,
    "n":2,
    "m":2,
    ",":2,
    "`":3
  }
  try:
    return keyboard[char]
  except:
    return 4
#----------------------------
def hackerman():
  while True:
    x = switch(input_char(""))
    x=int(str(x).replace("\n",""))
    if(x == 0):
      errormod(1,-1)
    elif(x == 1):
      errormod(2,-1)
    elif(x == 2):
      errormod(3,-1)
    elif(x == 4):
      hackerman()
#----------------------------
def errormod(computer, effect):
  global hack1,hack2,hack3
  if((hack1 == 10) or (hack2 == 10) or (hack3 == 10)):
    print("You lost")
    time.sleep(5)
    Start(0)
  if(type(effect)== type(True)):
    if(computer == 0):
      hack1 = hack1 + 1
    elif(computer == 1):
      hack2 = hack2 + 1
    elif(computer == 2):
      hack3 = hack3+1
    CompScreen(hack1,hack2,hack3)
  run()

#----------------------------

#----------------------------
def CompScreen(hack1,hack2,hack3):
  os.system('clear')
  if(hack1 >= 0):
    result1,hack1,x = hack1,"",0
    while(x<result1):
      hack1 = str(hack1) + "█"
      x = x+1
  if(hack2 >= 0):
    result2,hack2,x = hack2,"",0
    while(x<result2):
      hack2 = str(hack2) + "█"
      x = x+1
  if(hack3 >= 0):
    result3,hack3,x = hack3,"",0
    while(x<result3):
      hack3 = str(hack3) + "█"
      x = x+1
  print(str.format("\
  \n     ____________    ____________    ____________\n\
    | {0:10} |  | {1:10} |  | {2:10} |\n\
    |            |  |            |  |            |\n\
    |            |  |            |  |            |\n\
    |            |  |            |  |            |\n\
    |            |  |            |  |            |\n\
    +------------+  +------------+  +------------+\n\
        /||\\           /||\\            /||\\    \n\
       |__=__|        |__=__|         |__=__|\n",hack1,hack2,hack3))
  hackerman()

#----------------------------
def run():
  time.sleep(0.1)
  randomint = int(random.randint(1,6))
  
  if(randomint == 1):
    errormod(0,True) #aifuiawhia
  elif(randomint == 2):
    errormod(1,True)
  elif(randomint == 3):
    errormod(2,True)
  else:
    run() #beep boop poo
#----------------------------
def rules():
  os.system('clear')
  print("This is a keyboard spammer game \n your keyboard is split up into 3 sections and for the computer\n that is getting hacked you need to spam that part of the keyboard \n\n   Press Enter to return home")
  returnhome = input("")
  Start(0)
#----------------------------
def Start(x):
  os.system('clear')
  global hack1,hack2,hack3
  hack1,hack2,hack3 = 0,0,0
  print("Ready to begin? press enter to start")
  if(x == 0):
    startgame = input("")
  else:
    print("")
  os.system('clear')
  print("\n\n (1) Start Game\n (2) Rules")
  inputval = (input("")).replace(" ","")
  if(inputval == '1'):
    run()
  elif(inputval == '2'): #error spot 2
    rules()
  else:
    Start(1)
  
#----------------------------
Start(0)
?