L3viathan2142 Posted November 25, 2009 Posted November 25, 2009 (edited) Hi, I'm new here, but for more than a year member in peethebee's german autoit forum. This is text-only counterstrike. You just have a console-like interface, and four availible commands: go, jump, turn, shoot. No AI yet, opponent doesn't move and stands on field 9:9. Sample in&output: expandcollapse popupWelcome to Text-only Counterstrike >jump east Jumping two field east... I'm now at 2:0 >jump east Jumping two field east... I'm now at 4:0 >jump east Jumping two field east... I'm now at 6:0 >jump east Jumping two field east... I'm now at 8:0 >go east Going one field east... I'm now at 9:0 >shoot You hit the player and caused 11 damage. (89 remaining) >jump south Jumping two field south... I'm now at 9:2 >shoot You hit the player and caused 13 damage. (76 remaining) >jump south Jumping two field south... I'm now at 9:4 >shoot You hit the player and caused 15 damage. (61 remaining) >jump south Jumping two field south... I'm now at 9:6 >shoot You hit the player and caused 17 damage. (44 remaining) >jump south Jumping two field south... I'm now at 9:8 An opponent stands in front of you. >shoot You hit the player and caused 19 damage. (25 remaining) >shoot You hit the player and caused 19 damage. (6 remaining) >shoot Player killed. You won. expandcollapse popup#include <Array.au3> #include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <ScrollBarConstants.au3> #Region VAR Global $IAmNr=0 Dim $players[2][4]=[[0,0,"s",100],[9,9,"n",100]];x,y,blick(nswo),leben, Dim $board[10][10];[x][Y]; werte: ""=nix,"M"=Mauer","1/2"=player _clearBoard() #EndRegion VAR #Region GUI $Form1 = GUICreate("txtCS", 635, 448, 192, 119) $Input = GUICtrlCreateInput("", 0, 424, 633, 21) $Output = GUICtrlCreateEdit("Willkommen bei Text-only Counterstrike" & @CRLF, 0, 0, 633, 425) $Enter = GUICtrlCreateDummy() GUICtrlSetData(-1, "Edit1") GUISetState(@SW_SHOW) Dim $accelerators[1][2]=[["{ENTER}",$Enter]] GUISetAccelerators($accelerators) #EndRegion GUI ;besetze Felder: _setHumansToBoard() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Enter _input(GUICtrlRead($Input)) GUICtrlSetData($Input,"") EndSwitch WEnd Func _output($what) _GUICtrlEdit_AppendText($Output,$what & @CRLF) _GUICtrlEdit_Scroll($Output,$SB_LINEDOWN) EndFunc Func _input($what) ;~ commands: go, shoot, turn, jump, cheat If _beginsWith($what,"go ") Then _tryGo(StringTrimLeft($what,3)) ElseIf _beginsWith($what,"shoot") Then _tryShoot(StringTrimLeft($what,5)) ElseIf _beginsWith($what,"turn ") Then _tryTurn(StringTrimLeft($what,5)) ElseIf _beginsWith($what,"jump ") Then _tryJump(StringTrimLeft($what,5)) ElseIf _beginsWith($what,"cheat") Then $players[$IAmNr][0]=InputBox("X-Position","") $players[$IAmNr][1]=InputBox("Y-Position","") _clearBoard() _setHumansToBoard() Else _output("Befehl falsch geschrieben oder nicht vorhanden.") EndIf EndFunc Func _beginsWith($hay,$needle) If StringInStr($hay,$needle) = 1 Then return True return False EndFunc Func _tryGo($where) $xpos=$players[$IAmNr][0] $ypos=$players[$IAmNr][1] Switch $where Case "north" If $ypos=0 Then return _output("Kann nicht nach Norden gehen, Kartenrand erreicht.") If $board[$xpos][$ypos-1]<>"" Then return _output("Kann nicht nach Norden gehen, Mensch steht gegenüber.") $board[$xpos][$ypos-1]="M" $board[$xpos][$ypos]="" $players[$IAmNr][1]=$ypos-1 _output("Gehe ein Feld nach Norden...") _output("Bin jetzt auf " & $players[$IAmNr][0] & ":" & $players[$IAmNr][1]) Case "south" If $ypos=9 Then return _output("Kann nicht nach Süden gehen, Kartenrand erreicht.") If $board[$xpos][$ypos+1]<>"" Then return _output("Kann nicht nach Süden gehen, Mensch steht gegenüber.") $board[$xpos][$ypos+1]="M" $board[$xpos][$ypos]="" $players[$IAmNr][1]=$ypos+1 _output("Gehe ein Feld nach Süden...") _output("Bin jetzt auf " & $players[$IAmNr][0] & ":" & $players[$IAmNr][1]) Case "east" If $xpos=9 Then return _output("Kann nicht nach Osten gehen, Kartenrand erreicht.") If $board[$xpos+1][$ypos]<>"" Then return _output("Kann nicht nach Osten gehen, Mensch steht gegenüber.") $board[$xpos+1][$ypos]="M" $board[$xpos][$ypos]="" $players[$IAmNr][0]=$xpos+1 _output("Gehe ein Feld nach Osten...") _output("Bin jetzt auf " & $players[$IAmNr][0] & ":" & $players[$IAmNr][1]) Case "west" If $xpos=0 Then return _output("Kann nicht nach Westen gehen, Kartenrand erreicht.") If $board[$xpos-1][$ypos]<>"" Then return _output("Kann nicht nach Westen gehen, Mensch steht gegenüber.") $board[$xpos-1][$ypos]="M" $board[$xpos][$ypos]="" $players[$IAmNr][0]=$xpos-1 _output("Gehe ein Feld nach Westen...") _output("Bin jetzt auf " & $players[$IAmNr][0] & ":" & $players[$IAmNr][1]) Case Else _output("falsche Eingabe. go [north|south|east|west]") EndSwitch _look() EndFunc Func _tryJump($where) $xpos=$players[$IAmNr][0] $ypos=$players[$IAmNr][1] Switch $where Case "north" If $ypos<=1 Then return _output("Kann nicht nach Norden springen, Kartenrand erreicht.") If $board[$xpos][$ypos-2]<>"" Then return _output("Kann nicht nach Norden springen, Mensch steht auf dem Zielfeld") $board[$xpos][$ypos-2]="M" $board[$xpos][$ypos]="" $players[$IAmNr][1]=$ypos-2 _output("Springe zwei Felder nach Norden...") _output("Bin jetzt auf " & $players[$IAmNr][0] & ":" & $players[$IAmNr][1]) Case "south" If $ypos>=8 Then return _output("Kann nicht nach Süden springen, Kartenrand erreicht.") If $board[$xpos][$ypos+2]<>"" Then return _output("Kann nicht nach Süden springen, Mensch steht gegenüber.") $board[$xpos][$ypos+2]="M" $board[$xpos][$ypos]="" $players[$IAmNr][1]=$ypos+2 _output("Springe zwei Felder nach Süden...") _output("Bin jetzt auf " & $players[$IAmNr][0] & ":" & $players[$IAmNr][1]) Case "east" If $xpos>=8 Then return _output("Kann nicht nach Osten springen, Kartenrand erreicht.") If $board[$xpos+2][$ypos]<>"" Then return _output("Kann nicht nach Osten springen, Mensch steht gegenüber.") $board[$xpos+2][$ypos]="M" $board[$xpos][$ypos]="" $players[$IAmNr][0]=$xpos+2 _output("Springe zwei Felder nach Osten...") _output("Bin jetzt auf " & $players[$IAmNr][0] & ":" & $players[$IAmNr][1]) Case "west" If $xpos<=1 Then return _output("Kann nicht nach Westen springen, Kartenrand erreicht.") If $board[$xpos-2][$ypos]<>"" Then return _output("Kann nicht nach Westen springen, Mensch steht gegenüber.") $board[$xpos-2][$ypos]="M" $board[$xpos][$ypos]="" $players[$IAmNr][0]=$xpos-2 _output("Springe zwei Felder nach Westen...") _output("Bin jetzt auf " & $players[$IAmNr][0] & ":" & $players[$IAmNr][1]) Case Else _output("falsche Eingabe. go [north|south|east|west]") EndSwitch _look() EndFunc Func _tryShoot($where) $dir=$players[$IAmNr][2] $xpos=$players[$IAmNr][0] $ypos=$players[$IAmNr][1] Switch $dir Case "n" For $i=0 To UBound($players,1)-1 If $i=$IAmNr Then ContinueLoop If $players[$i][0]=$xpos And $players[$i][1] < $ypos Then $damage=20- ($ypos - $players[$i][1]); 20 could be the weapon $players[$i][3] -= $damage If $players[$i][3] > 0 Then _output("Spieler getroffen und ihm " & $damage & " Schadenspunkte zugefügt. (Noch " & $players[$i][3] & " Lebenspunkte)") Else _output("Spieler getötet. Spiel gewonnen.") _Win() EndIf EndIf Next Case "s" For $i=0 To UBound($players,1)-1 If $i=$IAmNr Then ContinueLoop If $players[$i][0]=$xpos And $players[$i][1] > $ypos Then $damage=20- ($players[$i][1] - $ypos) $players[$i][3] -= $damage If $players[$i][3] > 0 Then _output("Spieler getroffen und ihm " & $damage & " Schadenspunkte zugefügt. (Noch " & $players[$i][3] & " Lebenspunkte)") Else _output("Spieler getötet. Spiel gewonnen.") _Win() EndIf EndIf Next Case "w" For $i=0 To UBound($players,1)-1 If $i=$IAmNr Then ContinueLoop If $players[$i][1]=$ypos And $players[$i][0] < $ypos Then $damage=20- ($xpos - $players[$i][0]) $players[$i][3] -= $damage If $players[$i][3] > 0 Then _output("Spieler getroffen und ihm " & $damage & " Schadenspunkte zugefügt. (Noch " & $players[$i][3] & " Lebenspunkte)") Else _output("Spieler getötet. Spiel gewonnen.") _Win() EndIf EndIf Next Case "e" For $i=0 To UBound($players,1)-1 If $i=$IAmNr Then ContinueLoop If $players[$i][1]=$ypos And $players[$i][0] > $ypos Then $damage=20- ($players[$i][0] - $ypos) $players[$i][3] -= $damage If $players[$i][3] > 0 Then _output("Spieler getroffen und ihm " & $damage & " Schadenspunkte zugefügt. (Noch " & $players[$i][3] & " Lebenspunkte)") Else _output("Spieler getötet. Spiel gewonnen.") _Win() EndIf EndIf Next EndSwitch EndFunc Func _tryTurn($where) local $dir="" Switch $where Case "north" $dir="n" Case "south" $dir="s" Case "east" $dir="e" Case "west" $dir="w" Case Else Return _output("Keine gültige Himmelsrichtung. turn [norht|south|east|west]") EndSwitch $players[$IAmNr][2]=$dir _look() EndFunc Func _setHumansToBoard() For $i=0 To UBound($players,1)-1 $board[$players[$i][0]][$players[$i][1]]="M" Next EndFunc Func _look() $dir=$players[$IAmNr][2] $xpos=$players[$IAmNr][0] $ypos=$players[$IAmNr][1] Switch $dir Case "n" If $ypos = 0 Then Return If $board[$xpos][$ypos-1]<>"M" Then return case "s" If $ypos = 9 Then Return If $board[$xpos][$ypos+1]<>"M" Then return Case "e" If $xpos = 9 Then Return If $board[$xpos+1][$ypos]<>"M" Then return Case "w" If $xpos = 0 Then Return If $board[$xpos-1][$ypos]<>"M" Then return EndSwitch _output("Ein Mensch steht dir gegenüber.") EndFunc Func _Win() MsgBox(64,"Super","Du hast gewonnen") EndFunc Func _clearBoard() For $i=0 To 9 For $j=0 To 9 $board[$i][$j]="" Next Next EndFunc edit: It seams to be not working in this english version. I think I have damaged the code while search-replacing him from german to english... edit2: Now the german version. Will upload a translated version soon... Edited November 25, 2009 by L3viathan2142
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now